Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Functions #25

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

rhettg
Copy link

@rhettg rhettg commented Aug 17, 2023

As described in https://platform.openai.com/docs/guides/gpt/function-calling some models have been fine tuned to call functions based on their JSON representations.

This hasn't had a lot of use yet, I'm still playing with it. But it seems mostly right at least.

The only tricky part is serializing the JSON schema. I can't say I'm very happy with how this looks but it does work. Open to suggestions.

rhettg added 2 commits August 17, 2023 22:06
As described in
https://platform.openai.com/docs/guides/gpt/function-calling some models
have been fine tuned to call functions based on their JSON
representations.
To indicate an empty parameter, the properties must be emitted as `{}`.
But we also need a nil properties field to not be emitted at all. This
is not handled by `omitempty` because it treats nil and empty as the
same.
@rhettg rhettg changed the title Rhettg functions Add support for Functions Aug 17, 2023
rhettg added a commit to rhettg/openai-go that referenced this pull request Aug 21, 2023
These fields are required. Content is allowed to be empty. This behavior
can be observed by trying to include a FunctionCall Message (see also rakyll#25)
which has no Content. The API will reject it.

The OpenAPI specification for this type
(https://github.com/openai/openai-openapi/blob/e6277eabbbb5df1e90620e3657bb02da28dce460/openapi.yaml#L2195-L2197)
shows the following:

```yaml
    ChatCompletionRequestMessage:
      properties:
        ...

        content:
          type: string
          nullable: true
          description: The contents of the message. `content` is required for all messages, and may be null for assistant messages with function calls.

      ...
      required:
        - role
        - content
```

I've confirmed experimentally it accepts empty strings as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant