-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(anthropic): Implemented a web search tool, provided by Anthropic #3353
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
base: main
Are you sure you want to change the base?
feat(anthropic): Implemented a web search tool, provided by Anthropic #3353
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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 <[email protected]>
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.