Package org.springframework.ai.openai
Class OpenAiChatModel
java.lang.Object
org.springframework.ai.openai.OpenAiChatModel
- All Implemented Interfaces:
ChatModel,StreamingChatModel,Model<Prompt,,ChatResponse> StreamingModel<Prompt,ChatResponse>
Chat Model implementation using the OpenAI Java SDK.
- Author:
- Julien Dubois, Christian Tzolov, Soby Chacko, Ilayaperumal Gopinathan
-
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.Executes a method call to the AI model.Gets the chat options for this model.static com.openai.models.chat.completions.ChatCompletionToolChoiceOptionparseToolChoice(tools.jackson.databind.JsonNode node) @Nullable AssistantMessagesafeAssistantMessage(@Nullable ChatResponse response) Safely extracts the assistant message from a chat response.voidsetObservationConvention(ChatModelObservationConvention observationConvention) Use the provided convention for reporting observation datareactor.core.publisher.Flux<ChatResponse> Executes a method call to the AI model.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.StreamingChatModel
stream, stream
-
Method Details
-
builder
Creates a new builder forOpenAiChatModel.- Returns:
- a new builder instance
-
getOptions
Gets the chat options for this model.- Returns:
- the chat options
-
call
Description copied from interface:ModelExecutes a method call to the AI model. -
stream
Description copied from interface:StreamingModelExecutes a method call to the AI model.- Specified by:
streamin interfaceChatModel- Specified by:
streamin interfaceStreamingChatModel- Specified by:
streamin interfaceStreamingModel<Prompt,ChatResponse> - Parameters:
prompt- the request object to be sent to the AI model- Returns:
- the streaming response from the AI model
-
safeAssistantMessage
Safely extracts the assistant message from a chat response.- Parameters:
response- the chat response- Returns:
- the assistant message, or null if not available
-
parseToolChoice
public static com.openai.models.chat.completions.ChatCompletionToolChoiceOption parseToolChoice(tools.jackson.databind.JsonNode node) -
getDefaultOptions
- Specified by:
getDefaultOptionsin interfaceChatModel
-
setObservationConvention
Use the provided convention for reporting observation data- Parameters:
observationConvention- The provided convention
-