这是indexloc提供的服务,不要输入任何密码
Skip to content

Support parallel tool calls #39

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

Merged
merged 2 commits into from
Jun 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ public class CreateThreadAndRunRequest {
@JsonProperty("tool_choice")
ToolChoice toolChoice;

/**
* Whether to enable parallel function calling during tool use.
*/
@JsonProperty("parallel_tool_calls")
Boolean parallelToolCalls;


/**
* Specifies the format that the model must output. Compatible with GPT-4 Turbo and all GPT-3.5 Turbo models since gpt-3.5-turbo-1106.
* Setting to { "type": "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,12 @@ public class ChatCompletionRequest {
@JsonProperty("tool_choice")
ToolChoice toolChoice;

/**
* Whether to enable parallel function calling during tool use.
* {@see https://platform.openai.com/docs/guides/function-calling/parallel-function-calling}
*/
@JsonProperty("parallel_tool_calls")
Boolean parallelToolCalls;


}
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
}
}
],
"stream": true
"stream": true,
"parallel_tool_calls": true
}
3 changes: 2 additions & 1 deletion api/src/test/resources/fixtures/ChatCompletionRequest.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,6 @@
],
"stream_options": {
"include_usage": true
}
},
"parallel_tool_calls": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -715,4 +715,42 @@ void streamChatMultipleToolCalls() {
}


@Test
public void parallelToolCallTest() {
final List<ChatMessage> messages = new ArrayList<>();
final ChatMessage systemMessage = new SystemMessage("You are a helpful assistant.");
final ChatMessage userMessage = new UserMessage("What's the weather like in San Francisco, Tokyo, and Paris?");
messages.add(systemMessage);
messages.add(userMessage);

ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest
.builder()
.model("gpt-3.5-turbo")
.messages(messages)
.tools(Arrays.asList(new ChatTool(ToolUtil.weatherFunction())))
.toolChoice(ToolChoice.AUTO)
.parallelToolCalls(false)
.n(1)
.maxTokens(200)
.build();

AssistantMessage accumulatedMessage = service.mapStreamToAccumulator(service.streamChatCompletion(chatCompletionRequest))
.blockingLast()
.getAccumulatedMessage();

List<ChatToolCall> toolCalls = accumulatedMessage.getToolCalls();
assertEquals(1, toolCalls.size());
assertEquals("get_weather", toolCalls.get(0).getFunction().getName());
assertInstanceOf(ObjectNode.class, toolCalls.get(0).getFunction().getArguments());


chatCompletionRequest.setParallelToolCalls(true);
AssistantMessage accumulatedMessage2 = service.mapStreamToAccumulator(service.streamChatCompletion(chatCompletionRequest))
.blockingLast()
.getAccumulatedMessage();
List<ChatToolCall> toolCalls2 = accumulatedMessage2.getToolCalls();
assertEquals(3, toolCalls2.size());
assertEquals("get_weather", toolCalls2.get(0).getFunction().getName());
}

}