Skip to content

Commit b3d2950

Browse files
authored
feat(func): support for function calling in OpenAI API (#149)
- Add support for function calling in OpenAI API - Add support for parallel function calls in certain models - Allow function calling in the following models: gpt-4, gpt-4-turbo-preview, gpt-4-0125-preview, gpt-4-1106-preview, gpt-4-0613, gpt-3.5-turbo, gpt-3.5-turbo-0125, gpt-3.5-turbo-1106 - Add a check for the model version to allow function calling - Change the client struct to include a new field for the model version - Update the `allowFuncCall` function to check the model version and return true if the model supports function calling Signed-off-by: appleboy <appleboy.tw@gmail.com>
1 parent 296d527 commit b3d2950

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

openai/openai.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,28 @@ func New(opts ...Option) (*Client, error) {
296296

297297
// allowFuncCall returns true if the model supports function calls.
298298
// https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/function-calling
299-
// Function calling is available in the 2023-07-01-preview API version and works with version 0613 of
300-
// gpt-35-turbo, gpt-35-turbo-16k, gpt-4, and gpt-4-32k.
299+
// https://platform.openai.com/docs/guides/function-calling/supported-models
300+
// Not all model versions are trained with function calling data.
301+
// Function calling is supported with the following models:
302+
// gpt-4, gpt-4-turbo-preview, gpt-4-0125-preview, gpt-4-1106-preview, gpt-4-0613,
303+
// gpt-3.5-turbo, gpt-3.5-turbo-0125, gpt-3.5-turbo-1106, and gpt-3.5-turbo-0613
304+
// In addition, parallel function calls is supported on the following models:
305+
// gpt-4-turbo-preview, gpt-4-0125-preview, gpt-4-1106-preview,
306+
// gpt-3.5-turbo-0125, and gpt-3.5-turbo-1106
301307
func (c *Client) allowFuncCall(cfg *config) bool {
302308
if cfg.provider == AZURE && cfg.apiVersion == "2023-07-01-preview" {
303309
return true
304310
}
305311

306312
switch c.model {
307-
case openai.GPT432K0613, openai.GPT40613,
308-
openai.GPT3Dot5Turbo0613, openai.GPT3Dot5Turbo16K0613:
313+
case openai.GPT4TurboPreview,
314+
openai.GPT4Turbo0125,
315+
openai.GPT4Turbo1106,
316+
openai.GPT40613,
317+
openai.GPT3Dot5Turbo,
318+
openai.GPT3Dot5Turbo0125,
319+
openai.GPT3Dot5Turbo0613,
320+
openai.GPT3Dot5Turbo1106:
309321
return true
310322
default:
311323
return false

0 commit comments

Comments
 (0)