Skip to content

feat(openai): support object-type FunctionCallBehavior for forcing a …#1511

Draft
ljluestc wants to merge 1 commit into
tmc:mainfrom
ljluestc:private/issue-254-function-call-behavior-object
Draft

feat(openai): support object-type FunctionCallBehavior for forcing a …#1511
ljluestc wants to merge 1 commit into
tmc:mainfrom
ljluestc:private/issue-254-function-call-behavior-object

Conversation

@ljluestc

Copy link
Copy Markdown

…specific function

The OpenAI API allows function_call to be either a string ("none", "auto") or an object ({"name": "my_function"}) to force the model to call a particular function. Previously, FunctionCallBehavior was typed as a string and could not represent the object form.

Changes:

  • Change ChatRequest.FunctionCallBehavior from FunctionCallBehavior (string) to any in openaiclient, enabling both string and object forms
  • Change CallOptions.FunctionCallBehavior from FunctionCallBehavior to any in the llms package for the same reason
  • Add FunctionCallBehaviorFunctionObject struct with Name field
  • Add WithFunctionCallBehaviorFunction(name string) CallOption that sets function_call to {"name": ""} in the OpenAI request
  • Remove now-unnecessary type cast in openaillm.go
  • Add unit tests for the new option and JSON serialization of all forms

Existing string-valued behavior ("none", "auto", unset) is unchanged. The deprecated function_call field is superseded by tool_choice in the modern OpenAI API; users should prefer WithToolChoice for new code.

Closes #254

PR Checklist

  • Read the Contributing documentation.
  • Read the Code of conduct documentation.
  • Name your Pull Request title clearly, concisely, and prefixed with the name of the primarily affected package you changed according to Good commit messages (such as memory: add interfaces for X, Y or util: add whizzbang helpers).
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. Fixes #123).
  • Describes the source of new concepts.
  • References existing implementations as appropriate.
  • Contains test coverage for new functions.
  • Passes all golangci-lint checks.

…specific function

The OpenAI API allows function_call to be either a string ("none",
"auto") or an object ({"name": "my_function"}) to force the model
to call a particular function. Previously, FunctionCallBehavior was
typed as a string and could not represent the object form.

Changes:
- Change ChatRequest.FunctionCallBehavior from FunctionCallBehavior (string)
  to any in openaiclient, enabling both string and object forms
- Change CallOptions.FunctionCallBehavior from FunctionCallBehavior to any
  in the llms package for the same reason
- Add FunctionCallBehaviorFunctionObject struct with Name field
- Add WithFunctionCallBehaviorFunction(name string) CallOption that sets
  function_call to {"name": "<name>"} in the OpenAI request
- Remove now-unnecessary type cast in openaillm.go
- Add unit tests for the new option and JSON serialization of all forms

Existing string-valued behavior ("none", "auto", unset) is unchanged.
The deprecated function_call field is superseded by tool_choice in the
modern OpenAI API; users should prefer WithToolChoice for new code.

Closes tmc#254
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.

[Feature Request] support object type of FunctionCallBehavior

1 participant