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

feat (@ai-sdk/openai): add parallelToolCalls setting #1937

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pretty-jeans-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ai-sdk/openai': patch
---

feat (@ai-sdk/openai): add parallelToolCalls setting
4 changes: 4 additions & 0 deletions content/providers/01-ai-sdk-providers/01-openai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ The following optional settings are available for OpenAI chat models:
Setting to a number will return the log probabilities of the top n
tokens that were generated.

- **parallelToolCalls** _boolean_

Whether to enable parallel function calling during tool use. Default to true.

- **user** _string_

A unique identifier representing your end-user, which can help OpenAI to
Expand Down
4 changes: 4 additions & 0 deletions content/providers/01-ai-sdk-providers/02-azure.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ The following optional settings are available for OpenAI chat models:
Setting to a number will return the log probabilities of the top n
tokens that were generated.

- **parallelToolCalls** _boolean_

Whether to enable parallel function calling during tool use. Default to true.

- **user** _string_

A unique identifier representing your end-user, which can help OpenAI to
Expand Down
29 changes: 28 additions & 1 deletion packages/openai/src/openai-chat-language-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('doGenerate', () => {
| null;
} | null;
finish_reason?: string;
}) {
} = {}) {
server.responseBodyJson = {
id: 'chatcmpl-95ZTZkhr0mHNKqerQfiwkuox3PHAd',
object: 'chat.completion',
Expand Down Expand Up @@ -283,6 +283,33 @@ describe('doGenerate', () => {
});
});

it('should pass settings', async () => {
prepareJsonResponse();

await provider
.chat('gpt-3.5-turbo', {
logitBias: { 50256: -100 },
logprobs: 2,
parallelToolCalls: false,
user: 'test-user-id',
})
.doGenerate({
inputFormat: 'prompt',
mode: { type: 'regular' },
prompt: TEST_PROMPT,
});

expect(await server.getRequestBodyJson()).toStrictEqual({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: 'Hello' }],
logprobs: true,
top_logprobs: 2,
logit_bias: { 50256: -100 },
parallel_tool_calls: false,
user: 'test-user-id',
});
});

it('should pass tools and toolChoice', async () => {
prepareJsonResponse({ content: '' });

Expand Down
1 change: 1 addition & 0 deletions packages/openai/src/openai-chat-language-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class OpenAIChatLanguageModel implements LanguageModelV1 {
: undefined
: undefined,
user: this.settings.user,
parallel_tool_calls: this.settings.parallelToolCalls,

// standardized settings:
max_tokens: maxTokens,
Expand Down
5 changes: 5 additions & 0 deletions packages/openai/src/openai-chat-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ tokens that were generated.
*/
logprobs?: boolean | number;

/**
Whether to enable parallel function calling during tool use. Default to true.
*/
parallelToolCalls?: boolean;

/**
A unique identifier representing your end-user, which can help OpenAI to
monitor and detect abuse. Learn more.
Expand Down
Loading