diff --git a/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanChatModel.java b/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanChatModel.java index fe7f3f11b..03c2ca0c8 100644 --- a/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanChatModel.java +++ b/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanChatModel.java @@ -2,22 +2,25 @@ package dev.langchain4j.model.qianfan; import dev.langchain4j.agent.tool.ToolSpecification; -import dev.langchain4j.data.message.*; +import dev.langchain4j.data.message.AiMessage; +import dev.langchain4j.data.message.ChatMessage; import dev.langchain4j.internal.Utils; import dev.langchain4j.model.chat.ChatLanguageModel; import dev.langchain4j.model.output.Response; import dev.langchain4j.model.qianfan.client.QianfanClient; +import dev.langchain4j.model.qianfan.client.chat.ChatCompletionRequest; import dev.langchain4j.model.qianfan.client.chat.ChatCompletionResponse; import dev.langchain4j.model.qianfan.spi.QianfanChatModelBuilderFactory; import lombok.Builder; + +import java.net.Proxy; import java.util.List; + import static dev.langchain4j.internal.RetryUtils.withRetry; import static dev.langchain4j.internal.Utils.getOrDefault; import static dev.langchain4j.model.qianfan.InternalQianfanHelper.*; import static dev.langchain4j.spi.ServiceHelper.loadFactories; -import dev.langchain4j.model.qianfan.client.chat.ChatCompletionRequest; - /** * * see details here: https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Nlks5zkzu @@ -54,7 +57,8 @@ public class QianfanChatModel implements ChatLanguageModel { String responseFormat, Double penaltyScore, Boolean logRequests, - Boolean logResponses + Boolean logResponses, + Proxy proxy ) { if (Utils.isNullOrBlank(apiKey)||Utils.isNullOrBlank(secretKey)) { throw new IllegalArgumentException(" api key and secret key must be defined. It can be generated here: https://console.bce.baidu.com/qianfan/ais/console/applicationConsole/application"); @@ -75,6 +79,7 @@ public class QianfanChatModel implements ChatLanguageModel { .secretKey(secretKey) .logRequests(logRequests) .logResponses(logResponses) + .proxy(proxy) .build(); this.temperature = getOrDefault(temperature, 0.7); this.maxRetries = getOrDefault(maxRetries, 3); diff --git a/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanEmbeddingModel.java b/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanEmbeddingModel.java index c022fbfbc..4ad33a262 100644 --- a/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanEmbeddingModel.java +++ b/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanEmbeddingModel.java @@ -6,14 +6,17 @@ import dev.langchain4j.internal.Utils; import dev.langchain4j.model.embedding.EmbeddingModel; import dev.langchain4j.model.output.Response; import dev.langchain4j.model.qianfan.client.QianfanClient; -import dev.langchain4j.model.qianfan.client.embedding.EmbeddingResponse; import dev.langchain4j.model.qianfan.client.embedding.EmbeddingRequest; +import dev.langchain4j.model.qianfan.client.embedding.EmbeddingResponse; import dev.langchain4j.model.qianfan.spi.QianfanEmbeddingModelBuilderFactory; import lombok.Builder; + +import java.net.Proxy; import java.util.List; + import static dev.langchain4j.internal.RetryUtils.withRetry; import static dev.langchain4j.internal.Utils.getOrDefault; -import static dev.langchain4j.model.qianfan.InternalQianfanHelper.*; +import static dev.langchain4j.model.qianfan.InternalQianfanHelper.tokenUsageFrom; import static dev.langchain4j.spi.ServiceHelper.loadFactories; import static java.util.stream.Collectors.toList; /** @@ -46,7 +49,8 @@ public class QianfanEmbeddingModel implements EmbeddingModel { String endpoint, String user, Boolean logRequests, - Boolean logResponses + Boolean logResponses, + Proxy proxy ) { if (Utils.isNullOrBlank(apiKey)||Utils.isNullOrBlank(secretKey)) { throw new IllegalArgumentException(" api key and secret key must be defined. It can be generated here: https://console.bce.baidu.com/qianfan/ais/console/applicationConsole/application"); @@ -67,6 +71,7 @@ public class QianfanEmbeddingModel implements EmbeddingModel { .secretKey(secretKey) .logRequests(logRequests) .logResponses(logResponses) + .proxy(proxy) .build(); this.maxRetries = getOrDefault(maxRetries, 3); this.user = user; diff --git a/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanLanguageModel.java b/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanLanguageModel.java index d3d4afc9b..0f5799d3c 100644 --- a/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanLanguageModel.java +++ b/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanLanguageModel.java @@ -1,7 +1,6 @@ package dev.langchain4j.model.qianfan; - import dev.langchain4j.internal.Utils; import dev.langchain4j.model.language.LanguageModel; import dev.langchain4j.model.output.Response; @@ -10,9 +9,13 @@ import dev.langchain4j.model.qianfan.client.completion.CompletionRequest; import dev.langchain4j.model.qianfan.client.completion.CompletionResponse; import dev.langchain4j.model.qianfan.spi.QianfanLanguageModelBuilderFactory; import lombok.Builder; + +import java.net.Proxy; + import static dev.langchain4j.internal.RetryUtils.withRetry; import static dev.langchain4j.internal.Utils.getOrDefault; -import static dev.langchain4j.model.qianfan.InternalQianfanHelper.*; +import static dev.langchain4j.model.qianfan.InternalQianfanHelper.finishReasonFrom; +import static dev.langchain4j.model.qianfan.InternalQianfanHelper.tokenUsageFrom; import static dev.langchain4j.spi.ServiceHelper.loadFactories; @@ -51,7 +54,8 @@ public class QianfanLanguageModel implements LanguageModel { String endpoint, Double penaltyScore, Boolean logRequests, - Boolean logResponses + Boolean logResponses, + Proxy proxy ) { if (Utils.isNullOrBlank(apiKey)||Utils.isNullOrBlank(secretKey)) { throw new IllegalArgumentException(" api key and secret key must be defined. It can be generated here: https://console.bce.baidu.com/qianfan/ais/console/applicationConsole/application"); @@ -72,6 +76,7 @@ public class QianfanLanguageModel implements LanguageModel { .secretKey(secretKey) .logRequests(logRequests) .logResponses(logResponses) + .proxy(proxy) .build(); this.temperature = getOrDefault(temperature, 0.7); this.maxRetries = getOrDefault(maxRetries, 3); diff --git a/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanStreamingChatModel.java b/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanStreamingChatModel.java index 5ff6baa42..dc2550f0b 100644 --- a/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanStreamingChatModel.java +++ b/langchain4j-qianfan/src/main/java/dev/langchain4j/model/qianfan/QianfanStreamingChatModel.java @@ -15,9 +15,12 @@ import dev.langchain4j.model.qianfan.client.chat.ChatCompletionRequest; import dev.langchain4j.model.qianfan.client.chat.ChatCompletionResponse; import dev.langchain4j.model.qianfan.spi.QianfanStreamingChatModelBuilderFactory; import lombok.Builder; -import static dev.langchain4j.model.qianfan.InternalQianfanHelper.*; + +import java.net.Proxy; import java.util.List; + import static dev.langchain4j.internal.Utils.getOrDefault; +import static dev.langchain4j.model.qianfan.InternalQianfanHelper.getSystemMessage; import static dev.langchain4j.spi.ServiceHelper.loadFactories; /** @@ -52,7 +55,8 @@ public class QianfanStreamingChatModel implements StreamingChatLanguageModel { String responseFormat, Double penaltyScore, Boolean logRequests, - Boolean logResponses + Boolean logResponses, + Proxy proxy ) { if (Utils.isNullOrBlank(apiKey)||Utils.isNullOrBlank(secretKey)) { throw new IllegalArgumentException(" api key and secret key must be defined. It can be generated here: https://console.bce.baidu.com/qianfan/ais/console/applicationConsole/application"); @@ -71,6 +75,7 @@ public class QianfanStreamingChatModel implements StreamingChatLanguageModel { .secretKey(secretKey) .logRequests(logRequests) .logStreamingResponses(logResponses) + .proxy(proxy) .build(); this.temperature = getOrDefault(temperature, 0.7); this.topP = topP;