Skip to content
Open
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 @@ -16,6 +16,7 @@

package org.springframework.ai.anthropic;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -47,6 +48,7 @@
* @author Ilayaperumal Gopinathan
* @author Soby Chacko
* @author Austin Dase
* @author Hyunsang Han
* @since 1.0.0
*/
@JsonInclude(Include.NON_NULL)
Expand Down Expand Up @@ -102,6 +104,12 @@ public void setCacheOptions(AnthropicCacheOptions cacheOptions) {
@JsonIgnore
private Map<String, String> httpHeaders = new HashMap<>();

/**
* The timeout duration for the chat request.
*/
@JsonIgnore
private Duration timeout;

// @formatter:on

public static Builder builder() {
Expand All @@ -125,6 +133,7 @@ public static AnthropicChatOptions fromOptions(AnthropicChatOptions fromOptions)
.toolContext(fromOptions.getToolContext() != null ? new HashMap<>(fromOptions.getToolContext()) : null)
.httpHeaders(fromOptions.getHttpHeaders() != null ? new HashMap<>(fromOptions.getHttpHeaders()) : null)
.cacheOptions(fromOptions.getCacheOptions())
.timeout(fromOptions.getTimeout())
.build();
}

Expand Down Expand Up @@ -273,6 +282,17 @@ public void setHttpHeaders(Map<String, String> httpHeaders) {
this.httpHeaders = httpHeaders;
}

@Override
@Nullable
@JsonIgnore
public Duration getTimeout() {
return this.timeout;
}

public void setTimeout(Duration timeout) {
this.timeout = timeout;
}

@Override
@SuppressWarnings("unchecked")
public AnthropicChatOptions copy() {
Expand All @@ -297,14 +317,14 @@ public boolean equals(Object o) {
&& Objects.equals(this.internalToolExecutionEnabled, that.internalToolExecutionEnabled)
&& Objects.equals(this.toolContext, that.toolContext)
&& Objects.equals(this.httpHeaders, that.httpHeaders)
&& Objects.equals(this.cacheOptions, that.cacheOptions);
&& Objects.equals(this.cacheOptions, that.cacheOptions) && Objects.equals(this.timeout, that.timeout);
}

@Override
public int hashCode() {
return Objects.hash(this.model, this.maxTokens, this.metadata, this.stopSequences, this.temperature, this.topP,
this.topK, this.thinking, this.toolCallbacks, this.toolNames, this.internalToolExecutionEnabled,
this.toolContext, this.httpHeaders, this.cacheOptions);
this.toolContext, this.httpHeaders, this.cacheOptions, this.timeout);
}

public static class Builder {
Expand Down Expand Up @@ -409,6 +429,11 @@ public Builder cacheOptions(AnthropicCacheOptions cacheOptions) {
return this;
}

public Builder timeout(Duration timeout) {
this.options.timeout = timeout;
return this;
}

public AnthropicChatOptions build() {
return this.options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.ai.azure.openai;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -50,6 +51,7 @@
* @author Ilayaperumal Gopinathan
* @author Alexandros Pappas
* @author Andres da Silva Santos
* @author Hyunsang Han
*/
@JsonInclude(Include.NON_NULL)
public class AzureOpenAiChatOptions implements ToolCallingChatOptions {
Expand Down Expand Up @@ -222,6 +224,12 @@ public class AzureOpenAiChatOptions implements ToolCallingChatOptions {
@JsonIgnore
private Map<String, Object> toolContext = new HashMap<>();

/**
* The timeout duration for the chat request.
*/
@JsonIgnore
private Duration timeout;

/**
* Collection of {@link ToolCallback}s to be used for tool calling in the chat
* completion requests.
Expand Down Expand Up @@ -328,6 +336,7 @@ public static AzureOpenAiChatOptions fromOptions(AzureOpenAiChatOptions fromOpti
.toolContext(fromOptions.getToolContext() != null ? new HashMap<>(fromOptions.getToolContext()) : null)
.internalToolExecutionEnabled(fromOptions.getInternalToolExecutionEnabled())
.streamOptions(fromOptions.getStreamOptions())
.timeout(fromOptions.getTimeout())
.build();
}

Expand Down Expand Up @@ -522,6 +531,17 @@ public void setToolContext(Map<String, Object> toolContext) {
this.toolContext = toolContext;
}

@Override
@Nullable
@JsonIgnore
public Duration getTimeout() {
return this.timeout;
}

public void setTimeout(Duration timeout) {
this.timeout = timeout;
}

public ChatCompletionStreamOptions getStreamOptions() {
return this.streamOptions;
}
Expand Down Expand Up @@ -561,7 +581,8 @@ public boolean equals(Object o) {
&& Objects.equals(this.maxCompletionTokens, that.maxCompletionTokens)
&& Objects.equals(this.frequencyPenalty, that.frequencyPenalty)
&& Objects.equals(this.presencePenalty, that.presencePenalty)
&& Objects.equals(this.temperature, that.temperature) && Objects.equals(this.topP, that.topP);
&& Objects.equals(this.temperature, that.temperature) && Objects.equals(this.topP, that.topP)
&& Objects.equals(this.timeout, that.timeout);
}

@Override
Expand All @@ -570,7 +591,7 @@ public int hashCode() {
this.toolCallbacks, this.toolNames, this.internalToolExecutionEnabled, this.seed, this.logprobs,
this.topLogProbs, this.enhancements, this.streamOptions, this.reasoningEffort, this.enableStreamUsage,
this.toolContext, this.maxTokens, this.maxCompletionTokens, this.frequencyPenalty, this.presencePenalty,
this.temperature, this.topP);
this.temperature, this.topP, this.timeout);
}

public static class Builder {
Expand Down Expand Up @@ -778,6 +799,11 @@ public Builder internalToolExecutionEnabled(@Nullable Boolean internalToolExecut
return this;
}

public Builder timeout(Duration timeout) {
this.options.timeout = timeout;
return this;
}

public AzureOpenAiChatOptions build() {
return this.options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.ai.bedrock.converse;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -38,6 +39,7 @@
* The options to be used when sending a chat request to the Bedrock API.
*
* @author Sun Yuhan
* @author Hyunsang Han
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class BedrockChatOptions implements ToolCallingChatOptions {
Expand Down Expand Up @@ -81,6 +83,9 @@ public class BedrockChatOptions implements ToolCallingChatOptions {
@JsonIgnore
private Boolean internalToolExecutionEnabled;

@JsonIgnore
private Duration timeout;

public static Builder builder() {
return new Builder();
}
Expand All @@ -101,6 +106,7 @@ public static BedrockChatOptions fromOptions(BedrockChatOptions fromOptions) {
.toolNames(new HashSet<>(fromOptions.getToolNames()))
.toolContext(new HashMap<>(fromOptions.getToolContext()))
.internalToolExecutionEnabled(fromOptions.getInternalToolExecutionEnabled())
.timeout(fromOptions.getTimeout())
.build();
}

Expand Down Expand Up @@ -237,6 +243,17 @@ public void setInternalToolExecutionEnabled(@Nullable Boolean internalToolExecut
this.internalToolExecutionEnabled = internalToolExecutionEnabled;
}

@Override
@Nullable
@JsonIgnore
public Duration getTimeout() {
return this.timeout;
}

public void setTimeout(Duration timeout) {
this.timeout = timeout;
}

@Override
@SuppressWarnings("unchecked")
public BedrockChatOptions copy() {
Expand All @@ -259,14 +276,15 @@ public boolean equals(Object o) {
&& Objects.equals(this.temperature, that.temperature) && Objects.equals(this.topK, that.topK)
&& Objects.equals(this.topP, that.topP) && Objects.equals(this.toolCallbacks, that.toolCallbacks)
&& Objects.equals(this.toolNames, that.toolNames) && Objects.equals(this.toolContext, that.toolContext)
&& Objects.equals(this.internalToolExecutionEnabled, that.internalToolExecutionEnabled);
&& Objects.equals(this.internalToolExecutionEnabled, that.internalToolExecutionEnabled)
&& Objects.equals(this.timeout, that.timeout);
}

@Override
public int hashCode() {
return Objects.hash(this.model, this.frequencyPenalty, this.maxTokens, this.presencePenalty,
this.requestParameters, this.stopSequences, this.temperature, this.topK, this.topP, this.toolCallbacks,
this.toolNames, this.toolContext, this.internalToolExecutionEnabled);
this.toolNames, this.toolContext, this.internalToolExecutionEnabled, this.timeout);
}

public static class Builder {
Expand Down Expand Up @@ -356,6 +374,11 @@ public Builder internalToolExecutionEnabled(@Nullable Boolean internalToolExecut
return this;
}

public Builder timeout(Duration timeout) {
this.options.timeout = timeout;
return this;
}

public BedrockChatOptions build() {
return this.options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.ai.deepseek;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -43,6 +44,7 @@
* chat completion</a>
*
* @author Geng Rong
* @author Hyunsang Han
*/
@JsonInclude(Include.NON_NULL)
public class DeepSeekChatOptions implements ToolCallingChatOptions {
Expand Down Expand Up @@ -143,7 +145,10 @@ public class DeepSeekChatOptions implements ToolCallingChatOptions {
private Set<String> toolNames = new HashSet<>();

@JsonIgnore
private Map<String, Object> toolContext = new HashMap<>();;
private Map<String, Object> toolContext = new HashMap<>();

@JsonIgnore
private Duration timeout;

public static Builder builder() {
return new Builder();
Expand Down Expand Up @@ -289,6 +294,17 @@ public void setInternalToolExecutionEnabled(@Nullable Boolean internalToolExecut
this.internalToolExecutionEnabled = internalToolExecutionEnabled;
}

@Override
@Nullable
@JsonIgnore
public Duration getTimeout() {
return this.timeout;
}

public void setTimeout(Duration timeout) {
this.timeout = timeout;
}

public Boolean getLogprobs() {
return this.logprobs;
}
Expand Down Expand Up @@ -332,7 +348,7 @@ public int hashCode() {
return Objects.hash(this.model, this.frequencyPenalty, this.logprobs, this.topLogprobs,
this.maxTokens, this.presencePenalty, this.responseFormat,
this.stop, this.temperature, this.topP, this.tools, this.toolChoice,
this.toolCallbacks, this.toolNames, this.internalToolExecutionEnabled, this.toolContext);
this.toolCallbacks, this.toolNames, this.internalToolExecutionEnabled, this.toolContext, this.timeout);
}


Expand All @@ -357,7 +373,8 @@ public boolean equals(Object o) {
&& Objects.equals(this.toolCallbacks, other.toolCallbacks)
&& Objects.equals(this.toolNames, other.toolNames)
&& Objects.equals(this.toolContext, other.toolContext)
&& Objects.equals(this.internalToolExecutionEnabled, other.internalToolExecutionEnabled);
&& Objects.equals(this.internalToolExecutionEnabled, other.internalToolExecutionEnabled)
&& Objects.equals(this.timeout, other.timeout);
}

public static DeepSeekChatOptions fromOptions(DeepSeekChatOptions fromOptions) {
Expand All @@ -379,6 +396,7 @@ public static DeepSeekChatOptions fromOptions(DeepSeekChatOptions fromOptions) {
.toolNames(fromOptions.getToolNames() != null ? new HashSet<>(fromOptions.getToolNames()) : null)
.internalToolExecutionEnabled(fromOptions.getInternalToolExecutionEnabled())
.toolContext(fromOptions.getToolContext() != null ? new HashMap<>(fromOptions.getToolContext()) : null)
.timeout(fromOptions.getTimeout())
.build();
}

Expand Down Expand Up @@ -497,6 +515,11 @@ public Builder toolContext(Map<String, Object> toolContext) {
return this;
}

public Builder timeout(Duration timeout) {
this.options.timeout = timeout;
return this;
}

public DeepSeekChatOptions build() {
return this.options;
}
Expand Down
Loading