gpt-json

Structured and typehinted GPT responses in Python

MIT License

Stars
736
gpt-json - v0.5.1 Latest Release

Published by piercefreeman 3 months ago

What's Changed

New Contributors

Full Changelog: https://github.com/piercefreeman/gpt-json/compare/v0.5.0...v0.5.1

gpt-json - v0.5.1

Published by piercefreeman 3 months ago

What's Changed

New Contributors

Full Changelog: https://github.com/piercefreeman/gpt-json/compare/v0.5.0...v0.5.1

gpt-json - v0.5.0

Published by piercefreeman 7 months ago

What's Changed

GPT Vision

This release adds support for GPT Vision models by switching to the new content array syntax for prompting the GPT API. This allows messages to have an arbitrary amount of content specified, versus just the single string that was true in older API versions. If you provide a raw string to the GPTMessage constructor, we will handle this conversion internally. This makes the changes reverse compatible with older gpt-json versions.

You can use with the same syntax as sending a standard text message:

response = await gpt_json.run(
        messages=[
            GPTMessage(role=GPTMessageRole.SYSTEM, content=SYSTEM_PROMPT.strip()),
            GPTMessage(
                role=GPTMessageRole.USER,
                content=[
                    TextContent(text="Message text"),
                    ImageContent.from_url(my_image_url)
                ],
            ),
        ],
        format_variables=dict(post_content=post_text),
        max_response_tokens=500,
    )

New Included Models

We upgrade our supported GPTModelVersion to mirror the currently available list of models within the API.

class GPTModelVersion(Enum):
    GPT_3_5_0613
    GPT_3_5_1106
    GPT_3_5_0125

    GPT_4_0613
    GPT_4_32K_0613
    GPT_4_VISION_PREVIEW_1106
gpt-json - v0.4.2

Published by piercefreeman 7 months ago

What's Changed

Full Changelog: https://github.com/piercefreeman/gpt-json/compare/v0.4.1...v0.4.2

gpt-json - v0.4.2

Published by piercefreeman 7 months ago

What's Changed

Full Changelog: https://github.com/piercefreeman/gpt-json/compare/v0.4.1...v0.4.2

gpt-json - Release 0.4.1

Published by piercefreeman 12 months ago

gpt-json - Release 0.4.0

Published by piercefreeman about 1 year ago

🎉 Support for function calling syntax, typehinted with Pydantic

gpt-3.5-turbo-0613 and gpt-4-0613 were fine-tuned to support a specific syntax for function calls. This release adds support for these function calls, alongside typehinted support for their input arguments.

This PR is slightly backwards incompatible with 0.3.0. Instead of expanding the tuple list that is returned by gpt_json.run(), we migrate to a RunResponse object. This object will return the JSON object, fix transformations, and now the functions that were parsed from the response payload. If there was a failure in parsing, all the fields will be None. This saves users from having to independently parse the different response types.

Migrations should be straightforward.

# old syntax
response, _ = await gpt_json.run(...)
print(response)

# new syntax
payload = await gpt_json.run(...)
print(payload.response)

We also now require Pydantic V2. If you want to continue to use Pydantic V1, lock your version to the 0.3.x minor version.

gpt-json - Release 0.3.0

Published by piercefreeman about 1 year ago

Support Pydantic V2 alongside Pydantic V1.

gpt-json - Release 0.2.0

Published by piercefreeman over 1 year ago

Introduce a new model that allows clients to request multiple instances of their base schema back as the output of GPT. This replaces the old way of typehinting this behavior, via a list[] type alias.

from gpt_json.gpt import GPTJSON, ListResponse
gpt_json_multiple = GPTJSON[ListResponse[SentimentSchema]](API_KEY)
gpt-json - Release 0.1.12

Published by piercefreeman over 1 year ago

gpt-json - Release 0.1.11

Published by piercefreeman over 1 year ago

gpt-json has been type stable since https://github.com/piercefreeman/gpt-json/pull/17, but we haven't published a py.typed to indicate to downstream mypy installs that the types are available. This release adds this file so client typecheckers can validate the passed values to GPTJSON.

gpt-json - Release 0.1.10

Published by piercefreeman over 1 year ago

Transitions the GPTJSON(timeout=X) parameter to act as most clients intend, namely serving as an upper bound for each request when it's sent to the server. To maintain backwards compatibility, however, we now default the timeout parameter to None which won't enforce a timeout on the server requests.

gpt-json - Release 0.1.9

Published by piercefreeman over 1 year ago

gpt-json - Release 0.1.8

Published by piercefreeman over 1 year ago

gpt-json - Release 0.1.7

Published by piercefreeman over 1 year ago

Change logger name to a more interpretable gptjson_logger

gpt-json - Release 0.1.6

Published by piercefreeman over 1 year ago

gpt-json - Release 0.1.5

Published by piercefreeman over 1 year ago

Allow serialization of enums for json encoding (like client might use to caching requests on disk or in a database).

gpt-json - Release 0.1.4

Published by piercefreeman over 1 year ago

gpt-json - Release 0.1.3

Published by piercefreeman over 1 year ago

gpt-json - Release 0.1.2

Published by piercefreeman over 1 year ago

Add support for variables to be injected into the prompts.