Class OpenAiSdkChatModel
java.lang.Object
org.springframework.ai.openaisdk.OpenAiSdkChatModel
- All Implemented Interfaces:
ChatModel, StreamingChatModel, Model<Prompt, ChatResponse>, StreamingModel<Prompt, ChatResponse>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classResponse format (text, json_object, json_schema) for OpenAiSdkChatModel responses. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new OpenAiSdkChatModel with default options.OpenAiSdkChatModel(com.openai.client.OpenAIClient openAIClient, com.openai.client.OpenAIClientAsync openAiClientAsync) Creates a new OpenAiSdkChatModel with the given OpenAI clients.OpenAiSdkChatModel(com.openai.client.OpenAIClient openAIClient, com.openai.client.OpenAIClientAsync openAiClientAsync, OpenAiSdkChatOptions options) Creates a new OpenAiSdkChatModel with the given OpenAI clients and options.OpenAiSdkChatModel(com.openai.client.OpenAIClient openAIClient, com.openai.client.OpenAIClientAsync openAiClientAsync, OpenAiSdkChatOptions options, io.micrometer.observation.ObservationRegistry observationRegistry) Creates a new OpenAiSdkChatModel with the given OpenAI clients, options, and observation registry.OpenAiSdkChatModel(com.openai.client.OpenAIClient openAiClient, com.openai.client.OpenAIClientAsync openAiClientAsync, OpenAiSdkChatOptions options, ToolCallingManager toolCallingManager, io.micrometer.observation.ObservationRegistry observationRegistry, ToolExecutionEligibilityPredicate toolExecutionEligibilityPredicate) Creates a new OpenAiSdkChatModel with all configuration options.OpenAiSdkChatModel(OpenAiSdkChatOptions options) Creates a new OpenAiSdkChatModel with the given options.OpenAiSdkChatModel(OpenAiSdkChatOptions options, io.micrometer.observation.ObservationRegistry observationRegistry) Creates a new OpenAiSdkChatModel with the given options and observation registry.OpenAiSdkChatModel(OpenAiSdkChatOptions options, ToolCallingManager toolCallingManager, io.micrometer.observation.ObservationRegistry observationRegistry) Creates a new OpenAiSdkChatModel with the given options, tool calling manager, and observation registry. -
Method Summary
Modifier and TypeMethodDescriptionExecutes a method call to the AI model.Gets the chat options for this model.internalCall(Prompt prompt, ChatResponse previousChatResponse) Internal method to handle chat completion calls with tool execution support.reactor.core.publisher.Flux<ChatResponse> internalStream(Prompt prompt, ChatResponse previousChatResponse) Internal method to handle streaming chat completion calls with tool execution support.static com.openai.models.chat.completions.ChatCompletionToolChoiceOptionparseToolChoice(com.fasterxml.jackson.databind.JsonNode node) safeAssistantMessage(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 Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface StreamingChatModel
stream, stream
-
Constructor Details
-
OpenAiSdkChatModel
public OpenAiSdkChatModel()Creates a new OpenAiSdkChatModel with default options. -
OpenAiSdkChatModel
Creates a new OpenAiSdkChatModel with the given options.- Parameters:
options- the chat options
-
OpenAiSdkChatModel
public OpenAiSdkChatModel(OpenAiSdkChatOptions options, io.micrometer.observation.ObservationRegistry observationRegistry) Creates a new OpenAiSdkChatModel with the given options and observation registry.- Parameters:
options- the chat optionsobservationRegistry- the observation registry
-
OpenAiSdkChatModel
public OpenAiSdkChatModel(OpenAiSdkChatOptions options, ToolCallingManager toolCallingManager, io.micrometer.observation.ObservationRegistry observationRegistry) Creates a new OpenAiSdkChatModel with the given options, tool calling manager, and observation registry.- Parameters:
options- the chat optionstoolCallingManager- the tool calling managerobservationRegistry- the observation registry
-
OpenAiSdkChatModel
public OpenAiSdkChatModel(com.openai.client.OpenAIClient openAIClient, com.openai.client.OpenAIClientAsync openAiClientAsync) Creates a new OpenAiSdkChatModel with the given OpenAI clients.- Parameters:
openAIClient- the synchronous OpenAI clientopenAiClientAsync- the asynchronous OpenAI client
-
OpenAiSdkChatModel
public OpenAiSdkChatModel(com.openai.client.OpenAIClient openAIClient, com.openai.client.OpenAIClientAsync openAiClientAsync, OpenAiSdkChatOptions options) Creates a new OpenAiSdkChatModel with the given OpenAI clients and options.- Parameters:
openAIClient- the synchronous OpenAI clientopenAiClientAsync- the asynchronous OpenAI clientoptions- the chat options
-
OpenAiSdkChatModel
public OpenAiSdkChatModel(com.openai.client.OpenAIClient openAIClient, com.openai.client.OpenAIClientAsync openAiClientAsync, OpenAiSdkChatOptions options, io.micrometer.observation.ObservationRegistry observationRegistry) Creates a new OpenAiSdkChatModel with the given OpenAI clients, options, and observation registry.- Parameters:
openAIClient- the synchronous OpenAI clientopenAiClientAsync- the asynchronous OpenAI clientoptions- the chat optionsobservationRegistry- the observation registry
-
OpenAiSdkChatModel
public OpenAiSdkChatModel(com.openai.client.OpenAIClient openAiClient, com.openai.client.OpenAIClientAsync openAiClientAsync, OpenAiSdkChatOptions options, ToolCallingManager toolCallingManager, io.micrometer.observation.ObservationRegistry observationRegistry, ToolExecutionEligibilityPredicate toolExecutionEligibilityPredicate) Creates a new OpenAiSdkChatModel with all configuration options.- Parameters:
openAiClient- the synchronous OpenAI clientopenAiClientAsync- the asynchronous OpenAI clientoptions- the chat optionstoolCallingManager- the tool calling managerobservationRegistry- the observation registrytoolExecutionEligibilityPredicate- the predicate to determine tool execution eligibility
-
-
Method Details
-
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. -
internalCall
Internal method to handle chat completion calls with tool execution support.- Parameters:
prompt- the prompt for the chat completionpreviousChatResponse- the previous chat response for accumulating usage- Returns:
- the chat response
-
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
-
internalStream
public reactor.core.publisher.Flux<ChatResponse> internalStream(Prompt prompt, ChatResponse previousChatResponse) Internal method to handle streaming chat completion calls with tool execution support.- Parameters:
prompt- the prompt for the chat completionpreviousChatResponse- the previous chat response for accumulating usage- Returns:
- a Flux of chat responses
-
parseToolChoice
public static com.openai.models.chat.completions.ChatCompletionToolChoiceOption parseToolChoice(com.fasterxml.jackson.databind.JsonNode node) -
getDefaultOptions
- Specified by:
getDefaultOptionsin interfaceChatModel
-
setObservationConvention
Use the provided convention for reporting observation data- Parameters:
observationConvention- The provided convention
-