Package dev.langchain4j.model.openai
Class OpenAiStreamingChatModel
java.lang.Object
dev.langchain4j.model.openai.OpenAiStreamingChatModel
- All Implemented Interfaces:
dev.langchain4j.model.chat.StreamingChatLanguageModel
,dev.langchain4j.model.chat.TokenCountEstimator
public class OpenAiStreamingChatModel
extends Object
implements dev.langchain4j.model.chat.StreamingChatLanguageModel, dev.langchain4j.model.chat.TokenCountEstimator
Represents an OpenAI language model with a chat completion interface, such as gpt-3.5-turbo and gpt-4.
The model's response is streamed token by token and should be handled with
StreamingResponseHandler
.
You can find description of parameters here.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
-
Constructor Summary
ConstructorsConstructorDescriptionOpenAiStreamingChatModel
(String baseUrl, String apiKey, String organizationId, String modelName, Double temperature, Double topP, List<String> stop, Integer maxTokens, Integer maxCompletionTokens, Double presencePenalty, Double frequencyPenalty, Map<String, Integer> logitBias, String responseFormat, Integer seed, String user, Boolean strictTools, Boolean parallelToolCalls, Duration timeout, Proxy proxy, Boolean logRequests, Boolean logResponses, dev.langchain4j.model.Tokenizer tokenizer, Map<String, String> customHeaders, List<dev.langchain4j.model.chat.listener.ChatModelListener> listeners) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()
int
estimateTokenCount
(List<dev.langchain4j.data.message.ChatMessage> messages) void
generate
(List<dev.langchain4j.data.message.ChatMessage> messages, dev.langchain4j.agent.tool.ToolSpecification toolSpecification, dev.langchain4j.model.StreamingResponseHandler<dev.langchain4j.data.message.AiMessage> handler) void
generate
(List<dev.langchain4j.data.message.ChatMessage> messages, dev.langchain4j.model.StreamingResponseHandler<dev.langchain4j.data.message.AiMessage> handler) void
generate
(List<dev.langchain4j.data.message.ChatMessage> messages, List<dev.langchain4j.agent.tool.ToolSpecification> toolSpecifications, dev.langchain4j.model.StreamingResponseHandler<dev.langchain4j.data.message.AiMessage> handler) static OpenAiStreamingChatModel
withApiKey
(String apiKey) Deprecated.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface dev.langchain4j.model.chat.StreamingChatLanguageModel
generate, generate
Methods inherited from interface dev.langchain4j.model.chat.TokenCountEstimator
estimateTokenCount, estimateTokenCount, estimateTokenCount, estimateTokenCount
-
Constructor Details
-
OpenAiStreamingChatModel
public OpenAiStreamingChatModel(String baseUrl, String apiKey, String organizationId, String modelName, Double temperature, Double topP, List<String> stop, Integer maxTokens, Integer maxCompletionTokens, Double presencePenalty, Double frequencyPenalty, Map<String, Integer> logitBias, String responseFormat, Integer seed, String user, Boolean strictTools, Boolean parallelToolCalls, Duration timeout, Proxy proxy, Boolean logRequests, Boolean logResponses, dev.langchain4j.model.Tokenizer tokenizer, Map<String, String> customHeaders, List<dev.langchain4j.model.chat.listener.ChatModelListener> listeners)
-
-
Method Details
-
modelName
-
generate
public void generate(List<dev.langchain4j.data.message.ChatMessage> messages, dev.langchain4j.model.StreamingResponseHandler<dev.langchain4j.data.message.AiMessage> handler) - Specified by:
generate
in interfacedev.langchain4j.model.chat.StreamingChatLanguageModel
-
generate
public void generate(List<dev.langchain4j.data.message.ChatMessage> messages, List<dev.langchain4j.agent.tool.ToolSpecification> toolSpecifications, dev.langchain4j.model.StreamingResponseHandler<dev.langchain4j.data.message.AiMessage> handler) - Specified by:
generate
in interfacedev.langchain4j.model.chat.StreamingChatLanguageModel
-
generate
public void generate(List<dev.langchain4j.data.message.ChatMessage> messages, dev.langchain4j.agent.tool.ToolSpecification toolSpecification, dev.langchain4j.model.StreamingResponseHandler<dev.langchain4j.data.message.AiMessage> handler) - Specified by:
generate
in interfacedev.langchain4j.model.chat.StreamingChatLanguageModel
-
estimateTokenCount
- Specified by:
estimateTokenCount
in interfacedev.langchain4j.model.chat.TokenCountEstimator
-
withApiKey
Deprecated.usebuilder()
instead and explicitly set the model name and, if required, other parameters. -
builder
-
builder()
instead and explicitly set the model name and, if required, other parameters.