4.0.0 - Function Calling
Function Calling
In case you haven't been following the OpenAI news lately, about a week ago, they announced that their GPT models now support function calling. This allows developers to specify function signatures of their code to the assistant and let the assistant decide which function to call and with what parameters. Devs can then use this result to call their function, provide the function result back to the assistant, and get a natural language answer all based on the function result.
This release adds support to this feature so you can try it out right now in the new 4.0.0 major version. Note that at the time of writing this, Function Calling is only available on the gpt-3.5-turbo-0613
model and equivalent for GPT-4, but they're planned to release on the stable channel very soon!
You can see an example in the lib's README. All other packages have been updated to mitigate breaking changes, but none of them currently make use of the feature. This will probably come eventually in some form for the Web implementation, as it is the most popular implementation and most flexible to these kinds of features. Stay tuned!
Pricing changes
Along with this new feature, OpenAI has also lowered input costs by 25%. This has been updated in the lib's pricing table for GPT-3.5.
Breaking Changes
This is a major version as it introduces breaking changes that could affect existing applications as it did for most implementations.
Message.content
can now bestring | null
instead of juststring
. This is because function calls by the assistant will have a null content. Previously, the library did its best to always send you a string (empty or throw an error). Now, it actually needs to work with null contents.Message.role
can now also befunction
. Previously, onlyassistant
,user
andsystem
were possible.
These two changes are the most relevant with existing APIs. Here are some new APIs:
- There's a new
Conversation.functionPrompt
method to send your function results to the assistant. - There are 3 new methods (and exported types) on
Message
to help you, with type guards, to differentiate between standard completions, function calls and function messages:isCompletion
(CompletionMessage),isFunctionCall
(FunctionCallMessage) andisFunction
(FunctionMessage). Use these methods instead of doing null checks for a more robust check and automatic type inference.