Skip to content

Commit

Permalink
Merge pull request #507 from jmartisk/fault-tolerance
Browse files Browse the repository at this point in the history
Turn off built-in fault tolerance by default
  • Loading branch information
jmartisk committed Apr 25, 2024
2 parents c61b2ea + 734c463 commit e1c980f
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ public interface ChatModelConfig {
Integer topK();

/**
* The maximum number of retries for API requests.
* The maximum number of times to retry. 1 means exactly one attempt, with retrying disabled.
*
* @deprecated Using the fault tolerance mechanisms built in Langchain4j is not recommended. If possible,
* use MicroProfile Fault Tolerance instead.
*/
@WithDefault("3")
@WithDefault("1")
Integer maxRetries();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public QuarkusCohereScoringModel(
Integer maxRetries) {
this.model = model;
this.maxRetries = maxRetries;
if (this.maxRetries < 1) {
throw new IllegalArgumentException("max-retries must be at least 1");
}
ClientHeadersFactory factory = new ClientHeadersFactory() {
@Override
public MultivaluedMap<String, String> update(MultivaluedMap<String, String> incomingHeaders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ public interface CohereScoringModelConfig {
Duration timeout();

/**
* Maximum number of retries for Cohere API invocations.
* The maximum number of times to retry. 1 means exactly one attempt, with retrying disabled.
*
* @deprecated Using the fault tolerance mechanisms built in Langchain4j is not recommended. If possible,
* use MicroProfile Fault Tolerance instead.
*/
@WithDefault("3")
@WithDefault("1")
Integer maxRetries();

}
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ a| [[quarkus-langchain4j-anthropic_quarkus-langchain4j-anthropic-chat-model-max-

[.description]
--
The maximum number of retries for API requests.
The maximum number of times to retry. 1 means exactly one attempt, with retrying disabled.

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_ANTHROPIC_CHAT_MODEL_MAX_RETRIES+++[]
Expand All @@ -252,7 +252,7 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_ANTHROPIC_CHAT_MODEL_MAX_RETRIES+++`
endif::add-copy-button-to-env-var[]
--|int
|`3`
|`1`


a| [[quarkus-langchain4j-anthropic_quarkus-langchain4j-anthropic-chat-model-stop-sequences]]`link:#quarkus-langchain4j-anthropic_quarkus-langchain4j-anthropic-chat-model-stop-sequences[quarkus.langchain4j.anthropic.chat-model.stop-sequences]`
Expand Down Expand Up @@ -527,7 +527,7 @@ a| [[quarkus-langchain4j-anthropic_quarkus-langchain4j-anthropic-model-name-chat

[.description]
--
The maximum number of retries for API requests.
The maximum number of times to retry. 1 means exactly one attempt, with retrying disabled.

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_ANTHROPIC__MODEL_NAME__CHAT_MODEL_MAX_RETRIES+++[]
Expand All @@ -536,7 +536,7 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_ANTHROPIC__MODEL_NAME__CHAT_MODEL_MAX_RETRIES+++`
endif::add-copy-button-to-env-var[]
--|int
|`3`
|`1`


a| [[quarkus-langchain4j-anthropic_quarkus-langchain4j-anthropic-model-name-chat-model-stop-sequences]]`link:#quarkus-langchain4j-anthropic_quarkus-langchain4j-anthropic-model-name-chat-model-stop-sequences[quarkus.langchain4j.anthropic."model-name".chat-model.stop-sequences]`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ a| [[quarkus-langchain4j-cohere_quarkus-langchain4j-cohere-scoring-model-max-ret

[.description]
--
Maximum number of retries for Cohere API invocations.
The maximum number of times to retry. 1 means exactly one attempt, with retrying disabled.

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_COHERE_SCORING_MODEL_MAX_RETRIES+++[]
Expand All @@ -93,7 +93,7 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_COHERE_SCORING_MODEL_MAX_RETRIES+++`
endif::add-copy-button-to-env-var[]
--|int
|`3`
|`1`

|===
ifndef::no-duration-note[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-max-retries]]`link:#q

[.description]
--
The maximum number of times to retry
The maximum number of times to retry. 1 means exactly one attempt, with retrying disabled.

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI_MAX_RETRIES+++[]
Expand All @@ -161,7 +161,7 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI_MAX_RETRIES+++`
endif::add-copy-button-to-env-var[]
--|int
|`3`
|`1`


a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-log-requests]]`link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-log-requests[quarkus.langchain4j.openai.log-requests]`
Expand Down Expand Up @@ -771,7 +771,7 @@ a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-max-retrie

[.description]
--
The maximum number of times to retry
The maximum number of times to retry. 1 means exactly one attempt, with retrying disabled.

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__MAX_RETRIES+++[]
Expand All @@ -780,7 +780,7 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__MAX_RETRIES+++`
endif::add-copy-button-to-env-var[]
--|int
|`3`
|`1`


a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-log-requests]]`link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-log-requests[quarkus.langchain4j.openai."model-name".log-requests]`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ public AzureOpenAiChatModel(String endpoint,
this.maxTokens = maxTokens;
this.presencePenalty = presencePenalty;
this.frequencyPenalty = frequencyPenalty;
this.maxRetries = getOrDefault(maxRetries, 3);
this.maxRetries = getOrDefault(maxRetries, 1);
if (this.maxRetries < 1) {
throw new IllegalArgumentException("max-retries must be at least 1");
}
this.tokenizer = tokenizer;
this.responseFormat = responseFormat;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public AzureOpenAiEmbeddingModel(String endpoint,
Boolean logResponses) {

timeout = getOrDefault(timeout, ofSeconds(60));
if (maxRetries < 1) {
throw new IllegalArgumentException("max-retries must be at least 1");
}

this.client = ((QuarkusOpenAiClient.Builder) OpenAiClient.builder()
.baseUrl(ensureNotBlank(endpoint, "endpoint"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ interface AzureAiConfig {
Duration timeout();

/**
* The maximum number of times to retry
* The maximum number of times to retry. 1 means exactly one attempt, with retrying disabled.
*
* @deprecated Using the fault tolerance mechanisms built in Langchain4j is not recommended. If possible,
* use MicroProfile Fault Tolerance instead.
*/
@WithDefault("3")
@WithDefault("1")
Integer maxRetries();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public QuarkusOpenAiImageModel(String baseUrl, String apiKey, String organizatio
this.user = user;
this.responseFormat = responseFormat;
this.maxRetries = maxRetries;
if (this.maxRetries < 1) {
throw new IllegalArgumentException("max-retries must be at least 1");
}
this.persistDirectory = persistDirectory;

this.client = QuarkusOpenAiClient.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ interface OpenAiConfig {
Duration timeout();

/**
* The maximum number of times to retry
* The maximum number of times to retry. 1 means exactly one attempt, with retrying disabled.
*
* @deprecated Using the built-in fault tolerance mechanisms is not recommended. If possible,
* use MicroProfile Fault Tolerance instead.
*/
@WithDefault("3")
@WithDefault("1")
Integer maxRetries();

/**
Expand Down

0 comments on commit e1c980f

Please sign in to comment.