Skip to content

Commit

Permalink
added proxy properties
Browse files Browse the repository at this point in the history
  • Loading branch information
langchain4j committed Dec 22, 2023
1 parent 992371f commit 227f772
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ OpenAiChatModel openAiChatModel(Properties properties) {
.user(chatModelProperties.getUser())
.timeout(chatModelProperties.getTimeout())
.maxRetries(chatModelProperties.getMaxRetries())
.proxy(ProxyProperties.toProxy(chatModelProperties.getProxy()))
.logRequests(chatModelProperties.getLogRequests())
.logResponses(chatModelProperties.getLogResponses())
.build();
Expand All @@ -58,6 +59,7 @@ OpenAiStreamingChatModel openAiStreamingChatModel(Properties properties) {
.seed(chatModelProperties.getSeed())
.user(chatModelProperties.getUser())
.timeout(chatModelProperties.getTimeout())
.proxy(ProxyProperties.toProxy(chatModelProperties.getProxy()))
.logRequests(chatModelProperties.getLogRequests())
.logResponses(chatModelProperties.getLogResponses())
.build();
Expand All @@ -75,6 +77,7 @@ OpenAiLanguageModel openAiLanguageModel(Properties properties) {
.temperature(languageModelProperties.getTemperature())
.timeout(languageModelProperties.getTimeout())
.maxRetries(languageModelProperties.getMaxRetries())
.proxy(ProxyProperties.toProxy(languageModelProperties.getProxy()))
.logRequests(languageModelProperties.getLogRequests())
.logResponses(languageModelProperties.getLogResponses())
.build();
Expand All @@ -91,6 +94,7 @@ OpenAiStreamingLanguageModel openAiStreamingLanguageModel(Properties properties)
.modelName(languageModelProperties.getModelName())
.temperature(languageModelProperties.getTemperature())
.timeout(languageModelProperties.getTimeout())
.proxy(ProxyProperties.toProxy(languageModelProperties.getProxy()))
.logRequests(languageModelProperties.getLogRequests())
.logResponses(languageModelProperties.getLogResponses())
.build();
Expand All @@ -108,6 +112,7 @@ OpenAiEmbeddingModel openAiEmbeddingModel(Properties properties) {
.user(embeddingModelProperties.getUser())
.timeout(embeddingModelProperties.getTimeout())
.maxRetries(embeddingModelProperties.getMaxRetries())
.proxy(ProxyProperties.toProxy(embeddingModelProperties.getProxy()))
.logRequests(embeddingModelProperties.getLogRequests())
.logResponses(embeddingModelProperties.getLogResponses())
.build();
Expand All @@ -124,6 +129,7 @@ OpenAiModerationModel openAiModerationModel(Properties properties) {
.modelName(moderationModelProperties.getModelName())
.timeout(moderationModelProperties.getTimeout())
.maxRetries(moderationModelProperties.getMaxRetries())
.proxy(ProxyProperties.toProxy(moderationModelProperties.getProxy()))
.logRequests(moderationModelProperties.getLogRequests())
.logResponses(moderationModelProperties.getLogResponses())
.build();
Expand All @@ -145,6 +151,7 @@ OpenAiImageModel openAiImageModel(Properties properties) {
.responseFormat(imageModelProperties.getResponseFormat())
.timeout(imageModelProperties.getTimeout())
.maxRetries(imageModelProperties.getMaxRetries())
.proxy(ProxyProperties.toProxy(imageModelProperties.getProxy()))
.logRequests(imageModelProperties.getLogRequests())
.logResponses(imageModelProperties.getLogResponses())
.withPersisting(imageModelProperties.getWithPersisting())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

import java.time.Duration;
import java.util.List;
Expand All @@ -27,6 +28,8 @@ class ChatModelProperties {
String user;
Duration timeout;
Integer maxRetries;
@NestedConfigurationProperty
ProxyProperties proxy;
Boolean logRequests;
Boolean logResponses;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

import java.time.Duration;

Expand All @@ -16,6 +17,8 @@ class EmbeddingModelProperties {
String user;
Duration timeout;
Integer maxRetries;
@NestedConfigurationProperty
ProxyProperties proxy;
Boolean logRequests;
Boolean logResponses;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

import java.nio.file.Path;
import java.time.Duration;
Expand All @@ -21,6 +22,8 @@ class ImageModelProperties {
String responseFormat;
Duration timeout;
Integer maxRetries;
@NestedConfigurationProperty
ProxyProperties proxy;
Boolean logRequests;
Boolean logResponses;
Boolean withPersisting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

import java.time.Duration;

Expand All @@ -16,6 +17,8 @@ class LanguageModelProperties {
Double temperature;
Duration timeout;
Integer maxRetries;
@NestedConfigurationProperty
ProxyProperties proxy;
Boolean logRequests;
Boolean logResponses;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

import java.time.Duration;

Expand All @@ -15,6 +16,8 @@ class ModerationModelProperties {
String modelName;
Duration timeout;
Integer maxRetries;
@NestedConfigurationProperty
ProxyProperties proxy;
Boolean logRequests;
Boolean logResponses;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.langchain4j.openai.spring;

import lombok.Getter;
import lombok.Setter;

import java.net.InetSocketAddress;
import java.net.Proxy;

@Getter
@Setter
class ProxyProperties {

Proxy.Type type;
String host;
Integer port;

static Proxy toProxy(ProxyProperties proxy) {
if (proxy == null) {
return null;
}
return new Proxy(proxy.type, new InetSocketAddress(proxy.host, proxy.port));
}
}

0 comments on commit 227f772

Please sign in to comment.