Skip to content

Commit bbacbfe

Browse files
committed
adding proxy configuration for azure openai
1 parent 34b8f97 commit bbacbfe

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

model-providers/openai/azure-openai/runtime/src/main/java/io/quarkiverse/langchain4j/azure/openai/runtime/AzureOpenAiRecorder.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import static io.quarkiverse.langchain4j.runtime.OptionalUtil.firstOrDefault;
44

5+
import java.net.InetSocketAddress;
6+
import java.net.Proxy;
7+
import java.net.Proxy.Type;
58
import java.nio.file.Path;
69
import java.nio.file.Paths;
710
import java.time.Duration;
@@ -84,6 +87,11 @@ public Function<SyntheticCreationalContext<ChatModel>, ChatModel> chatModel(Stri
8487
.frequencyPenalty(chatModelConfig.frequencyPenalty())
8588
.responseFormat(chatModelConfig.responseFormat().orElse(null));
8689

90+
azureAiConfig.proxyHost().ifPresent(host -> {
91+
builder.proxy(new Proxy(
92+
Type.valueOf(azureAiConfig.proxyType()),
93+
new InetSocketAddress(host, azureAiConfig.proxyPort())));
94+
});
8795
if (chatModelConfig.maxTokens().isPresent()) {
8896
builder.maxTokens(chatModelConfig.maxTokens().get());
8997
}
@@ -133,6 +141,12 @@ public Function<SyntheticCreationalContext<StreamingChatModel>, StreamingChatMod
133141
.frequencyPenalty(chatModelConfig.frequencyPenalty())
134142
.responseFormat(chatModelConfig.responseFormat().orElse(null));
135143

144+
azureAiConfig.proxyHost().ifPresent(host -> {
145+
builder.proxy(new Proxy(
146+
Type.valueOf(azureAiConfig.proxyType()),
147+
new InetSocketAddress(host, azureAiConfig.proxyPort())));
148+
});
149+
136150
if (chatModelConfig.maxTokens().isPresent()) {
137151
builder.maxTokens(chatModelConfig.maxTokens().get());
138152
}
@@ -176,6 +190,12 @@ public Function<SyntheticCreationalContext<EmbeddingModel>, EmbeddingModel> embe
176190
.logRequests(firstOrDefault(false, embeddingModelConfig.logRequests(), azureAiConfig.logRequests()))
177191
.logResponses(firstOrDefault(false, embeddingModelConfig.logResponses(), azureAiConfig.logResponses()));
178192

193+
azureAiConfig.proxyHost().ifPresent(host -> {
194+
builder.proxy(new Proxy(
195+
Type.valueOf(azureAiConfig.proxyType()),
196+
new InetSocketAddress(host, azureAiConfig.proxyPort())));
197+
});
198+
179199
return new Function<>() {
180200
@Override
181201
public EmbeddingModel apply(SyntheticCreationalContext<EmbeddingModel> context) {

model-providers/openai/azure-openai/runtime/src/main/java/io/quarkiverse/langchain4j/azure/openai/runtime/config/LangChain4jAzureOpenAiConfig.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,23 @@ interface AzureAiConfig {
136136
@WithDefault("true")
137137
Boolean enableIntegration();
138138

139+
/**
140+
* The Proxy type
141+
*/
142+
@WithDefault("HTTP")
143+
String proxyType();
144+
145+
/**
146+
* The Proxy host
147+
*/
148+
Optional<String> proxyHost();
149+
150+
/**
151+
* The Proxy port
152+
*/
153+
@WithDefault("3128")
154+
Integer proxyPort();
155+
139156
/**
140157
* Chat model related settings
141158
*/

0 commit comments

Comments
 (0)