Skip to content

Commit

Permalink
Merge pull request #814 from zhfeng/issue_813_proxy_support_for_openai
Browse files Browse the repository at this point in the history
Fix #813 to add proxy support for openai
  • Loading branch information
jmartisk authored Aug 12, 2024
2 parents 8b5ce02 + 95f496e commit 7e0fdfb
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
102 changes: 102 additions & 0 deletions docs/modules/ROOT/pages/includes/quarkus-langchain4j-openai.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,57 @@ endif::add-copy-button-to-env-var[]
|`true`


a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-proxy-type]]`link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-proxy-type[quarkus.langchain4j.openai.proxy-type]`


[.description]
--
The Proxy type

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI_PROXY_TYPE+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI_PROXY_TYPE+++`
endif::add-copy-button-to-env-var[]
--|string
|`HTTP`


a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-proxy-host]]`link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-proxy-host[quarkus.langchain4j.openai.proxy-host]`


[.description]
--
The Proxy host

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI_PROXY_HOST+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI_PROXY_HOST+++`
endif::add-copy-button-to-env-var[]
--|string
|


a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-proxy-port]]`link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-proxy-port[quarkus.langchain4j.openai.proxy-port]`


[.description]
--
The Proxy port

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI_PROXY_PORT+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI_PROXY_PORT+++`
endif::add-copy-button-to-env-var[]
--|int
|`3128`


a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-chat-model-model-name]]`link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-chat-model-model-name[quarkus.langchain4j.openai.chat-model.model-name]`


Expand Down Expand Up @@ -851,6 +902,57 @@ endif::add-copy-button-to-env-var[]
|`true`


a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-proxy-type]]`link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-proxy-type[quarkus.langchain4j.openai."model-name".proxy-type]`


[.description]
--
The Proxy type

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__PROXY_TYPE+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__PROXY_TYPE+++`
endif::add-copy-button-to-env-var[]
--|string
|`HTTP`


a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-proxy-host]]`link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-proxy-host[quarkus.langchain4j.openai."model-name".proxy-host]`


[.description]
--
The Proxy host

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__PROXY_HOST+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__PROXY_HOST+++`
endif::add-copy-button-to-env-var[]
--|string
|


a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-proxy-port]]`link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-proxy-port[quarkus.langchain4j.openai."model-name".proxy-port]`


[.description]
--
The Proxy port

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__PROXY_PORT+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LANGCHAIN4J_OPENAI__MODEL_NAME__PROXY_PORT+++`
endif::add-copy-button-to-env-var[]
--|int
|`3128`


a| [[quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-chat-model-model-name]]`link:#quarkus-langchain4j-openai_quarkus-langchain4j-openai-model-name-chat-model-model-name[quarkus.langchain4j.openai."model-name".chat-model.model-name]`


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.quarkiverse.langchain4j.openai.runtime;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
Expand Down Expand Up @@ -74,6 +77,10 @@ public Function<SyntheticCreationalContext<ChatLanguageModel>, ChatLanguageModel
.stop(chatModelConfig.stop().orElse(null));

openAiConfig.organizationId().ifPresent(builder::organizationId);
openAiConfig.proxyHost().ifPresent(host -> {
builder.proxy(new Proxy(Type.valueOf(openAiConfig.proxyType()),
new InetSocketAddress(host, openAiConfig.proxyPort())));
});

if (chatModelConfig.maxTokens().isPresent()) {
builder.maxTokens(chatModelConfig.maxTokens().get());
Expand Down Expand Up @@ -121,6 +128,10 @@ public Supplier<StreamingChatLanguageModel> streamingChatModel(LangChain4jOpenAi
.stop(chatModelConfig.stop().orElse(null));

openAiConfig.organizationId().ifPresent(builder::organizationId);
openAiConfig.proxyHost().ifPresent(host -> {
builder.proxy(new Proxy(Type.valueOf(openAiConfig.proxyType()),
new InetSocketAddress(host, openAiConfig.proxyPort())));
});

if (chatModelConfig.maxTokens().isPresent()) {
builder.maxTokens(chatModelConfig.maxTokens().get());
Expand Down Expand Up @@ -165,6 +176,10 @@ public Supplier<EmbeddingModel> embeddingModel(LangChain4jOpenAiConfig runtimeCo
}

openAiConfig.organizationId().ifPresent(builder::organizationId);
openAiConfig.proxyHost().ifPresent(host -> {
builder.proxy(new Proxy(Type.valueOf(openAiConfig.proxyType()),
new InetSocketAddress(host, openAiConfig.proxyPort())));
});

return new Supplier<>() {
@Override
Expand Down Expand Up @@ -201,6 +216,10 @@ public Supplier<ModerationModel> moderationModel(LangChain4jOpenAiConfig runtime
.modelName(moderationModelConfig.modelName());

openAiConfig.organizationId().ifPresent(builder::organizationId);
openAiConfig.proxyHost().ifPresent(host -> {
builder.proxy(new Proxy(Type.valueOf(openAiConfig.proxyType()),
new InetSocketAddress(host, openAiConfig.proxyPort())));
});

return new Supplier<>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ interface OpenAiConfig {
@WithDefault("true")
Boolean enableIntegration();

/**
* The Proxy type
*/
@WithDefault("HTTP")
String proxyType();

/**
* The Proxy host
*/
Optional<String> proxyHost();

/**
* The Proxy port
*/
@WithDefault("3128")
Integer proxyPort();

/**
* Chat model related settings
*/
Expand Down

0 comments on commit 7e0fdfb

Please sign in to comment.