feat(anthropic): Implemented a web search tool, provided by Anthropic#3353
feat(anthropic): Implemented a web search tool, provided by Anthropic#3353dev-jonghoonpark wants to merge 1 commit intospring-projects:mainfrom
Conversation
d086f6e to
9efd6a5
Compare
|
We will review, then we can discuss the streaming support. |
models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/api/AnthropicApi.java
Outdated
Show resolved
Hide resolved
9efd6a5 to
3aafc80
Compare
| @@ -526,22 +540,31 @@ else if (message.getMessageType() == MessageType.TOOL) { | |||
|
|
|||
| // Add the tool definitions to the request's tools parameter. | |||
| List<ToolDefinition> toolDefinitions = this.toolCallingManager.resolveToolDefinitions(requestOptions); | |||
| Stream<Tool> toolStream = Stream.empty(); | |||
| if (!CollectionUtils.isEmpty(toolDefinitions)) { | |||
| request = ModelOptionsUtils.merge(request, this.defaultOptions, ChatCompletionRequest.class); | |||
There was a problem hiding this comment.
request = ModelOptionsUtils.merge(request, this.defaultOptions, ChatCompletionRequest.class);
I'm not sure why this code is needed or what it does.
I kept it to preserve the existing logic.
If I can understand why this is necessary, I think I can improve the code further.
There was a problem hiding this comment.
@dev-jonghoonpark Good point. This line makes sure to update the ChatCompletionRequest with any of the missing chat options which can be set via default chat options.
Though we use the default options to create the ChatCompletion Request:
ChatCompletionRequest request = new ChatCompletionRequest(this.defaultOptions.getModel(), userMessages,
systemPrompt, this.defaultOptions.getMaxTokens(), this.defaultOptions.getTemperature(), stream);
not all the properties are updated in this and the model options utils helps merging any of the missing ones.
There was a problem hiding this comment.
@ilayaperumalg Thank you for the explanation.
However, why is it called only when !CollectionUtils.isEmpty(toolDefinitions) is true?
This web search tool is categorized as a `server tool`. related doc: https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool Signed-off-by: jonghoonpark <dev@jonghoonpark.com>
3aafc80 to
936505c
Compare
|
Resolve conflicts with PR: #3365 |
Implemented a web search tool, provided by Anthropic
This web search tool is categorized as a
server tool.related doc: https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-search-tool
Changes
The serverTools property has been added to AnthropicChatOptions.
It can be used as follows:
Note 1
I'm not sure if this is a temporary issue, but I was occasionally getting a 529 error (
overloaded_error: Anthropic's API is temporarily overloaded.) during development.related doc: https://docs.anthropic.com/en/api/errors
Note 2
The stream part was not developed in this PR.