Class OpenAiChatCompletionRequest
java.lang.Object
com.sap.ai.sdk.foundationmodels.openai.OpenAiChatCompletionRequest
Represents a request for OpenAI chat completion, including conversation messages and parameters.
- Since:
- 1.4.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionOpenAiChatCompletionRequest(OpenAiMessage message, OpenAiMessage... messages) Creates an OpenAiChatCompletionPrompt with a multiple unpacked messages.OpenAiChatCompletionRequest(String message) Creates an OpenAiChatCompletionPrompt with string as user message.OpenAiChatCompletionRequest(List<OpenAiMessage> messages) Creates an OpenAiChatCompletionPrompt with a list of messages. -
Method Summary
Modifier and TypeMethodDescriptionbooleaninthashCode()toString()withFrequencyPenalty(BigDecimal frequencyPenalty) Encourage new topic by penalising tokens based on their frequency in the completion.withLogitBias(Map<String, Integer> logitBias) A map that adjusts the likelihood of specified tokens by adding a bias value (between -100 and 100) to the logits before sampling.withLogprobs(Boolean logprobs) Sets the log probabilities option.withMaxCompletionTokens(Integer maxCompletionTokens) Maximum number of tokens that can be generated for the completion, including consumed reasoning tokens.withMaxTokens(Integer maxTokens) Maximum number of tokens that can be generated for the completion.withMessages(List<OpenAiMessage> messages) List of messages from the conversation.Number of completions to generate.withParallelToolCalls(Boolean parallelToolCalls) Sets the parallel tool calls option.withPresencePenalty(BigDecimal presencePenalty) Encourage new topic by penalising token based on their presence in the completion.withResponseFormat(CreateChatCompletionRequestAllOfResponseFormat responseFormat) Response format for the completion.Seed for random number generation.Adds stop sequences to the request.Upto 4 Stop sequences to interrupts token generation and returns a response without them.withStreamOptions(ChatCompletionStreamOptions streamOptions) Options for streaming the completion response.withTemperature(BigDecimal temperature) Controls the randomness of the completion.withToolChoice(OpenAiToolChoice choice) Define the model behavior towards calling functions.withTools(List<ChatCompletionTool> tools) Tools the model may invoke during chat completion (metadata only).withToolsExecutable(List<OpenAiTool> toolsExecutable) Tools the model may invoke during chat completion that are also executable at application runtime.withTopLogprobs(Integer topLogprobs) Number of top log probabilities to return for each token.withTopP(BigDecimal topP) Controls the cumulative probability threshold used for nucleus sampling.Unique identifier for the end-user making the request.
-
Constructor Details
-
OpenAiChatCompletionRequest
Creates an OpenAiChatCompletionPrompt with string as user message.- Parameters:
message- the message to be added to the prompt
-
OpenAiChatCompletionRequest
public OpenAiChatCompletionRequest(@Nonnull OpenAiMessage message, @Nonnull OpenAiMessage... messages) Creates an OpenAiChatCompletionPrompt with a multiple unpacked messages.- Parameters:
message- the primary message to be added to the promptmessages- additional messages to be added to the prompt
-
OpenAiChatCompletionRequest
Creates an OpenAiChatCompletionPrompt with a list of messages.- Parameters:
messages- the list of messages to be added to the prompt- Since:
- 1.6.0
-
-
Method Details
-
withStop
@Nonnull public OpenAiChatCompletionRequest withStop(@Nonnull String sequence, @Nonnull String... sequences) Adds stop sequences to the request.- Parameters:
sequence- the primary stop sequencesequences- additional stop sequences- Returns:
- a new OpenAiChatCompletionRequest instance with the specified stop sequences
-
withParallelToolCalls
@Nonnull public OpenAiChatCompletionRequest withParallelToolCalls(@Nonnull Boolean parallelToolCalls) Sets the parallel tool calls option.- Parameters:
parallelToolCalls- Whether to allow parallel tool calls.- Returns:
- A new instance with the specified option.
-
withLogprobs
Sets the log probabilities option.- Parameters:
logprobs- Whether to include log probabilities in the response.- Returns:
- A new instance with the specified option.
-
withToolChoice
Define the model behavior towards calling functions.Example:
.withToolChoice(OpenAiToolChoice.NONE).withToolChoice(OpenAiToolChoice.OPTIONAL).withToolChoice(OpenAiToolChoice.REQUIRED).withToolChoice(OpenAiToolChoice.function("fibonacci")
- Parameters:
choice- the generic tool choice.- Returns:
- the current OpenAiChatCompletionRequest instance.
-
equals
-
hashCode
public int hashCode() -
toString
-
withMessages
List of messages from the conversation.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withStop
Upto 4 Stop sequences to interrupts token generation and returns a response without them.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withTemperature
Controls the randomness of the completion.Lower values (e.g. 0.0) make the model more deterministic and repetitive, while higher values (e.g. 1.0) make the model more random and creative.
- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withTopP
Controls the cumulative probability threshold used for nucleus sampling. Alternative totemperature.Lower values (e.g. 0.1) limit the model to consider only the smallest set of tokens whose combined probabilities add up to at least 10% of the total.
- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withMaxTokens
Maximum number of tokens that can be generated for the completion.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withMaxCompletionTokens
Maximum number of tokens that can be generated for the completion, including consumed reasoning tokens. This field supersedesmaxTokensand should be used with newer models.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withPresencePenalty
Encourage new topic by penalising token based on their presence in the completion.Value should be in range [-2, 2].
- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withFrequencyPenalty
Encourage new topic by penalising tokens based on their frequency in the completion.Value should be in range [-2, 2].
- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withLogitBias
A map that adjusts the likelihood of specified tokens by adding a bias value (between -100 and 100) to the logits before sampling. Extreme values can effectively ban or enforce the selection of tokens.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withUser
Unique identifier for the end-user making the request. This can help with monitoring and abuse detection.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withTopLogprobs
Number of top log probabilities to return for each token. An integer between 0 and 20. This is only relevant iflogprobsis enabled.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withN
Number of completions to generate.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withSeed
Seed for random number generation.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withStreamOptions
public OpenAiChatCompletionRequest withStreamOptions(@Nullable ChatCompletionStreamOptions streamOptions) Options for streaming the completion response.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withResponseFormat
public OpenAiChatCompletionRequest withResponseFormat(@Nullable CreateChatCompletionRequestAllOfResponseFormat responseFormat) Response format for the completion.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withTools
Tools the model may invoke during chat completion (metadata only).Use
withToolsExecutable(java.util.List<com.sap.ai.sdk.foundationmodels.openai.OpenAiTool>)for registering executable tools.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
withToolsExecutable
Tools the model may invoke during chat completion that are also executable at application runtime.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed). - Since:
- 1.8.0
-