Package org.springframework.ai.openai
Class OpenAiChatModel
java.lang.Object
org.springframework.ai.openai.OpenAiChatModel
- All Implemented Interfaces:
org.springframework.ai.chat.model.ChatModel,org.springframework.ai.chat.model.StreamingChatModel,org.springframework.ai.model.Model<org.springframework.ai.chat.prompt.Prompt,,org.springframework.ai.chat.model.ChatResponse> org.springframework.ai.model.StreamingModel<org.springframework.ai.chat.prompt.Prompt,org.springframework.ai.chat.model.ChatResponse>
public final class OpenAiChatModel
extends Object
implements org.springframework.ai.chat.model.ChatModel
Chat Model implementation using the OpenAI Java SDK.
- Author:
- Julien Dubois, Christian Tzolov, Soby Chacko, Ilayaperumal Gopinathan, Thomas Vitale, Eric Bottard, Taewoong Kim, Jewoo Shin, guan xu
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for creatingOpenAiChatModelinstances.static classResponse format (text, json_object, json_schema) for OpenAiChatModel responses. -
Method Summary
Modifier and TypeMethodDescriptionstatic OpenAiChatModel.Builderbuilder()Creates a new builder forOpenAiChatModel.org.springframework.ai.chat.model.ChatResponsecall(org.springframework.ai.chat.prompt.Prompt prompt) org.springframework.ai.chat.prompt.ChatOptionsDeprecated, for removal: This API element is subject to removal in a future version.Gets the chat options for this model.static com.openai.models.chat.completions.ChatCompletionToolChoiceOptionparseToolChoice(tools.jackson.databind.JsonNode node) voidsetObservationConvention(org.springframework.ai.chat.observation.ChatModelObservationConvention observationConvention) Use the provided convention for reporting observation datareactor.core.publisher.Flux<org.springframework.ai.chat.model.ChatResponse>stream(org.springframework.ai.chat.prompt.Prompt prompt) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.ai.chat.model.ChatModel
call, callMethods inherited from interface org.springframework.ai.chat.model.StreamingChatModel
stream, stream
-
Method Details
-
builder
Creates a new builder forOpenAiChatModel.- Returns:
- a new builder instance
-
getOptions
Gets the chat options for this model.- Specified by:
getOptionsin interfaceorg.springframework.ai.chat.model.ChatModel- Returns:
- the chat options
- Since:
- 2.0.0
-
getDefaultOptions
@Deprecated(forRemoval=true) public org.springframework.ai.chat.prompt.ChatOptions getDefaultOptions()Deprecated, for removal: This API element is subject to removal in a future version.usegetOptions()instead.- Specified by:
getDefaultOptionsin interfaceorg.springframework.ai.chat.model.ChatModel
-
call
public org.springframework.ai.chat.model.ChatResponse call(org.springframework.ai.chat.prompt.Prompt prompt) - Specified by:
callin interfaceorg.springframework.ai.chat.model.ChatModel- Specified by:
callin interfaceorg.springframework.ai.model.Model<org.springframework.ai.chat.prompt.Prompt,org.springframework.ai.chat.model.ChatResponse>
-
stream
public reactor.core.publisher.Flux<org.springframework.ai.chat.model.ChatResponse> stream(org.springframework.ai.chat.prompt.Prompt prompt) - Specified by:
streamin interfaceorg.springframework.ai.chat.model.ChatModel- Specified by:
streamin interfaceorg.springframework.ai.chat.model.StreamingChatModel- Specified by:
streamin interfaceorg.springframework.ai.model.StreamingModel<org.springframework.ai.chat.prompt.Prompt,org.springframework.ai.chat.model.ChatResponse>
-
parseToolChoice
public static com.openai.models.chat.completions.ChatCompletionToolChoiceOption parseToolChoice(tools.jackson.databind.JsonNode node) -
setObservationConvention
public void setObservationConvention(org.springframework.ai.chat.observation.ChatModelObservationConvention observationConvention) Use the provided convention for reporting observation data- Parameters:
observationConvention- The provided convention
-
getOptions()instead.