diff --git a/.pipeline/checkstyle-suppressions.xml b/.pipeline/checkstyle-suppressions.xml index b30fd0568..01c0e6f64 100644 --- a/.pipeline/checkstyle-suppressions.xml +++ b/.pipeline/checkstyle-suppressions.xml @@ -8,7 +8,10 @@ + + + diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/JacksonMixins.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/JacksonMixins.java new file mode 100644 index 000000000..dd50f3515 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/JacksonMixins.java @@ -0,0 +1,14 @@ +package com.sap.ai.sdk.foundationmodels.openai; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionStreamResponse; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +final class JacksonMixins { + @JsonTypeInfo(use = JsonTypeInfo.Id.NONE) + @JsonDeserialize(as = CreateChatCompletionStreamResponse.class) + public interface DefaultChatCompletionCreate200ResponseMixIn {} +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiAssistantMessage.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiAssistantMessage.java new file mode 100644 index 000000000..d2fadda31 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiAssistantMessage.java @@ -0,0 +1,31 @@ +package com.sap.ai.sdk.foundationmodels.openai; + +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestAssistantMessage; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestAssistantMessageContent; +import javax.annotation.Nonnull; +import lombok.Value; +import lombok.experimental.Accessors; + +/** Represents a chat message as 'assistant' to OpenAI service. */ +@Value +@Accessors(fluent = true) +class OpenAiAssistantMessage implements OpenAiMessage { + + /** The role of the message. */ + @Nonnull String role = "assistant"; + + /** The content of the message. */ + @Nonnull String content; + + /** + * Converts the message to a serializable object. + * + * @return the corresponding {@code ChatCompletionRequestAssistantMessage} object. + */ + @Nonnull + public ChatCompletionRequestAssistantMessage createDTO() { + return new ChatCompletionRequestAssistantMessage() + .role(ChatCompletionRequestAssistantMessage.RoleEnum.fromValue(role())) + .content(ChatCompletionRequestAssistantMessageContent.create(content)); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionDelta.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionDelta.java new file mode 100644 index 000000000..c3cfe42ed --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionDelta.java @@ -0,0 +1,74 @@ +package com.sap.ai.sdk.foundationmodels.openai; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.annotations.Beta; +import com.sap.ai.sdk.core.common.StreamedDelta; +import com.sap.ai.sdk.foundationmodels.openai.model2.CompletionUsage; +import com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionStreamResponse; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import lombok.Data; +import lombok.RequiredArgsConstructor; + +/** + * Represents an OpenAI chat completion output delta for streaming. + * + * @since 1.3.0 + */ +@Beta +@Data +@RequiredArgsConstructor(onConstructor_ = @JsonCreator) +public class OpenAiChatCompletionDelta implements StreamedDelta { + /** The original response from the chat completion stream. */ + @Nonnull final CreateChatCompletionStreamResponse originalResponse; + + /** + * Retrieves the delta content from the original response. + * + * @return The delta content as a string, or an empty string if not available. + */ + @Nonnull + @Override + public String getDeltaContent() { + final var choices = getOriginalResponse().getChoices(); + if (!choices.isEmpty() && choices.get(0).getIndex() == 0) { + final var message = choices.get(0).getDelta(); + return Objects.requireNonNullElse(message.getContent(), ""); + } + return ""; + } + + /** + * Retrieves the finish reason from the original response. + * + * @return The finish reason as a string, or null if not available. + */ + @Nullable + @Override + public String getFinishReason() { + final var choices = getOriginalResponse().getChoices(); + if (!choices.isEmpty()) { + final var finishReason = choices.get(0).getFinishReason(); + return finishReason != null ? finishReason.getValue() : null; + } + return null; + } + + /** + * Retrieves the completion usage from the response, or null if it is not available. + * + * @param objectMapper The object mapper to use for conversion. + * @return The completion usage or null. + */ + @Nullable + public CompletionUsage getCompletionUsage(@Nonnull final ObjectMapper objectMapper) { + if (getOriginalResponse().getCustomFieldNames().contains("usage") + && getOriginalResponse().getCustomField("usage") instanceof Map usage) { + return objectMapper.convertValue(usage, CompletionUsage.class); + } + return null; + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionRequest.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionRequest.java new file mode 100644 index 000000000..c54dd8e6b --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionRequest.java @@ -0,0 +1,152 @@ +package com.sap.ai.sdk.foundationmodels.openai; + +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionStreamOptions; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionTool; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionToolChoiceOption; +import com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionRequest; +import com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionRequestAllOfResponseFormat; +import com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionRequestAllOfStop; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * Represents a request for OpenAI chat completion, including conversation messages and parameters. + */ +@Accessors(fluent = true) +@Data +public class OpenAiChatCompletionRequest { + /** List of messages from the conversation. */ + @Nonnull private final List messages = new ArrayList<>(); + + /** Stop sequences for the completion. */ + @Nullable private List stop; + + /** Temperature for the completion. */ + @Nullable private BigDecimal temperature; + + /** Top-p sampling parameter. */ + @Nullable private BigDecimal topP; + + /** Whether to stream the completion. */ + @Nullable private Boolean stream; + + /** Maximum number of tokens for the completion. */ + @Nullable private Integer maxTokens; + + /** Maximum number of tokens for the completion response. */ + @Nullable private Integer maxCompletionTokens; + + /** Presence penalty for the completion. */ + @Nullable private BigDecimal presencePenalty; + + /** Frequency penalty for the completion. */ + @Nullable private BigDecimal frequencyPenalty; + + /** Logit bias for the completion. */ + @Nullable private Map logitBias; + + /** User identifier for the completion. */ + @Nullable private String user; + + /** Whether to include log probabilities in the response. */ + @Nullable private Boolean logprobs; + + /** Number of top log probabilities to include. */ + @Nullable private Integer topLogprobs; + + /** Number of completions to generate. */ + @Nullable private Integer n; + + /** Whether to allow parallel tool calls. */ + @Nullable private Boolean parallelToolCalls; + + /** Seed for random number generation. */ + @Nullable private Integer seed; + + /** Options for streaming the completion. */ + @Nullable private ChatCompletionStreamOptions streamOptions; + + /** Response format for the completion. */ + @Nullable private CreateChatCompletionRequestAllOfResponseFormat responseFormat; + + /** List of tools for the completion. */ + @Nullable private List tools; + + /** Tool choice option for the completion. */ + @Nullable private ChatCompletionToolChoiceOption toolChoice; + + /** + * Creates an OpenAiChatCompletionPrompt with a single message. + * + * @param message the message to be added to the prompt + */ + public OpenAiChatCompletionRequest(@Nonnull final String message) { + messages.add(OpenAiMessage.user(message)); + } + + /** + * Creates an OpenAiChatCompletionPrompt with a multiple unpacked messages. + * + * @param message the primary message to be added to the prompt + * @param messages additional messages to be added to the prompt + */ + public OpenAiChatCompletionRequest( + @Nonnull final OpenAiMessage message, @Nonnull final OpenAiMessage... messages) { + this.messages.add(message); + this.messages.addAll(Arrays.asList(messages)); + } + + /** + * Sets the stop sequences for the prompt. + * + * @param values the stop sequences to be set + * @return the current OpenAiChatCompletionPrompt instance + */ + @Nonnull + public OpenAiChatCompletionRequest stop( + @Nonnull final String value, @Nonnull final String... values) { + this.stop = new ArrayList<>(); + + this.stop.add(value); + this.stop.addAll(Arrays.asList(values)); + + return this; + } + + CreateChatCompletionRequest toCreateChatCompletionRequest() { + final var request = new CreateChatCompletionRequest(); + this.messages().forEach(message -> request.addMessagesItem(message.createDTO())); + + request.stop( + this.stop() != null ? CreateChatCompletionRequestAllOfStop.create(this.stop()) : null); + + request.temperature(this.temperature()); + request.topP(this.topP()); + request.stream(this.stream()); + request.maxTokens(this.maxTokens()); + request.maxCompletionTokens(this.maxCompletionTokens()); + request.presencePenalty(this.presencePenalty()); + request.frequencyPenalty(this.frequencyPenalty()); + request.logitBias(this.logitBias()); + request.user(this.user()); + request.logprobs(this.logprobs()); + request.topLogprobs(this.topLogprobs()); + request.n(this.n()); + request.parallelToolCalls(this.parallelToolCalls()); + request.seed(this.seed()); + request.streamOptions(this.streamOptions()); + request.responseFormat(this.responseFormat()); + request.tools(this.tools()); + request.toolChoice(this.toolChoice()); + request.functionCall(null); + request.functions(null); + return request; + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionResponse.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionResponse.java new file mode 100644 index 000000000..e91217896 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiChatCompletionResponse.java @@ -0,0 +1,55 @@ +package com.sap.ai.sdk.foundationmodels.openai; + +import static com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionResponseChoicesInner.FinishReasonEnum.CONTENT_FILTER; +import static lombok.AccessLevel.PACKAGE; + +import com.sap.ai.sdk.foundationmodels.openai.model2.CompletionUsage; +import com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionResponse; +import com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionResponseChoicesInner; +import java.util.Objects; +import javax.annotation.Nonnull; +import lombok.Data; +import lombok.RequiredArgsConstructor; + +/** Represents the output of an OpenAI chat completion. */ +@Data +@RequiredArgsConstructor(access = PACKAGE) +public class OpenAiChatCompletionResponse { + /** The original response from the OpenAI API. */ + @Nonnull final CreateChatCompletionResponse originalResponse; + + /** + * Gets the token usage from the original response. + * + * @return the token usage + */ + @Nonnull + public CompletionUsage getTokenUsage() { + return getOriginalResponse().getUsage(); + } + + /** + * Gets the first choice from the original response. + * + * @return the first choice + */ + @Nonnull + public CreateChatCompletionResponseChoicesInner getChoice() { + return getOriginalResponse().getChoices().get(0); + } + + /** + * Gets the content of the first choice. + * + * @return the content of the first choice + * @throws OpenAiClientException if the content is filtered by the content filter + */ + @Nonnull + public String getContent() { + if (CONTENT_FILTER.equals(getOriginalResponse().getChoices().get(0).getFinishReason())) { + throw new OpenAiClientException("Content filter filtered the output."); + } + + return Objects.requireNonNullElse(getChoice().getMessage().getContent(), ""); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClient.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClient.java index 8699201a7..d3fae6761 100644 --- a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClient.java +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClient.java @@ -10,14 +10,17 @@ import com.sap.ai.sdk.core.common.ClientResponseHandler; import com.sap.ai.sdk.core.common.ClientStreamingHandler; import com.sap.ai.sdk.core.common.StreamedDelta; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionDelta; import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionOutput; import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionParameters; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatMessage.OpenAiChatSystemMessage; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatMessage.OpenAiChatUserMessage; import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiEmbeddingOutput; import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiEmbeddingParameters; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiError; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionStreamOptions; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionsCreate200Response; +import com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionRequest; +import com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionResponse; +import com.sap.ai.sdk.foundationmodels.openai.model2.EmbeddingsCreate200Response; +import com.sap.ai.sdk.foundationmodels.openai.model2.EmbeddingsCreateRequest; +import com.sap.ai.sdk.foundationmodels.openai.model2.EmbeddingsCreateRequestInput; import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor; import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination; import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; @@ -40,10 +43,16 @@ public final class OpenAiClient { private static final String DEFAULT_API_VERSION = "2024-02-01"; static final ObjectMapper JACKSON = getDefaultObjectMapper(); - @Nullable private String systemPrompt = null; + @Nullable private OpenAiMessage systemPrompt = null; @Nonnull private final Destination destination; + static { + JACKSON.addMixIn( + ChatCompletionsCreate200Response.class, + JacksonMixins.DefaultChatCompletionCreate200ResponseMixIn.class); + } + /** * Create a new OpenAI client for the given foundation model, using the default resource group. * @@ -107,42 +116,86 @@ public static OpenAiClient withCustomDestination(@Nonnull final Destination dest } /** - * Add a system prompt before user prompts. + * Use this method to set a system prompt that should be used across multiple chat completions + * with basic string prompts {@link #streamChatCompletionDeltas(OpenAiChatCompletionRequest)}. + * + *

Note: The system prompt will be ignored on chat completions invoked with + * OpenAiChatCompletionPrompt. * * @param systemPrompt the system prompt * @return the client */ @Nonnull public OpenAiClient withSystemPrompt(@Nonnull final String systemPrompt) { - this.systemPrompt = systemPrompt; + this.systemPrompt = OpenAiMessage.system(systemPrompt); return this; } /** - * Generate a completion for the given user prompt. + * Generate a completion for the given string prompt as user. * * @param prompt a text message. * @return the completion output * @throws OpenAiClientException if the request fails */ @Nonnull - public OpenAiChatCompletionOutput chatCompletion(@Nonnull final String prompt) + public OpenAiChatCompletionResponse chatCompletion(@Nonnull final String prompt) throws OpenAiClientException { - final OpenAiChatCompletionParameters parameters = new OpenAiChatCompletionParameters(); - if (systemPrompt != null) { - parameters.addMessages(new OpenAiChatSystemMessage().setContent(systemPrompt)); + final var userPrompt = OpenAiMessage.user(prompt); + + final var request = + (systemPrompt != null) + ? new OpenAiChatCompletionRequest(systemPrompt, userPrompt) + : new OpenAiChatCompletionRequest(userPrompt); + + return new OpenAiChatCompletionResponse( + chatCompletion(request.toCreateChatCompletionRequest())); + } + + private static void throwOnContentFilter(@Nonnull final OpenAiChatCompletionDelta delta) { + final String finishReason = delta.getFinishReason(); + if (finishReason != null && finishReason.equals("content_filter")) { + throw new OpenAiClientException("Content filter filtered the output."); } - parameters.addMessages(new OpenAiChatUserMessage().addText(prompt)); - return chatCompletion(parameters); } /** - * Generate a completion for the given prompt. + * Generate a completion for the given conversation and request parameters. + * + * @param request the completion request. + * @return the completion output + * @throws OpenAiClientException if the request fails + */ + @Nonnull + public OpenAiChatCompletionResponse chatCompletion( + @Nonnull final OpenAiChatCompletionRequest request) throws OpenAiClientException { + warnIfUnsupportedUsage(); + return new OpenAiChatCompletionResponse( + chatCompletion(request.toCreateChatCompletionRequest())); + } + + /** + * Generate a completion for the given low-level request object. + * + * @param request the completion request. + * @return the completion output + * @throws OpenAiClientException if the request fails + */ + @Nonnull + public CreateChatCompletionResponse chatCompletion( + @Nonnull final CreateChatCompletionRequest request) throws OpenAiClientException { + return execute("/chat/completions", request, CreateChatCompletionResponse.class); + } + + /** + * Generate a completion for the given conversation and request parameters. * - * @param parameters the prompt, including messages and other parameters. + * @param parameters the completion request. * @return the completion output * @throws OpenAiClientException if the request fails + * @deprecated Use {@link #chatCompletion(OpenAiChatCompletionRequest)} instead. */ + @Deprecated(since = "1.3.0") @Nonnull public OpenAiChatCompletionOutput chatCompletion( @Nonnull final OpenAiChatCompletionParameters parameters) throws OpenAiClientException { @@ -151,9 +204,10 @@ public OpenAiChatCompletionOutput chatCompletion( } /** - * Stream a completion for the given prompt. Returns a lazily populated stream of text - * chunks. To access more details about the individual chunks, use {@link - * #streamChatCompletionDeltas(OpenAiChatCompletionParameters)}. + * Stream a completion for the given string prompt as user. + * + *

Returns a lazily populated stream of text chunks. To access more details about the + * individual chunks, use {@link #streamChatCompletionDeltas(OpenAiChatCompletionRequest)}. * *

The stream should be consumed using a try-with-resources block to ensure that the underlying * HTTP connection is closed. @@ -171,33 +225,30 @@ public OpenAiChatCompletionOutput chatCompletion( * Stream#parallel()} on this stream is not supported. * * @param prompt a text message. - * @return A stream of message deltas + * @return A stream of text chunks * @throws OpenAiClientException if the request fails or if the finish reason is content_filter - * @see #streamChatCompletionDeltas(OpenAiChatCompletionParameters) + * @see #streamChatCompletionDeltas(OpenAiChatCompletionRequest) */ @Nonnull public Stream streamChatCompletion(@Nonnull final String prompt) throws OpenAiClientException { - final OpenAiChatCompletionParameters parameters = new OpenAiChatCompletionParameters(); - if (systemPrompt != null) { - parameters.addMessages(new OpenAiChatSystemMessage().setContent(systemPrompt)); - } - parameters.addMessages(new OpenAiChatUserMessage().addText(prompt)); - return streamChatCompletionDeltas(parameters) + final var userPrompt = OpenAiMessage.user(prompt); + + final var request = + systemPrompt != null + ? new OpenAiChatCompletionRequest(systemPrompt, userPrompt) + : new OpenAiChatCompletionRequest(userPrompt); + + return streamChatCompletionDeltas(request.toCreateChatCompletionRequest()) .peek(OpenAiClient::throwOnContentFilter) .map(OpenAiChatCompletionDelta::getDeltaContent); } - private static void throwOnContentFilter(@Nonnull final OpenAiChatCompletionDelta delta) { - final String finishReason = delta.getFinishReason(); - if (finishReason != null && finishReason.equals("content_filter")) { - throw new OpenAiClientException("Content filter filtered the output."); - } - } - /** - * Stream a completion for the given prompt. Returns a lazily populated stream of delta - * objects. To simply stream the text chunks use {@link #streamChatCompletion(String)} + * Stream a completion for the given conversation and request parameters. + * + *

Returns a lazily populated stream of delta objects. To simply stream the text chunks + * use {@link #streamChatCompletion(String)} * *

The stream should be consumed using a try-with-resources block to ensure that the underlying * HTTP connection is closed. @@ -205,7 +256,7 @@ private static void throwOnContentFilter(@Nonnull final OpenAiChatCompletionDelt *

Example: * *

{@code
-   * try (var stream = client.streamChatCompletionDeltas(params)) {
+   * try (var stream = client.streamChatCompletionDeltas(prompt)) {
    *       stream
    *           .peek(delta -> System.out.println(delta.getUsage()))
    *           .map(OpenAiChatCompletionDelta::getDeltaContent)
@@ -217,17 +268,73 @@ private static void throwOnContentFilter(@Nonnull final OpenAiChatCompletionDelt
    * block until all chunks are consumed. Also, for obvious reasons, invoking {@link
    * Stream#parallel()} on this stream is not supported.
    *
-   * @param parameters The prompt, including messages and other parameters.
+   * @param request The prompt, including a list of messages.
    * @return A stream of message deltas
    * @throws OpenAiClientException if the request fails or if the finish reason is content_filter
    * @see #streamChatCompletion(String)
    */
   @Nonnull
   public Stream streamChatCompletionDeltas(
-      @Nonnull final OpenAiChatCompletionParameters parameters) throws OpenAiClientException {
+      @Nonnull final OpenAiChatCompletionRequest request) throws OpenAiClientException {
+    return streamChatCompletionDeltas(request.toCreateChatCompletionRequest());
+  }
+
+  /**
+   * Stream a completion for the given low-level request object. Returns a lazily populated
+   * stream of delta objects.
+   *
+   * @param request The completion request.
+   * @return A stream of message deltas
+   * @throws OpenAiClientException if the request fails or if the finish reason is content_filter
+   * @see #streamChatCompletionDeltas(OpenAiChatCompletionRequest) for a higher-level API
+   */
+  @Nonnull
+  public Stream streamChatCompletionDeltas(
+      @Nonnull final CreateChatCompletionRequest request) throws OpenAiClientException {
+    request.stream(true).streamOptions(new ChatCompletionStreamOptions().includeUsage(true));
+    return executeStream("/chat/completions", request, OpenAiChatCompletionDelta.class);
+  }
+
+  /**
+   * Stream a completion for the given conversation and request parameters.
+   *
+   * 

Returns a lazily populated stream of delta objects. To simply stream the text chunks + * use {@link #streamChatCompletion(String)} + * + *

The stream should be consumed using a try-with-resources block to ensure that the underlying + * HTTP connection is closed. + * + *

Example: + * + *

{@code
+   * try (var stream = client.streamChatCompletionDeltas(request)) {
+   *       stream
+   *           .peek(delta -> System.out.println(delta.getUsage()))
+   *           .map(com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionDelta::getDeltaContent)
+   *           .forEach(System.out::println);
+   * }
+   * }
+ * + *

Please keep in mind that using a terminal stream operation like {@link Stream#forEach} will + * block until all chunks are consumed. Also, for obvious reasons, invoking {@link + * Stream#parallel()} on this stream is not supported. + * + * @param parameters The prompt, including a list of messages. + * @return A stream of message deltas + * @throws OpenAiClientException if the request fails or if the finish reason is content_filter + * @deprecated Use {@link #streamChatCompletionDeltas(OpenAiChatCompletionRequest)} instead. + */ + @Deprecated(since = "1.3.0") + @Nonnull + public Stream + streamChatCompletionDeltas(@Nonnull final OpenAiChatCompletionParameters parameters) + throws OpenAiClientException { warnIfUnsupportedUsage(); parameters.enableStreaming(); - return executeStream("/chat/completions", parameters, OpenAiChatCompletionDelta.class); + return executeStream( + "/chat/completions", + parameters, + com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionDelta.class); } private void warnIfUnsupportedUsage() { @@ -237,6 +344,35 @@ private void warnIfUnsupportedUsage() { } } + /** + * Get a vector representation of a given string input that can be easily consumed by machine + * learning models and algorithms. + * + * @param input the input text. + * @return the embedding output + * @throws OpenAiClientException if the request fails + */ + @Nonnull + public EmbeddingsCreate200Response embedding(@Nonnull final String input) + throws OpenAiClientException { + return embedding( + new EmbeddingsCreateRequest().input(EmbeddingsCreateRequestInput.create(input))); + } + + /** + * Get a vector representation of a given request with input that can be easily consumed by + * machine learning models and algorithms. + * + * @param request the request with input text. + * @return the embedding output + * @throws OpenAiClientException if the request fails + */ + @Nonnull + public EmbeddingsCreate200Response embedding(@Nonnull final EmbeddingsCreateRequest request) + throws OpenAiClientException { + return execute("/embeddings", request, EmbeddingsCreate200Response.class); + } + /** * Get a vector representation of a given input that can be easily consumed by machine learning * models and algorithms. @@ -300,6 +436,7 @@ private Stream streamRequest( try { final var client = ApacheHttpClient5Accessor.getHttpClient(destination); return new ClientStreamingHandler<>(deltaType, OpenAiError.class, OpenAiClientException::new) + .objectMapper(JACKSON) .handleStreamingResponse(client.executeOpen(null, request, null)); } catch (final IOException e) { throw new OpenAiClientException("Request to OpenAI model failed", e); diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiError.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiError.java new file mode 100644 index 000000000..7c732ea8d --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiError.java @@ -0,0 +1,31 @@ +package com.sap.ai.sdk.foundationmodels.openai; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.google.common.annotations.Beta; +import com.sap.ai.sdk.core.common.ClientError; +import com.sap.ai.sdk.foundationmodels.openai.model2.ErrorResponse; +import javax.annotation.Nonnull; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Value; +import lombok.experimental.Delegate; + +/** Represents an error response from the OpenAI API. */ +@Beta +@Value +@AllArgsConstructor(onConstructor = @__({@JsonCreator}), access = AccessLevel.PROTECTED) +public class OpenAiError implements ClientError { + /** The original error response from the OpenAI API. */ + @Delegate(types = {ClientError.class}) + ErrorResponse originalResponse; + + /** + * Gets the error message from the contained original response. + * + * @return the error message + */ + @Nonnull + public String getMessage() { + return originalResponse.getError().getMessage(); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiMessage.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiMessage.java new file mode 100644 index 000000000..cb62c630c --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiMessage.java @@ -0,0 +1,49 @@ +package com.sap.ai.sdk.foundationmodels.openai; + +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestMessage; +import javax.annotation.Nonnull; + +/** Interface representing convenience wrappers of chat message to the openai service. */ +public interface OpenAiMessage { + + /** + * A convenience method to create a user message. + * + * @param msg the message content. + * @return the user message. + */ + @Nonnull + static OpenAiMessage user(@Nonnull final String msg) { + return new OpenAiUserMessage(msg); + } + + /** + * A convenience method to create an assistant message. + * + * @param msg the message content. + * @return the assistant message. + */ + @Nonnull + static OpenAiMessage assistant(@Nonnull final String msg) { + return new OpenAiAssistantMessage(msg); + } + + /** + * A convenience method to create a system message. + * + * @param msg the message content. + * @return the system message. + */ + @Nonnull + static OpenAiMessage system(@Nonnull final String msg) { + return new OpenAiSystemMessage(msg); + } + + /** + * Converts the message to a serializable object. + * + * @return the corresponding serializable object. + */ + @Nonnull + ChatCompletionRequestMessage createDTO(); +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiSystemMessage.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiSystemMessage.java new file mode 100644 index 000000000..739c9ff5a --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiSystemMessage.java @@ -0,0 +1,31 @@ +package com.sap.ai.sdk.foundationmodels.openai; + +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestSystemMessage; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestSystemMessageContent; +import javax.annotation.Nonnull; +import lombok.Value; +import lombok.experimental.Accessors; + +/** Represents a chat message as 'system' to OpenAI service. */ +@Value +@Accessors(fluent = true) +class OpenAiSystemMessage implements OpenAiMessage { + + /** The role of the message. */ + @Nonnull String role = "system"; + + /** The content of the message. */ + @Nonnull String content; + + /** + * Converts the message to a serializable object. + * + * @return the corresponding {@code ChatCompletionRequestSystemMessage} object. + */ + @Nonnull + public ChatCompletionRequestSystemMessage createDTO() { + return new ChatCompletionRequestSystemMessage() + .role(ChatCompletionRequestSystemMessage.RoleEnum.fromValue(role())) + .content(ChatCompletionRequestSystemMessageContent.create(content())); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiUserMessage.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiUserMessage.java new file mode 100644 index 000000000..6dc2cd6a3 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiUserMessage.java @@ -0,0 +1,31 @@ +package com.sap.ai.sdk.foundationmodels.openai; + +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestUserMessage; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestUserMessageContent; +import javax.annotation.Nonnull; +import lombok.Value; +import lombok.experimental.Accessors; + +/** Represents a chat message as 'user' to OpenAI service. */ +@Value +@Accessors(fluent = true) +class OpenAiUserMessage implements OpenAiMessage { + + /** The role of the message. */ + @Nonnull String role = "user"; + + /** The content of the message. */ + @Nonnull String content; + + /** + * Converts the message to a serializable object. + * + * @return the corresponding {@code ChatCompletionRequestUserMessage} object. + */ + @Nonnull + public ChatCompletionRequestUserMessage createDTO() { + return new ChatCompletionRequestUserMessage() + .role(ChatCompletionRequestUserMessage.RoleEnum.fromValue(role())) + .content(ChatCompletionRequestUserMessageContent.create(content())); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionFunctionCall.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionFunctionCall.java new file mode 100644 index 000000000..6575f33ad --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionFunctionCall.java @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Deprecated and replaced by `tool_calls`. The name and arguments of a function that + * should be called, as generated by the model. + */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionFunctionCall +// CHECKSTYLE:ON +{ + @JsonProperty("name") + private String name; + + @JsonProperty("arguments") + private String arguments; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the name of this {@link ChatCompletionFunctionCall} instance and return the same instance. + * + * @param name The name of the function to call. + * @return The same instance of this {@link ChatCompletionFunctionCall} class + */ + @Nonnull + public ChatCompletionFunctionCall name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * The name of the function to call. + * + * @return name The name of this {@link ChatCompletionFunctionCall} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link ChatCompletionFunctionCall} instance. + * + * @param name The name of the function to call. + */ + public void setName(@Nonnull final String name) { + this.name = name; + } + + /** + * Set the arguments of this {@link ChatCompletionFunctionCall} instance and return the same + * instance. + * + * @param arguments The arguments to call the function with, as generated by the model in JSON + * format. Note that the model does not always generate valid JSON, and may hallucinate + * parameters not defined by your function schema. Validate the arguments in your code before + * calling your function. + * @return The same instance of this {@link ChatCompletionFunctionCall} class + */ + @Nonnull + public ChatCompletionFunctionCall arguments(@Nonnull final String arguments) { + this.arguments = arguments; + return this; + } + + /** + * The arguments to call the function with, as generated by the model in JSON format. Note that + * the model does not always generate valid JSON, and may hallucinate parameters not defined by + * your function schema. Validate the arguments in your code before calling your function. + * + * @return arguments The arguments of this {@link ChatCompletionFunctionCall} instance. + */ + @Nonnull + public String getArguments() { + return arguments; + } + + /** + * Set the arguments of this {@link ChatCompletionFunctionCall} instance. + * + * @param arguments The arguments to call the function with, as generated by the model in JSON + * format. Note that the model does not always generate valid JSON, and may hallucinate + * parameters not defined by your function schema. Validate the arguments in your code before + * calling your function. + */ + public void setArguments(@Nonnull final String arguments) { + this.arguments = arguments; + } + + /** + * Get the names of the unrecognizable properties of the {@link ChatCompletionFunctionCall}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionFunctionCall} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionFunctionCall has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionFunctionCall} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionFunctionCall chatCompletionFunctionCall = (ChatCompletionFunctionCall) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionFunctionCall.cloudSdkCustomFields) + && Objects.equals(this.name, chatCompletionFunctionCall.name) + && Objects.equals(this.arguments, chatCompletionFunctionCall.arguments); + } + + @Override + public int hashCode() { + return Objects.hash(name, arguments, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionFunctionCall {\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" arguments: ").append(toIndentedString(arguments)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionFunctionCallOption.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionFunctionCallOption.java new file mode 100644 index 000000000..14cd0ed3d --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionFunctionCallOption.java @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Specifying a particular function via `{\"name\": \"my_function\"}` + * forces the model to call that function. + */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionFunctionCallOption +// CHECKSTYLE:ON +{ + @JsonProperty("name") + private String name; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the name of this {@link ChatCompletionFunctionCallOption} instance and return the same + * instance. + * + * @param name The name of the function to call. + * @return The same instance of this {@link ChatCompletionFunctionCallOption} class + */ + @Nonnull + public ChatCompletionFunctionCallOption name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * The name of the function to call. + * + * @return name The name of this {@link ChatCompletionFunctionCallOption} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link ChatCompletionFunctionCallOption} instance. + * + * @param name The name of the function to call. + */ + public void setName(@Nonnull final String name) { + this.name = name; + } + + /** + * Get the names of the unrecognizable properties of the {@link ChatCompletionFunctionCallOption}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionFunctionCallOption} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionFunctionCallOption has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionFunctionCallOption} instance. If + * the map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionFunctionCallOption chatCompletionFunctionCallOption = + (ChatCompletionFunctionCallOption) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionFunctionCallOption.cloudSdkCustomFields) + && Objects.equals(this.name, chatCompletionFunctionCallOption.name); + } + + @Override + public int hashCode() { + return Objects.hash(name, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionFunctionCallOption {\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionFunctions.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionFunctions.java new file mode 100644 index 000000000..8315d0f80 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionFunctions.java @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * ChatCompletionFunctions + * + * @deprecated + */ +@Deprecated +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionFunctions +// CHECKSTYLE:ON +{ + @JsonProperty("description") + private String description; + + @JsonProperty("name") + private String name; + + @JsonProperty("parameters") + private Map parameters = new HashMap<>(); + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the description of this {@link ChatCompletionFunctions} instance and return the same + * instance. + * + * @param description A description of what the function does, used by the model to choose when + * and how to call the function. + * @return The same instance of this {@link ChatCompletionFunctions} class + */ + @Nonnull + public ChatCompletionFunctions description(@Nullable final String description) { + this.description = description; + return this; + } + + /** + * A description of what the function does, used by the model to choose when and how to call the + * function. + * + * @return description The description of this {@link ChatCompletionFunctions} instance. + */ + @Nonnull + public String getDescription() { + return description; + } + + /** + * Set the description of this {@link ChatCompletionFunctions} instance. + * + * @param description A description of what the function does, used by the model to choose when + * and how to call the function. + */ + public void setDescription(@Nullable final String description) { + this.description = description; + } + + /** + * Set the name of this {@link ChatCompletionFunctions} instance and return the same instance. + * + * @param name The name of the function to be called. Must be a-z, A-Z, 0-9, or contain + * underscores and dashes, with a maximum length of 64. + * @return The same instance of this {@link ChatCompletionFunctions} class + */ + @Nonnull + public ChatCompletionFunctions name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and + * dashes, with a maximum length of 64. + * + * @return name The name of this {@link ChatCompletionFunctions} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link ChatCompletionFunctions} instance. + * + * @param name The name of the function to be called. Must be a-z, A-Z, 0-9, or contain + * underscores and dashes, with a maximum length of 64. + */ + public void setName(@Nonnull final String name) { + this.name = name; + } + + /** + * Set the parameters of this {@link ChatCompletionFunctions} instance and return the same + * instance. + * + * @param parameters The parameters the functions accepts, described as a JSON Schema object. See + * the + * guide](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/function-calling) + * for examples, and the [JSON Schema + * reference](https://json-schema.org/understanding-json-schema/) for documentation about the + * format. Omitting `parameters` defines a function with an empty parameter list. + * @return The same instance of this {@link ChatCompletionFunctions} class + */ + @Nonnull + public ChatCompletionFunctions parameters(@Nullable final Map parameters) { + this.parameters = parameters; + return this; + } + + /** + * Put one parameters instance to this {@link ChatCompletionFunctions} instance. + * + * @param key The String key of this parameters instance + * @param parametersItem The parameters that should be added under the given key + * @return The same instance of type {@link ChatCompletionFunctions} + */ + @Nonnull + public ChatCompletionFunctions putparametersItem( + @Nonnull final String key, @Nullable final Object parametersItem) { + if (this.parameters == null) { + this.parameters = new HashMap<>(); + } + this.parameters.put(key, parametersItem); + return this; + } + + /** + * The parameters the functions accepts, described as a JSON Schema object. See the + * guide](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/function-calling) for + * examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) + * for documentation about the format. Omitting `parameters` defines a function with an + * empty parameter list. + * + * @return parameters The parameters of this {@link ChatCompletionFunctions} instance. + */ + @Nonnull + public Map getParameters() { + return parameters; + } + + /** + * Set the parameters of this {@link ChatCompletionFunctions} instance. + * + * @param parameters The parameters the functions accepts, described as a JSON Schema object. See + * the + * guide](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/function-calling) + * for examples, and the [JSON Schema + * reference](https://json-schema.org/understanding-json-schema/) for documentation about the + * format. Omitting `parameters` defines a function with an empty parameter list. + */ + public void setParameters(@Nullable final Map parameters) { + this.parameters = parameters; + } + + /** + * Get the names of the unrecognizable properties of the {@link ChatCompletionFunctions}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionFunctions} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionFunctions has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionFunctions} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionFunctions chatCompletionFunctions = (ChatCompletionFunctions) o; + return Objects.equals(this.cloudSdkCustomFields, chatCompletionFunctions.cloudSdkCustomFields) + && Objects.equals(this.description, chatCompletionFunctions.description) + && Objects.equals(this.name, chatCompletionFunctions.name) + && Objects.equals(this.parameters, chatCompletionFunctions.parameters); + } + + @Override + public int hashCode() { + return Objects.hash(description, name, parameters, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionFunctions {\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" parameters: ").append(toIndentedString(parameters)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionMessageToolCall.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionMessageToolCall.java new file mode 100644 index 000000000..4c55c8ff3 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionMessageToolCall.java @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionMessageToolCall */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionMessageToolCall +// CHECKSTYLE:ON +{ + @JsonProperty("id") + private String id; + + @JsonProperty("type") + private ToolCallType type; + + @JsonProperty("function") + private ChatCompletionMessageToolCallFunction function; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the id of this {@link ChatCompletionMessageToolCall} instance and return the same instance. + * + * @param id The ID of the tool call. + * @return The same instance of this {@link ChatCompletionMessageToolCall} class + */ + @Nonnull + public ChatCompletionMessageToolCall id(@Nonnull final String id) { + this.id = id; + return this; + } + + /** + * The ID of the tool call. + * + * @return id The id of this {@link ChatCompletionMessageToolCall} instance. + */ + @Nonnull + public String getId() { + return id; + } + + /** + * Set the id of this {@link ChatCompletionMessageToolCall} instance. + * + * @param id The ID of the tool call. + */ + public void setId(@Nonnull final String id) { + this.id = id; + } + + /** + * Set the type of this {@link ChatCompletionMessageToolCall} instance and return the same + * instance. + * + * @param type The type of this {@link ChatCompletionMessageToolCall} + * @return The same instance of this {@link ChatCompletionMessageToolCall} class + */ + @Nonnull + public ChatCompletionMessageToolCall type(@Nonnull final ToolCallType type) { + this.type = type; + return this; + } + + /** + * Get type + * + * @return type The type of this {@link ChatCompletionMessageToolCall} instance. + */ + @Nonnull + public ToolCallType getType() { + return type; + } + + /** + * Set the type of this {@link ChatCompletionMessageToolCall} instance. + * + * @param type The type of this {@link ChatCompletionMessageToolCall} + */ + public void setType(@Nonnull final ToolCallType type) { + this.type = type; + } + + /** + * Set the function of this {@link ChatCompletionMessageToolCall} instance and return the same + * instance. + * + * @param function The function of this {@link ChatCompletionMessageToolCall} + * @return The same instance of this {@link ChatCompletionMessageToolCall} class + */ + @Nonnull + public ChatCompletionMessageToolCall function( + @Nonnull final ChatCompletionMessageToolCallFunction function) { + this.function = function; + return this; + } + + /** + * Get function + * + * @return function The function of this {@link ChatCompletionMessageToolCall} instance. + */ + @Nonnull + public ChatCompletionMessageToolCallFunction getFunction() { + return function; + } + + /** + * Set the function of this {@link ChatCompletionMessageToolCall} instance. + * + * @param function The function of this {@link ChatCompletionMessageToolCall} + */ + public void setFunction(@Nonnull final ChatCompletionMessageToolCallFunction function) { + this.function = function; + } + + /** + * Get the names of the unrecognizable properties of the {@link ChatCompletionMessageToolCall}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionMessageToolCall} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionMessageToolCall has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionMessageToolCall} instance. If the + * map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionMessageToolCall chatCompletionMessageToolCall = + (ChatCompletionMessageToolCall) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionMessageToolCall.cloudSdkCustomFields) + && Objects.equals(this.id, chatCompletionMessageToolCall.id) + && Objects.equals(this.type, chatCompletionMessageToolCall.type) + && Objects.equals(this.function, chatCompletionMessageToolCall.function); + } + + @Override + public int hashCode() { + return Objects.hash(id, type, function, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionMessageToolCall {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" function: ").append(toIndentedString(function)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionMessageToolCallChunk.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionMessageToolCallChunk.java new file mode 100644 index 000000000..17cec9e62 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionMessageToolCallChunk.java @@ -0,0 +1,324 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionMessageToolCallChunk */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionMessageToolCallChunk +// CHECKSTYLE:ON +{ + @JsonProperty("index") + private Integer index; + + @JsonProperty("id") + private String id; + + /** The type of the tool. Currently, only `function` is supported. */ + public enum TypeEnum { + /** The FUNCTION option of this ChatCompletionMessageToolCallChunk */ + FUNCTION("function"); + + private String value; + + TypeEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ChatCompletionMessageToolCallChunk + */ + @JsonCreator + @Nonnull + public static TypeEnum fromValue(@Nonnull final String value) { + for (TypeEnum b : TypeEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("type") + private TypeEnum type; + + @JsonProperty("function") + private ChatCompletionMessageToolCallChunkFunction function; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the index of this {@link ChatCompletionMessageToolCallChunk} instance and return the same + * instance. + * + * @param index The index of this {@link ChatCompletionMessageToolCallChunk} + * @return The same instance of this {@link ChatCompletionMessageToolCallChunk} class + */ + @Nonnull + public ChatCompletionMessageToolCallChunk index(@Nonnull final Integer index) { + this.index = index; + return this; + } + + /** + * Get index + * + * @return index The index of this {@link ChatCompletionMessageToolCallChunk} instance. + */ + @Nonnull + public Integer getIndex() { + return index; + } + + /** + * Set the index of this {@link ChatCompletionMessageToolCallChunk} instance. + * + * @param index The index of this {@link ChatCompletionMessageToolCallChunk} + */ + public void setIndex(@Nonnull final Integer index) { + this.index = index; + } + + /** + * Set the id of this {@link ChatCompletionMessageToolCallChunk} instance and return the same + * instance. + * + * @param id The ID of the tool call. + * @return The same instance of this {@link ChatCompletionMessageToolCallChunk} class + */ + @Nonnull + public ChatCompletionMessageToolCallChunk id(@Nullable final String id) { + this.id = id; + return this; + } + + /** + * The ID of the tool call. + * + * @return id The id of this {@link ChatCompletionMessageToolCallChunk} instance. + */ + @Nonnull + public String getId() { + return id; + } + + /** + * Set the id of this {@link ChatCompletionMessageToolCallChunk} instance. + * + * @param id The ID of the tool call. + */ + public void setId(@Nullable final String id) { + this.id = id; + } + + /** + * Set the type of this {@link ChatCompletionMessageToolCallChunk} instance and return the same + * instance. + * + * @param type The type of the tool. Currently, only `function` is supported. + * @return The same instance of this {@link ChatCompletionMessageToolCallChunk} class + */ + @Nonnull + public ChatCompletionMessageToolCallChunk type(@Nullable final TypeEnum type) { + this.type = type; + return this; + } + + /** + * The type of the tool. Currently, only `function` is supported. + * + * @return type The type of this {@link ChatCompletionMessageToolCallChunk} instance. + */ + @Nonnull + public TypeEnum getType() { + return type; + } + + /** + * Set the type of this {@link ChatCompletionMessageToolCallChunk} instance. + * + * @param type The type of the tool. Currently, only `function` is supported. + */ + public void setType(@Nullable final TypeEnum type) { + this.type = type; + } + + /** + * Set the function of this {@link ChatCompletionMessageToolCallChunk} instance and return the + * same instance. + * + * @param function The function of this {@link ChatCompletionMessageToolCallChunk} + * @return The same instance of this {@link ChatCompletionMessageToolCallChunk} class + */ + @Nonnull + public ChatCompletionMessageToolCallChunk function( + @Nullable final ChatCompletionMessageToolCallChunkFunction function) { + this.function = function; + return this; + } + + /** + * Get function + * + * @return function The function of this {@link ChatCompletionMessageToolCallChunk} instance. + */ + @Nonnull + public ChatCompletionMessageToolCallChunkFunction getFunction() { + return function; + } + + /** + * Set the function of this {@link ChatCompletionMessageToolCallChunk} instance. + * + * @param function The function of this {@link ChatCompletionMessageToolCallChunk} + */ + public void setFunction(@Nullable final ChatCompletionMessageToolCallChunkFunction function) { + this.function = function; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionMessageToolCallChunk}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionMessageToolCallChunk} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionMessageToolCallChunk has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionMessageToolCallChunk} instance. If + * the map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionMessageToolCallChunk chatCompletionMessageToolCallChunk = + (ChatCompletionMessageToolCallChunk) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionMessageToolCallChunk.cloudSdkCustomFields) + && Objects.equals(this.index, chatCompletionMessageToolCallChunk.index) + && Objects.equals(this.id, chatCompletionMessageToolCallChunk.id) + && Objects.equals(this.type, chatCompletionMessageToolCallChunk.type) + && Objects.equals(this.function, chatCompletionMessageToolCallChunk.function); + } + + @Override + public int hashCode() { + return Objects.hash(index, id, type, function, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionMessageToolCallChunk {\n"); + sb.append(" index: ").append(toIndentedString(index)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" function: ").append(toIndentedString(function)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionMessageToolCallChunkFunction.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionMessageToolCallChunkFunction.java new file mode 100644 index 000000000..68531d3a2 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionMessageToolCallChunkFunction.java @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionMessageToolCallChunkFunction */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionMessageToolCallChunkFunction +// CHECKSTYLE:ON +{ + @JsonProperty("name") + private String name; + + @JsonProperty("arguments") + private String arguments; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the name of this {@link ChatCompletionMessageToolCallChunkFunction} instance and return the + * same instance. + * + * @param name The name of the function to call. + * @return The same instance of this {@link ChatCompletionMessageToolCallChunkFunction} class + */ + @Nonnull + public ChatCompletionMessageToolCallChunkFunction name(@Nullable final String name) { + this.name = name; + return this; + } + + /** + * The name of the function to call. + * + * @return name The name of this {@link ChatCompletionMessageToolCallChunkFunction} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link ChatCompletionMessageToolCallChunkFunction} instance. + * + * @param name The name of the function to call. + */ + public void setName(@Nullable final String name) { + this.name = name; + } + + /** + * Set the arguments of this {@link ChatCompletionMessageToolCallChunkFunction} instance and + * return the same instance. + * + * @param arguments The arguments to call the function with, as generated by the model in JSON + * format. Note that the model does not always generate valid JSON, and may hallucinate + * parameters not defined by your function schema. Validate the arguments in your code before + * calling your function. + * @return The same instance of this {@link ChatCompletionMessageToolCallChunkFunction} class + */ + @Nonnull + public ChatCompletionMessageToolCallChunkFunction arguments(@Nullable final String arguments) { + this.arguments = arguments; + return this; + } + + /** + * The arguments to call the function with, as generated by the model in JSON format. Note that + * the model does not always generate valid JSON, and may hallucinate parameters not defined by + * your function schema. Validate the arguments in your code before calling your function. + * + * @return arguments The arguments of this {@link ChatCompletionMessageToolCallChunkFunction} + * instance. + */ + @Nonnull + public String getArguments() { + return arguments; + } + + /** + * Set the arguments of this {@link ChatCompletionMessageToolCallChunkFunction} instance. + * + * @param arguments The arguments to call the function with, as generated by the model in JSON + * format. Note that the model does not always generate valid JSON, and may hallucinate + * parameters not defined by your function schema. Validate the arguments in your code before + * calling your function. + */ + public void setArguments(@Nullable final String arguments) { + this.arguments = arguments; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionMessageToolCallChunkFunction}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * ChatCompletionMessageToolCallChunkFunction} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionMessageToolCallChunkFunction has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionMessageToolCallChunkFunction} + * instance. If the map previously contained a mapping for the key, the old value is replaced by + * the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionMessageToolCallChunkFunction chatCompletionMessageToolCallChunkFunction = + (ChatCompletionMessageToolCallChunkFunction) o; + return Objects.equals( + this.cloudSdkCustomFields, + chatCompletionMessageToolCallChunkFunction.cloudSdkCustomFields) + && Objects.equals(this.name, chatCompletionMessageToolCallChunkFunction.name) + && Objects.equals(this.arguments, chatCompletionMessageToolCallChunkFunction.arguments); + } + + @Override + public int hashCode() { + return Objects.hash(name, arguments, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionMessageToolCallChunkFunction {\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" arguments: ").append(toIndentedString(arguments)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionMessageToolCallFunction.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionMessageToolCallFunction.java new file mode 100644 index 000000000..fceb95fcf --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionMessageToolCallFunction.java @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** The function that the model called. */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionMessageToolCallFunction +// CHECKSTYLE:ON +{ + @JsonProperty("name") + private String name; + + @JsonProperty("arguments") + private String arguments; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the name of this {@link ChatCompletionMessageToolCallFunction} instance and return the same + * instance. + * + * @param name The name of the function to call. + * @return The same instance of this {@link ChatCompletionMessageToolCallFunction} class + */ + @Nonnull + public ChatCompletionMessageToolCallFunction name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * The name of the function to call. + * + * @return name The name of this {@link ChatCompletionMessageToolCallFunction} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link ChatCompletionMessageToolCallFunction} instance. + * + * @param name The name of the function to call. + */ + public void setName(@Nonnull final String name) { + this.name = name; + } + + /** + * Set the arguments of this {@link ChatCompletionMessageToolCallFunction} instance and return the + * same instance. + * + * @param arguments The arguments to call the function with, as generated by the model in JSON + * format. Note that the model does not always generate valid JSON, and may hallucinate + * parameters not defined by your function schema. Validate the arguments in your code before + * calling your function. + * @return The same instance of this {@link ChatCompletionMessageToolCallFunction} class + */ + @Nonnull + public ChatCompletionMessageToolCallFunction arguments(@Nonnull final String arguments) { + this.arguments = arguments; + return this; + } + + /** + * The arguments to call the function with, as generated by the model in JSON format. Note that + * the model does not always generate valid JSON, and may hallucinate parameters not defined by + * your function schema. Validate the arguments in your code before calling your function. + * + * @return arguments The arguments of this {@link ChatCompletionMessageToolCallFunction} instance. + */ + @Nonnull + public String getArguments() { + return arguments; + } + + /** + * Set the arguments of this {@link ChatCompletionMessageToolCallFunction} instance. + * + * @param arguments The arguments to call the function with, as generated by the model in JSON + * format. Note that the model does not always generate valid JSON, and may hallucinate + * parameters not defined by your function schema. Validate the arguments in your code before + * calling your function. + */ + public void setArguments(@Nonnull final String arguments) { + this.arguments = arguments; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionMessageToolCallFunction}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * ChatCompletionMessageToolCallFunction} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionMessageToolCallFunction has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionMessageToolCallFunction} instance. + * If the map previously contained a mapping for the key, the old value is replaced by the + * specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionMessageToolCallFunction chatCompletionMessageToolCallFunction = + (ChatCompletionMessageToolCallFunction) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionMessageToolCallFunction.cloudSdkCustomFields) + && Objects.equals(this.name, chatCompletionMessageToolCallFunction.name) + && Objects.equals(this.arguments, chatCompletionMessageToolCallFunction.arguments); + } + + @Override + public int hashCode() { + return Objects.hash(name, arguments, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionMessageToolCallFunction {\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" arguments: ").append(toIndentedString(arguments)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionNamedToolChoice.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionNamedToolChoice.java new file mode 100644 index 000000000..59e1f3fee --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionNamedToolChoice.java @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** Specifies a tool the model should use. Use to force the model to call a specific function. */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionNamedToolChoice +// CHECKSTYLE:ON +{ + /** The type of the tool. Currently, only `function` is supported. */ + public enum TypeEnum { + /** The FUNCTION option of this ChatCompletionNamedToolChoice */ + FUNCTION("function"); + + private String value; + + TypeEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ChatCompletionNamedToolChoice + */ + @JsonCreator + @Nonnull + public static TypeEnum fromValue(@Nonnull final String value) { + for (TypeEnum b : TypeEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("type") + private TypeEnum type; + + @JsonProperty("function") + private ChatCompletionNamedToolChoiceFunction function; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the type of this {@link ChatCompletionNamedToolChoice} instance and return the same + * instance. + * + * @param type The type of the tool. Currently, only `function` is supported. + * @return The same instance of this {@link ChatCompletionNamedToolChoice} class + */ + @Nonnull + public ChatCompletionNamedToolChoice type(@Nonnull final TypeEnum type) { + this.type = type; + return this; + } + + /** + * The type of the tool. Currently, only `function` is supported. + * + * @return type The type of this {@link ChatCompletionNamedToolChoice} instance. + */ + @Nonnull + public TypeEnum getType() { + return type; + } + + /** + * Set the type of this {@link ChatCompletionNamedToolChoice} instance. + * + * @param type The type of the tool. Currently, only `function` is supported. + */ + public void setType(@Nonnull final TypeEnum type) { + this.type = type; + } + + /** + * Set the function of this {@link ChatCompletionNamedToolChoice} instance and return the same + * instance. + * + * @param function The function of this {@link ChatCompletionNamedToolChoice} + * @return The same instance of this {@link ChatCompletionNamedToolChoice} class + */ + @Nonnull + public ChatCompletionNamedToolChoice function( + @Nonnull final ChatCompletionNamedToolChoiceFunction function) { + this.function = function; + return this; + } + + /** + * Get function + * + * @return function The function of this {@link ChatCompletionNamedToolChoice} instance. + */ + @Nonnull + public ChatCompletionNamedToolChoiceFunction getFunction() { + return function; + } + + /** + * Set the function of this {@link ChatCompletionNamedToolChoice} instance. + * + * @param function The function of this {@link ChatCompletionNamedToolChoice} + */ + public void setFunction(@Nonnull final ChatCompletionNamedToolChoiceFunction function) { + this.function = function; + } + + /** + * Get the names of the unrecognizable properties of the {@link ChatCompletionNamedToolChoice}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionNamedToolChoice} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionNamedToolChoice has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionNamedToolChoice} instance. If the + * map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionNamedToolChoice chatCompletionNamedToolChoice = + (ChatCompletionNamedToolChoice) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionNamedToolChoice.cloudSdkCustomFields) + && Objects.equals(this.type, chatCompletionNamedToolChoice.type) + && Objects.equals(this.function, chatCompletionNamedToolChoice.function); + } + + @Override + public int hashCode() { + return Objects.hash(type, function, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionNamedToolChoice {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" function: ").append(toIndentedString(function)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionNamedToolChoiceFunction.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionNamedToolChoiceFunction.java new file mode 100644 index 000000000..a71fa9162 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionNamedToolChoiceFunction.java @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionNamedToolChoiceFunction */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionNamedToolChoiceFunction +// CHECKSTYLE:ON +{ + @JsonProperty("name") + private String name; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the name of this {@link ChatCompletionNamedToolChoiceFunction} instance and return the same + * instance. + * + * @param name The name of the function to call. + * @return The same instance of this {@link ChatCompletionNamedToolChoiceFunction} class + */ + @Nonnull + public ChatCompletionNamedToolChoiceFunction name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * The name of the function to call. + * + * @return name The name of this {@link ChatCompletionNamedToolChoiceFunction} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link ChatCompletionNamedToolChoiceFunction} instance. + * + * @param name The name of the function to call. + */ + public void setName(@Nonnull final String name) { + this.name = name; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionNamedToolChoiceFunction}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * ChatCompletionNamedToolChoiceFunction} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionNamedToolChoiceFunction has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionNamedToolChoiceFunction} instance. + * If the map previously contained a mapping for the key, the old value is replaced by the + * specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionNamedToolChoiceFunction chatCompletionNamedToolChoiceFunction = + (ChatCompletionNamedToolChoiceFunction) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionNamedToolChoiceFunction.cloudSdkCustomFields) + && Objects.equals(this.name, chatCompletionNamedToolChoiceFunction.name); + } + + @Override + public int hashCode() { + return Objects.hash(name, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionNamedToolChoiceFunction {\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestAssistantMessage.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestAssistantMessage.java new file mode 100644 index 000000000..f27181a2a --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestAssistantMessage.java @@ -0,0 +1,426 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionRequestAssistantMessage */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionRequestAssistantMessage implements ChatCompletionRequestMessage +// CHECKSTYLE:ON +{ + @JsonProperty("content") + private ChatCompletionRequestAssistantMessageContent content; + + @JsonProperty("refusal") + private String refusal; + + /** The role of the messages author, in this case `assistant`. */ + public enum RoleEnum { + /** The ASSISTANT option of this ChatCompletionRequestAssistantMessage */ + ASSISTANT("assistant"); + + private String value; + + RoleEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ChatCompletionRequestAssistantMessage + */ + @JsonCreator + @Nonnull + public static RoleEnum fromValue(@Nonnull final String value) { + for (RoleEnum b : RoleEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("role") + private RoleEnum role; + + @JsonProperty("name") + private String name; + + @JsonProperty("tool_calls") + private List toolCalls = new ArrayList<>(); + + @JsonProperty("function_call") + private ChatCompletionRequestAssistantMessageFunctionCall functionCall; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the content of this {@link ChatCompletionRequestAssistantMessage} instance and return the + * same instance. + * + * @param content The content of this {@link ChatCompletionRequestAssistantMessage} + * @return The same instance of this {@link ChatCompletionRequestAssistantMessage} class + */ + @Nonnull + public ChatCompletionRequestAssistantMessage content( + @Nullable final ChatCompletionRequestAssistantMessageContent content) { + this.content = content; + return this; + } + + /** + * Get content + * + * @return content The content of this {@link ChatCompletionRequestAssistantMessage} instance. + */ + @Nullable + public ChatCompletionRequestAssistantMessageContent getContent() { + return content; + } + + /** + * Set the content of this {@link ChatCompletionRequestAssistantMessage} instance. + * + * @param content The content of this {@link ChatCompletionRequestAssistantMessage} + */ + public void setContent(@Nullable final ChatCompletionRequestAssistantMessageContent content) { + this.content = content; + } + + /** + * Set the refusal of this {@link ChatCompletionRequestAssistantMessage} instance and return the + * same instance. + * + * @param refusal The refusal message by the assistant. + * @return The same instance of this {@link ChatCompletionRequestAssistantMessage} class + */ + @Nonnull + public ChatCompletionRequestAssistantMessage refusal(@Nullable final String refusal) { + this.refusal = refusal; + return this; + } + + /** + * The refusal message by the assistant. + * + * @return refusal The refusal of this {@link ChatCompletionRequestAssistantMessage} instance. + */ + @Nullable + public String getRefusal() { + return refusal; + } + + /** + * Set the refusal of this {@link ChatCompletionRequestAssistantMessage} instance. + * + * @param refusal The refusal message by the assistant. + */ + public void setRefusal(@Nullable final String refusal) { + this.refusal = refusal; + } + + /** + * Set the role of this {@link ChatCompletionRequestAssistantMessage} instance and return the same + * instance. + * + * @param role The role of the messages author, in this case `assistant`. + * @return The same instance of this {@link ChatCompletionRequestAssistantMessage} class + */ + @Nonnull + public ChatCompletionRequestAssistantMessage role(@Nonnull final RoleEnum role) { + this.role = role; + return this; + } + + /** + * The role of the messages author, in this case `assistant`. + * + * @return role The role of this {@link ChatCompletionRequestAssistantMessage} instance. + */ + @Nonnull + public RoleEnum getRole() { + return role; + } + + /** + * Set the role of this {@link ChatCompletionRequestAssistantMessage} instance. + * + * @param role The role of the messages author, in this case `assistant`. + */ + public void setRole(@Nonnull final RoleEnum role) { + this.role = role; + } + + /** + * Set the name of this {@link ChatCompletionRequestAssistantMessage} instance and return the same + * instance. + * + * @param name An optional name for the participant. Provides the model information to + * differentiate between participants of the same role. + * @return The same instance of this {@link ChatCompletionRequestAssistantMessage} class + */ + @Nonnull + public ChatCompletionRequestAssistantMessage name(@Nullable final String name) { + this.name = name; + return this; + } + + /** + * An optional name for the participant. Provides the model information to differentiate between + * participants of the same role. + * + * @return name The name of this {@link ChatCompletionRequestAssistantMessage} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link ChatCompletionRequestAssistantMessage} instance. + * + * @param name An optional name for the participant. Provides the model information to + * differentiate between participants of the same role. + */ + public void setName(@Nullable final String name) { + this.name = name; + } + + /** + * Set the toolCalls of this {@link ChatCompletionRequestAssistantMessage} instance and return the + * same instance. + * + * @param toolCalls The tool calls generated by the model, such as function calls. + * @return The same instance of this {@link ChatCompletionRequestAssistantMessage} class + */ + @Nonnull + public ChatCompletionRequestAssistantMessage toolCalls( + @Nullable final List toolCalls) { + this.toolCalls = toolCalls; + return this; + } + + /** + * Add one toolCalls instance to this {@link ChatCompletionRequestAssistantMessage}. + * + * @param toolCallsItem The toolCalls that should be added + * @return The same instance of type {@link ChatCompletionRequestAssistantMessage} + */ + @Nonnull + public ChatCompletionRequestAssistantMessage addToolCallsItem( + @Nonnull final ChatCompletionMessageToolCall toolCallsItem) { + if (this.toolCalls == null) { + this.toolCalls = new ArrayList<>(); + } + this.toolCalls.add(toolCallsItem); + return this; + } + + /** + * The tool calls generated by the model, such as function calls. + * + * @return toolCalls The toolCalls of this {@link ChatCompletionRequestAssistantMessage} instance. + */ + @Nonnull + public List getToolCalls() { + return toolCalls; + } + + /** + * Set the toolCalls of this {@link ChatCompletionRequestAssistantMessage} instance. + * + * @param toolCalls The tool calls generated by the model, such as function calls. + */ + public void setToolCalls(@Nullable final List toolCalls) { + this.toolCalls = toolCalls; + } + + /** + * Set the functionCall of this {@link ChatCompletionRequestAssistantMessage} instance and return + * the same instance. + * + * @param functionCall The functionCall of this {@link ChatCompletionRequestAssistantMessage} + * @return The same instance of this {@link ChatCompletionRequestAssistantMessage} class + */ + @Nonnull + public ChatCompletionRequestAssistantMessage functionCall( + @Nullable final ChatCompletionRequestAssistantMessageFunctionCall functionCall) { + this.functionCall = functionCall; + return this; + } + + /** + * Get functionCall + * + * @return functionCall The functionCall of this {@link ChatCompletionRequestAssistantMessage} + * instance. + * @deprecated + */ + @Deprecated + @Nullable + public ChatCompletionRequestAssistantMessageFunctionCall getFunctionCall() { + return functionCall; + } + + /** + * Set the functionCall of this {@link ChatCompletionRequestAssistantMessage} instance. + * + * @param functionCall The functionCall of this {@link ChatCompletionRequestAssistantMessage} + */ + public void setFunctionCall( + @Nullable final ChatCompletionRequestAssistantMessageFunctionCall functionCall) { + this.functionCall = functionCall; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionRequestAssistantMessage}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * ChatCompletionRequestAssistantMessage} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionRequestAssistantMessage has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionRequestAssistantMessage} instance. + * If the map previously contained a mapping for the key, the old value is replaced by the + * specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionRequestAssistantMessage chatCompletionRequestAssistantMessage = + (ChatCompletionRequestAssistantMessage) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionRequestAssistantMessage.cloudSdkCustomFields) + && Objects.equals(this.content, chatCompletionRequestAssistantMessage.content) + && Objects.equals(this.refusal, chatCompletionRequestAssistantMessage.refusal) + && Objects.equals(this.role, chatCompletionRequestAssistantMessage.role) + && Objects.equals(this.name, chatCompletionRequestAssistantMessage.name) + && Objects.equals(this.toolCalls, chatCompletionRequestAssistantMessage.toolCalls) + && Objects.equals(this.functionCall, chatCompletionRequestAssistantMessage.functionCall); + } + + @Override + public int hashCode() { + return Objects.hash( + content, refusal, role, name, toolCalls, functionCall, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionRequestAssistantMessage {\n"); + sb.append(" content: ").append(toIndentedString(content)).append("\n"); + sb.append(" refusal: ").append(toIndentedString(refusal)).append("\n"); + sb.append(" role: ").append(toIndentedString(role)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" toolCalls: ").append(toIndentedString(toolCalls)).append("\n"); + sb.append(" functionCall: ").append(toIndentedString(functionCall)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestAssistantMessageContent.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestAssistantMessageContent.java new file mode 100644 index 000000000..3f0ff3cf7 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestAssistantMessageContent.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import java.util.List; + +/** + * The contents of the assistant message. Required unless `tool_calls` or + * `function_call` is specified. + */ +@com.google.common.annotations.Beta +public interface ChatCompletionRequestAssistantMessageContent { + /** + * Helper class to create a String that implements {@link + * ChatCompletionRequestAssistantMessageContent}. + */ + record InnerString(@com.fasterxml.jackson.annotation.JsonValue String value) + implements ChatCompletionRequestAssistantMessageContent {} + + /** + * Creator to enable deserialization of a String. + * + * @param val the value to use + * @return a new instance of {@link InnerString}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + static InnerString create(String val) { + return new InnerString(val); + } + + /** + * Helper class to create a list of ChatCompletionRequestAssistantMessageContentPart that + * implements {@link ChatCompletionRequestAssistantMessageContent}. + */ + record InnerChatCompletionRequestAssistantMessageContentParts( + @com.fasterxml.jackson.annotation.JsonValue + List values) + implements ChatCompletionRequestAssistantMessageContent {} + + /** + * Creator to enable deserialization of a list of + * ChatCompletionRequestAssistantMessageContentPart. + * + * @param val the value to use + * @return a new instance of {@link InnerChatCompletionRequestAssistantMessageContentParts}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + static InnerChatCompletionRequestAssistantMessageContentParts create( + List val) { + return new InnerChatCompletionRequestAssistantMessageContentParts(val); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestAssistantMessageContentPart.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestAssistantMessageContentPart.java new file mode 100644 index 000000000..adec1bb15 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestAssistantMessageContentPart.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +/** ChatCompletionRequestAssistantMessageContentPart */ +@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION) +@JsonSubTypes({ + @JsonSubTypes.Type(value = ChatCompletionRequestMessageContentPartRefusal.class), + @JsonSubTypes.Type(value = ChatCompletionRequestMessageContentPartText.class), +}) +@com.google.common.annotations.Beta +public interface ChatCompletionRequestAssistantMessageContentPart {} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestAssistantMessageFunctionCall.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestAssistantMessageFunctionCall.java new file mode 100644 index 000000000..d0765edd2 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestAssistantMessageFunctionCall.java @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Deprecated and replaced by `tool_calls`. The name and arguments of a function that + * should be called, as generated by the model. + * + * @deprecated + */ +@Deprecated +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionRequestAssistantMessageFunctionCall +// CHECKSTYLE:ON +{ + @JsonProperty("arguments") + private String arguments; + + @JsonProperty("name") + private String name; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the arguments of this {@link ChatCompletionRequestAssistantMessageFunctionCall} instance + * and return the same instance. + * + * @param arguments The arguments to call the function with, as generated by the model in JSON + * format. Note that the model does not always generate valid JSON, and may hallucinate + * parameters not defined by your function schema. Validate the arguments in your code before + * calling your function. + * @return The same instance of this {@link ChatCompletionRequestAssistantMessageFunctionCall} + * class + */ + @Nonnull + public ChatCompletionRequestAssistantMessageFunctionCall arguments( + @Nonnull final String arguments) { + this.arguments = arguments; + return this; + } + + /** + * The arguments to call the function with, as generated by the model in JSON format. Note that + * the model does not always generate valid JSON, and may hallucinate parameters not defined by + * your function schema. Validate the arguments in your code before calling your function. + * + * @return arguments The arguments of this {@link + * ChatCompletionRequestAssistantMessageFunctionCall} instance. + */ + @Nonnull + public String getArguments() { + return arguments; + } + + /** + * Set the arguments of this {@link ChatCompletionRequestAssistantMessageFunctionCall} instance. + * + * @param arguments The arguments to call the function with, as generated by the model in JSON + * format. Note that the model does not always generate valid JSON, and may hallucinate + * parameters not defined by your function schema. Validate the arguments in your code before + * calling your function. + */ + public void setArguments(@Nonnull final String arguments) { + this.arguments = arguments; + } + + /** + * Set the name of this {@link ChatCompletionRequestAssistantMessageFunctionCall} instance and + * return the same instance. + * + * @param name The name of the function to call. + * @return The same instance of this {@link ChatCompletionRequestAssistantMessageFunctionCall} + * class + */ + @Nonnull + public ChatCompletionRequestAssistantMessageFunctionCall name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * The name of the function to call. + * + * @return name The name of this {@link ChatCompletionRequestAssistantMessageFunctionCall} + * instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link ChatCompletionRequestAssistantMessageFunctionCall} instance. + * + * @param name The name of the function to call. + */ + public void setName(@Nonnull final String name) { + this.name = name; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionRequestAssistantMessageFunctionCall}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * ChatCompletionRequestAssistantMessageFunctionCall} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionRequestAssistantMessageFunctionCall has no field with name '" + + name + + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link + * ChatCompletionRequestAssistantMessageFunctionCall} instance. If the map previously contained a + * mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionRequestAssistantMessageFunctionCall + chatCompletionRequestAssistantMessageFunctionCall = + (ChatCompletionRequestAssistantMessageFunctionCall) o; + return Objects.equals( + this.cloudSdkCustomFields, + chatCompletionRequestAssistantMessageFunctionCall.cloudSdkCustomFields) + && Objects.equals( + this.arguments, chatCompletionRequestAssistantMessageFunctionCall.arguments) + && Objects.equals(this.name, chatCompletionRequestAssistantMessageFunctionCall.name); + } + + @Override + public int hashCode() { + return Objects.hash(arguments, name, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionRequestAssistantMessageFunctionCall {\n"); + sb.append(" arguments: ").append(toIndentedString(arguments)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestFunctionMessage.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestFunctionMessage.java new file mode 100644 index 000000000..7cdedfd40 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestFunctionMessage.java @@ -0,0 +1,291 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * ChatCompletionRequestFunctionMessage + * + * @deprecated + */ +@Deprecated +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionRequestFunctionMessage implements ChatCompletionRequestMessage +// CHECKSTYLE:ON +{ + /** The role of the messages author, in this case `function`. */ + public enum RoleEnum { + /** The FUNCTION option of this ChatCompletionRequestFunctionMessage */ + FUNCTION("function"); + + private String value; + + RoleEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ChatCompletionRequestFunctionMessage + */ + @JsonCreator + @Nonnull + public static RoleEnum fromValue(@Nonnull final String value) { + for (RoleEnum b : RoleEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("role") + private RoleEnum role; + + @JsonProperty("content") + private String content; + + @JsonProperty("name") + private String name; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the role of this {@link ChatCompletionRequestFunctionMessage} instance and return the same + * instance. + * + * @param role The role of the messages author, in this case `function`. + * @return The same instance of this {@link ChatCompletionRequestFunctionMessage} class + */ + @Nonnull + public ChatCompletionRequestFunctionMessage role(@Nonnull final RoleEnum role) { + this.role = role; + return this; + } + + /** + * The role of the messages author, in this case `function`. + * + * @return role The role of this {@link ChatCompletionRequestFunctionMessage} instance. + */ + @Nonnull + public RoleEnum getRole() { + return role; + } + + /** + * Set the role of this {@link ChatCompletionRequestFunctionMessage} instance. + * + * @param role The role of the messages author, in this case `function`. + */ + public void setRole(@Nonnull final RoleEnum role) { + this.role = role; + } + + /** + * Set the content of this {@link ChatCompletionRequestFunctionMessage} instance and return the + * same instance. + * + * @param content The contents of the function message. + * @return The same instance of this {@link ChatCompletionRequestFunctionMessage} class + */ + @Nonnull + public ChatCompletionRequestFunctionMessage content(@Nullable final String content) { + this.content = content; + return this; + } + + /** + * The contents of the function message. + * + * @return content The content of this {@link ChatCompletionRequestFunctionMessage} instance. + */ + @Nullable + public String getContent() { + return content; + } + + /** + * Set the content of this {@link ChatCompletionRequestFunctionMessage} instance. + * + * @param content The contents of the function message. + */ + public void setContent(@Nullable final String content) { + this.content = content; + } + + /** + * Set the name of this {@link ChatCompletionRequestFunctionMessage} instance and return the same + * instance. + * + * @param name The name of the function to call. + * @return The same instance of this {@link ChatCompletionRequestFunctionMessage} class + */ + @Nonnull + public ChatCompletionRequestFunctionMessage name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * The name of the function to call. + * + * @return name The name of this {@link ChatCompletionRequestFunctionMessage} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link ChatCompletionRequestFunctionMessage} instance. + * + * @param name The name of the function to call. + */ + public void setName(@Nonnull final String name) { + this.name = name; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionRequestFunctionMessage}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * ChatCompletionRequestFunctionMessage} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionRequestFunctionMessage has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionRequestFunctionMessage} instance. + * If the map previously contained a mapping for the key, the old value is replaced by the + * specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionRequestFunctionMessage chatCompletionRequestFunctionMessage = + (ChatCompletionRequestFunctionMessage) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionRequestFunctionMessage.cloudSdkCustomFields) + && Objects.equals(this.role, chatCompletionRequestFunctionMessage.role) + && Objects.equals(this.content, chatCompletionRequestFunctionMessage.content) + && Objects.equals(this.name, chatCompletionRequestFunctionMessage.name); + } + + @Override + public int hashCode() { + return Objects.hash(role, content, name, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionRequestFunctionMessage {\n"); + sb.append(" role: ").append(toIndentedString(role)).append("\n"); + sb.append(" content: ").append(toIndentedString(content)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessage.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessage.java new file mode 100644 index 000000000..c36594d40 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessage.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +/** ChatCompletionRequestMessage */ +@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION) +@JsonSubTypes({ + @JsonSubTypes.Type(value = ChatCompletionRequestAssistantMessage.class), + @JsonSubTypes.Type(value = ChatCompletionRequestFunctionMessage.class), + @JsonSubTypes.Type(value = ChatCompletionRequestSystemMessage.class), + @JsonSubTypes.Type(value = ChatCompletionRequestToolMessage.class), + @JsonSubTypes.Type(value = ChatCompletionRequestUserMessage.class), +}) +@com.google.common.annotations.Beta +public interface ChatCompletionRequestMessage {} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageContentPartImage.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageContentPartImage.java new file mode 100644 index 000000000..7e2941e5f --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageContentPartImage.java @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionRequestMessageContentPartImage */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionRequestMessageContentPartImage + implements ChatCompletionRequestUserMessageContentPart +// CHECKSTYLE:ON +{ + /** The type of the content part. */ + public enum TypeEnum { + /** The IMAGE_URL option of this ChatCompletionRequestMessageContentPartImage */ + IMAGE_URL("image_url"); + + private String value; + + TypeEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ChatCompletionRequestMessageContentPartImage + */ + @JsonCreator + @Nonnull + public static TypeEnum fromValue(@Nonnull final String value) { + for (TypeEnum b : TypeEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("type") + private TypeEnum type; + + @JsonProperty("image_url") + private ChatCompletionRequestMessageContentPartImageImageUrl imageUrl; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the type of this {@link ChatCompletionRequestMessageContentPartImage} instance and return + * the same instance. + * + * @param type The type of the content part. + * @return The same instance of this {@link ChatCompletionRequestMessageContentPartImage} class + */ + @Nonnull + public ChatCompletionRequestMessageContentPartImage type(@Nonnull final TypeEnum type) { + this.type = type; + return this; + } + + /** + * The type of the content part. + * + * @return type The type of this {@link ChatCompletionRequestMessageContentPartImage} instance. + */ + @Nonnull + public TypeEnum getType() { + return type; + } + + /** + * Set the type of this {@link ChatCompletionRequestMessageContentPartImage} instance. + * + * @param type The type of the content part. + */ + public void setType(@Nonnull final TypeEnum type) { + this.type = type; + } + + /** + * Set the imageUrl of this {@link ChatCompletionRequestMessageContentPartImage} instance and + * return the same instance. + * + * @param imageUrl The imageUrl of this {@link ChatCompletionRequestMessageContentPartImage} + * @return The same instance of this {@link ChatCompletionRequestMessageContentPartImage} class + */ + @Nonnull + public ChatCompletionRequestMessageContentPartImage imageUrl( + @Nonnull final ChatCompletionRequestMessageContentPartImageImageUrl imageUrl) { + this.imageUrl = imageUrl; + return this; + } + + /** + * Get imageUrl + * + * @return imageUrl The imageUrl of this {@link ChatCompletionRequestMessageContentPartImage} + * instance. + */ + @Nonnull + public ChatCompletionRequestMessageContentPartImageImageUrl getImageUrl() { + return imageUrl; + } + + /** + * Set the imageUrl of this {@link ChatCompletionRequestMessageContentPartImage} instance. + * + * @param imageUrl The imageUrl of this {@link ChatCompletionRequestMessageContentPartImage} + */ + public void setImageUrl( + @Nonnull final ChatCompletionRequestMessageContentPartImageImageUrl imageUrl) { + this.imageUrl = imageUrl; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionRequestMessageContentPartImage}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * ChatCompletionRequestMessageContentPartImage} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionRequestMessageContentPartImage has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionRequestMessageContentPartImage} + * instance. If the map previously contained a mapping for the key, the old value is replaced by + * the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionRequestMessageContentPartImage + chatCompletionRequestMessageContentPartImage = + (ChatCompletionRequestMessageContentPartImage) o; + return Objects.equals( + this.cloudSdkCustomFields, + chatCompletionRequestMessageContentPartImage.cloudSdkCustomFields) + && Objects.equals(this.type, chatCompletionRequestMessageContentPartImage.type) + && Objects.equals(this.imageUrl, chatCompletionRequestMessageContentPartImage.imageUrl); + } + + @Override + public int hashCode() { + return Objects.hash(type, imageUrl, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionRequestMessageContentPartImage {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" imageUrl: ").append(toIndentedString(imageUrl)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageContentPartImageImageUrl.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageContentPartImageImageUrl.java new file mode 100644 index 000000000..cd8fca0c6 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageContentPartImageImageUrl.java @@ -0,0 +1,271 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.net.URI; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionRequestMessageContentPartImageImageUrl */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionRequestMessageContentPartImageImageUrl +// CHECKSTYLE:ON +{ + @JsonProperty("url") + private URI url; + + /** + * Specifies the detail level of the image. Learn more in the [Vision + * guide](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/gpt-with-vision?tabs=rest%2Csystem-assigned%2Cresource#detail-parameter-settings-in-image-processing-low-high-auto). + */ + public enum DetailEnum { + /** The AUTO option of this ChatCompletionRequestMessageContentPartImageImageUrl */ + AUTO("auto"), + + /** The LOW option of this ChatCompletionRequestMessageContentPartImageImageUrl */ + LOW("low"), + + /** The HIGH option of this ChatCompletionRequestMessageContentPartImageImageUrl */ + HIGH("high"); + + private String value; + + DetailEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ChatCompletionRequestMessageContentPartImageImageUrl + */ + @JsonCreator + @Nonnull + public static DetailEnum fromValue(@Nonnull final String value) { + for (DetailEnum b : DetailEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("detail") + private DetailEnum detail = DetailEnum.AUTO; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the url of this {@link ChatCompletionRequestMessageContentPartImageImageUrl} instance and + * return the same instance. + * + * @param url Either a URL of the image or the base64 encoded image data. + * @return The same instance of this {@link ChatCompletionRequestMessageContentPartImageImageUrl} + * class + */ + @Nonnull + public ChatCompletionRequestMessageContentPartImageImageUrl url(@Nonnull final URI url) { + this.url = url; + return this; + } + + /** + * Either a URL of the image or the base64 encoded image data. + * + * @return url The url of this {@link ChatCompletionRequestMessageContentPartImageImageUrl} + * instance. + */ + @Nonnull + public URI getUrl() { + return url; + } + + /** + * Set the url of this {@link ChatCompletionRequestMessageContentPartImageImageUrl} instance. + * + * @param url Either a URL of the image or the base64 encoded image data. + */ + public void setUrl(@Nonnull final URI url) { + this.url = url; + } + + /** + * Set the detail of this {@link ChatCompletionRequestMessageContentPartImageImageUrl} instance + * and return the same instance. + * + * @param detail Specifies the detail level of the image. Learn more in the [Vision + * guide](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/gpt-with-vision?tabs=rest%2Csystem-assigned%2Cresource#detail-parameter-settings-in-image-processing-low-high-auto). + * @return The same instance of this {@link ChatCompletionRequestMessageContentPartImageImageUrl} + * class + */ + @Nonnull + public ChatCompletionRequestMessageContentPartImageImageUrl detail( + @Nullable final DetailEnum detail) { + this.detail = detail; + return this; + } + + /** + * Specifies the detail level of the image. Learn more in the [Vision + * guide](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/gpt-with-vision?tabs=rest%2Csystem-assigned%2Cresource#detail-parameter-settings-in-image-processing-low-high-auto). + * + * @return detail The detail of this {@link ChatCompletionRequestMessageContentPartImageImageUrl} + * instance. + */ + @Nonnull + public DetailEnum getDetail() { + return detail; + } + + /** + * Set the detail of this {@link ChatCompletionRequestMessageContentPartImageImageUrl} instance. + * + * @param detail Specifies the detail level of the image. Learn more in the [Vision + * guide](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/gpt-with-vision?tabs=rest%2Csystem-assigned%2Cresource#detail-parameter-settings-in-image-processing-low-high-auto). + */ + public void setDetail(@Nullable final DetailEnum detail) { + this.detail = detail; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionRequestMessageContentPartImageImageUrl}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * ChatCompletionRequestMessageContentPartImageImageUrl} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionRequestMessageContentPartImageImageUrl has no field with name '" + + name + + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link + * ChatCompletionRequestMessageContentPartImageImageUrl} instance. If the map previously contained + * a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionRequestMessageContentPartImageImageUrl + chatCompletionRequestMessageContentPartImageImageUrl = + (ChatCompletionRequestMessageContentPartImageImageUrl) o; + return Objects.equals( + this.cloudSdkCustomFields, + chatCompletionRequestMessageContentPartImageImageUrl.cloudSdkCustomFields) + && Objects.equals(this.url, chatCompletionRequestMessageContentPartImageImageUrl.url) + && Objects.equals(this.detail, chatCompletionRequestMessageContentPartImageImageUrl.detail); + } + + @Override + public int hashCode() { + return Objects.hash(url, detail, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionRequestMessageContentPartImageImageUrl {\n"); + sb.append(" url: ").append(toIndentedString(url)).append("\n"); + sb.append(" detail: ").append(toIndentedString(detail)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageContentPartRefusal.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageContentPartRefusal.java new file mode 100644 index 000000000..dc3201db3 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageContentPartRefusal.java @@ -0,0 +1,253 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionRequestMessageContentPartRefusal */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionRequestMessageContentPartRefusal + implements ChatCompletionRequestAssistantMessageContentPart +// CHECKSTYLE:ON +{ + /** The type of the content part. */ + public enum TypeEnum { + /** The REFUSAL option of this ChatCompletionRequestMessageContentPartRefusal */ + REFUSAL("refusal"); + + private String value; + + TypeEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ChatCompletionRequestMessageContentPartRefusal + */ + @JsonCreator + @Nonnull + public static TypeEnum fromValue(@Nonnull final String value) { + for (TypeEnum b : TypeEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("type") + private TypeEnum type; + + @JsonProperty("refusal") + private String refusal; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the type of this {@link ChatCompletionRequestMessageContentPartRefusal} instance and return + * the same instance. + * + * @param type The type of the content part. + * @return The same instance of this {@link ChatCompletionRequestMessageContentPartRefusal} class + */ + @Nonnull + public ChatCompletionRequestMessageContentPartRefusal type(@Nonnull final TypeEnum type) { + this.type = type; + return this; + } + + /** + * The type of the content part. + * + * @return type The type of this {@link ChatCompletionRequestMessageContentPartRefusal} instance. + */ + @Nonnull + public TypeEnum getType() { + return type; + } + + /** + * Set the type of this {@link ChatCompletionRequestMessageContentPartRefusal} instance. + * + * @param type The type of the content part. + */ + public void setType(@Nonnull final TypeEnum type) { + this.type = type; + } + + /** + * Set the refusal of this {@link ChatCompletionRequestMessageContentPartRefusal} instance and + * return the same instance. + * + * @param refusal The refusal message generated by the model. + * @return The same instance of this {@link ChatCompletionRequestMessageContentPartRefusal} class + */ + @Nonnull + public ChatCompletionRequestMessageContentPartRefusal refusal(@Nonnull final String refusal) { + this.refusal = refusal; + return this; + } + + /** + * The refusal message generated by the model. + * + * @return refusal The refusal of this {@link ChatCompletionRequestMessageContentPartRefusal} + * instance. + */ + @Nonnull + public String getRefusal() { + return refusal; + } + + /** + * Set the refusal of this {@link ChatCompletionRequestMessageContentPartRefusal} instance. + * + * @param refusal The refusal message generated by the model. + */ + public void setRefusal(@Nonnull final String refusal) { + this.refusal = refusal; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionRequestMessageContentPartRefusal}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * ChatCompletionRequestMessageContentPartRefusal} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionRequestMessageContentPartRefusal has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionRequestMessageContentPartRefusal} + * instance. If the map previously contained a mapping for the key, the old value is replaced by + * the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionRequestMessageContentPartRefusal + chatCompletionRequestMessageContentPartRefusal = + (ChatCompletionRequestMessageContentPartRefusal) o; + return Objects.equals( + this.cloudSdkCustomFields, + chatCompletionRequestMessageContentPartRefusal.cloudSdkCustomFields) + && Objects.equals(this.type, chatCompletionRequestMessageContentPartRefusal.type) + && Objects.equals(this.refusal, chatCompletionRequestMessageContentPartRefusal.refusal); + } + + @Override + public int hashCode() { + return Objects.hash(type, refusal, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionRequestMessageContentPartRefusal {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" refusal: ").append(toIndentedString(refusal)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageContentPartText.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageContentPartText.java new file mode 100644 index 000000000..e433bf929 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageContentPartText.java @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionRequestMessageContentPartText */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionRequestMessageContentPartText + implements ChatCompletionRequestAssistantMessageContentPart, + ChatCompletionRequestSystemMessageContentPart, + ChatCompletionRequestToolMessageContentPart, + ChatCompletionRequestUserMessageContentPart +// CHECKSTYLE:ON +{ + /** The type of the content part. */ + public enum TypeEnum { + /** The TEXT option of this ChatCompletionRequestMessageContentPartText */ + TEXT("text"); + + private String value; + + TypeEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ChatCompletionRequestMessageContentPartText + */ + @JsonCreator + @Nonnull + public static TypeEnum fromValue(@Nonnull final String value) { + for (TypeEnum b : TypeEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("type") + private TypeEnum type; + + @JsonProperty("text") + private String text; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the type of this {@link ChatCompletionRequestMessageContentPartText} instance and return + * the same instance. + * + * @param type The type of the content part. + * @return The same instance of this {@link ChatCompletionRequestMessageContentPartText} class + */ + @Nonnull + public ChatCompletionRequestMessageContentPartText type(@Nonnull final TypeEnum type) { + this.type = type; + return this; + } + + /** + * The type of the content part. + * + * @return type The type of this {@link ChatCompletionRequestMessageContentPartText} instance. + */ + @Nonnull + public TypeEnum getType() { + return type; + } + + /** + * Set the type of this {@link ChatCompletionRequestMessageContentPartText} instance. + * + * @param type The type of the content part. + */ + public void setType(@Nonnull final TypeEnum type) { + this.type = type; + } + + /** + * Set the text of this {@link ChatCompletionRequestMessageContentPartText} instance and return + * the same instance. + * + * @param text The text content. + * @return The same instance of this {@link ChatCompletionRequestMessageContentPartText} class + */ + @Nonnull + public ChatCompletionRequestMessageContentPartText text(@Nonnull final String text) { + this.text = text; + return this; + } + + /** + * The text content. + * + * @return text The text of this {@link ChatCompletionRequestMessageContentPartText} instance. + */ + @Nonnull + public String getText() { + return text; + } + + /** + * Set the text of this {@link ChatCompletionRequestMessageContentPartText} instance. + * + * @param text The text content. + */ + public void setText(@Nonnull final String text) { + this.text = text; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionRequestMessageContentPartText}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * ChatCompletionRequestMessageContentPartText} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionRequestMessageContentPartText has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionRequestMessageContentPartText} + * instance. If the map previously contained a mapping for the key, the old value is replaced by + * the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionRequestMessageContentPartText chatCompletionRequestMessageContentPartText = + (ChatCompletionRequestMessageContentPartText) o; + return Objects.equals( + this.cloudSdkCustomFields, + chatCompletionRequestMessageContentPartText.cloudSdkCustomFields) + && Objects.equals(this.type, chatCompletionRequestMessageContentPartText.type) + && Objects.equals(this.text, chatCompletionRequestMessageContentPartText.text); + } + + @Override + public int hashCode() { + return Objects.hash(type, text, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionRequestMessageContentPartText {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" text: ").append(toIndentedString(text)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageFunction.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageFunction.java new file mode 100644 index 000000000..080ad60f7 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageFunction.java @@ -0,0 +1,460 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionRequestMessageFunction */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionRequestMessageFunction +// CHECKSTYLE:ON +{ + @JsonProperty("content") + private String content; + + /** The role of the messages author, in this case `function`. */ + public enum RoleEnum { + /** The FUNCTION option of this ChatCompletionRequestMessageFunction */ + FUNCTION("function"); + + private String value; + + RoleEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ChatCompletionRequestMessageFunction + */ + @JsonCreator + @Nonnull + public static RoleEnum fromValue(@Nonnull final String value) { + for (RoleEnum b : RoleEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("role") + private RoleEnum role; + + @JsonProperty("name") + private String name; + + @JsonProperty("refusal") + private String refusal; + + @JsonProperty("tool_calls") + private List toolCalls = new ArrayList<>(); + + @JsonProperty("function_call") + private ChatCompletionRequestAssistantMessageFunctionCall functionCall; + + @JsonProperty("tool_call_id") + private String toolCallId; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the content of this {@link ChatCompletionRequestMessageFunction} instance and return the + * same instance. + * + * @param content The contents of the message. + * @return The same instance of this {@link ChatCompletionRequestMessageFunction} class + */ + @Nonnull + public ChatCompletionRequestMessageFunction content(@Nullable final String content) { + this.content = content; + return this; + } + + /** + * The contents of the message. + * + * @return content The content of this {@link ChatCompletionRequestMessageFunction} instance. + */ + @Nullable + public String getContent() { + return content; + } + + /** + * Set the content of this {@link ChatCompletionRequestMessageFunction} instance. + * + * @param content The contents of the message. + */ + public void setContent(@Nullable final String content) { + this.content = content; + } + + /** + * Set the role of this {@link ChatCompletionRequestMessageFunction} instance and return the same + * instance. + * + * @param role The role of the messages author, in this case `function`. + * @return The same instance of this {@link ChatCompletionRequestMessageFunction} class + */ + @Nonnull + public ChatCompletionRequestMessageFunction role(@Nonnull final RoleEnum role) { + this.role = role; + return this; + } + + /** + * The role of the messages author, in this case `function`. + * + * @return role The role of this {@link ChatCompletionRequestMessageFunction} instance. + */ + @Nonnull + public RoleEnum getRole() { + return role; + } + + /** + * Set the role of this {@link ChatCompletionRequestMessageFunction} instance. + * + * @param role The role of the messages author, in this case `function`. + */ + public void setRole(@Nonnull final RoleEnum role) { + this.role = role; + } + + /** + * Set the name of this {@link ChatCompletionRequestMessageFunction} instance and return the same + * instance. + * + * @param name The contents of the message. + * @return The same instance of this {@link ChatCompletionRequestMessageFunction} class + */ + @Nonnull + public ChatCompletionRequestMessageFunction name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * The contents of the message. + * + * @return name The name of this {@link ChatCompletionRequestMessageFunction} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link ChatCompletionRequestMessageFunction} instance. + * + * @param name The contents of the message. + */ + public void setName(@Nonnull final String name) { + this.name = name; + } + + /** + * Set the refusal of this {@link ChatCompletionRequestMessageFunction} instance and return the + * same instance. + * + * @param refusal The refusal message by the assistant. + * @return The same instance of this {@link ChatCompletionRequestMessageFunction} class + */ + @Nonnull + public ChatCompletionRequestMessageFunction refusal(@Nullable final String refusal) { + this.refusal = refusal; + return this; + } + + /** + * The refusal message by the assistant. + * + * @return refusal The refusal of this {@link ChatCompletionRequestMessageFunction} instance. + */ + @Nullable + public String getRefusal() { + return refusal; + } + + /** + * Set the refusal of this {@link ChatCompletionRequestMessageFunction} instance. + * + * @param refusal The refusal message by the assistant. + */ + public void setRefusal(@Nullable final String refusal) { + this.refusal = refusal; + } + + /** + * Set the toolCalls of this {@link ChatCompletionRequestMessageFunction} instance and return the + * same instance. + * + * @param toolCalls The tool calls generated by the model, such as function calls. + * @return The same instance of this {@link ChatCompletionRequestMessageFunction} class + */ + @Nonnull + public ChatCompletionRequestMessageFunction toolCalls( + @Nullable final List toolCalls) { + this.toolCalls = toolCalls; + return this; + } + + /** + * Add one toolCalls instance to this {@link ChatCompletionRequestMessageFunction}. + * + * @param toolCallsItem The toolCalls that should be added + * @return The same instance of type {@link ChatCompletionRequestMessageFunction} + */ + @Nonnull + public ChatCompletionRequestMessageFunction addToolCallsItem( + @Nonnull final ChatCompletionMessageToolCall toolCallsItem) { + if (this.toolCalls == null) { + this.toolCalls = new ArrayList<>(); + } + this.toolCalls.add(toolCallsItem); + return this; + } + + /** + * The tool calls generated by the model, such as function calls. + * + * @return toolCalls The toolCalls of this {@link ChatCompletionRequestMessageFunction} instance. + */ + @Nonnull + public List getToolCalls() { + return toolCalls; + } + + /** + * Set the toolCalls of this {@link ChatCompletionRequestMessageFunction} instance. + * + * @param toolCalls The tool calls generated by the model, such as function calls. + */ + public void setToolCalls(@Nullable final List toolCalls) { + this.toolCalls = toolCalls; + } + + /** + * Set the functionCall of this {@link ChatCompletionRequestMessageFunction} instance and return + * the same instance. + * + * @param functionCall The functionCall of this {@link ChatCompletionRequestMessageFunction} + * @return The same instance of this {@link ChatCompletionRequestMessageFunction} class + */ + @Nonnull + public ChatCompletionRequestMessageFunction functionCall( + @Nullable final ChatCompletionRequestAssistantMessageFunctionCall functionCall) { + this.functionCall = functionCall; + return this; + } + + /** + * Get functionCall + * + * @return functionCall The functionCall of this {@link ChatCompletionRequestMessageFunction} + * instance. + * @deprecated + */ + @Deprecated + @Nullable + public ChatCompletionRequestAssistantMessageFunctionCall getFunctionCall() { + return functionCall; + } + + /** + * Set the functionCall of this {@link ChatCompletionRequestMessageFunction} instance. + * + * @param functionCall The functionCall of this {@link ChatCompletionRequestMessageFunction} + */ + public void setFunctionCall( + @Nullable final ChatCompletionRequestAssistantMessageFunctionCall functionCall) { + this.functionCall = functionCall; + } + + /** + * Set the toolCallId of this {@link ChatCompletionRequestMessageFunction} instance and return the + * same instance. + * + * @param toolCallId Tool call that this message is responding to. + * @return The same instance of this {@link ChatCompletionRequestMessageFunction} class + */ + @Nonnull + public ChatCompletionRequestMessageFunction toolCallId(@Nonnull final String toolCallId) { + this.toolCallId = toolCallId; + return this; + } + + /** + * Tool call that this message is responding to. + * + * @return toolCallId The toolCallId of this {@link ChatCompletionRequestMessageFunction} + * instance. + */ + @Nonnull + public String getToolCallId() { + return toolCallId; + } + + /** + * Set the toolCallId of this {@link ChatCompletionRequestMessageFunction} instance. + * + * @param toolCallId Tool call that this message is responding to. + */ + public void setToolCallId(@Nonnull final String toolCallId) { + this.toolCallId = toolCallId; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionRequestMessageFunction}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * ChatCompletionRequestMessageFunction} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionRequestMessageFunction has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionRequestMessageFunction} instance. + * If the map previously contained a mapping for the key, the old value is replaced by the + * specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionRequestMessageFunction chatCompletionRequestMessageFunction = + (ChatCompletionRequestMessageFunction) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionRequestMessageFunction.cloudSdkCustomFields) + && Objects.equals(this.content, chatCompletionRequestMessageFunction.content) + && Objects.equals(this.role, chatCompletionRequestMessageFunction.role) + && Objects.equals(this.name, chatCompletionRequestMessageFunction.name) + && Objects.equals(this.refusal, chatCompletionRequestMessageFunction.refusal) + && Objects.equals(this.toolCalls, chatCompletionRequestMessageFunction.toolCalls) + && Objects.equals(this.functionCall, chatCompletionRequestMessageFunction.functionCall) + && Objects.equals(this.toolCallId, chatCompletionRequestMessageFunction.toolCallId); + } + + @Override + public int hashCode() { + return Objects.hash( + content, role, name, refusal, toolCalls, functionCall, toolCallId, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionRequestMessageFunction {\n"); + sb.append(" content: ").append(toIndentedString(content)).append("\n"); + sb.append(" role: ").append(toIndentedString(role)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" refusal: ").append(toIndentedString(refusal)).append("\n"); + sb.append(" toolCalls: ").append(toIndentedString(toolCalls)).append("\n"); + sb.append(" functionCall: ").append(toIndentedString(functionCall)).append("\n"); + sb.append(" toolCallId: ").append(toIndentedString(toolCallId)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageTool.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageTool.java new file mode 100644 index 000000000..5185637b3 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestMessageTool.java @@ -0,0 +1,458 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionRequestMessageTool */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionRequestMessageTool +// CHECKSTYLE:ON +{ + @JsonProperty("content") + private String content; + + /** The role of the messages author, in this case `function`. */ + public enum RoleEnum { + /** The FUNCTION option of this ChatCompletionRequestMessageTool */ + FUNCTION("function"); + + private String value; + + RoleEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ChatCompletionRequestMessageTool + */ + @JsonCreator + @Nonnull + public static RoleEnum fromValue(@Nonnull final String value) { + for (RoleEnum b : RoleEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("role") + private RoleEnum role; + + @JsonProperty("name") + private String name; + + @JsonProperty("refusal") + private String refusal; + + @JsonProperty("tool_calls") + private List toolCalls = new ArrayList<>(); + + @JsonProperty("function_call") + private ChatCompletionRequestAssistantMessageFunctionCall functionCall; + + @JsonProperty("tool_call_id") + private String toolCallId; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the content of this {@link ChatCompletionRequestMessageTool} instance and return the same + * instance. + * + * @param content The contents of the message. + * @return The same instance of this {@link ChatCompletionRequestMessageTool} class + */ + @Nonnull + public ChatCompletionRequestMessageTool content(@Nullable final String content) { + this.content = content; + return this; + } + + /** + * The contents of the message. + * + * @return content The content of this {@link ChatCompletionRequestMessageTool} instance. + */ + @Nullable + public String getContent() { + return content; + } + + /** + * Set the content of this {@link ChatCompletionRequestMessageTool} instance. + * + * @param content The contents of the message. + */ + public void setContent(@Nullable final String content) { + this.content = content; + } + + /** + * Set the role of this {@link ChatCompletionRequestMessageTool} instance and return the same + * instance. + * + * @param role The role of the messages author, in this case `function`. + * @return The same instance of this {@link ChatCompletionRequestMessageTool} class + */ + @Nonnull + public ChatCompletionRequestMessageTool role(@Nonnull final RoleEnum role) { + this.role = role; + return this; + } + + /** + * The role of the messages author, in this case `function`. + * + * @return role The role of this {@link ChatCompletionRequestMessageTool} instance. + */ + @Nonnull + public RoleEnum getRole() { + return role; + } + + /** + * Set the role of this {@link ChatCompletionRequestMessageTool} instance. + * + * @param role The role of the messages author, in this case `function`. + */ + public void setRole(@Nonnull final RoleEnum role) { + this.role = role; + } + + /** + * Set the name of this {@link ChatCompletionRequestMessageTool} instance and return the same + * instance. + * + * @param name The name of the function to call. + * @return The same instance of this {@link ChatCompletionRequestMessageTool} class + */ + @Nonnull + public ChatCompletionRequestMessageTool name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * The name of the function to call. + * + * @return name The name of this {@link ChatCompletionRequestMessageTool} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link ChatCompletionRequestMessageTool} instance. + * + * @param name The name of the function to call. + */ + public void setName(@Nonnull final String name) { + this.name = name; + } + + /** + * Set the refusal of this {@link ChatCompletionRequestMessageTool} instance and return the same + * instance. + * + * @param refusal The refusal message by the assistant. + * @return The same instance of this {@link ChatCompletionRequestMessageTool} class + */ + @Nonnull + public ChatCompletionRequestMessageTool refusal(@Nullable final String refusal) { + this.refusal = refusal; + return this; + } + + /** + * The refusal message by the assistant. + * + * @return refusal The refusal of this {@link ChatCompletionRequestMessageTool} instance. + */ + @Nullable + public String getRefusal() { + return refusal; + } + + /** + * Set the refusal of this {@link ChatCompletionRequestMessageTool} instance. + * + * @param refusal The refusal message by the assistant. + */ + public void setRefusal(@Nullable final String refusal) { + this.refusal = refusal; + } + + /** + * Set the toolCalls of this {@link ChatCompletionRequestMessageTool} instance and return the same + * instance. + * + * @param toolCalls The tool calls generated by the model, such as function calls. + * @return The same instance of this {@link ChatCompletionRequestMessageTool} class + */ + @Nonnull + public ChatCompletionRequestMessageTool toolCalls( + @Nullable final List toolCalls) { + this.toolCalls = toolCalls; + return this; + } + + /** + * Add one toolCalls instance to this {@link ChatCompletionRequestMessageTool}. + * + * @param toolCallsItem The toolCalls that should be added + * @return The same instance of type {@link ChatCompletionRequestMessageTool} + */ + @Nonnull + public ChatCompletionRequestMessageTool addToolCallsItem( + @Nonnull final ChatCompletionMessageToolCall toolCallsItem) { + if (this.toolCalls == null) { + this.toolCalls = new ArrayList<>(); + } + this.toolCalls.add(toolCallsItem); + return this; + } + + /** + * The tool calls generated by the model, such as function calls. + * + * @return toolCalls The toolCalls of this {@link ChatCompletionRequestMessageTool} instance. + */ + @Nonnull + public List getToolCalls() { + return toolCalls; + } + + /** + * Set the toolCalls of this {@link ChatCompletionRequestMessageTool} instance. + * + * @param toolCalls The tool calls generated by the model, such as function calls. + */ + public void setToolCalls(@Nullable final List toolCalls) { + this.toolCalls = toolCalls; + } + + /** + * Set the functionCall of this {@link ChatCompletionRequestMessageTool} instance and return the + * same instance. + * + * @param functionCall The functionCall of this {@link ChatCompletionRequestMessageTool} + * @return The same instance of this {@link ChatCompletionRequestMessageTool} class + */ + @Nonnull + public ChatCompletionRequestMessageTool functionCall( + @Nullable final ChatCompletionRequestAssistantMessageFunctionCall functionCall) { + this.functionCall = functionCall; + return this; + } + + /** + * Get functionCall + * + * @return functionCall The functionCall of this {@link ChatCompletionRequestMessageTool} + * instance. + * @deprecated + */ + @Deprecated + @Nullable + public ChatCompletionRequestAssistantMessageFunctionCall getFunctionCall() { + return functionCall; + } + + /** + * Set the functionCall of this {@link ChatCompletionRequestMessageTool} instance. + * + * @param functionCall The functionCall of this {@link ChatCompletionRequestMessageTool} + */ + public void setFunctionCall( + @Nullable final ChatCompletionRequestAssistantMessageFunctionCall functionCall) { + this.functionCall = functionCall; + } + + /** + * Set the toolCallId of this {@link ChatCompletionRequestMessageTool} instance and return the + * same instance. + * + * @param toolCallId Tool call that this message is responding to. + * @return The same instance of this {@link ChatCompletionRequestMessageTool} class + */ + @Nonnull + public ChatCompletionRequestMessageTool toolCallId(@Nonnull final String toolCallId) { + this.toolCallId = toolCallId; + return this; + } + + /** + * Tool call that this message is responding to. + * + * @return toolCallId The toolCallId of this {@link ChatCompletionRequestMessageTool} instance. + */ + @Nonnull + public String getToolCallId() { + return toolCallId; + } + + /** + * Set the toolCallId of this {@link ChatCompletionRequestMessageTool} instance. + * + * @param toolCallId Tool call that this message is responding to. + */ + public void setToolCallId(@Nonnull final String toolCallId) { + this.toolCallId = toolCallId; + } + + /** + * Get the names of the unrecognizable properties of the {@link ChatCompletionRequestMessageTool}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionRequestMessageTool} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionRequestMessageTool has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionRequestMessageTool} instance. If + * the map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionRequestMessageTool chatCompletionRequestMessageTool = + (ChatCompletionRequestMessageTool) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionRequestMessageTool.cloudSdkCustomFields) + && Objects.equals(this.content, chatCompletionRequestMessageTool.content) + && Objects.equals(this.role, chatCompletionRequestMessageTool.role) + && Objects.equals(this.name, chatCompletionRequestMessageTool.name) + && Objects.equals(this.refusal, chatCompletionRequestMessageTool.refusal) + && Objects.equals(this.toolCalls, chatCompletionRequestMessageTool.toolCalls) + && Objects.equals(this.functionCall, chatCompletionRequestMessageTool.functionCall) + && Objects.equals(this.toolCallId, chatCompletionRequestMessageTool.toolCallId); + } + + @Override + public int hashCode() { + return Objects.hash( + content, role, name, refusal, toolCalls, functionCall, toolCallId, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionRequestMessageTool {\n"); + sb.append(" content: ").append(toIndentedString(content)).append("\n"); + sb.append(" role: ").append(toIndentedString(role)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" refusal: ").append(toIndentedString(refusal)).append("\n"); + sb.append(" toolCalls: ").append(toIndentedString(toolCalls)).append("\n"); + sb.append(" functionCall: ").append(toIndentedString(functionCall)).append("\n"); + sb.append(" toolCallId: ").append(toIndentedString(toolCallId)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestSystemMessage.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestSystemMessage.java new file mode 100644 index 000000000..f46b232fe --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestSystemMessage.java @@ -0,0 +1,290 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionRequestSystemMessage */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionRequestSystemMessage implements ChatCompletionRequestMessage +// CHECKSTYLE:ON +{ + @JsonProperty("content") + private ChatCompletionRequestSystemMessageContent content; + + /** The role of the messages author, in this case `system`. */ + public enum RoleEnum { + /** The SYSTEM option of this ChatCompletionRequestSystemMessage */ + SYSTEM("system"); + + private String value; + + RoleEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ChatCompletionRequestSystemMessage + */ + @JsonCreator + @Nonnull + public static RoleEnum fromValue(@Nonnull final String value) { + for (RoleEnum b : RoleEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("role") + private RoleEnum role; + + @JsonProperty("name") + private String name; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the content of this {@link ChatCompletionRequestSystemMessage} instance and return the same + * instance. + * + * @param content The content of this {@link ChatCompletionRequestSystemMessage} + * @return The same instance of this {@link ChatCompletionRequestSystemMessage} class + */ + @Nonnull + public ChatCompletionRequestSystemMessage content( + @Nonnull final ChatCompletionRequestSystemMessageContent content) { + this.content = content; + return this; + } + + /** + * Get content + * + * @return content The content of this {@link ChatCompletionRequestSystemMessage} instance. + */ + @Nonnull + public ChatCompletionRequestSystemMessageContent getContent() { + return content; + } + + /** + * Set the content of this {@link ChatCompletionRequestSystemMessage} instance. + * + * @param content The content of this {@link ChatCompletionRequestSystemMessage} + */ + public void setContent(@Nonnull final ChatCompletionRequestSystemMessageContent content) { + this.content = content; + } + + /** + * Set the role of this {@link ChatCompletionRequestSystemMessage} instance and return the same + * instance. + * + * @param role The role of the messages author, in this case `system`. + * @return The same instance of this {@link ChatCompletionRequestSystemMessage} class + */ + @Nonnull + public ChatCompletionRequestSystemMessage role(@Nonnull final RoleEnum role) { + this.role = role; + return this; + } + + /** + * The role of the messages author, in this case `system`. + * + * @return role The role of this {@link ChatCompletionRequestSystemMessage} instance. + */ + @Nonnull + public RoleEnum getRole() { + return role; + } + + /** + * Set the role of this {@link ChatCompletionRequestSystemMessage} instance. + * + * @param role The role of the messages author, in this case `system`. + */ + public void setRole(@Nonnull final RoleEnum role) { + this.role = role; + } + + /** + * Set the name of this {@link ChatCompletionRequestSystemMessage} instance and return the same + * instance. + * + * @param name An optional name for the participant. Provides the model information to + * differentiate between participants of the same role. + * @return The same instance of this {@link ChatCompletionRequestSystemMessage} class + */ + @Nonnull + public ChatCompletionRequestSystemMessage name(@Nullable final String name) { + this.name = name; + return this; + } + + /** + * An optional name for the participant. Provides the model information to differentiate between + * participants of the same role. + * + * @return name The name of this {@link ChatCompletionRequestSystemMessage} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link ChatCompletionRequestSystemMessage} instance. + * + * @param name An optional name for the participant. Provides the model information to + * differentiate between participants of the same role. + */ + public void setName(@Nullable final String name) { + this.name = name; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionRequestSystemMessage}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionRequestSystemMessage} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionRequestSystemMessage has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionRequestSystemMessage} instance. If + * the map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionRequestSystemMessage chatCompletionRequestSystemMessage = + (ChatCompletionRequestSystemMessage) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionRequestSystemMessage.cloudSdkCustomFields) + && Objects.equals(this.content, chatCompletionRequestSystemMessage.content) + && Objects.equals(this.role, chatCompletionRequestSystemMessage.role) + && Objects.equals(this.name, chatCompletionRequestSystemMessage.name); + } + + @Override + public int hashCode() { + return Objects.hash(content, role, name, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionRequestSystemMessage {\n"); + sb.append(" content: ").append(toIndentedString(content)).append("\n"); + sb.append(" role: ").append(toIndentedString(role)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestSystemMessageContent.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestSystemMessageContent.java new file mode 100644 index 000000000..6cf2d7db8 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestSystemMessageContent.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import java.util.List; + +/** The contents of the system message. */ +@com.google.common.annotations.Beta +public interface ChatCompletionRequestSystemMessageContent { + /** + * Helper class to create a String that implements {@link + * ChatCompletionRequestSystemMessageContent}. + */ + record InnerString(@com.fasterxml.jackson.annotation.JsonValue String value) + implements ChatCompletionRequestSystemMessageContent {} + + /** + * Creator to enable deserialization of a String. + * + * @param val the value to use + * @return a new instance of {@link InnerString}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + static InnerString create(String val) { + return new InnerString(val); + } + + /** + * Helper class to create a list of ChatCompletionRequestSystemMessageContentPart that implements + * {@link ChatCompletionRequestSystemMessageContent}. + */ + record InnerChatCompletionRequestSystemMessageContentParts( + @com.fasterxml.jackson.annotation.JsonValue + List values) + implements ChatCompletionRequestSystemMessageContent {} + + /** + * Creator to enable deserialization of a list of ChatCompletionRequestSystemMessageContentPart. + * + * @param val the value to use + * @return a new instance of {@link InnerChatCompletionRequestSystemMessageContentParts}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + static InnerChatCompletionRequestSystemMessageContentParts create( + List val) { + return new InnerChatCompletionRequestSystemMessageContentParts(val); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestSystemMessageContentPart.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestSystemMessageContentPart.java new file mode 100644 index 000000000..6d24a3d08 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestSystemMessageContentPart.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +/** ChatCompletionRequestSystemMessageContentPart */ +@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION) +@JsonSubTypes({ + @JsonSubTypes.Type(value = ChatCompletionRequestMessageContentPartText.class), +}) +@com.google.common.annotations.Beta +public interface ChatCompletionRequestSystemMessageContentPart {} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestToolMessage.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestToolMessage.java new file mode 100644 index 000000000..b4069d83e --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestToolMessage.java @@ -0,0 +1,286 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionRequestToolMessage */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionRequestToolMessage implements ChatCompletionRequestMessage +// CHECKSTYLE:ON +{ + /** The role of the messages author, in this case `tool`. */ + public enum RoleEnum { + /** The TOOL option of this ChatCompletionRequestToolMessage */ + TOOL("tool"); + + private String value; + + RoleEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ChatCompletionRequestToolMessage + */ + @JsonCreator + @Nonnull + public static RoleEnum fromValue(@Nonnull final String value) { + for (RoleEnum b : RoleEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("role") + private RoleEnum role; + + @JsonProperty("content") + private ChatCompletionRequestToolMessageContent content; + + @JsonProperty("tool_call_id") + private String toolCallId; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the role of this {@link ChatCompletionRequestToolMessage} instance and return the same + * instance. + * + * @param role The role of the messages author, in this case `tool`. + * @return The same instance of this {@link ChatCompletionRequestToolMessage} class + */ + @Nonnull + public ChatCompletionRequestToolMessage role(@Nonnull final RoleEnum role) { + this.role = role; + return this; + } + + /** + * The role of the messages author, in this case `tool`. + * + * @return role The role of this {@link ChatCompletionRequestToolMessage} instance. + */ + @Nonnull + public RoleEnum getRole() { + return role; + } + + /** + * Set the role of this {@link ChatCompletionRequestToolMessage} instance. + * + * @param role The role of the messages author, in this case `tool`. + */ + public void setRole(@Nonnull final RoleEnum role) { + this.role = role; + } + + /** + * Set the content of this {@link ChatCompletionRequestToolMessage} instance and return the same + * instance. + * + * @param content The content of this {@link ChatCompletionRequestToolMessage} + * @return The same instance of this {@link ChatCompletionRequestToolMessage} class + */ + @Nonnull + public ChatCompletionRequestToolMessage content( + @Nonnull final ChatCompletionRequestToolMessageContent content) { + this.content = content; + return this; + } + + /** + * Get content + * + * @return content The content of this {@link ChatCompletionRequestToolMessage} instance. + */ + @Nonnull + public ChatCompletionRequestToolMessageContent getContent() { + return content; + } + + /** + * Set the content of this {@link ChatCompletionRequestToolMessage} instance. + * + * @param content The content of this {@link ChatCompletionRequestToolMessage} + */ + public void setContent(@Nonnull final ChatCompletionRequestToolMessageContent content) { + this.content = content; + } + + /** + * Set the toolCallId of this {@link ChatCompletionRequestToolMessage} instance and return the + * same instance. + * + * @param toolCallId Tool call that this message is responding to. + * @return The same instance of this {@link ChatCompletionRequestToolMessage} class + */ + @Nonnull + public ChatCompletionRequestToolMessage toolCallId(@Nonnull final String toolCallId) { + this.toolCallId = toolCallId; + return this; + } + + /** + * Tool call that this message is responding to. + * + * @return toolCallId The toolCallId of this {@link ChatCompletionRequestToolMessage} instance. + */ + @Nonnull + public String getToolCallId() { + return toolCallId; + } + + /** + * Set the toolCallId of this {@link ChatCompletionRequestToolMessage} instance. + * + * @param toolCallId Tool call that this message is responding to. + */ + public void setToolCallId(@Nonnull final String toolCallId) { + this.toolCallId = toolCallId; + } + + /** + * Get the names of the unrecognizable properties of the {@link ChatCompletionRequestToolMessage}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionRequestToolMessage} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionRequestToolMessage has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionRequestToolMessage} instance. If + * the map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionRequestToolMessage chatCompletionRequestToolMessage = + (ChatCompletionRequestToolMessage) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionRequestToolMessage.cloudSdkCustomFields) + && Objects.equals(this.role, chatCompletionRequestToolMessage.role) + && Objects.equals(this.content, chatCompletionRequestToolMessage.content) + && Objects.equals(this.toolCallId, chatCompletionRequestToolMessage.toolCallId); + } + + @Override + public int hashCode() { + return Objects.hash(role, content, toolCallId, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionRequestToolMessage {\n"); + sb.append(" role: ").append(toIndentedString(role)).append("\n"); + sb.append(" content: ").append(toIndentedString(content)).append("\n"); + sb.append(" toolCallId: ").append(toIndentedString(toolCallId)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestToolMessageContent.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestToolMessageContent.java new file mode 100644 index 000000000..6e8a8d32d --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestToolMessageContent.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import java.util.List; + +/** The contents of the tool message. */ +@com.google.common.annotations.Beta +public interface ChatCompletionRequestToolMessageContent { + /** + * Helper class to create a String that implements {@link + * ChatCompletionRequestToolMessageContent}. + */ + record InnerString(@com.fasterxml.jackson.annotation.JsonValue String value) + implements ChatCompletionRequestToolMessageContent {} + + /** + * Creator to enable deserialization of a String. + * + * @param val the value to use + * @return a new instance of {@link InnerString}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + static InnerString create(String val) { + return new InnerString(val); + } + + /** + * Helper class to create a list of ChatCompletionRequestToolMessageContentPart that implements + * {@link ChatCompletionRequestToolMessageContent}. + */ + record InnerChatCompletionRequestToolMessageContentParts( + @com.fasterxml.jackson.annotation.JsonValue + List values) + implements ChatCompletionRequestToolMessageContent {} + + /** + * Creator to enable deserialization of a list of ChatCompletionRequestToolMessageContentPart. + * + * @param val the value to use + * @return a new instance of {@link InnerChatCompletionRequestToolMessageContentParts}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + static InnerChatCompletionRequestToolMessageContentParts create( + List val) { + return new InnerChatCompletionRequestToolMessageContentParts(val); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestToolMessageContentPart.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestToolMessageContentPart.java new file mode 100644 index 000000000..7ffb1f36d --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestToolMessageContentPart.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +/** ChatCompletionRequestToolMessageContentPart */ +@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION) +@JsonSubTypes({ + @JsonSubTypes.Type(value = ChatCompletionRequestMessageContentPartText.class), +}) +@com.google.common.annotations.Beta +public interface ChatCompletionRequestToolMessageContentPart {} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestUserMessage.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestUserMessage.java new file mode 100644 index 000000000..443dd994d --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestUserMessage.java @@ -0,0 +1,289 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionRequestUserMessage */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionRequestUserMessage implements ChatCompletionRequestMessage +// CHECKSTYLE:ON +{ + @JsonProperty("content") + private ChatCompletionRequestUserMessageContent content; + + /** The role of the messages author, in this case `user`. */ + public enum RoleEnum { + /** The USER option of this ChatCompletionRequestUserMessage */ + USER("user"); + + private String value; + + RoleEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ChatCompletionRequestUserMessage + */ + @JsonCreator + @Nonnull + public static RoleEnum fromValue(@Nonnull final String value) { + for (RoleEnum b : RoleEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("role") + private RoleEnum role; + + @JsonProperty("name") + private String name; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the content of this {@link ChatCompletionRequestUserMessage} instance and return the same + * instance. + * + * @param content The content of this {@link ChatCompletionRequestUserMessage} + * @return The same instance of this {@link ChatCompletionRequestUserMessage} class + */ + @Nonnull + public ChatCompletionRequestUserMessage content( + @Nonnull final ChatCompletionRequestUserMessageContent content) { + this.content = content; + return this; + } + + /** + * Get content + * + * @return content The content of this {@link ChatCompletionRequestUserMessage} instance. + */ + @Nonnull + public ChatCompletionRequestUserMessageContent getContent() { + return content; + } + + /** + * Set the content of this {@link ChatCompletionRequestUserMessage} instance. + * + * @param content The content of this {@link ChatCompletionRequestUserMessage} + */ + public void setContent(@Nonnull final ChatCompletionRequestUserMessageContent content) { + this.content = content; + } + + /** + * Set the role of this {@link ChatCompletionRequestUserMessage} instance and return the same + * instance. + * + * @param role The role of the messages author, in this case `user`. + * @return The same instance of this {@link ChatCompletionRequestUserMessage} class + */ + @Nonnull + public ChatCompletionRequestUserMessage role(@Nonnull final RoleEnum role) { + this.role = role; + return this; + } + + /** + * The role of the messages author, in this case `user`. + * + * @return role The role of this {@link ChatCompletionRequestUserMessage} instance. + */ + @Nonnull + public RoleEnum getRole() { + return role; + } + + /** + * Set the role of this {@link ChatCompletionRequestUserMessage} instance. + * + * @param role The role of the messages author, in this case `user`. + */ + public void setRole(@Nonnull final RoleEnum role) { + this.role = role; + } + + /** + * Set the name of this {@link ChatCompletionRequestUserMessage} instance and return the same + * instance. + * + * @param name An optional name for the participant. Provides the model information to + * differentiate between participants of the same role. + * @return The same instance of this {@link ChatCompletionRequestUserMessage} class + */ + @Nonnull + public ChatCompletionRequestUserMessage name(@Nullable final String name) { + this.name = name; + return this; + } + + /** + * An optional name for the participant. Provides the model information to differentiate between + * participants of the same role. + * + * @return name The name of this {@link ChatCompletionRequestUserMessage} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link ChatCompletionRequestUserMessage} instance. + * + * @param name An optional name for the participant. Provides the model information to + * differentiate between participants of the same role. + */ + public void setName(@Nullable final String name) { + this.name = name; + } + + /** + * Get the names of the unrecognizable properties of the {@link ChatCompletionRequestUserMessage}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionRequestUserMessage} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionRequestUserMessage has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionRequestUserMessage} instance. If + * the map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionRequestUserMessage chatCompletionRequestUserMessage = + (ChatCompletionRequestUserMessage) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionRequestUserMessage.cloudSdkCustomFields) + && Objects.equals(this.content, chatCompletionRequestUserMessage.content) + && Objects.equals(this.role, chatCompletionRequestUserMessage.role) + && Objects.equals(this.name, chatCompletionRequestUserMessage.name); + } + + @Override + public int hashCode() { + return Objects.hash(content, role, name, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionRequestUserMessage {\n"); + sb.append(" content: ").append(toIndentedString(content)).append("\n"); + sb.append(" role: ").append(toIndentedString(role)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestUserMessageContent.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestUserMessageContent.java new file mode 100644 index 000000000..8c892bca0 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestUserMessageContent.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import java.util.List; + +/** The contents of the user message. */ +@com.google.common.annotations.Beta +public interface ChatCompletionRequestUserMessageContent { + /** + * Helper class to create a String that implements {@link + * ChatCompletionRequestUserMessageContent}. + */ + record InnerString(@com.fasterxml.jackson.annotation.JsonValue String value) + implements ChatCompletionRequestUserMessageContent {} + + /** + * Creator to enable deserialization of a String. + * + * @param val the value to use + * @return a new instance of {@link InnerString}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + static InnerString create(String val) { + return new InnerString(val); + } + + /** + * Helper class to create a list of ChatCompletionRequestUserMessageContentPart that implements + * {@link ChatCompletionRequestUserMessageContent}. + */ + record InnerChatCompletionRequestUserMessageContentParts( + @com.fasterxml.jackson.annotation.JsonValue + List values) + implements ChatCompletionRequestUserMessageContent {} + + /** + * Creator to enable deserialization of a list of ChatCompletionRequestUserMessageContentPart. + * + * @param val the value to use + * @return a new instance of {@link InnerChatCompletionRequestUserMessageContentParts}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + static InnerChatCompletionRequestUserMessageContentParts create( + List val) { + return new InnerChatCompletionRequestUserMessageContentParts(val); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestUserMessageContentPart.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestUserMessageContentPart.java new file mode 100644 index 000000000..466e0ff0b --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionRequestUserMessageContentPart.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +/** ChatCompletionRequestUserMessageContentPart */ +@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION) +@JsonSubTypes({ + @JsonSubTypes.Type(value = ChatCompletionRequestMessageContentPartImage.class), + @JsonSubTypes.Type(value = ChatCompletionRequestMessageContentPartText.class), +}) +@com.google.common.annotations.Beta +public interface ChatCompletionRequestUserMessageContentPart {} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionResponseMessage.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionResponseMessage.java new file mode 100644 index 000000000..3ae998650 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionResponseMessage.java @@ -0,0 +1,329 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** A chat completion message generated by the model. */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionResponseMessage +// CHECKSTYLE:ON +{ + @JsonProperty("role") + private ChatCompletionResponseMessageRole role; + + @JsonProperty("refusal") + private String refusal; + + @JsonProperty("content") + private String content; + + @JsonProperty("tool_calls") + private List toolCalls = new ArrayList<>(); + + @JsonProperty("function_call") + private ChatCompletionFunctionCall functionCall; + + // @JsonProperty("context") // TODO: add context + // private AzureChatExtensionsMessageContext context; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the role of this {@link ChatCompletionResponseMessage} instance and return the same + * instance. + * + * @param role The role of this {@link ChatCompletionResponseMessage} + * @return The same instance of this {@link ChatCompletionResponseMessage} class + */ + @Nonnull + public ChatCompletionResponseMessage role(@Nonnull final ChatCompletionResponseMessageRole role) { + this.role = role; + return this; + } + + /** + * Get role + * + * @return role The role of this {@link ChatCompletionResponseMessage} instance. + */ + @Nonnull + public ChatCompletionResponseMessageRole getRole() { + return role; + } + + /** + * Set the role of this {@link ChatCompletionResponseMessage} instance. + * + * @param role The role of this {@link ChatCompletionResponseMessage} + */ + public void setRole(@Nonnull final ChatCompletionResponseMessageRole role) { + this.role = role; + } + + /** + * Set the refusal of this {@link ChatCompletionResponseMessage} instance and return the same + * instance. + * + * @param refusal The refusal message generated by the model. + * @return The same instance of this {@link ChatCompletionResponseMessage} class + */ + @Nonnull + public ChatCompletionResponseMessage refusal(@Nullable final String refusal) { + this.refusal = refusal; + return this; + } + + /** + * The refusal message generated by the model. + * + * @return refusal The refusal of this {@link ChatCompletionResponseMessage} instance. + */ + @Nullable + public String getRefusal() { + return refusal; + } + + /** + * Set the refusal of this {@link ChatCompletionResponseMessage} instance. + * + * @param refusal The refusal message generated by the model. + */ + public void setRefusal(@Nullable final String refusal) { + this.refusal = refusal; + } + + /** + * Set the content of this {@link ChatCompletionResponseMessage} instance and return the same + * instance. + * + * @param content The contents of the message. + * @return The same instance of this {@link ChatCompletionResponseMessage} class + */ + @Nonnull + public ChatCompletionResponseMessage content(@Nullable final String content) { + this.content = content; + return this; + } + + /** + * The contents of the message. + * + * @return content The content of this {@link ChatCompletionResponseMessage} instance. + */ + @Nullable + public String getContent() { + return content; + } + + /** + * Set the content of this {@link ChatCompletionResponseMessage} instance. + * + * @param content The contents of the message. + */ + public void setContent(@Nullable final String content) { + this.content = content; + } + + /** + * Set the toolCalls of this {@link ChatCompletionResponseMessage} instance and return the same + * instance. + * + * @param toolCalls The tool calls generated by the model, such as function calls. + * @return The same instance of this {@link ChatCompletionResponseMessage} class + */ + @Nonnull + public ChatCompletionResponseMessage toolCalls( + @Nullable final List toolCalls) { + this.toolCalls = toolCalls; + return this; + } + + /** + * Add one toolCalls instance to this {@link ChatCompletionResponseMessage}. + * + * @param toolCallsItem The toolCalls that should be added + * @return The same instance of type {@link ChatCompletionResponseMessage} + */ + @Nonnull + public ChatCompletionResponseMessage addToolCallsItem( + @Nonnull final ChatCompletionMessageToolCall toolCallsItem) { + if (this.toolCalls == null) { + this.toolCalls = new ArrayList<>(); + } + this.toolCalls.add(toolCallsItem); + return this; + } + + /** + * The tool calls generated by the model, such as function calls. + * + * @return toolCalls The toolCalls of this {@link ChatCompletionResponseMessage} instance. + */ + @Nonnull + public List getToolCalls() { + return toolCalls; + } + + /** + * Set the toolCalls of this {@link ChatCompletionResponseMessage} instance. + * + * @param toolCalls The tool calls generated by the model, such as function calls. + */ + public void setToolCalls(@Nullable final List toolCalls) { + this.toolCalls = toolCalls; + } + + /** + * Set the functionCall of this {@link ChatCompletionResponseMessage} instance and return the same + * instance. + * + * @param functionCall The functionCall of this {@link ChatCompletionResponseMessage} + * @return The same instance of this {@link ChatCompletionResponseMessage} class + */ + @Nonnull + public ChatCompletionResponseMessage functionCall( + @Nullable final ChatCompletionFunctionCall functionCall) { + this.functionCall = functionCall; + return this; + } + + /** + * Get functionCall + * + * @return functionCall The functionCall of this {@link ChatCompletionResponseMessage} instance. + */ + @Nonnull + public ChatCompletionFunctionCall getFunctionCall() { + return functionCall; + } + + /** + * Set the functionCall of this {@link ChatCompletionResponseMessage} instance. + * + * @param functionCall The functionCall of this {@link ChatCompletionResponseMessage} + */ + public void setFunctionCall(@Nullable final ChatCompletionFunctionCall functionCall) { + this.functionCall = functionCall; + } + + /** + * Get the names of the unrecognizable properties of the {@link ChatCompletionResponseMessage}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionResponseMessage} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionResponseMessage has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionResponseMessage} instance. If the + * map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionResponseMessage chatCompletionResponseMessage = + (ChatCompletionResponseMessage) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionResponseMessage.cloudSdkCustomFields) + && Objects.equals(this.role, chatCompletionResponseMessage.role) + && Objects.equals(this.refusal, chatCompletionResponseMessage.refusal) + && Objects.equals(this.content, chatCompletionResponseMessage.content) + && Objects.equals(this.toolCalls, chatCompletionResponseMessage.toolCalls) + && Objects.equals(this.functionCall, chatCompletionResponseMessage.functionCall); + } + + @Override + public int hashCode() { + return Objects.hash(role, refusal, content, toolCalls, functionCall, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionResponseMessage {\n"); + sb.append(" role: ").append(toIndentedString(role)).append("\n"); + sb.append(" refusal: ").append(toIndentedString(refusal)).append("\n"); + sb.append(" content: ").append(toIndentedString(content)).append("\n"); + sb.append(" toolCalls: ").append(toIndentedString(toolCalls)).append("\n"); + sb.append(" functionCall: ").append(toIndentedString(functionCall)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionResponseMessageRole.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionResponseMessageRole.java new file mode 100644 index 000000000..761e66c1b --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionResponseMessageRole.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import javax.annotation.Nonnull; + +/** The role of the author of the response message. */ +@com.google.common.annotations.Beta +public enum ChatCompletionResponseMessageRole { + ASSISTANT("assistant"); + + private final String value; + + ChatCompletionResponseMessageRole(String value) { + this.value = value; + } + + /** + * @return The enum value. + */ + @JsonValue + public String getValue() { + return value; + } + + /** + * @return The String representation of the enum value. + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Converts the given value to its enum representation. + * + * @param value The input value. + * @return The enum representation of the given value. + */ + @JsonCreator + public static ChatCompletionResponseMessageRole fromValue(@Nonnull final String value) { + for (final ChatCompletionResponseMessageRole b : ChatCompletionResponseMessageRole.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionStreamOptions.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionStreamOptions.java new file mode 100644 index 000000000..720091d0c --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionStreamOptions.java @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** Options for streaming response. Only set this when you set `stream: true`. */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionStreamOptions +// CHECKSTYLE:ON +{ + @JsonProperty("include_usage") + private Boolean includeUsage; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the includeUsage of this {@link ChatCompletionStreamOptions} instance and return the same + * instance. + * + * @param includeUsage If set, an additional chunk will be streamed before the `data: + * [DONE]` message. The `usage` field on this chunk shows the token usage + * statistics for the entire request, and the `choices` field will always be an + * empty array. All other chunks will also include a `usage` field, but with a null + * value. + * @return The same instance of this {@link ChatCompletionStreamOptions} class + */ + @Nonnull + public ChatCompletionStreamOptions includeUsage(@Nullable final Boolean includeUsage) { + this.includeUsage = includeUsage; + return this; + } + + /** + * If set, an additional chunk will be streamed before the `data: [DONE]` message. The + * `usage` field on this chunk shows the token usage statistics for the entire request, + * and the `choices` field will always be an empty array. All other chunks will also + * include a `usage` field, but with a null value. + * + * @return includeUsage The includeUsage of this {@link ChatCompletionStreamOptions} instance. + */ + @Nonnull + public Boolean isIncludeUsage() { + return includeUsage; + } + + /** + * Set the includeUsage of this {@link ChatCompletionStreamOptions} instance. + * + * @param includeUsage If set, an additional chunk will be streamed before the `data: + * [DONE]` message. The `usage` field on this chunk shows the token usage + * statistics for the entire request, and the `choices` field will always be an + * empty array. All other chunks will also include a `usage` field, but with a null + * value. + */ + public void setIncludeUsage(@Nullable final Boolean includeUsage) { + this.includeUsage = includeUsage; + } + + /** + * Get the names of the unrecognizable properties of the {@link ChatCompletionStreamOptions}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionStreamOptions} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionStreamOptions has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionStreamOptions} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionStreamOptions chatCompletionStreamOptions = (ChatCompletionStreamOptions) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionStreamOptions.cloudSdkCustomFields) + && Objects.equals(this.includeUsage, chatCompletionStreamOptions.includeUsage); + } + + @Override + public int hashCode() { + return Objects.hash(includeUsage, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionStreamOptions {\n"); + sb.append(" includeUsage: ").append(toIndentedString(includeUsage)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionStreamResponseDelta.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionStreamResponseDelta.java new file mode 100644 index 000000000..4b772f23b --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionStreamResponseDelta.java @@ -0,0 +1,393 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** A chat completion delta generated by streamed model responses. */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionStreamResponseDelta +// CHECKSTYLE:ON +{ + @JsonProperty("content") + private String content; + + @JsonProperty("function_call") + private ChatCompletionStreamResponseDeltaFunctionCall functionCall; + + @JsonProperty("tool_calls") + private List toolCalls = new ArrayList<>(); + + /** The role of the author of this message. */ + public enum RoleEnum { + /** The SYSTEM option of this ChatCompletionStreamResponseDelta */ + SYSTEM("system"), + + /** The USER option of this ChatCompletionStreamResponseDelta */ + USER("user"), + + /** The ASSISTANT option of this ChatCompletionStreamResponseDelta */ + ASSISTANT("assistant"), + + /** The TOOL option of this ChatCompletionStreamResponseDelta */ + TOOL("tool"); + + private String value; + + RoleEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ChatCompletionStreamResponseDelta + */ + @JsonCreator + @Nonnull + public static RoleEnum fromValue(@Nonnull final String value) { + for (RoleEnum b : RoleEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("role") + private RoleEnum role; + + @JsonProperty("refusal") + private String refusal; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the content of this {@link ChatCompletionStreamResponseDelta} instance and return the same + * instance. + * + * @param content The contents of the chunk message. + * @return The same instance of this {@link ChatCompletionStreamResponseDelta} class + */ + @Nonnull + public ChatCompletionStreamResponseDelta content(@Nullable final String content) { + this.content = content; + return this; + } + + /** + * The contents of the chunk message. + * + * @return content The content of this {@link ChatCompletionStreamResponseDelta} instance. + */ + @Nullable + public String getContent() { + return content; + } + + /** + * Set the content of this {@link ChatCompletionStreamResponseDelta} instance. + * + * @param content The contents of the chunk message. + */ + public void setContent(@Nullable final String content) { + this.content = content; + } + + /** + * Set the functionCall of this {@link ChatCompletionStreamResponseDelta} instance and return the + * same instance. + * + * @param functionCall The functionCall of this {@link ChatCompletionStreamResponseDelta} + * @return The same instance of this {@link ChatCompletionStreamResponseDelta} class + */ + @Nonnull + public ChatCompletionStreamResponseDelta functionCall( + @Nullable final ChatCompletionStreamResponseDeltaFunctionCall functionCall) { + this.functionCall = functionCall; + return this; + } + + /** + * Get functionCall + * + * @return functionCall The functionCall of this {@link ChatCompletionStreamResponseDelta} + * instance. + * @deprecated + */ + @Deprecated + @Nonnull + public ChatCompletionStreamResponseDeltaFunctionCall getFunctionCall() { + return functionCall; + } + + /** + * Set the functionCall of this {@link ChatCompletionStreamResponseDelta} instance. + * + * @param functionCall The functionCall of this {@link ChatCompletionStreamResponseDelta} + */ + public void setFunctionCall( + @Nullable final ChatCompletionStreamResponseDeltaFunctionCall functionCall) { + this.functionCall = functionCall; + } + + /** + * Set the toolCalls of this {@link ChatCompletionStreamResponseDelta} instance and return the + * same instance. + * + * @param toolCalls The toolCalls of this {@link ChatCompletionStreamResponseDelta} + * @return The same instance of this {@link ChatCompletionStreamResponseDelta} class + */ + @Nonnull + public ChatCompletionStreamResponseDelta toolCalls( + @Nullable final List toolCalls) { + this.toolCalls = toolCalls; + return this; + } + + /** + * Add one toolCalls instance to this {@link ChatCompletionStreamResponseDelta}. + * + * @param toolCallsItem The toolCalls that should be added + * @return The same instance of type {@link ChatCompletionStreamResponseDelta} + */ + @Nonnull + public ChatCompletionStreamResponseDelta addToolCallsItem( + @Nonnull final ChatCompletionMessageToolCallChunk toolCallsItem) { + if (this.toolCalls == null) { + this.toolCalls = new ArrayList<>(); + } + this.toolCalls.add(toolCallsItem); + return this; + } + + /** + * Get toolCalls + * + * @return toolCalls The toolCalls of this {@link ChatCompletionStreamResponseDelta} instance. + */ + @Nonnull + public List getToolCalls() { + return toolCalls; + } + + /** + * Set the toolCalls of this {@link ChatCompletionStreamResponseDelta} instance. + * + * @param toolCalls The toolCalls of this {@link ChatCompletionStreamResponseDelta} + */ + public void setToolCalls(@Nullable final List toolCalls) { + this.toolCalls = toolCalls; + } + + /** + * Set the role of this {@link ChatCompletionStreamResponseDelta} instance and return the same + * instance. + * + * @param role The role of the author of this message. + * @return The same instance of this {@link ChatCompletionStreamResponseDelta} class + */ + @Nonnull + public ChatCompletionStreamResponseDelta role(@Nullable final RoleEnum role) { + this.role = role; + return this; + } + + /** + * The role of the author of this message. + * + * @return role The role of this {@link ChatCompletionStreamResponseDelta} instance. + */ + @Nonnull + public RoleEnum getRole() { + return role; + } + + /** + * Set the role of this {@link ChatCompletionStreamResponseDelta} instance. + * + * @param role The role of the author of this message. + */ + public void setRole(@Nullable final RoleEnum role) { + this.role = role; + } + + /** + * Set the refusal of this {@link ChatCompletionStreamResponseDelta} instance and return the same + * instance. + * + * @param refusal The refusal message generated by the model. + * @return The same instance of this {@link ChatCompletionStreamResponseDelta} class + */ + @Nonnull + public ChatCompletionStreamResponseDelta refusal(@Nullable final String refusal) { + this.refusal = refusal; + return this; + } + + /** + * The refusal message generated by the model. + * + * @return refusal The refusal of this {@link ChatCompletionStreamResponseDelta} instance. + */ + @Nullable + public String getRefusal() { + return refusal; + } + + /** + * Set the refusal of this {@link ChatCompletionStreamResponseDelta} instance. + * + * @param refusal The refusal message generated by the model. + */ + public void setRefusal(@Nullable final String refusal) { + this.refusal = refusal; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionStreamResponseDelta}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionStreamResponseDelta} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionStreamResponseDelta has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionStreamResponseDelta} instance. If + * the map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionStreamResponseDelta chatCompletionStreamResponseDelta = + (ChatCompletionStreamResponseDelta) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionStreamResponseDelta.cloudSdkCustomFields) + && Objects.equals(this.content, chatCompletionStreamResponseDelta.content) + && Objects.equals(this.functionCall, chatCompletionStreamResponseDelta.functionCall) + && Objects.equals(this.toolCalls, chatCompletionStreamResponseDelta.toolCalls) + && Objects.equals(this.role, chatCompletionStreamResponseDelta.role) + && Objects.equals(this.refusal, chatCompletionStreamResponseDelta.refusal); + } + + @Override + public int hashCode() { + return Objects.hash(content, functionCall, toolCalls, role, refusal, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionStreamResponseDelta {\n"); + sb.append(" content: ").append(toIndentedString(content)).append("\n"); + sb.append(" functionCall: ").append(toIndentedString(functionCall)).append("\n"); + sb.append(" toolCalls: ").append(toIndentedString(toolCalls)).append("\n"); + sb.append(" role: ").append(toIndentedString(role)).append("\n"); + sb.append(" refusal: ").append(toIndentedString(refusal)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionStreamResponseDeltaFunctionCall.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionStreamResponseDeltaFunctionCall.java new file mode 100644 index 000000000..172d4f474 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionStreamResponseDeltaFunctionCall.java @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Deprecated and replaced by `tool_calls`. The name and arguments of a function that + * should be called, as generated by the model. + * + * @deprecated + */ +@Deprecated +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionStreamResponseDeltaFunctionCall +// CHECKSTYLE:ON +{ + @JsonProperty("arguments") + private String arguments; + + @JsonProperty("name") + private String name; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the arguments of this {@link ChatCompletionStreamResponseDeltaFunctionCall} instance and + * return the same instance. + * + * @param arguments The arguments to call the function with, as generated by the model in JSON + * format. Note that the model does not always generate valid JSON, and may hallucinate + * parameters not defined by your function schema. Validate the arguments in your code before + * calling your function. + * @return The same instance of this {@link ChatCompletionStreamResponseDeltaFunctionCall} class + */ + @Nonnull + public ChatCompletionStreamResponseDeltaFunctionCall arguments(@Nullable final String arguments) { + this.arguments = arguments; + return this; + } + + /** + * The arguments to call the function with, as generated by the model in JSON format. Note that + * the model does not always generate valid JSON, and may hallucinate parameters not defined by + * your function schema. Validate the arguments in your code before calling your function. + * + * @return arguments The arguments of this {@link ChatCompletionStreamResponseDeltaFunctionCall} + * instance. + */ + @Nonnull + public String getArguments() { + return arguments; + } + + /** + * Set the arguments of this {@link ChatCompletionStreamResponseDeltaFunctionCall} instance. + * + * @param arguments The arguments to call the function with, as generated by the model in JSON + * format. Note that the model does not always generate valid JSON, and may hallucinate + * parameters not defined by your function schema. Validate the arguments in your code before + * calling your function. + */ + public void setArguments(@Nullable final String arguments) { + this.arguments = arguments; + } + + /** + * Set the name of this {@link ChatCompletionStreamResponseDeltaFunctionCall} instance and return + * the same instance. + * + * @param name The name of the function to call. + * @return The same instance of this {@link ChatCompletionStreamResponseDeltaFunctionCall} class + */ + @Nonnull + public ChatCompletionStreamResponseDeltaFunctionCall name(@Nullable final String name) { + this.name = name; + return this; + } + + /** + * The name of the function to call. + * + * @return name The name of this {@link ChatCompletionStreamResponseDeltaFunctionCall} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link ChatCompletionStreamResponseDeltaFunctionCall} instance. + * + * @param name The name of the function to call. + */ + public void setName(@Nullable final String name) { + this.name = name; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionStreamResponseDeltaFunctionCall}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * ChatCompletionStreamResponseDeltaFunctionCall} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionStreamResponseDeltaFunctionCall has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionStreamResponseDeltaFunctionCall} + * instance. If the map previously contained a mapping for the key, the old value is replaced by + * the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionStreamResponseDeltaFunctionCall + chatCompletionStreamResponseDeltaFunctionCall = + (ChatCompletionStreamResponseDeltaFunctionCall) o; + return Objects.equals( + this.cloudSdkCustomFields, + chatCompletionStreamResponseDeltaFunctionCall.cloudSdkCustomFields) + && Objects.equals(this.arguments, chatCompletionStreamResponseDeltaFunctionCall.arguments) + && Objects.equals(this.name, chatCompletionStreamResponseDeltaFunctionCall.name); + } + + @Override + public int hashCode() { + return Objects.hash(arguments, name, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionStreamResponseDeltaFunctionCall {\n"); + sb.append(" arguments: ").append(toIndentedString(arguments)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionTokenLogprob.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionTokenLogprob.java new file mode 100644 index 000000000..de06082e0 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionTokenLogprob.java @@ -0,0 +1,315 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionTokenLogprob */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionTokenLogprob +// CHECKSTYLE:ON +{ + @JsonProperty("token") + private String token; + + @JsonProperty("logprob") + private BigDecimal logprob; + + @JsonProperty("bytes") + private List bytes; + + @JsonProperty("top_logprobs") + private List topLogprobs = new ArrayList<>(); + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the token of this {@link ChatCompletionTokenLogprob} instance and return the same instance. + * + * @param token The token. + * @return The same instance of this {@link ChatCompletionTokenLogprob} class + */ + @Nonnull + public ChatCompletionTokenLogprob token(@Nonnull final String token) { + this.token = token; + return this; + } + + /** + * The token. + * + * @return token The token of this {@link ChatCompletionTokenLogprob} instance. + */ + @Nonnull + public String getToken() { + return token; + } + + /** + * Set the token of this {@link ChatCompletionTokenLogprob} instance. + * + * @param token The token. + */ + public void setToken(@Nonnull final String token) { + this.token = token; + } + + /** + * Set the logprob of this {@link ChatCompletionTokenLogprob} instance and return the same + * instance. + * + * @param logprob The log probability of this token. + * @return The same instance of this {@link ChatCompletionTokenLogprob} class + */ + @Nonnull + public ChatCompletionTokenLogprob logprob(@Nonnull final BigDecimal logprob) { + this.logprob = logprob; + return this; + } + + /** + * The log probability of this token. + * + * @return logprob The logprob of this {@link ChatCompletionTokenLogprob} instance. + */ + @Nonnull + public BigDecimal getLogprob() { + return logprob; + } + + /** + * Set the logprob of this {@link ChatCompletionTokenLogprob} instance. + * + * @param logprob The log probability of this token. + */ + public void setLogprob(@Nonnull final BigDecimal logprob) { + this.logprob = logprob; + } + + /** + * Set the bytes of this {@link ChatCompletionTokenLogprob} instance and return the same instance. + * + * @param bytes A list of integers representing the UTF-8 bytes representation of the token. + * Useful in instances where characters are represented by multiple tokens and their byte + * representations must be combined to generate the correct text representation. Can be + * `null` if there is no bytes representation for the token. + * @return The same instance of this {@link ChatCompletionTokenLogprob} class + */ + @Nonnull + public ChatCompletionTokenLogprob bytes(@Nullable final List bytes) { + this.bytes = bytes; + return this; + } + + /** + * Add one bytes instance to this {@link ChatCompletionTokenLogprob}. + * + * @param bytesItem The bytes that should be added + * @return The same instance of type {@link ChatCompletionTokenLogprob} + */ + @Nonnull + public ChatCompletionTokenLogprob addBytesItem(@Nonnull final Integer bytesItem) { + if (this.bytes == null) { + this.bytes = new ArrayList<>(); + } + this.bytes.add(bytesItem); + return this; + } + + /** + * A list of integers representing the UTF-8 bytes representation of the token. Useful in + * instances where characters are represented by multiple tokens and their byte representations + * must be combined to generate the correct text representation. Can be `null` if there + * is no bytes representation for the token. + * + * @return bytes The bytes of this {@link ChatCompletionTokenLogprob} instance. + */ + @Nullable + public List getBytes() { + return bytes; + } + + /** + * Set the bytes of this {@link ChatCompletionTokenLogprob} instance. + * + * @param bytes A list of integers representing the UTF-8 bytes representation of the token. + * Useful in instances where characters are represented by multiple tokens and their byte + * representations must be combined to generate the correct text representation. Can be + * `null` if there is no bytes representation for the token. + */ + public void setBytes(@Nullable final List bytes) { + this.bytes = bytes; + } + + /** + * Set the topLogprobs of this {@link ChatCompletionTokenLogprob} instance and return the same + * instance. + * + * @param topLogprobs List of the most likely tokens and their log probability, at this token + * position. In rare cases, there may be fewer than the number of requested + * `top_logprobs` returned. + * @return The same instance of this {@link ChatCompletionTokenLogprob} class + */ + @Nonnull + public ChatCompletionTokenLogprob topLogprobs( + @Nonnull final List topLogprobs) { + this.topLogprobs = topLogprobs; + return this; + } + + /** + * Add one topLogprobs instance to this {@link ChatCompletionTokenLogprob}. + * + * @param topLogprobsItem The topLogprobs that should be added + * @return The same instance of type {@link ChatCompletionTokenLogprob} + */ + @Nonnull + public ChatCompletionTokenLogprob addTopLogprobsItem( + @Nonnull final ChatCompletionTokenLogprobTopLogprobsInner topLogprobsItem) { + if (this.topLogprobs == null) { + this.topLogprobs = new ArrayList<>(); + } + this.topLogprobs.add(topLogprobsItem); + return this; + } + + /** + * List of the most likely tokens and their log probability, at this token position. In rare + * cases, there may be fewer than the number of requested `top_logprobs` returned. + * + * @return topLogprobs The topLogprobs of this {@link ChatCompletionTokenLogprob} instance. + */ + @Nonnull + public List getTopLogprobs() { + return topLogprobs; + } + + /** + * Set the topLogprobs of this {@link ChatCompletionTokenLogprob} instance. + * + * @param topLogprobs List of the most likely tokens and their log probability, at this token + * position. In rare cases, there may be fewer than the number of requested + * `top_logprobs` returned. + */ + public void setTopLogprobs( + @Nonnull final List topLogprobs) { + this.topLogprobs = topLogprobs; + } + + /** + * Get the names of the unrecognizable properties of the {@link ChatCompletionTokenLogprob}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionTokenLogprob} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionTokenLogprob has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionTokenLogprob} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionTokenLogprob chatCompletionTokenLogprob = (ChatCompletionTokenLogprob) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionTokenLogprob.cloudSdkCustomFields) + && Objects.equals(this.token, chatCompletionTokenLogprob.token) + && Objects.equals(this.logprob, chatCompletionTokenLogprob.logprob) + && Objects.equals(this.bytes, chatCompletionTokenLogprob.bytes) + && Objects.equals(this.topLogprobs, chatCompletionTokenLogprob.topLogprobs); + } + + @Override + public int hashCode() { + return Objects.hash(token, logprob, bytes, topLogprobs, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionTokenLogprob {\n"); + sb.append(" token: ").append(toIndentedString(token)).append("\n"); + sb.append(" logprob: ").append(toIndentedString(logprob)).append("\n"); + sb.append(" bytes: ").append(toIndentedString(bytes)).append("\n"); + sb.append(" topLogprobs: ").append(toIndentedString(topLogprobs)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionTokenLogprobTopLogprobsInner.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionTokenLogprobTopLogprobsInner.java new file mode 100644 index 000000000..41e2260f4 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionTokenLogprobTopLogprobsInner.java @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionTokenLogprobTopLogprobsInner */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionTokenLogprobTopLogprobsInner +// CHECKSTYLE:ON +{ + @JsonProperty("token") + private String token; + + @JsonProperty("logprob") + private BigDecimal logprob; + + @JsonProperty("bytes") + private List bytes; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the token of this {@link ChatCompletionTokenLogprobTopLogprobsInner} instance and return + * the same instance. + * + * @param token The token. + * @return The same instance of this {@link ChatCompletionTokenLogprobTopLogprobsInner} class + */ + @Nonnull + public ChatCompletionTokenLogprobTopLogprobsInner token(@Nonnull final String token) { + this.token = token; + return this; + } + + /** + * The token. + * + * @return token The token of this {@link ChatCompletionTokenLogprobTopLogprobsInner} instance. + */ + @Nonnull + public String getToken() { + return token; + } + + /** + * Set the token of this {@link ChatCompletionTokenLogprobTopLogprobsInner} instance. + * + * @param token The token. + */ + public void setToken(@Nonnull final String token) { + this.token = token; + } + + /** + * Set the logprob of this {@link ChatCompletionTokenLogprobTopLogprobsInner} instance and return + * the same instance. + * + * @param logprob The log probability of this token. + * @return The same instance of this {@link ChatCompletionTokenLogprobTopLogprobsInner} class + */ + @Nonnull + public ChatCompletionTokenLogprobTopLogprobsInner logprob(@Nonnull final BigDecimal logprob) { + this.logprob = logprob; + return this; + } + + /** + * The log probability of this token. + * + * @return logprob The logprob of this {@link ChatCompletionTokenLogprobTopLogprobsInner} + * instance. + */ + @Nonnull + public BigDecimal getLogprob() { + return logprob; + } + + /** + * Set the logprob of this {@link ChatCompletionTokenLogprobTopLogprobsInner} instance. + * + * @param logprob The log probability of this token. + */ + public void setLogprob(@Nonnull final BigDecimal logprob) { + this.logprob = logprob; + } + + /** + * Set the bytes of this {@link ChatCompletionTokenLogprobTopLogprobsInner} instance and return + * the same instance. + * + * @param bytes A list of integers representing the UTF-8 bytes representation of the token. + * Useful in instances where characters are represented by multiple tokens and their byte + * representations must be combined to generate the correct text representation. Can be + * `null` if there is no bytes representation for the token. + * @return The same instance of this {@link ChatCompletionTokenLogprobTopLogprobsInner} class + */ + @Nonnull + public ChatCompletionTokenLogprobTopLogprobsInner bytes(@Nullable final List bytes) { + this.bytes = bytes; + return this; + } + + /** + * Add one bytes instance to this {@link ChatCompletionTokenLogprobTopLogprobsInner}. + * + * @param bytesItem The bytes that should be added + * @return The same instance of type {@link ChatCompletionTokenLogprobTopLogprobsInner} + */ + @Nonnull + public ChatCompletionTokenLogprobTopLogprobsInner addBytesItem(@Nonnull final Integer bytesItem) { + if (this.bytes == null) { + this.bytes = new ArrayList<>(); + } + this.bytes.add(bytesItem); + return this; + } + + /** + * A list of integers representing the UTF-8 bytes representation of the token. Useful in + * instances where characters are represented by multiple tokens and their byte representations + * must be combined to generate the correct text representation. Can be `null` if there + * is no bytes representation for the token. + * + * @return bytes The bytes of this {@link ChatCompletionTokenLogprobTopLogprobsInner} instance. + */ + @Nullable + public List getBytes() { + return bytes; + } + + /** + * Set the bytes of this {@link ChatCompletionTokenLogprobTopLogprobsInner} instance. + * + * @param bytes A list of integers representing the UTF-8 bytes representation of the token. + * Useful in instances where characters are represented by multiple tokens and their byte + * representations must be combined to generate the correct text representation. Can be + * `null` if there is no bytes representation for the token. + */ + public void setBytes(@Nullable final List bytes) { + this.bytes = bytes; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ChatCompletionTokenLogprobTopLogprobsInner}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * ChatCompletionTokenLogprobTopLogprobsInner} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionTokenLogprobTopLogprobsInner has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionTokenLogprobTopLogprobsInner} + * instance. If the map previously contained a mapping for the key, the old value is replaced by + * the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionTokenLogprobTopLogprobsInner chatCompletionTokenLogprobTopLogprobsInner = + (ChatCompletionTokenLogprobTopLogprobsInner) o; + return Objects.equals( + this.cloudSdkCustomFields, + chatCompletionTokenLogprobTopLogprobsInner.cloudSdkCustomFields) + && Objects.equals(this.token, chatCompletionTokenLogprobTopLogprobsInner.token) + && Objects.equals(this.logprob, chatCompletionTokenLogprobTopLogprobsInner.logprob) + && Objects.equals(this.bytes, chatCompletionTokenLogprobTopLogprobsInner.bytes); + } + + @Override + public int hashCode() { + return Objects.hash(token, logprob, bytes, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionTokenLogprobTopLogprobsInner {\n"); + sb.append(" token: ").append(toIndentedString(token)).append("\n"); + sb.append(" logprob: ").append(toIndentedString(logprob)).append("\n"); + sb.append(" bytes: ").append(toIndentedString(bytes)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionTool.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionTool.java new file mode 100644 index 000000000..503501d81 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionTool.java @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionTool */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionTool +// CHECKSTYLE:ON +{ + /** The type of the tool. Currently, only `function` is supported. */ + public enum TypeEnum { + /** The FUNCTION option of this ChatCompletionTool */ + FUNCTION("function"); + + private String value; + + TypeEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ChatCompletionTool + */ + @JsonCreator + @Nonnull + public static TypeEnum fromValue(@Nonnull final String value) { + for (TypeEnum b : TypeEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("type") + private TypeEnum type; + + @JsonProperty("function") + private FunctionObject function; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the type of this {@link ChatCompletionTool} instance and return the same instance. + * + * @param type The type of the tool. Currently, only `function` is supported. + * @return The same instance of this {@link ChatCompletionTool} class + */ + @Nonnull + public ChatCompletionTool type(@Nonnull final TypeEnum type) { + this.type = type; + return this; + } + + /** + * The type of the tool. Currently, only `function` is supported. + * + * @return type The type of this {@link ChatCompletionTool} instance. + */ + @Nonnull + public TypeEnum getType() { + return type; + } + + /** + * Set the type of this {@link ChatCompletionTool} instance. + * + * @param type The type of the tool. Currently, only `function` is supported. + */ + public void setType(@Nonnull final TypeEnum type) { + this.type = type; + } + + /** + * Set the function of this {@link ChatCompletionTool} instance and return the same instance. + * + * @param function The function of this {@link ChatCompletionTool} + * @return The same instance of this {@link ChatCompletionTool} class + */ + @Nonnull + public ChatCompletionTool function(@Nonnull final FunctionObject function) { + this.function = function; + return this; + } + + /** + * Get function + * + * @return function The function of this {@link ChatCompletionTool} instance. + */ + @Nonnull + public FunctionObject getFunction() { + return function; + } + + /** + * Set the function of this {@link ChatCompletionTool} instance. + * + * @param function The function of this {@link ChatCompletionTool} + */ + public void setFunction(@Nonnull final FunctionObject function) { + this.function = function; + } + + /** + * Get the names of the unrecognizable properties of the {@link ChatCompletionTool}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionTool} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException("ChatCompletionTool has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionTool} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionTool chatCompletionTool = (ChatCompletionTool) o; + return Objects.equals(this.cloudSdkCustomFields, chatCompletionTool.cloudSdkCustomFields) + && Objects.equals(this.type, chatCompletionTool.type) + && Objects.equals(this.function, chatCompletionTool.function); + } + + @Override + public int hashCode() { + return Objects.hash(type, function, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionTool {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" function: ").append(toIndentedString(function)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionToolChoiceOption.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionToolChoiceOption.java new file mode 100644 index 000000000..36553808c --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionToolChoiceOption.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Controls which (if any) tool is called by the model. `none` means the model will not + * call any tool and instead generates a message. `auto` means the model can pick between + * generating a message or calling one or more tools. `required` means the model must call + * one or more tools. Specifying a particular tool via `{\"type\": + * \"function\", \"function\": {\"name\": + * \"my_function\"}}` forces the model to call that tool. `none` is the + * default when no tools are present. `auto` is the default if tools are present. + */ +@com.google.common.annotations.Beta +public interface ChatCompletionToolChoiceOption { + /** + * Helper class to create a ChatCompletionNamedToolChoice that implements {@link + * ChatCompletionToolChoiceOption}. + */ + record InnerChatCompletionNamedToolChoice(@JsonValue ChatCompletionNamedToolChoice value) + implements ChatCompletionToolChoiceOption {} + + /** + * Creator to enable deserialization of a ChatCompletionNamedToolChoice. + * + * @param val the value to use + * @return a new instance of {@link InnerChatCompletionNamedToolChoice}. + */ + @JsonCreator + static InnerChatCompletionNamedToolChoice create(ChatCompletionNamedToolChoice val) { + return new InnerChatCompletionNamedToolChoice(val); + } + + /** Helper class to create a String that implements {@link ChatCompletionToolChoiceOption}. */ + record InnerString(@JsonValue String value) implements ChatCompletionToolChoiceOption {} + + /** + * Creator to enable deserialization of a String. + * + * @param val the value to use + * @return a new instance of {@link InnerString}. + */ + @JsonCreator + static InnerString create(String val) { + return new InnerString(val); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionsCreate200Response.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionsCreate200Response.java new file mode 100644 index 000000000..595bb0243 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionsCreate200Response.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +/** ChatCompletionsCreate200Response */ +@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION) +@JsonSubTypes({ + @JsonSubTypes.Type(value = CreateChatCompletionResponse.class), + @JsonSubTypes.Type(value = CreateChatCompletionStreamResponse.class), +}) +@com.google.common.annotations.Beta +public interface ChatCompletionsCreate200Response {} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionsRequestCommon.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionsRequestCommon.java new file mode 100644 index 000000000..6f8c099e4 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionsRequestCommon.java @@ -0,0 +1,575 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ChatCompletionsRequestCommon */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ChatCompletionsRequestCommon +// CHECKSTYLE:ON +{ + @JsonProperty("temperature") + private BigDecimal temperature = new BigDecimal("1"); + + @JsonProperty("top_p") + private BigDecimal topP = new BigDecimal("1"); + + @JsonProperty("stream") + private Boolean stream = false; + + @JsonProperty("stop") + private ChatCompletionsRequestCommonStop stop = null; + + @JsonProperty("max_tokens") + private Integer maxTokens = 4096; + + @JsonProperty("max_completion_tokens") + private Integer maxCompletionTokens; + + @JsonProperty("presence_penalty") + private BigDecimal presencePenalty = new BigDecimal("0"); + + @JsonProperty("frequency_penalty") + private BigDecimal frequencyPenalty = new BigDecimal("0"); + + @JsonProperty("logit_bias") + private Object logitBias; + + @JsonProperty("user") + private String user; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the temperature of this {@link ChatCompletionsRequestCommon} instance and return the same + * instance. + * + * @param temperature What sampling temperature to use, between 0 and 2. Higher values like 0.8 + * will make the output more random, while lower values like 0.2 will make it more focused and + * deterministic. We generally recommend altering this or `top_p` but not both. + * Minimum: 0 Maximum: 2 + * @return The same instance of this {@link ChatCompletionsRequestCommon} class + */ + @Nonnull + public ChatCompletionsRequestCommon temperature(@Nullable final BigDecimal temperature) { + this.temperature = temperature; + return this; + } + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output + * more random, while lower values like 0.2 will make it more focused and deterministic. We + * generally recommend altering this or `top_p` but not both. minimum: 0 maximum: 2 + * + * @return temperature The temperature of this {@link ChatCompletionsRequestCommon} instance. + */ + @Nullable + public BigDecimal getTemperature() { + return temperature; + } + + /** + * Set the temperature of this {@link ChatCompletionsRequestCommon} instance. + * + * @param temperature What sampling temperature to use, between 0 and 2. Higher values like 0.8 + * will make the output more random, while lower values like 0.2 will make it more focused and + * deterministic. We generally recommend altering this or `top_p` but not both. + * Minimum: 0 Maximum: 2 + */ + public void setTemperature(@Nullable final BigDecimal temperature) { + this.temperature = temperature; + } + + /** + * Set the topP of this {@link ChatCompletionsRequestCommon} instance and return the same + * instance. + * + * @param topP An alternative to sampling with temperature, called nucleus sampling, where the + * model considers the results of the tokens with top_p probability mass. So 0.1 means only + * the tokens comprising the top 10% probability mass are considered. We generally recommend + * altering this or `temperature` but not both. Minimum: 0 Maximum: 1 + * @return The same instance of this {@link ChatCompletionsRequestCommon} class + */ + @Nonnull + public ChatCompletionsRequestCommon topP(@Nullable final BigDecimal topP) { + this.topP = topP; + return this; + } + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model considers + * the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising + * the top 10% probability mass are considered. We generally recommend altering this or + * `temperature` but not both. minimum: 0 maximum: 1 + * + * @return topP The topP of this {@link ChatCompletionsRequestCommon} instance. + */ + @Nullable + public BigDecimal getTopP() { + return topP; + } + + /** + * Set the topP of this {@link ChatCompletionsRequestCommon} instance. + * + * @param topP An alternative to sampling with temperature, called nucleus sampling, where the + * model considers the results of the tokens with top_p probability mass. So 0.1 means only + * the tokens comprising the top 10% probability mass are considered. We generally recommend + * altering this or `temperature` but not both. Minimum: 0 Maximum: 1 + */ + public void setTopP(@Nullable final BigDecimal topP) { + this.topP = topP; + } + + /** + * Set the stream of this {@link ChatCompletionsRequestCommon} instance and return the same + * instance. + * + * @param stream If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent + * as data-only server-sent events as they become available, with the stream terminated by a + * `data: [DONE]` message. + * @return The same instance of this {@link ChatCompletionsRequestCommon} class + */ + @Nonnull + public ChatCompletionsRequestCommon stream(@Nullable final Boolean stream) { + this.stream = stream; + return this; + } + + /** + * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only + * server-sent events as they become available, with the stream terminated by a `data: + * [DONE]` message. + * + * @return stream The stream of this {@link ChatCompletionsRequestCommon} instance. + */ + @Nullable + public Boolean isStream() { + return stream; + } + + /** + * Set the stream of this {@link ChatCompletionsRequestCommon} instance. + * + * @param stream If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent + * as data-only server-sent events as they become available, with the stream terminated by a + * `data: [DONE]` message. + */ + public void setStream(@Nullable final Boolean stream) { + this.stream = stream; + } + + /** + * Set the stop of this {@link ChatCompletionsRequestCommon} instance and return the same + * instance. + * + * @param stop The stop of this {@link ChatCompletionsRequestCommon} + * @return The same instance of this {@link ChatCompletionsRequestCommon} class + */ + @Nonnull + public ChatCompletionsRequestCommon stop(@Nullable final ChatCompletionsRequestCommonStop stop) { + this.stop = stop; + return this; + } + + /** + * Get stop + * + * @return stop The stop of this {@link ChatCompletionsRequestCommon} instance. + */ + @Nonnull + public ChatCompletionsRequestCommonStop getStop() { + return stop; + } + + /** + * Set the stop of this {@link ChatCompletionsRequestCommon} instance. + * + * @param stop The stop of this {@link ChatCompletionsRequestCommon} + */ + public void setStop(@Nullable final ChatCompletionsRequestCommonStop stop) { + this.stop = stop; + } + + /** + * Set the maxTokens of this {@link ChatCompletionsRequestCommon} instance and return the same + * instance. + * + * @param maxTokens The maximum number of tokens allowed for the generated answer. By default, the + * number of tokens the model can return will be (4096 - prompt tokens). This value is now + * deprecated in favor of `max_completion_tokens`, and is not compatible with o1 + * series models. + * @return The same instance of this {@link ChatCompletionsRequestCommon} class + */ + @Nonnull + public ChatCompletionsRequestCommon maxTokens(@Nullable final Integer maxTokens) { + this.maxTokens = maxTokens; + return this; + } + + /** + * The maximum number of tokens allowed for the generated answer. By default, the number of tokens + * the model can return will be (4096 - prompt tokens). This value is now deprecated in favor of + * `max_completion_tokens`, and is not compatible with o1 series models. + * + * @return maxTokens The maxTokens of this {@link ChatCompletionsRequestCommon} instance. + */ + @Nonnull + public Integer getMaxTokens() { + return maxTokens; + } + + /** + * Set the maxTokens of this {@link ChatCompletionsRequestCommon} instance. + * + * @param maxTokens The maximum number of tokens allowed for the generated answer. By default, the + * number of tokens the model can return will be (4096 - prompt tokens). This value is now + * deprecated in favor of `max_completion_tokens`, and is not compatible with o1 + * series models. + */ + public void setMaxTokens(@Nullable final Integer maxTokens) { + this.maxTokens = maxTokens; + } + + /** + * Set the maxCompletionTokens of this {@link ChatCompletionsRequestCommon} instance and return + * the same instance. + * + * @param maxCompletionTokens An upper bound for the number of tokens that can be generated for a + * completion, including visible output tokens and reasoning tokens. + * @return The same instance of this {@link ChatCompletionsRequestCommon} class + */ + @Nonnull + public ChatCompletionsRequestCommon maxCompletionTokens( + @Nullable final Integer maxCompletionTokens) { + this.maxCompletionTokens = maxCompletionTokens; + return this; + } + + /** + * An upper bound for the number of tokens that can be generated for a completion, including + * visible output tokens and reasoning tokens. + * + * @return maxCompletionTokens The maxCompletionTokens of this {@link + * ChatCompletionsRequestCommon} instance. + */ + @Nullable + public Integer getMaxCompletionTokens() { + return maxCompletionTokens; + } + + /** + * Set the maxCompletionTokens of this {@link ChatCompletionsRequestCommon} instance. + * + * @param maxCompletionTokens An upper bound for the number of tokens that can be generated for a + * completion, including visible output tokens and reasoning tokens. + */ + public void setMaxCompletionTokens(@Nullable final Integer maxCompletionTokens) { + this.maxCompletionTokens = maxCompletionTokens; + } + + /** + * Set the presencePenalty of this {@link ChatCompletionsRequestCommon} instance and return the + * same instance. + * + * @param presencePenalty Number between -2.0 and 2.0. Positive values penalize new tokens based + * on whether they appear in the text so far, increasing the model's likelihood to talk + * about new topics. Minimum: -2 Maximum: 2 + * @return The same instance of this {@link ChatCompletionsRequestCommon} class + */ + @Nonnull + public ChatCompletionsRequestCommon presencePenalty(@Nullable final BigDecimal presencePenalty) { + this.presencePenalty = presencePenalty; + return this; + } + + /** + * Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear + * in the text so far, increasing the model's likelihood to talk about new topics. minimum: -2 + * maximum: 2 + * + * @return presencePenalty The presencePenalty of this {@link ChatCompletionsRequestCommon} + * instance. + */ + @Nonnull + public BigDecimal getPresencePenalty() { + return presencePenalty; + } + + /** + * Set the presencePenalty of this {@link ChatCompletionsRequestCommon} instance. + * + * @param presencePenalty Number between -2.0 and 2.0. Positive values penalize new tokens based + * on whether they appear in the text so far, increasing the model's likelihood to talk + * about new topics. Minimum: -2 Maximum: 2 + */ + public void setPresencePenalty(@Nullable final BigDecimal presencePenalty) { + this.presencePenalty = presencePenalty; + } + + /** + * Set the frequencyPenalty of this {@link ChatCompletionsRequestCommon} instance and return the + * same instance. + * + * @param frequencyPenalty Number between -2.0 and 2.0. Positive values penalize new tokens based + * on their existing frequency in the text so far, decreasing the model's likelihood to + * repeat the same line verbatim. Minimum: -2 Maximum: 2 + * @return The same instance of this {@link ChatCompletionsRequestCommon} class + */ + @Nonnull + public ChatCompletionsRequestCommon frequencyPenalty( + @Nullable final BigDecimal frequencyPenalty) { + this.frequencyPenalty = frequencyPenalty; + return this; + } + + /** + * Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing + * frequency in the text so far, decreasing the model's likelihood to repeat the same line + * verbatim. minimum: -2 maximum: 2 + * + * @return frequencyPenalty The frequencyPenalty of this {@link ChatCompletionsRequestCommon} + * instance. + */ + @Nonnull + public BigDecimal getFrequencyPenalty() { + return frequencyPenalty; + } + + /** + * Set the frequencyPenalty of this {@link ChatCompletionsRequestCommon} instance. + * + * @param frequencyPenalty Number between -2.0 and 2.0. Positive values penalize new tokens based + * on their existing frequency in the text so far, decreasing the model's likelihood to + * repeat the same line verbatim. Minimum: -2 Maximum: 2 + */ + public void setFrequencyPenalty(@Nullable final BigDecimal frequencyPenalty) { + this.frequencyPenalty = frequencyPenalty; + } + + /** + * Set the logitBias of this {@link ChatCompletionsRequestCommon} instance and return the same + * instance. + * + * @param logitBias Modify the likelihood of specified tokens appearing in the completion. Accepts + * a json object that maps tokens (specified by their token ID in the tokenizer) to an + * associated bias value from -100 to 100. Mathematically, the bias is added to the logits + * generated by the model prior to sampling. The exact effect will vary per model, but values + * between -1 and 1 should decrease or increase likelihood of selection; values like -100 or + * 100 should result in a ban or exclusive selection of the relevant token. + * @return The same instance of this {@link ChatCompletionsRequestCommon} class + */ + @Nonnull + public ChatCompletionsRequestCommon logitBias(@Nullable final Object logitBias) { + this.logitBias = logitBias; + return this; + } + + /** + * Modify the likelihood of specified tokens appearing in the completion. Accepts a json object + * that maps tokens (specified by their token ID in the tokenizer) to an associated bias value + * from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior + * to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease + * or increase likelihood of selection; values like -100 or 100 should result in a ban or + * exclusive selection of the relevant token. + * + * @return logitBias The logitBias of this {@link ChatCompletionsRequestCommon} instance. + */ + @Nullable + public Object getLogitBias() { + return logitBias; + } + + /** + * Set the logitBias of this {@link ChatCompletionsRequestCommon} instance. + * + * @param logitBias Modify the likelihood of specified tokens appearing in the completion. Accepts + * a json object that maps tokens (specified by their token ID in the tokenizer) to an + * associated bias value from -100 to 100. Mathematically, the bias is added to the logits + * generated by the model prior to sampling. The exact effect will vary per model, but values + * between -1 and 1 should decrease or increase likelihood of selection; values like -100 or + * 100 should result in a ban or exclusive selection of the relevant token. + */ + public void setLogitBias(@Nullable final Object logitBias) { + this.logitBias = logitBias; + } + + /** + * Set the user of this {@link ChatCompletionsRequestCommon} instance and return the same + * instance. + * + * @param user A unique identifier representing your end-user, which can help Azure OpenAI to + * monitor and detect abuse. + * @return The same instance of this {@link ChatCompletionsRequestCommon} class + */ + @Nonnull + public ChatCompletionsRequestCommon user(@Nullable final String user) { + this.user = user; + return this; + } + + /** + * A unique identifier representing your end-user, which can help Azure OpenAI to monitor and + * detect abuse. + * + * @return user The user of this {@link ChatCompletionsRequestCommon} instance. + */ + @Nonnull + public String getUser() { + return user; + } + + /** + * Set the user of this {@link ChatCompletionsRequestCommon} instance. + * + * @param user A unique identifier representing your end-user, which can help Azure OpenAI to + * monitor and detect abuse. + */ + public void setUser(@Nullable final String user) { + this.user = user; + } + + /** + * Get the names of the unrecognizable properties of the {@link ChatCompletionsRequestCommon}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ChatCompletionsRequestCommon} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ChatCompletionsRequestCommon has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ChatCompletionsRequestCommon} instance. If the + * map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ChatCompletionsRequestCommon chatCompletionsRequestCommon = + (ChatCompletionsRequestCommon) o; + return Objects.equals( + this.cloudSdkCustomFields, chatCompletionsRequestCommon.cloudSdkCustomFields) + && Objects.equals(this.temperature, chatCompletionsRequestCommon.temperature) + && Objects.equals(this.topP, chatCompletionsRequestCommon.topP) + && Objects.equals(this.stream, chatCompletionsRequestCommon.stream) + && Objects.equals(this.stop, chatCompletionsRequestCommon.stop) + && Objects.equals(this.maxTokens, chatCompletionsRequestCommon.maxTokens) + && Objects.equals( + this.maxCompletionTokens, chatCompletionsRequestCommon.maxCompletionTokens) + && Objects.equals(this.presencePenalty, chatCompletionsRequestCommon.presencePenalty) + && Objects.equals(this.frequencyPenalty, chatCompletionsRequestCommon.frequencyPenalty) + && Objects.equals(this.logitBias, chatCompletionsRequestCommon.logitBias) + && Objects.equals(this.user, chatCompletionsRequestCommon.user); + } + + @Override + public int hashCode() { + return Objects.hash( + temperature, + topP, + stream, + stop, + maxTokens, + maxCompletionTokens, + presencePenalty, + frequencyPenalty, + logitBias, + user, + cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ChatCompletionsRequestCommon {\n"); + sb.append(" temperature: ").append(toIndentedString(temperature)).append("\n"); + sb.append(" topP: ").append(toIndentedString(topP)).append("\n"); + sb.append(" stream: ").append(toIndentedString(stream)).append("\n"); + sb.append(" stop: ").append(toIndentedString(stop)).append("\n"); + sb.append(" maxTokens: ").append(toIndentedString(maxTokens)).append("\n"); + sb.append(" maxCompletionTokens: ") + .append(toIndentedString(maxCompletionTokens)) + .append("\n"); + sb.append(" presencePenalty: ").append(toIndentedString(presencePenalty)).append("\n"); + sb.append(" frequencyPenalty: ").append(toIndentedString(frequencyPenalty)).append("\n"); + sb.append(" logitBias: ").append(toIndentedString(logitBias)).append("\n"); + sb.append(" user: ").append(toIndentedString(user)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionsRequestCommonStop.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionsRequestCommonStop.java new file mode 100644 index 000000000..372b32a23 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ChatCompletionsRequestCommonStop.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import java.util.List; + +/** Up to 4 sequences where the API will stop generating further tokens. */ +@com.google.common.annotations.Beta +public interface ChatCompletionsRequestCommonStop { + /** Helper class to create a String that implements {@link ChatCompletionsRequestCommonStop}. */ + record InnerString(@com.fasterxml.jackson.annotation.JsonValue String value) + implements ChatCompletionsRequestCommonStop {} + + /** + * Creator to enable deserialization of a String. + * + * @param val the value to use + * @return a new instance of {@link InnerString}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + static InnerString create(String val) { + return new InnerString(val); + } + + /** + * Helper class to create a list of String that implements {@link + * ChatCompletionsRequestCommonStop}. + */ + record InnerStrings(@com.fasterxml.jackson.annotation.JsonValue List values) + implements ChatCompletionsRequestCommonStop {} + + /** + * Creator to enable deserialization of a list of String. + * + * @param val the value to use + * @return a new instance of {@link InnerStrings}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + static InnerStrings create(List val) { + return new InnerStrings(val); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CompletionUsage.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CompletionUsage.java new file mode 100644 index 000000000..964031ae0 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CompletionUsage.java @@ -0,0 +1,267 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** Usage statistics for the completion request. */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class CompletionUsage +// CHECKSTYLE:ON +{ + @JsonProperty("prompt_tokens") + private Integer promptTokens; + + @JsonProperty("completion_tokens") + private Integer completionTokens; + + @JsonProperty("total_tokens") + private Integer totalTokens; + + @JsonProperty("completion_tokens_details") + private CompletionUsageCompletionTokensDetails completionTokensDetails; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the promptTokens of this {@link CompletionUsage} instance and return the same instance. + * + * @param promptTokens Number of tokens in the prompt. + * @return The same instance of this {@link CompletionUsage} class + */ + @Nonnull + public CompletionUsage promptTokens(@Nonnull final Integer promptTokens) { + this.promptTokens = promptTokens; + return this; + } + + /** + * Number of tokens in the prompt. + * + * @return promptTokens The promptTokens of this {@link CompletionUsage} instance. + */ + @Nonnull + public Integer getPromptTokens() { + return promptTokens; + } + + /** + * Set the promptTokens of this {@link CompletionUsage} instance. + * + * @param promptTokens Number of tokens in the prompt. + */ + public void setPromptTokens(@Nonnull final Integer promptTokens) { + this.promptTokens = promptTokens; + } + + /** + * Set the completionTokens of this {@link CompletionUsage} instance and return the same instance. + * + * @param completionTokens Number of tokens in the generated completion. + * @return The same instance of this {@link CompletionUsage} class + */ + @Nonnull + public CompletionUsage completionTokens(@Nonnull final Integer completionTokens) { + this.completionTokens = completionTokens; + return this; + } + + /** + * Number of tokens in the generated completion. + * + * @return completionTokens The completionTokens of this {@link CompletionUsage} instance. + */ + @Nonnull + public Integer getCompletionTokens() { + return completionTokens; + } + + /** + * Set the completionTokens of this {@link CompletionUsage} instance. + * + * @param completionTokens Number of tokens in the generated completion. + */ + public void setCompletionTokens(@Nonnull final Integer completionTokens) { + this.completionTokens = completionTokens; + } + + /** + * Set the totalTokens of this {@link CompletionUsage} instance and return the same instance. + * + * @param totalTokens Total number of tokens used in the request (prompt + completion). + * @return The same instance of this {@link CompletionUsage} class + */ + @Nonnull + public CompletionUsage totalTokens(@Nonnull final Integer totalTokens) { + this.totalTokens = totalTokens; + return this; + } + + /** + * Total number of tokens used in the request (prompt + completion). + * + * @return totalTokens The totalTokens of this {@link CompletionUsage} instance. + */ + @Nonnull + public Integer getTotalTokens() { + return totalTokens; + } + + /** + * Set the totalTokens of this {@link CompletionUsage} instance. + * + * @param totalTokens Total number of tokens used in the request (prompt + completion). + */ + public void setTotalTokens(@Nonnull final Integer totalTokens) { + this.totalTokens = totalTokens; + } + + /** + * Set the completionTokensDetails of this {@link CompletionUsage} instance and return the same + * instance. + * + * @param completionTokensDetails The completionTokensDetails of this {@link CompletionUsage} + * @return The same instance of this {@link CompletionUsage} class + */ + @Nonnull + public CompletionUsage completionTokensDetails( + @Nullable final CompletionUsageCompletionTokensDetails completionTokensDetails) { + this.completionTokensDetails = completionTokensDetails; + return this; + } + + /** + * Get completionTokensDetails + * + * @return completionTokensDetails The completionTokensDetails of this {@link CompletionUsage} + * instance. + */ + @Nonnull + public CompletionUsageCompletionTokensDetails getCompletionTokensDetails() { + return completionTokensDetails; + } + + /** + * Set the completionTokensDetails of this {@link CompletionUsage} instance. + * + * @param completionTokensDetails The completionTokensDetails of this {@link CompletionUsage} + */ + public void setCompletionTokensDetails( + @Nullable final CompletionUsageCompletionTokensDetails completionTokensDetails) { + this.completionTokensDetails = completionTokensDetails; + } + + /** + * Get the names of the unrecognizable properties of the {@link CompletionUsage}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link CompletionUsage} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException("CompletionUsage has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link CompletionUsage} instance. If the map previously + * contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final CompletionUsage completionUsage = (CompletionUsage) o; + return Objects.equals(this.cloudSdkCustomFields, completionUsage.cloudSdkCustomFields) + && Objects.equals(this.promptTokens, completionUsage.promptTokens) + && Objects.equals(this.completionTokens, completionUsage.completionTokens) + && Objects.equals(this.totalTokens, completionUsage.totalTokens) + && Objects.equals(this.completionTokensDetails, completionUsage.completionTokensDetails); + } + + @Override + public int hashCode() { + return Objects.hash( + promptTokens, completionTokens, totalTokens, completionTokensDetails, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class CompletionUsage {\n"); + sb.append(" promptTokens: ").append(toIndentedString(promptTokens)).append("\n"); + sb.append(" completionTokens: ").append(toIndentedString(completionTokens)).append("\n"); + sb.append(" totalTokens: ").append(toIndentedString(totalTokens)).append("\n"); + sb.append(" completionTokensDetails: ") + .append(toIndentedString(completionTokensDetails)) + .append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CompletionUsageCompletionTokensDetails.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CompletionUsageCompletionTokensDetails.java new file mode 100644 index 000000000..d48730912 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CompletionUsageCompletionTokensDetails.java @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** Breakdown of tokens used in a completion. */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class CompletionUsageCompletionTokensDetails +// CHECKSTYLE:ON +{ + @JsonProperty("reasoning_tokens") + private Integer reasoningTokens; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the reasoningTokens of this {@link CompletionUsageCompletionTokensDetails} instance and + * return the same instance. + * + * @param reasoningTokens Tokens generated by the model for reasoning. + * @return The same instance of this {@link CompletionUsageCompletionTokensDetails} class + */ + @Nonnull + public CompletionUsageCompletionTokensDetails reasoningTokens( + @Nullable final Integer reasoningTokens) { + this.reasoningTokens = reasoningTokens; + return this; + } + + /** + * Tokens generated by the model for reasoning. + * + * @return reasoningTokens The reasoningTokens of this {@link + * CompletionUsageCompletionTokensDetails} instance. + */ + @Nonnull + public Integer getReasoningTokens() { + return reasoningTokens; + } + + /** + * Set the reasoningTokens of this {@link CompletionUsageCompletionTokensDetails} instance. + * + * @param reasoningTokens Tokens generated by the model for reasoning. + */ + public void setReasoningTokens(@Nullable final Integer reasoningTokens) { + this.reasoningTokens = reasoningTokens; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * CompletionUsageCompletionTokensDetails}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * CompletionUsageCompletionTokensDetails} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "CompletionUsageCompletionTokensDetails has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link CompletionUsageCompletionTokensDetails} instance. + * If the map previously contained a mapping for the key, the old value is replaced by the + * specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final CompletionUsageCompletionTokensDetails completionUsageCompletionTokensDetails = + (CompletionUsageCompletionTokensDetails) o; + return Objects.equals( + this.cloudSdkCustomFields, completionUsageCompletionTokensDetails.cloudSdkCustomFields) + && Objects.equals( + this.reasoningTokens, completionUsageCompletionTokensDetails.reasoningTokens); + } + + @Override + public int hashCode() { + return Objects.hash(reasoningTokens, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class CompletionUsageCompletionTokensDetails {\n"); + sb.append(" reasoningTokens: ").append(toIndentedString(reasoningTokens)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterChoiceResults.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterChoiceResults.java new file mode 100644 index 000000000..209258016 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterChoiceResults.java @@ -0,0 +1,445 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Information about the content filtering category (hate, sexual, violence, self_harm), if it has + * been detected, as well as the severity level (very_low, low, medium, high-scale that determines + * the intensity and risk level of harmful content) and if it has been filtered or not. Information + * about third party text and profanity, if it has been detected, and if it has been filtered or + * not. And information about customer block list, if it has been filtered and its id. + */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ContentFilterChoiceResults +// CHECKSTYLE:ON +{ + @JsonProperty("sexual") + private ContentFilterSeverityResult sexual; + + @JsonProperty("violence") + private ContentFilterSeverityResult violence; + + @JsonProperty("hate") + private ContentFilterSeverityResult hate; + + @JsonProperty("self_harm") + private ContentFilterSeverityResult selfHarm; + + @JsonProperty("profanity") + private ContentFilterDetectedResult profanity; + + @JsonProperty("error") + private ErrorBase error; + + @JsonProperty("protected_material_text") + private ContentFilterDetectedResult protectedMaterialText; + + @JsonProperty("protected_material_code") + private ContentFilterDetectedWithCitationResult protectedMaterialCode; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the sexual of this {@link ContentFilterChoiceResults} instance and return the same + * instance. + * + * @param sexual The sexual of this {@link ContentFilterChoiceResults} + * @return The same instance of this {@link ContentFilterChoiceResults} class + */ + @Nonnull + public ContentFilterChoiceResults sexual(@Nullable final ContentFilterSeverityResult sexual) { + this.sexual = sexual; + return this; + } + + /** + * Get sexual + * + * @return sexual The sexual of this {@link ContentFilterChoiceResults} instance. + */ + @Nonnull + public ContentFilterSeverityResult getSexual() { + return sexual; + } + + /** + * Set the sexual of this {@link ContentFilterChoiceResults} instance. + * + * @param sexual The sexual of this {@link ContentFilterChoiceResults} + */ + public void setSexual(@Nullable final ContentFilterSeverityResult sexual) { + this.sexual = sexual; + } + + /** + * Set the violence of this {@link ContentFilterChoiceResults} instance and return the same + * instance. + * + * @param violence The violence of this {@link ContentFilterChoiceResults} + * @return The same instance of this {@link ContentFilterChoiceResults} class + */ + @Nonnull + public ContentFilterChoiceResults violence(@Nullable final ContentFilterSeverityResult violence) { + this.violence = violence; + return this; + } + + /** + * Get violence + * + * @return violence The violence of this {@link ContentFilterChoiceResults} instance. + */ + @Nonnull + public ContentFilterSeverityResult getViolence() { + return violence; + } + + /** + * Set the violence of this {@link ContentFilterChoiceResults} instance. + * + * @param violence The violence of this {@link ContentFilterChoiceResults} + */ + public void setViolence(@Nullable final ContentFilterSeverityResult violence) { + this.violence = violence; + } + + /** + * Set the hate of this {@link ContentFilterChoiceResults} instance and return the same instance. + * + * @param hate The hate of this {@link ContentFilterChoiceResults} + * @return The same instance of this {@link ContentFilterChoiceResults} class + */ + @Nonnull + public ContentFilterChoiceResults hate(@Nullable final ContentFilterSeverityResult hate) { + this.hate = hate; + return this; + } + + /** + * Get hate + * + * @return hate The hate of this {@link ContentFilterChoiceResults} instance. + */ + @Nonnull + public ContentFilterSeverityResult getHate() { + return hate; + } + + /** + * Set the hate of this {@link ContentFilterChoiceResults} instance. + * + * @param hate The hate of this {@link ContentFilterChoiceResults} + */ + public void setHate(@Nullable final ContentFilterSeverityResult hate) { + this.hate = hate; + } + + /** + * Set the selfHarm of this {@link ContentFilterChoiceResults} instance and return the same + * instance. + * + * @param selfHarm The selfHarm of this {@link ContentFilterChoiceResults} + * @return The same instance of this {@link ContentFilterChoiceResults} class + */ + @Nonnull + public ContentFilterChoiceResults selfHarm(@Nullable final ContentFilterSeverityResult selfHarm) { + this.selfHarm = selfHarm; + return this; + } + + /** + * Get selfHarm + * + * @return selfHarm The selfHarm of this {@link ContentFilterChoiceResults} instance. + */ + @Nonnull + public ContentFilterSeverityResult getSelfHarm() { + return selfHarm; + } + + /** + * Set the selfHarm of this {@link ContentFilterChoiceResults} instance. + * + * @param selfHarm The selfHarm of this {@link ContentFilterChoiceResults} + */ + public void setSelfHarm(@Nullable final ContentFilterSeverityResult selfHarm) { + this.selfHarm = selfHarm; + } + + /** + * Set the profanity of this {@link ContentFilterChoiceResults} instance and return the same + * instance. + * + * @param profanity The profanity of this {@link ContentFilterChoiceResults} + * @return The same instance of this {@link ContentFilterChoiceResults} class + */ + @Nonnull + public ContentFilterChoiceResults profanity( + @Nullable final ContentFilterDetectedResult profanity) { + this.profanity = profanity; + return this; + } + + /** + * Get profanity + * + * @return profanity The profanity of this {@link ContentFilterChoiceResults} instance. + */ + @Nonnull + public ContentFilterDetectedResult getProfanity() { + return profanity; + } + + /** + * Set the profanity of this {@link ContentFilterChoiceResults} instance. + * + * @param profanity The profanity of this {@link ContentFilterChoiceResults} + */ + public void setProfanity(@Nullable final ContentFilterDetectedResult profanity) { + this.profanity = profanity; + } + + /** + * Set the error of this {@link ContentFilterChoiceResults} instance and return the same instance. + * + * @param error The error of this {@link ContentFilterChoiceResults} + * @return The same instance of this {@link ContentFilterChoiceResults} class + */ + @Nonnull + public ContentFilterChoiceResults error(@Nullable final ErrorBase error) { + this.error = error; + return this; + } + + /** + * Get error + * + * @return error The error of this {@link ContentFilterChoiceResults} instance. + */ + @Nonnull + public ErrorBase getError() { + return error; + } + + /** + * Set the error of this {@link ContentFilterChoiceResults} instance. + * + * @param error The error of this {@link ContentFilterChoiceResults} + */ + public void setError(@Nullable final ErrorBase error) { + this.error = error; + } + + /** + * Set the protectedMaterialText of this {@link ContentFilterChoiceResults} instance and return + * the same instance. + * + * @param protectedMaterialText The protectedMaterialText of this {@link + * ContentFilterChoiceResults} + * @return The same instance of this {@link ContentFilterChoiceResults} class + */ + @Nonnull + public ContentFilterChoiceResults protectedMaterialText( + @Nullable final ContentFilterDetectedResult protectedMaterialText) { + this.protectedMaterialText = protectedMaterialText; + return this; + } + + /** + * Get protectedMaterialText + * + * @return protectedMaterialText The protectedMaterialText of this {@link + * ContentFilterChoiceResults} instance. + */ + @Nonnull + public ContentFilterDetectedResult getProtectedMaterialText() { + return protectedMaterialText; + } + + /** + * Set the protectedMaterialText of this {@link ContentFilterChoiceResults} instance. + * + * @param protectedMaterialText The protectedMaterialText of this {@link + * ContentFilterChoiceResults} + */ + public void setProtectedMaterialText( + @Nullable final ContentFilterDetectedResult protectedMaterialText) { + this.protectedMaterialText = protectedMaterialText; + } + + /** + * Set the protectedMaterialCode of this {@link ContentFilterChoiceResults} instance and return + * the same instance. + * + * @param protectedMaterialCode The protectedMaterialCode of this {@link + * ContentFilterChoiceResults} + * @return The same instance of this {@link ContentFilterChoiceResults} class + */ + @Nonnull + public ContentFilterChoiceResults protectedMaterialCode( + @Nullable final ContentFilterDetectedWithCitationResult protectedMaterialCode) { + this.protectedMaterialCode = protectedMaterialCode; + return this; + } + + /** + * Get protectedMaterialCode + * + * @return protectedMaterialCode The protectedMaterialCode of this {@link + * ContentFilterChoiceResults} instance. + */ + @Nonnull + public ContentFilterDetectedWithCitationResult getProtectedMaterialCode() { + return protectedMaterialCode; + } + + /** + * Set the protectedMaterialCode of this {@link ContentFilterChoiceResults} instance. + * + * @param protectedMaterialCode The protectedMaterialCode of this {@link + * ContentFilterChoiceResults} + */ + public void setProtectedMaterialCode( + @Nullable final ContentFilterDetectedWithCitationResult protectedMaterialCode) { + this.protectedMaterialCode = protectedMaterialCode; + } + + /** + * Get the names of the unrecognizable properties of the {@link ContentFilterChoiceResults}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ContentFilterChoiceResults} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ContentFilterChoiceResults has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ContentFilterChoiceResults} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ContentFilterChoiceResults contentFilterChoiceResults = (ContentFilterChoiceResults) o; + return Objects.equals( + this.cloudSdkCustomFields, contentFilterChoiceResults.cloudSdkCustomFields) + && Objects.equals(this.sexual, contentFilterChoiceResults.sexual) + && Objects.equals(this.violence, contentFilterChoiceResults.violence) + && Objects.equals(this.hate, contentFilterChoiceResults.hate) + && Objects.equals(this.selfHarm, contentFilterChoiceResults.selfHarm) + && Objects.equals(this.profanity, contentFilterChoiceResults.profanity) + && Objects.equals(this.error, contentFilterChoiceResults.error) + && Objects.equals( + this.protectedMaterialText, contentFilterChoiceResults.protectedMaterialText) + && Objects.equals( + this.protectedMaterialCode, contentFilterChoiceResults.protectedMaterialCode); + } + + @Override + public int hashCode() { + return Objects.hash( + sexual, + violence, + hate, + selfHarm, + profanity, + error, + protectedMaterialText, + protectedMaterialCode, + cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ContentFilterChoiceResults {\n"); + sb.append(" sexual: ").append(toIndentedString(sexual)).append("\n"); + sb.append(" violence: ").append(toIndentedString(violence)).append("\n"); + sb.append(" hate: ").append(toIndentedString(hate)).append("\n"); + sb.append(" selfHarm: ").append(toIndentedString(selfHarm)).append("\n"); + sb.append(" profanity: ").append(toIndentedString(profanity)).append("\n"); + sb.append(" error: ").append(toIndentedString(error)).append("\n"); + sb.append(" protectedMaterialText: ") + .append(toIndentedString(protectedMaterialText)) + .append("\n"); + sb.append(" protectedMaterialCode: ") + .append(toIndentedString(protectedMaterialCode)) + .append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterDetectedResult.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterDetectedResult.java new file mode 100644 index 000000000..37ebe89f4 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterDetectedResult.java @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ContentFilterDetectedResult */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ContentFilterDetectedResult +// CHECKSTYLE:ON +{ + @JsonProperty("filtered") + private Boolean filtered; + + @JsonProperty("detected") + private Boolean detected; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the filtered of this {@link ContentFilterDetectedResult} instance and return the same + * instance. + * + * @param filtered The filtered of this {@link ContentFilterDetectedResult} + * @return The same instance of this {@link ContentFilterDetectedResult} class + */ + @Nonnull + public ContentFilterDetectedResult filtered(@Nonnull final Boolean filtered) { + this.filtered = filtered; + return this; + } + + /** + * Get filtered + * + * @return filtered The filtered of this {@link ContentFilterDetectedResult} instance. + */ + @Nonnull + public Boolean isFiltered() { + return filtered; + } + + /** + * Set the filtered of this {@link ContentFilterDetectedResult} instance. + * + * @param filtered The filtered of this {@link ContentFilterDetectedResult} + */ + public void setFiltered(@Nonnull final Boolean filtered) { + this.filtered = filtered; + } + + /** + * Set the detected of this {@link ContentFilterDetectedResult} instance and return the same + * instance. + * + * @param detected The detected of this {@link ContentFilterDetectedResult} + * @return The same instance of this {@link ContentFilterDetectedResult} class + */ + @Nonnull + public ContentFilterDetectedResult detected(@Nonnull final Boolean detected) { + this.detected = detected; + return this; + } + + /** + * Get detected + * + * @return detected The detected of this {@link ContentFilterDetectedResult} instance. + */ + @Nonnull + public Boolean isDetected() { + return detected; + } + + /** + * Set the detected of this {@link ContentFilterDetectedResult} instance. + * + * @param detected The detected of this {@link ContentFilterDetectedResult} + */ + public void setDetected(@Nonnull final Boolean detected) { + this.detected = detected; + } + + /** + * Get the names of the unrecognizable properties of the {@link ContentFilterDetectedResult}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ContentFilterDetectedResult} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ContentFilterDetectedResult has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ContentFilterDetectedResult} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ContentFilterDetectedResult contentFilterDetectedResult = (ContentFilterDetectedResult) o; + return Objects.equals( + this.cloudSdkCustomFields, contentFilterDetectedResult.cloudSdkCustomFields) + && Objects.equals(this.filtered, contentFilterDetectedResult.filtered) + && Objects.equals(this.detected, contentFilterDetectedResult.detected); + } + + @Override + public int hashCode() { + return Objects.hash(filtered, detected, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ContentFilterDetectedResult {\n"); + sb.append(" filtered: ").append(toIndentedString(filtered)).append("\n"); + sb.append(" detected: ").append(toIndentedString(detected)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterDetectedWithCitationResult.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterDetectedWithCitationResult.java new file mode 100644 index 000000000..5846eeaf4 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterDetectedWithCitationResult.java @@ -0,0 +1,235 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ContentFilterDetectedWithCitationResult */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ContentFilterDetectedWithCitationResult +// CHECKSTYLE:ON +{ + @JsonProperty("filtered") + private Boolean filtered; + + @JsonProperty("detected") + private Boolean detected; + + @JsonProperty("citation") + private ContentFilterDetectedWithCitationResultAllOfCitation citation; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the filtered of this {@link ContentFilterDetectedWithCitationResult} instance and return + * the same instance. + * + * @param filtered The filtered of this {@link ContentFilterDetectedWithCitationResult} + * @return The same instance of this {@link ContentFilterDetectedWithCitationResult} class + */ + @Nonnull + public ContentFilterDetectedWithCitationResult filtered(@Nonnull final Boolean filtered) { + this.filtered = filtered; + return this; + } + + /** + * Get filtered + * + * @return filtered The filtered of this {@link ContentFilterDetectedWithCitationResult} instance. + */ + @Nonnull + public Boolean isFiltered() { + return filtered; + } + + /** + * Set the filtered of this {@link ContentFilterDetectedWithCitationResult} instance. + * + * @param filtered The filtered of this {@link ContentFilterDetectedWithCitationResult} + */ + public void setFiltered(@Nonnull final Boolean filtered) { + this.filtered = filtered; + } + + /** + * Set the detected of this {@link ContentFilterDetectedWithCitationResult} instance and return + * the same instance. + * + * @param detected The detected of this {@link ContentFilterDetectedWithCitationResult} + * @return The same instance of this {@link ContentFilterDetectedWithCitationResult} class + */ + @Nonnull + public ContentFilterDetectedWithCitationResult detected(@Nonnull final Boolean detected) { + this.detected = detected; + return this; + } + + /** + * Get detected + * + * @return detected The detected of this {@link ContentFilterDetectedWithCitationResult} instance. + */ + @Nonnull + public Boolean isDetected() { + return detected; + } + + /** + * Set the detected of this {@link ContentFilterDetectedWithCitationResult} instance. + * + * @param detected The detected of this {@link ContentFilterDetectedWithCitationResult} + */ + public void setDetected(@Nonnull final Boolean detected) { + this.detected = detected; + } + + /** + * Set the citation of this {@link ContentFilterDetectedWithCitationResult} instance and return + * the same instance. + * + * @param citation The citation of this {@link ContentFilterDetectedWithCitationResult} + * @return The same instance of this {@link ContentFilterDetectedWithCitationResult} class + */ + @Nonnull + public ContentFilterDetectedWithCitationResult citation( + @Nullable final ContentFilterDetectedWithCitationResultAllOfCitation citation) { + this.citation = citation; + return this; + } + + /** + * Get citation + * + * @return citation The citation of this {@link ContentFilterDetectedWithCitationResult} instance. + */ + @Nonnull + public ContentFilterDetectedWithCitationResultAllOfCitation getCitation() { + return citation; + } + + /** + * Set the citation of this {@link ContentFilterDetectedWithCitationResult} instance. + * + * @param citation The citation of this {@link ContentFilterDetectedWithCitationResult} + */ + public void setCitation( + @Nullable final ContentFilterDetectedWithCitationResultAllOfCitation citation) { + this.citation = citation; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ContentFilterDetectedWithCitationResult}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * ContentFilterDetectedWithCitationResult} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ContentFilterDetectedWithCitationResult has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ContentFilterDetectedWithCitationResult} + * instance. If the map previously contained a mapping for the key, the old value is replaced by + * the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ContentFilterDetectedWithCitationResult contentFilterDetectedWithCitationResult = + (ContentFilterDetectedWithCitationResult) o; + return Objects.equals( + this.cloudSdkCustomFields, contentFilterDetectedWithCitationResult.cloudSdkCustomFields) + && Objects.equals(this.filtered, contentFilterDetectedWithCitationResult.filtered) + && Objects.equals(this.detected, contentFilterDetectedWithCitationResult.detected) + && Objects.equals(this.citation, contentFilterDetectedWithCitationResult.citation); + } + + @Override + public int hashCode() { + return Objects.hash(filtered, detected, citation, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ContentFilterDetectedWithCitationResult {\n"); + sb.append(" filtered: ").append(toIndentedString(filtered)).append("\n"); + sb.append(" detected: ").append(toIndentedString(detected)).append("\n"); + sb.append(" citation: ").append(toIndentedString(citation)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterDetectedWithCitationResultAllOfCitation.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterDetectedWithCitationResultAllOfCitation.java new file mode 100644 index 000000000..335e3c76b --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterDetectedWithCitationResultAllOfCitation.java @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ContentFilterDetectedWithCitationResultAllOfCitation */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ContentFilterDetectedWithCitationResultAllOfCitation +// CHECKSTYLE:ON +{ + @JsonProperty("URL") + private String URL; + + @JsonProperty("license") + private String license; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the URL of this {@link ContentFilterDetectedWithCitationResultAllOfCitation} instance and + * return the same instance. + * + * @param URL The URL of this {@link ContentFilterDetectedWithCitationResultAllOfCitation} + * @return The same instance of this {@link ContentFilterDetectedWithCitationResultAllOfCitation} + * class + */ + @Nonnull + public ContentFilterDetectedWithCitationResultAllOfCitation URL(@Nullable final String URL) { + this.URL = URL; + return this; + } + + /** + * Get URL + * + * @return URL The URL of this {@link ContentFilterDetectedWithCitationResultAllOfCitation} + * instance. + */ + @Nonnull + public String getURL() { + return URL; + } + + /** + * Set the URL of this {@link ContentFilterDetectedWithCitationResultAllOfCitation} instance. + * + * @param URL The URL of this {@link ContentFilterDetectedWithCitationResultAllOfCitation} + */ + public void setURL(@Nullable final String URL) { + this.URL = URL; + } + + /** + * Set the license of this {@link ContentFilterDetectedWithCitationResultAllOfCitation} instance + * and return the same instance. + * + * @param license The license of this {@link ContentFilterDetectedWithCitationResultAllOfCitation} + * @return The same instance of this {@link ContentFilterDetectedWithCitationResultAllOfCitation} + * class + */ + @Nonnull + public ContentFilterDetectedWithCitationResultAllOfCitation license( + @Nullable final String license) { + this.license = license; + return this; + } + + /** + * Get license + * + * @return license The license of this {@link + * ContentFilterDetectedWithCitationResultAllOfCitation} instance. + */ + @Nonnull + public String getLicense() { + return license; + } + + /** + * Set the license of this {@link ContentFilterDetectedWithCitationResultAllOfCitation} instance. + * + * @param license The license of this {@link ContentFilterDetectedWithCitationResultAllOfCitation} + */ + public void setLicense(@Nullable final String license) { + this.license = license; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ContentFilterDetectedWithCitationResultAllOfCitation}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * ContentFilterDetectedWithCitationResultAllOfCitation} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ContentFilterDetectedWithCitationResultAllOfCitation has no field with name '" + + name + + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link + * ContentFilterDetectedWithCitationResultAllOfCitation} instance. If the map previously contained + * a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ContentFilterDetectedWithCitationResultAllOfCitation + contentFilterDetectedWithCitationResultAllOfCitation = + (ContentFilterDetectedWithCitationResultAllOfCitation) o; + return Objects.equals( + this.cloudSdkCustomFields, + contentFilterDetectedWithCitationResultAllOfCitation.cloudSdkCustomFields) + && Objects.equals(this.URL, contentFilterDetectedWithCitationResultAllOfCitation.URL) + && Objects.equals( + this.license, contentFilterDetectedWithCitationResultAllOfCitation.license); + } + + @Override + public int hashCode() { + return Objects.hash(URL, license, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ContentFilterDetectedWithCitationResultAllOfCitation {\n"); + sb.append(" URL: ").append(toIndentedString(URL)).append("\n"); + sb.append(" license: ").append(toIndentedString(license)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterPromptResults.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterPromptResults.java new file mode 100644 index 000000000..d28068b89 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterPromptResults.java @@ -0,0 +1,385 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Information about the content filtering category (hate, sexual, violence, self_harm), if it has + * been detected, as well as the severity level (very_low, low, medium, high-scale that determines + * the intensity and risk level of harmful content) and if it has been filtered or not. Information + * about jailbreak content and profanity, if it has been detected, and if it has been filtered or + * not. And information about customer block list, if it has been filtered and its id. + */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ContentFilterPromptResults +// CHECKSTYLE:ON +{ + @JsonProperty("sexual") + private ContentFilterSeverityResult sexual; + + @JsonProperty("violence") + private ContentFilterSeverityResult violence; + + @JsonProperty("hate") + private ContentFilterSeverityResult hate; + + @JsonProperty("self_harm") + private ContentFilterSeverityResult selfHarm; + + @JsonProperty("profanity") + private ContentFilterDetectedResult profanity; + + @JsonProperty("error") + private ErrorBase error; + + @JsonProperty("jailbreak") + private ContentFilterDetectedResult jailbreak; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the sexual of this {@link ContentFilterPromptResults} instance and return the same + * instance. + * + * @param sexual The sexual of this {@link ContentFilterPromptResults} + * @return The same instance of this {@link ContentFilterPromptResults} class + */ + @Nonnull + public ContentFilterPromptResults sexual(@Nullable final ContentFilterSeverityResult sexual) { + this.sexual = sexual; + return this; + } + + /** + * Get sexual + * + * @return sexual The sexual of this {@link ContentFilterPromptResults} instance. + */ + @Nonnull + public ContentFilterSeverityResult getSexual() { + return sexual; + } + + /** + * Set the sexual of this {@link ContentFilterPromptResults} instance. + * + * @param sexual The sexual of this {@link ContentFilterPromptResults} + */ + public void setSexual(@Nullable final ContentFilterSeverityResult sexual) { + this.sexual = sexual; + } + + /** + * Set the violence of this {@link ContentFilterPromptResults} instance and return the same + * instance. + * + * @param violence The violence of this {@link ContentFilterPromptResults} + * @return The same instance of this {@link ContentFilterPromptResults} class + */ + @Nonnull + public ContentFilterPromptResults violence(@Nullable final ContentFilterSeverityResult violence) { + this.violence = violence; + return this; + } + + /** + * Get violence + * + * @return violence The violence of this {@link ContentFilterPromptResults} instance. + */ + @Nonnull + public ContentFilterSeverityResult getViolence() { + return violence; + } + + /** + * Set the violence of this {@link ContentFilterPromptResults} instance. + * + * @param violence The violence of this {@link ContentFilterPromptResults} + */ + public void setViolence(@Nullable final ContentFilterSeverityResult violence) { + this.violence = violence; + } + + /** + * Set the hate of this {@link ContentFilterPromptResults} instance and return the same instance. + * + * @param hate The hate of this {@link ContentFilterPromptResults} + * @return The same instance of this {@link ContentFilterPromptResults} class + */ + @Nonnull + public ContentFilterPromptResults hate(@Nullable final ContentFilterSeverityResult hate) { + this.hate = hate; + return this; + } + + /** + * Get hate + * + * @return hate The hate of this {@link ContentFilterPromptResults} instance. + */ + @Nonnull + public ContentFilterSeverityResult getHate() { + return hate; + } + + /** + * Set the hate of this {@link ContentFilterPromptResults} instance. + * + * @param hate The hate of this {@link ContentFilterPromptResults} + */ + public void setHate(@Nullable final ContentFilterSeverityResult hate) { + this.hate = hate; + } + + /** + * Set the selfHarm of this {@link ContentFilterPromptResults} instance and return the same + * instance. + * + * @param selfHarm The selfHarm of this {@link ContentFilterPromptResults} + * @return The same instance of this {@link ContentFilterPromptResults} class + */ + @Nonnull + public ContentFilterPromptResults selfHarm(@Nullable final ContentFilterSeverityResult selfHarm) { + this.selfHarm = selfHarm; + return this; + } + + /** + * Get selfHarm + * + * @return selfHarm The selfHarm of this {@link ContentFilterPromptResults} instance. + */ + @Nonnull + public ContentFilterSeverityResult getSelfHarm() { + return selfHarm; + } + + /** + * Set the selfHarm of this {@link ContentFilterPromptResults} instance. + * + * @param selfHarm The selfHarm of this {@link ContentFilterPromptResults} + */ + public void setSelfHarm(@Nullable final ContentFilterSeverityResult selfHarm) { + this.selfHarm = selfHarm; + } + + /** + * Set the profanity of this {@link ContentFilterPromptResults} instance and return the same + * instance. + * + * @param profanity The profanity of this {@link ContentFilterPromptResults} + * @return The same instance of this {@link ContentFilterPromptResults} class + */ + @Nonnull + public ContentFilterPromptResults profanity( + @Nullable final ContentFilterDetectedResult profanity) { + this.profanity = profanity; + return this; + } + + /** + * Get profanity + * + * @return profanity The profanity of this {@link ContentFilterPromptResults} instance. + */ + @Nonnull + public ContentFilterDetectedResult getProfanity() { + return profanity; + } + + /** + * Set the profanity of this {@link ContentFilterPromptResults} instance. + * + * @param profanity The profanity of this {@link ContentFilterPromptResults} + */ + public void setProfanity(@Nullable final ContentFilterDetectedResult profanity) { + this.profanity = profanity; + } + + /** + * Set the error of this {@link ContentFilterPromptResults} instance and return the same instance. + * + * @param error The error of this {@link ContentFilterPromptResults} + * @return The same instance of this {@link ContentFilterPromptResults} class + */ + @Nonnull + public ContentFilterPromptResults error(@Nullable final ErrorBase error) { + this.error = error; + return this; + } + + /** + * Get error + * + * @return error The error of this {@link ContentFilterPromptResults} instance. + */ + @Nonnull + public ErrorBase getError() { + return error; + } + + /** + * Set the error of this {@link ContentFilterPromptResults} instance. + * + * @param error The error of this {@link ContentFilterPromptResults} + */ + public void setError(@Nullable final ErrorBase error) { + this.error = error; + } + + /** + * Set the jailbreak of this {@link ContentFilterPromptResults} instance and return the same + * instance. + * + * @param jailbreak The jailbreak of this {@link ContentFilterPromptResults} + * @return The same instance of this {@link ContentFilterPromptResults} class + */ + @Nonnull + public ContentFilterPromptResults jailbreak( + @Nullable final ContentFilterDetectedResult jailbreak) { + this.jailbreak = jailbreak; + return this; + } + + /** + * Get jailbreak + * + * @return jailbreak The jailbreak of this {@link ContentFilterPromptResults} instance. + */ + @Nonnull + public ContentFilterDetectedResult getJailbreak() { + return jailbreak; + } + + /** + * Set the jailbreak of this {@link ContentFilterPromptResults} instance. + * + * @param jailbreak The jailbreak of this {@link ContentFilterPromptResults} + */ + public void setJailbreak(@Nullable final ContentFilterDetectedResult jailbreak) { + this.jailbreak = jailbreak; + } + + /** + * Get the names of the unrecognizable properties of the {@link ContentFilterPromptResults}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ContentFilterPromptResults} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ContentFilterPromptResults has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ContentFilterPromptResults} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ContentFilterPromptResults contentFilterPromptResults = (ContentFilterPromptResults) o; + return Objects.equals( + this.cloudSdkCustomFields, contentFilterPromptResults.cloudSdkCustomFields) + && Objects.equals(this.sexual, contentFilterPromptResults.sexual) + && Objects.equals(this.violence, contentFilterPromptResults.violence) + && Objects.equals(this.hate, contentFilterPromptResults.hate) + && Objects.equals(this.selfHarm, contentFilterPromptResults.selfHarm) + && Objects.equals(this.profanity, contentFilterPromptResults.profanity) + && Objects.equals(this.error, contentFilterPromptResults.error) + && Objects.equals(this.jailbreak, contentFilterPromptResults.jailbreak); + } + + @Override + public int hashCode() { + return Objects.hash( + sexual, violence, hate, selfHarm, profanity, error, jailbreak, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ContentFilterPromptResults {\n"); + sb.append(" sexual: ").append(toIndentedString(sexual)).append("\n"); + sb.append(" violence: ").append(toIndentedString(violence)).append("\n"); + sb.append(" hate: ").append(toIndentedString(hate)).append("\n"); + sb.append(" selfHarm: ").append(toIndentedString(selfHarm)).append("\n"); + sb.append(" profanity: ").append(toIndentedString(profanity)).append("\n"); + sb.append(" error: ").append(toIndentedString(error)).append("\n"); + sb.append(" jailbreak: ").append(toIndentedString(jailbreak)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterResultBase.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterResultBase.java new file mode 100644 index 000000000..eae12bf14 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterResultBase.java @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ContentFilterResultBase */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ContentFilterResultBase +// CHECKSTYLE:ON +{ + @JsonProperty("filtered") + private Boolean filtered; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the filtered of this {@link ContentFilterResultBase} instance and return the same instance. + * + * @param filtered The filtered of this {@link ContentFilterResultBase} + * @return The same instance of this {@link ContentFilterResultBase} class + */ + @Nonnull + public ContentFilterResultBase filtered(@Nonnull final Boolean filtered) { + this.filtered = filtered; + return this; + } + + /** + * Get filtered + * + * @return filtered The filtered of this {@link ContentFilterResultBase} instance. + */ + @Nonnull + public Boolean isFiltered() { + return filtered; + } + + /** + * Set the filtered of this {@link ContentFilterResultBase} instance. + * + * @param filtered The filtered of this {@link ContentFilterResultBase} + */ + public void setFiltered(@Nonnull final Boolean filtered) { + this.filtered = filtered; + } + + /** + * Get the names of the unrecognizable properties of the {@link ContentFilterResultBase}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ContentFilterResultBase} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ContentFilterResultBase has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ContentFilterResultBase} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ContentFilterResultBase contentFilterResultBase = (ContentFilterResultBase) o; + return Objects.equals(this.cloudSdkCustomFields, contentFilterResultBase.cloudSdkCustomFields) + && Objects.equals(this.filtered, contentFilterResultBase.filtered); + } + + @Override + public int hashCode() { + return Objects.hash(filtered, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ContentFilterResultBase {\n"); + sb.append(" filtered: ").append(toIndentedString(filtered)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterResultsBase.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterResultsBase.java new file mode 100644 index 000000000..572a2951f --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterResultsBase.java @@ -0,0 +1,336 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** Information about the content filtering results. */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ContentFilterResultsBase +// CHECKSTYLE:ON +{ + @JsonProperty("sexual") + private ContentFilterSeverityResult sexual; + + @JsonProperty("violence") + private ContentFilterSeverityResult violence; + + @JsonProperty("hate") + private ContentFilterSeverityResult hate; + + @JsonProperty("self_harm") + private ContentFilterSeverityResult selfHarm; + + @JsonProperty("profanity") + private ContentFilterDetectedResult profanity; + + @JsonProperty("error") + private ErrorBase error; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the sexual of this {@link ContentFilterResultsBase} instance and return the same instance. + * + * @param sexual The sexual of this {@link ContentFilterResultsBase} + * @return The same instance of this {@link ContentFilterResultsBase} class + */ + @Nonnull + public ContentFilterResultsBase sexual(@Nullable final ContentFilterSeverityResult sexual) { + this.sexual = sexual; + return this; + } + + /** + * Get sexual + * + * @return sexual The sexual of this {@link ContentFilterResultsBase} instance. + */ + @Nonnull + public ContentFilterSeverityResult getSexual() { + return sexual; + } + + /** + * Set the sexual of this {@link ContentFilterResultsBase} instance. + * + * @param sexual The sexual of this {@link ContentFilterResultsBase} + */ + public void setSexual(@Nullable final ContentFilterSeverityResult sexual) { + this.sexual = sexual; + } + + /** + * Set the violence of this {@link ContentFilterResultsBase} instance and return the same + * instance. + * + * @param violence The violence of this {@link ContentFilterResultsBase} + * @return The same instance of this {@link ContentFilterResultsBase} class + */ + @Nonnull + public ContentFilterResultsBase violence(@Nullable final ContentFilterSeverityResult violence) { + this.violence = violence; + return this; + } + + /** + * Get violence + * + * @return violence The violence of this {@link ContentFilterResultsBase} instance. + */ + @Nonnull + public ContentFilterSeverityResult getViolence() { + return violence; + } + + /** + * Set the violence of this {@link ContentFilterResultsBase} instance. + * + * @param violence The violence of this {@link ContentFilterResultsBase} + */ + public void setViolence(@Nullable final ContentFilterSeverityResult violence) { + this.violence = violence; + } + + /** + * Set the hate of this {@link ContentFilterResultsBase} instance and return the same instance. + * + * @param hate The hate of this {@link ContentFilterResultsBase} + * @return The same instance of this {@link ContentFilterResultsBase} class + */ + @Nonnull + public ContentFilterResultsBase hate(@Nullable final ContentFilterSeverityResult hate) { + this.hate = hate; + return this; + } + + /** + * Get hate + * + * @return hate The hate of this {@link ContentFilterResultsBase} instance. + */ + @Nonnull + public ContentFilterSeverityResult getHate() { + return hate; + } + + /** + * Set the hate of this {@link ContentFilterResultsBase} instance. + * + * @param hate The hate of this {@link ContentFilterResultsBase} + */ + public void setHate(@Nullable final ContentFilterSeverityResult hate) { + this.hate = hate; + } + + /** + * Set the selfHarm of this {@link ContentFilterResultsBase} instance and return the same + * instance. + * + * @param selfHarm The selfHarm of this {@link ContentFilterResultsBase} + * @return The same instance of this {@link ContentFilterResultsBase} class + */ + @Nonnull + public ContentFilterResultsBase selfHarm(@Nullable final ContentFilterSeverityResult selfHarm) { + this.selfHarm = selfHarm; + return this; + } + + /** + * Get selfHarm + * + * @return selfHarm The selfHarm of this {@link ContentFilterResultsBase} instance. + */ + @Nonnull + public ContentFilterSeverityResult getSelfHarm() { + return selfHarm; + } + + /** + * Set the selfHarm of this {@link ContentFilterResultsBase} instance. + * + * @param selfHarm The selfHarm of this {@link ContentFilterResultsBase} + */ + public void setSelfHarm(@Nullable final ContentFilterSeverityResult selfHarm) { + this.selfHarm = selfHarm; + } + + /** + * Set the profanity of this {@link ContentFilterResultsBase} instance and return the same + * instance. + * + * @param profanity The profanity of this {@link ContentFilterResultsBase} + * @return The same instance of this {@link ContentFilterResultsBase} class + */ + @Nonnull + public ContentFilterResultsBase profanity(@Nullable final ContentFilterDetectedResult profanity) { + this.profanity = profanity; + return this; + } + + /** + * Get profanity + * + * @return profanity The profanity of this {@link ContentFilterResultsBase} instance. + */ + @Nonnull + public ContentFilterDetectedResult getProfanity() { + return profanity; + } + + /** + * Set the profanity of this {@link ContentFilterResultsBase} instance. + * + * @param profanity The profanity of this {@link ContentFilterResultsBase} + */ + public void setProfanity(@Nullable final ContentFilterDetectedResult profanity) { + this.profanity = profanity; + } + + /** + * Set the error of this {@link ContentFilterResultsBase} instance and return the same instance. + * + * @param error The error of this {@link ContentFilterResultsBase} + * @return The same instance of this {@link ContentFilterResultsBase} class + */ + @Nonnull + public ContentFilterResultsBase error(@Nullable final ErrorBase error) { + this.error = error; + return this; + } + + /** + * Get error + * + * @return error The error of this {@link ContentFilterResultsBase} instance. + */ + @Nonnull + public ErrorBase getError() { + return error; + } + + /** + * Set the error of this {@link ContentFilterResultsBase} instance. + * + * @param error The error of this {@link ContentFilterResultsBase} + */ + public void setError(@Nullable final ErrorBase error) { + this.error = error; + } + + /** + * Get the names of the unrecognizable properties of the {@link ContentFilterResultsBase}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ContentFilterResultsBase} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ContentFilterResultsBase has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ContentFilterResultsBase} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ContentFilterResultsBase contentFilterResultsBase = (ContentFilterResultsBase) o; + return Objects.equals(this.cloudSdkCustomFields, contentFilterResultsBase.cloudSdkCustomFields) + && Objects.equals(this.sexual, contentFilterResultsBase.sexual) + && Objects.equals(this.violence, contentFilterResultsBase.violence) + && Objects.equals(this.hate, contentFilterResultsBase.hate) + && Objects.equals(this.selfHarm, contentFilterResultsBase.selfHarm) + && Objects.equals(this.profanity, contentFilterResultsBase.profanity) + && Objects.equals(this.error, contentFilterResultsBase.error); + } + + @Override + public int hashCode() { + return Objects.hash(sexual, violence, hate, selfHarm, profanity, error, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ContentFilterResultsBase {\n"); + sb.append(" sexual: ").append(toIndentedString(sexual)).append("\n"); + sb.append(" violence: ").append(toIndentedString(violence)).append("\n"); + sb.append(" hate: ").append(toIndentedString(hate)).append("\n"); + sb.append(" selfHarm: ").append(toIndentedString(selfHarm)).append("\n"); + sb.append(" profanity: ").append(toIndentedString(profanity)).append("\n"); + sb.append(" error: ").append(toIndentedString(error)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterSeverityResult.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterSeverityResult.java new file mode 100644 index 000000000..ecaa77dd8 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ContentFilterSeverityResult.java @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ContentFilterSeverityResult */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ContentFilterSeverityResult +// CHECKSTYLE:ON +{ + @JsonProperty("filtered") + private Boolean filtered; + + /** Gets or Sets severity */ + public enum SeverityEnum { + /** The SAFE option of this ContentFilterSeverityResult */ + SAFE("safe"), + + /** The LOW option of this ContentFilterSeverityResult */ + LOW("low"), + + /** The MEDIUM option of this ContentFilterSeverityResult */ + MEDIUM("medium"), + + /** The HIGH option of this ContentFilterSeverityResult */ + HIGH("high"); + + private String value; + + SeverityEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ContentFilterSeverityResult + */ + @JsonCreator + @Nonnull + public static SeverityEnum fromValue(@Nonnull final String value) { + for (SeverityEnum b : SeverityEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("severity") + private SeverityEnum severity; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the filtered of this {@link ContentFilterSeverityResult} instance and return the same + * instance. + * + * @param filtered The filtered of this {@link ContentFilterSeverityResult} + * @return The same instance of this {@link ContentFilterSeverityResult} class + */ + @Nonnull + public ContentFilterSeverityResult filtered(@Nonnull final Boolean filtered) { + this.filtered = filtered; + return this; + } + + /** + * Get filtered + * + * @return filtered The filtered of this {@link ContentFilterSeverityResult} instance. + */ + @Nonnull + public Boolean isFiltered() { + return filtered; + } + + /** + * Set the filtered of this {@link ContentFilterSeverityResult} instance. + * + * @param filtered The filtered of this {@link ContentFilterSeverityResult} + */ + public void setFiltered(@Nonnull final Boolean filtered) { + this.filtered = filtered; + } + + /** + * Set the severity of this {@link ContentFilterSeverityResult} instance and return the same + * instance. + * + * @param severity The severity of this {@link ContentFilterSeverityResult} + * @return The same instance of this {@link ContentFilterSeverityResult} class + */ + @Nonnull + public ContentFilterSeverityResult severity(@Nonnull final SeverityEnum severity) { + this.severity = severity; + return this; + } + + /** + * Get severity + * + * @return severity The severity of this {@link ContentFilterSeverityResult} instance. + */ + @Nonnull + public SeverityEnum getSeverity() { + return severity; + } + + /** + * Set the severity of this {@link ContentFilterSeverityResult} instance. + * + * @param severity The severity of this {@link ContentFilterSeverityResult} + */ + public void setSeverity(@Nonnull final SeverityEnum severity) { + this.severity = severity; + } + + /** + * Get the names of the unrecognizable properties of the {@link ContentFilterSeverityResult}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ContentFilterSeverityResult} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ContentFilterSeverityResult has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ContentFilterSeverityResult} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ContentFilterSeverityResult contentFilterSeverityResult = (ContentFilterSeverityResult) o; + return Objects.equals( + this.cloudSdkCustomFields, contentFilterSeverityResult.cloudSdkCustomFields) + && Objects.equals(this.filtered, contentFilterSeverityResult.filtered) + && Objects.equals(this.severity, contentFilterSeverityResult.severity); + } + + @Override + public int hashCode() { + return Objects.hash(filtered, severity, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ContentFilterSeverityResult {\n"); + sb.append(" filtered: ").append(toIndentedString(filtered)).append("\n"); + sb.append(" severity: ").append(toIndentedString(severity)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionRequest.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionRequest.java new file mode 100644 index 000000000..a1042b7c8 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionRequest.java @@ -0,0 +1,1157 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** CreateChatCompletionRequest */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class CreateChatCompletionRequest +// CHECKSTYLE:ON +{ + @JsonProperty("temperature") + private BigDecimal temperature = new BigDecimal("1"); + + @JsonProperty("top_p") + private BigDecimal topP = new BigDecimal("1"); + + @JsonProperty("stream") + private Boolean stream = false; + + @JsonProperty("stop") + private CreateChatCompletionRequestAllOfStop stop = null; + + @JsonProperty("max_tokens") + private Integer maxTokens; + + @JsonProperty("max_completion_tokens") + private Integer maxCompletionTokens; + + @JsonProperty("presence_penalty") + private BigDecimal presencePenalty = new BigDecimal("0"); + + @JsonProperty("frequency_penalty") + private BigDecimal frequencyPenalty = new BigDecimal("0"); + + @JsonProperty("logit_bias") + private Map logitBias; + + @JsonProperty("user") + private String user; + + @JsonProperty("messages") + private List messages = new ArrayList<>(); + + // @JsonProperty("data_sources") // IGNORED TODO + // private List dataSources = new ArrayList<>(); + + @JsonProperty("logprobs") + private Boolean logprobs = false; + + @JsonProperty("top_logprobs") + private Integer topLogprobs; + + @JsonProperty("n") + private Integer n = 1; + + @JsonProperty("parallel_tool_calls") + private Boolean parallelToolCalls = true; + + @JsonProperty("response_format") + private CreateChatCompletionRequestAllOfResponseFormat responseFormat; + + @JsonProperty("seed") + private Integer seed; + + @JsonProperty("stream_options") + private ChatCompletionStreamOptions streamOptions; + + @JsonProperty("tools") + private List tools = new ArrayList<>(); + + @JsonProperty("tool_choice") + private ChatCompletionToolChoiceOption toolChoice; + + @JsonProperty("function_call") + private CreateChatCompletionRequestAllOfFunctionCall functionCall; + + @JsonProperty("functions") + private List functions = new ArrayList<>(); + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the temperature of this {@link CreateChatCompletionRequest} instance and return the same + * instance. + * + * @param temperature What sampling temperature to use, between 0 and 2. Higher values like 0.8 + * will make the output more random, while lower values like 0.2 will make it more focused and + * deterministic. We generally recommend altering this or `top_p` but not both. + * Minimum: 0 Maximum: 2 + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest temperature(@Nullable final BigDecimal temperature) { + this.temperature = temperature; + return this; + } + + /** + * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output + * more random, while lower values like 0.2 will make it more focused and deterministic. We + * generally recommend altering this or `top_p` but not both. minimum: 0 maximum: 2 + * + * @return temperature The temperature of this {@link CreateChatCompletionRequest} instance. + */ + @Nullable + public BigDecimal getTemperature() { + return temperature; + } + + /** + * Set the temperature of this {@link CreateChatCompletionRequest} instance. + * + * @param temperature What sampling temperature to use, between 0 and 2. Higher values like 0.8 + * will make the output more random, while lower values like 0.2 will make it more focused and + * deterministic. We generally recommend altering this or `top_p` but not both. + * Minimum: 0 Maximum: 2 + */ + public void setTemperature(@Nullable final BigDecimal temperature) { + this.temperature = temperature; + } + + /** + * Set the topP of this {@link CreateChatCompletionRequest} instance and return the same instance. + * + * @param topP An alternative to sampling with temperature, called nucleus sampling, where the + * model considers the results of the tokens with top_p probability mass. So 0.1 means only + * the tokens comprising the top 10% probability mass are considered. We generally recommend + * altering this or `temperature` but not both. Minimum: 0 Maximum: 1 + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest topP(@Nullable final BigDecimal topP) { + this.topP = topP; + return this; + } + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model considers + * the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising + * the top 10% probability mass are considered. We generally recommend altering this or + * `temperature` but not both. minimum: 0 maximum: 1 + * + * @return topP The topP of this {@link CreateChatCompletionRequest} instance. + */ + @Nullable + public BigDecimal getTopP() { + return topP; + } + + /** + * Set the topP of this {@link CreateChatCompletionRequest} instance. + * + * @param topP An alternative to sampling with temperature, called nucleus sampling, where the + * model considers the results of the tokens with top_p probability mass. So 0.1 means only + * the tokens comprising the top 10% probability mass are considered. We generally recommend + * altering this or `temperature` but not both. Minimum: 0 Maximum: 1 + */ + public void setTopP(@Nullable final BigDecimal topP) { + this.topP = topP; + } + + /** + * Set the stream of this {@link CreateChatCompletionRequest} instance and return the same + * instance. + * + * @param stream If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent + * as data-only [server-sent + * events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) + * as they become available, with the stream terminated by a `data: [DONE]` message. + * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions). + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest stream(@Nullable final Boolean stream) { + this.stream = stream; + return this; + } + + /** + * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only + * [server-sent + * events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) + * as they become available, with the stream terminated by a `data: [DONE]` message. + * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions). + * + * @return stream The stream of this {@link CreateChatCompletionRequest} instance. + */ + @Nullable + public Boolean isStream() { + return stream; + } + + /** + * Set the stream of this {@link CreateChatCompletionRequest} instance. + * + * @param stream If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent + * as data-only [server-sent + * events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) + * as they become available, with the stream terminated by a `data: [DONE]` message. + * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions). + */ + public void setStream(@Nullable final Boolean stream) { + this.stream = stream; + } + + /** + * Set the stop of this {@link CreateChatCompletionRequest} instance and return the same instance. + * + * @param stop The stop of this {@link CreateChatCompletionRequest} + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest stop( + @Nullable final CreateChatCompletionRequestAllOfStop stop) { + this.stop = stop; + return this; + } + + /** + * Get stop + * + * @return stop The stop of this {@link CreateChatCompletionRequest} instance. + */ + @Nonnull + public CreateChatCompletionRequestAllOfStop getStop() { + return stop; + } + + /** + * Set the stop of this {@link CreateChatCompletionRequest} instance. + * + * @param stop The stop of this {@link CreateChatCompletionRequest} + */ + public void setStop(@Nullable final CreateChatCompletionRequestAllOfStop stop) { + this.stop = stop; + } + + /** + * Set the maxTokens of this {@link CreateChatCompletionRequest} instance and return the same + * instance. + * + * @param maxTokens The maximum number of [tokens](/tokenizer) that can be generated in the chat + * completion. The total length of input tokens and generated tokens is limited by the + * model's context length. [Example Python + * code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting + * tokens. + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest maxTokens(@Nullable final Integer maxTokens) { + this.maxTokens = maxTokens; + return this; + } + + /** + * The maximum number of [tokens](/tokenizer) that can be generated in the chat completion. The + * total length of input tokens and generated tokens is limited by the model's context length. + * [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) + * for counting tokens. + * + * @return maxTokens The maxTokens of this {@link CreateChatCompletionRequest} instance. + */ + @Nullable + public Integer getMaxTokens() { + return maxTokens; + } + + /** + * Set the maxTokens of this {@link CreateChatCompletionRequest} instance. + * + * @param maxTokens The maximum number of [tokens](/tokenizer) that can be generated in the chat + * completion. The total length of input tokens and generated tokens is limited by the + * model's context length. [Example Python + * code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting + * tokens. + */ + public void setMaxTokens(@Nullable final Integer maxTokens) { + this.maxTokens = maxTokens; + } + + /** + * Set the maxCompletionTokens of this {@link CreateChatCompletionRequest} instance and return the + * same instance. + * + * @param maxCompletionTokens An upper bound for the number of tokens that can be generated for a + * completion, including visible output tokens and reasoning tokens. + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest maxCompletionTokens( + @Nullable final Integer maxCompletionTokens) { + this.maxCompletionTokens = maxCompletionTokens; + return this; + } + + /** + * An upper bound for the number of tokens that can be generated for a completion, including + * visible output tokens and reasoning tokens. + * + * @return maxCompletionTokens The maxCompletionTokens of this {@link CreateChatCompletionRequest} + * instance. + */ + @Nullable + public Integer getMaxCompletionTokens() { + return maxCompletionTokens; + } + + /** + * Set the maxCompletionTokens of this {@link CreateChatCompletionRequest} instance. + * + * @param maxCompletionTokens An upper bound for the number of tokens that can be generated for a + * completion, including visible output tokens and reasoning tokens. + */ + public void setMaxCompletionTokens(@Nullable final Integer maxCompletionTokens) { + this.maxCompletionTokens = maxCompletionTokens; + } + + /** + * Set the presencePenalty of this {@link CreateChatCompletionRequest} instance and return the + * same instance. + * + * @param presencePenalty Number between -2.0 and 2.0. Positive values penalize new tokens based + * on whether they appear in the text so far, increasing the model's likelihood to talk + * about new topics. Minimum: -2 Maximum: 2 + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest presencePenalty(@Nullable final BigDecimal presencePenalty) { + this.presencePenalty = presencePenalty; + return this; + } + + /** + * Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear + * in the text so far, increasing the model's likelihood to talk about new topics. minimum: -2 + * maximum: 2 + * + * @return presencePenalty The presencePenalty of this {@link CreateChatCompletionRequest} + * instance. + */ + @Nullable + public BigDecimal getPresencePenalty() { + return presencePenalty; + } + + /** + * Set the presencePenalty of this {@link CreateChatCompletionRequest} instance. + * + * @param presencePenalty Number between -2.0 and 2.0. Positive values penalize new tokens based + * on whether they appear in the text so far, increasing the model's likelihood to talk + * about new topics. Minimum: -2 Maximum: 2 + */ + public void setPresencePenalty(@Nullable final BigDecimal presencePenalty) { + this.presencePenalty = presencePenalty; + } + + /** + * Set the frequencyPenalty of this {@link CreateChatCompletionRequest} instance and return the + * same instance. + * + * @param frequencyPenalty Number between -2.0 and 2.0. Positive values penalize new tokens based + * on their existing frequency in the text so far, decreasing the model's likelihood to + * repeat the same line verbatim. Minimum: -2 Maximum: 2 + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest frequencyPenalty(@Nullable final BigDecimal frequencyPenalty) { + this.frequencyPenalty = frequencyPenalty; + return this; + } + + /** + * Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing + * frequency in the text so far, decreasing the model's likelihood to repeat the same line + * verbatim. minimum: -2 maximum: 2 + * + * @return frequencyPenalty The frequencyPenalty of this {@link CreateChatCompletionRequest} + * instance. + */ + @Nullable + public BigDecimal getFrequencyPenalty() { + return frequencyPenalty; + } + + /** + * Set the frequencyPenalty of this {@link CreateChatCompletionRequest} instance. + * + * @param frequencyPenalty Number between -2.0 and 2.0. Positive values penalize new tokens based + * on their existing frequency in the text so far, decreasing the model's likelihood to + * repeat the same line verbatim. Minimum: -2 Maximum: 2 + */ + public void setFrequencyPenalty(@Nullable final BigDecimal frequencyPenalty) { + this.frequencyPenalty = frequencyPenalty; + } + + /** + * Set the logitBias of this {@link CreateChatCompletionRequest} instance and return the same + * instance. + * + * @param logitBias Modify the likelihood of specified tokens appearing in the completion. Accepts + * a JSON object that maps tokens (specified by their token ID in the tokenizer) to an + * associated bias value from -100 to 100. Mathematically, the bias is added to the logits + * generated by the model prior to sampling. The exact effect will vary per model, but values + * between -1 and 1 should decrease or increase likelihood of selection; values like -100 or + * 100 should result in a ban or exclusive selection of the relevant token. + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest logitBias(@Nullable final Map logitBias) { + this.logitBias = logitBias; + return this; + } + + /** + * Put one logitBias instance to this {@link CreateChatCompletionRequest} instance. + * + * @param key The String key of this logitBias instance + * @param logitBiasItem The logitBias that should be added under the given key + * @return The same instance of type {@link CreateChatCompletionRequest} + */ + @Nonnull + public CreateChatCompletionRequest putlogitBiasItem( + @Nonnull final String key, @Nonnull final Integer logitBiasItem) { + if (this.logitBias == null) { + this.logitBias = new HashMap<>(); + } + this.logitBias.put(key, logitBiasItem); + return this; + } + + /** + * Modify the likelihood of specified tokens appearing in the completion. Accepts a JSON object + * that maps tokens (specified by their token ID in the tokenizer) to an associated bias value + * from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior + * to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease + * or increase likelihood of selection; values like -100 or 100 should result in a ban or + * exclusive selection of the relevant token. + * + * @return logitBias The logitBias of this {@link CreateChatCompletionRequest} instance. + */ + @Nullable + public Map getLogitBias() { + return logitBias; + } + + /** + * Set the logitBias of this {@link CreateChatCompletionRequest} instance. + * + * @param logitBias Modify the likelihood of specified tokens appearing in the completion. Accepts + * a JSON object that maps tokens (specified by their token ID in the tokenizer) to an + * associated bias value from -100 to 100. Mathematically, the bias is added to the logits + * generated by the model prior to sampling. The exact effect will vary per model, but values + * between -1 and 1 should decrease or increase likelihood of selection; values like -100 or + * 100 should result in a ban or exclusive selection of the relevant token. + */ + public void setLogitBias(@Nullable final Map logitBias) { + this.logitBias = logitBias; + } + + /** + * Set the user of this {@link CreateChatCompletionRequest} instance and return the same instance. + * + * @param user A unique identifier representing your end-user, which can help to monitor and + * detect abuse. + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest user(@Nullable final String user) { + this.user = user; + return this; + } + + /** + * A unique identifier representing your end-user, which can help to monitor and detect abuse. + * + * @return user The user of this {@link CreateChatCompletionRequest} instance. + */ + @Nonnull + public String getUser() { + return user; + } + + /** + * Set the user of this {@link CreateChatCompletionRequest} instance. + * + * @param user A unique identifier representing your end-user, which can help to monitor and + * detect abuse. + */ + public void setUser(@Nullable final String user) { + this.user = user; + } + + /** + * Set the messages of this {@link CreateChatCompletionRequest} instance and return the same + * instance. + * + * @param messages A list of messages comprising the conversation so far. [Example Python + * code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb). + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest messages( + @Nonnull final List messages) { + this.messages = messages; + return this; + } + + /** + * Add one messages instance to this {@link CreateChatCompletionRequest}. + * + * @param messagesItem The messages that should be added + * @return The same instance of type {@link CreateChatCompletionRequest} + */ + @Nonnull + public CreateChatCompletionRequest addMessagesItem( + @Nonnull final ChatCompletionRequestMessage messagesItem) { + if (this.messages == null) { + this.messages = new ArrayList<>(); + } + this.messages.add(messagesItem); + return this; + } + + /** + * A list of messages comprising the conversation so far. [Example Python + * code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb). + * + * @return messages The messages of this {@link CreateChatCompletionRequest} instance. + */ + @Nonnull + public List getMessages() { + return messages; + } + + /** + * Set the messages of this {@link CreateChatCompletionRequest} instance. + * + * @param messages A list of messages comprising the conversation so far. [Example Python + * code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb). + */ + public void setMessages(@Nonnull final List messages) { + this.messages = messages; + } + + /** + * Set the logprobs of this {@link CreateChatCompletionRequest} instance and return the same + * instance. + * + * @param logprobs Whether to return log probabilities of the output tokens or not. If true, + * returns the log probabilities of each output token returned in the `content` of + * `message`. + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest logprobs(@Nullable final Boolean logprobs) { + this.logprobs = logprobs; + return this; + } + + /** + * Whether to return log probabilities of the output tokens or not. If true, returns the log + * probabilities of each output token returned in the `content` of `message`. + * + * @return logprobs The logprobs of this {@link CreateChatCompletionRequest} instance. + */ + @Nullable + public Boolean isLogprobs() { + return logprobs; + } + + /** + * Set the logprobs of this {@link CreateChatCompletionRequest} instance. + * + * @param logprobs Whether to return log probabilities of the output tokens or not. If true, + * returns the log probabilities of each output token returned in the `content` of + * `message`. + */ + public void setLogprobs(@Nullable final Boolean logprobs) { + this.logprobs = logprobs; + } + + /** + * Set the topLogprobs of this {@link CreateChatCompletionRequest} instance and return the same + * instance. + * + * @param topLogprobs An integer between 0 and 20 specifying the number of most likely tokens to + * return at each token position, each with an associated log probability. + * `logprobs` must be set to `true` if this parameter is used. Minimum: 0 + * Maximum: 20 + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest topLogprobs(@Nullable final Integer topLogprobs) { + this.topLogprobs = topLogprobs; + return this; + } + + /** + * An integer between 0 and 20 specifying the number of most likely tokens to return at each token + * position, each with an associated log probability. `logprobs` must be set to + * `true` if this parameter is used. minimum: 0 maximum: 20 + * + * @return topLogprobs The topLogprobs of this {@link CreateChatCompletionRequest} instance. + */ + @Nullable + public Integer getTopLogprobs() { + return topLogprobs; + } + + /** + * Set the topLogprobs of this {@link CreateChatCompletionRequest} instance. + * + * @param topLogprobs An integer between 0 and 20 specifying the number of most likely tokens to + * return at each token position, each with an associated log probability. + * `logprobs` must be set to `true` if this parameter is used. Minimum: 0 + * Maximum: 20 + */ + public void setTopLogprobs(@Nullable final Integer topLogprobs) { + this.topLogprobs = topLogprobs; + } + + /** + * Set the n of this {@link CreateChatCompletionRequest} instance and return the same instance. + * + * @param n How many chat completion choices to generate for each input message. Note that you + * will be charged based on the number of generated tokens across all of the choices. Keep + * `n` as `1` to minimize costs. Minimum: 1 Maximum: 128 + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest n(@Nullable final Integer n) { + this.n = n; + return this; + } + + /** + * How many chat completion choices to generate for each input message. Note that you will be + * charged based on the number of generated tokens across all of the choices. Keep `n` + * as `1` to minimize costs. minimum: 1 maximum: 128 + * + * @return n The n of this {@link CreateChatCompletionRequest} instance. + */ + @Nullable + public Integer getN() { + return n; + } + + /** + * Set the n of this {@link CreateChatCompletionRequest} instance. + * + * @param n How many chat completion choices to generate for each input message. Note that you + * will be charged based on the number of generated tokens across all of the choices. Keep + * `n` as `1` to minimize costs. Minimum: 1 Maximum: 128 + */ + public void setN(@Nullable final Integer n) { + this.n = n; + } + + /** + * Set the parallelToolCalls of this {@link CreateChatCompletionRequest} instance and return the + * same instance. + * + * @param parallelToolCalls Whether to enable parallel function calling during tool use. + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest parallelToolCalls(@Nullable final Boolean parallelToolCalls) { + this.parallelToolCalls = parallelToolCalls; + return this; + } + + /** + * Whether to enable parallel function calling during tool use. + * + * @return parallelToolCalls The parallelToolCalls of this {@link CreateChatCompletionRequest} + * instance. + */ + @Nonnull + public Boolean isParallelToolCalls() { + return parallelToolCalls; + } + + /** + * Set the parallelToolCalls of this {@link CreateChatCompletionRequest} instance. + * + * @param parallelToolCalls Whether to enable parallel function calling during tool use. + */ + public void setParallelToolCalls(@Nullable final Boolean parallelToolCalls) { + this.parallelToolCalls = parallelToolCalls; + } + + /** + * Set the responseFormat of this {@link CreateChatCompletionRequest} instance and return the same + * instance. + * + * @param responseFormat The responseFormat of this {@link CreateChatCompletionRequest} + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest responseFormat( + @Nullable final CreateChatCompletionRequestAllOfResponseFormat responseFormat) { + this.responseFormat = responseFormat; + return this; + } + + /** + * Get responseFormat + * + * @return responseFormat The responseFormat of this {@link CreateChatCompletionRequest} instance. + */ + @Nonnull + public CreateChatCompletionRequestAllOfResponseFormat getResponseFormat() { + return responseFormat; + } + + /** + * Set the responseFormat of this {@link CreateChatCompletionRequest} instance. + * + * @param responseFormat The responseFormat of this {@link CreateChatCompletionRequest} + */ + public void setResponseFormat( + @Nullable final CreateChatCompletionRequestAllOfResponseFormat responseFormat) { + this.responseFormat = responseFormat; + } + + /** + * Set the seed of this {@link CreateChatCompletionRequest} instance and return the same instance. + * + * @param seed This feature is in Beta. If specified, our system will make a best effort to sample + * deterministically, such that repeated requests with the same `seed` and + * parameters should return the same result. Determinism is not guaranteed, and you should + * refer to the `system_fingerprint` response parameter to monitor changes in the + * backend. Minimum: -9223372036854775808 Maximum: 9223372036854775807 + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest seed(@Nullable final Integer seed) { + this.seed = seed; + return this; + } + + /** + * This feature is in Beta. If specified, our system will make a best effort to sample + * deterministically, such that repeated requests with the same `seed` and parameters + * should return the same result. Determinism is not guaranteed, and you should refer to the + * `system_fingerprint` response parameter to monitor changes in the backend. minimum: + * -9223372036854775808 maximum: 9223372036854775807 + * + * @return seed The seed of this {@link CreateChatCompletionRequest} instance. + */ + @Nullable + public Integer getSeed() { + return seed; + } + + /** + * Set the seed of this {@link CreateChatCompletionRequest} instance. + * + * @param seed This feature is in Beta. If specified, our system will make a best effort to sample + * deterministically, such that repeated requests with the same `seed` and + * parameters should return the same result. Determinism is not guaranteed, and you should + * refer to the `system_fingerprint` response parameter to monitor changes in the + * backend. Minimum: -9223372036854775808 Maximum: 9223372036854775807 + */ + public void setSeed(@Nullable final Integer seed) { + this.seed = seed; + } + + /** + * Set the streamOptions of this {@link CreateChatCompletionRequest} instance and return the same + * instance. + * + * @param streamOptions The streamOptions of this {@link CreateChatCompletionRequest} + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest streamOptions( + @Nullable final ChatCompletionStreamOptions streamOptions) { + this.streamOptions = streamOptions; + return this; + } + + /** + * Get streamOptions + * + * @return streamOptions The streamOptions of this {@link CreateChatCompletionRequest} instance. + */ + @Nullable + public ChatCompletionStreamOptions getStreamOptions() { + return streamOptions; + } + + /** + * Set the streamOptions of this {@link CreateChatCompletionRequest} instance. + * + * @param streamOptions The streamOptions of this {@link CreateChatCompletionRequest} + */ + public void setStreamOptions(@Nullable final ChatCompletionStreamOptions streamOptions) { + this.streamOptions = streamOptions; + } + + /** + * Set the tools of this {@link CreateChatCompletionRequest} instance and return the same + * instance. + * + * @param tools A list of tools the model may call. Currently, only functions are supported as a + * tool. Use this to provide a list of functions the model may generate JSON inputs for. A max + * of 128 functions are supported. + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest tools(@Nullable final List tools) { + this.tools = tools; + return this; + } + + /** + * Add one tools instance to this {@link CreateChatCompletionRequest}. + * + * @param toolsItem The tools that should be added + * @return The same instance of type {@link CreateChatCompletionRequest} + */ + @Nonnull + public CreateChatCompletionRequest addToolsItem(@Nonnull final ChatCompletionTool toolsItem) { + if (this.tools == null) { + this.tools = new ArrayList<>(); + } + this.tools.add(toolsItem); + return this; + } + + /** + * A list of tools the model may call. Currently, only functions are supported as a tool. Use this + * to provide a list of functions the model may generate JSON inputs for. A max of 128 functions + * are supported. + * + * @return tools The tools of this {@link CreateChatCompletionRequest} instance. + */ + @Nonnull + public List getTools() { + return tools; + } + + /** + * Set the tools of this {@link CreateChatCompletionRequest} instance. + * + * @param tools A list of tools the model may call. Currently, only functions are supported as a + * tool. Use this to provide a list of functions the model may generate JSON inputs for. A max + * of 128 functions are supported. + */ + public void setTools(@Nullable final List tools) { + this.tools = tools; + } + + /** + * Set the toolChoice of this {@link CreateChatCompletionRequest} instance and return the same + * instance. + * + * @param toolChoice The toolChoice of this {@link CreateChatCompletionRequest} + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest toolChoice( + @Nullable final ChatCompletionToolChoiceOption toolChoice) { + this.toolChoice = toolChoice; + return this; + } + + /** + * Get toolChoice + * + * @return toolChoice The toolChoice of this {@link CreateChatCompletionRequest} instance. + */ + @Nonnull + public ChatCompletionToolChoiceOption getToolChoice() { + return toolChoice; + } + + /** + * Set the toolChoice of this {@link CreateChatCompletionRequest} instance. + * + * @param toolChoice The toolChoice of this {@link CreateChatCompletionRequest} + */ + public void setToolChoice(@Nullable final ChatCompletionToolChoiceOption toolChoice) { + this.toolChoice = toolChoice; + } + + /** + * Set the functionCall of this {@link CreateChatCompletionRequest} instance and return the same + * instance. + * + * @param functionCall The functionCall of this {@link CreateChatCompletionRequest} + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest functionCall( + @Nullable final CreateChatCompletionRequestAllOfFunctionCall functionCall) { + this.functionCall = functionCall; + return this; + } + + /** + * Get functionCall + * + * @return functionCall The functionCall of this {@link CreateChatCompletionRequest} instance. + * @deprecated + */ + @Deprecated + @Nonnull + public CreateChatCompletionRequestAllOfFunctionCall getFunctionCall() { + return functionCall; + } + + /** + * Set the functionCall of this {@link CreateChatCompletionRequest} instance. + * + * @param functionCall The functionCall of this {@link CreateChatCompletionRequest} + */ + public void setFunctionCall( + @Nullable final CreateChatCompletionRequestAllOfFunctionCall functionCall) { + this.functionCall = functionCall; + } + + /** + * Set the functions of this {@link CreateChatCompletionRequest} instance and return the same + * instance. + * + * @param functions Deprecated in favor of `tools`. A list of functions the model may + * generate JSON inputs for. + * @return The same instance of this {@link CreateChatCompletionRequest} class + */ + @Nonnull + public CreateChatCompletionRequest functions( + @Nullable final List functions) { + this.functions = functions; + return this; + } + + /** + * Add one functions instance to this {@link CreateChatCompletionRequest}. + * + * @param functionsItem The functions that should be added + * @return The same instance of type {@link CreateChatCompletionRequest} + */ + @Nonnull + public CreateChatCompletionRequest addFunctionsItem( + @Nonnull final ChatCompletionFunctions functionsItem) { + if (this.functions == null) { + this.functions = new ArrayList<>(); + } + this.functions.add(functionsItem); + return this; + } + + /** + * Deprecated in favor of `tools`. A list of functions the model may generate JSON + * inputs for. + * + * @return functions The functions of this {@link CreateChatCompletionRequest} instance. + * @deprecated + */ + @Deprecated + @Nonnull + public List getFunctions() { + return functions; + } + + /** + * Set the functions of this {@link CreateChatCompletionRequest} instance. + * + * @param functions Deprecated in favor of `tools`. A list of functions the model may + * generate JSON inputs for. + */ + public void setFunctions(@Nullable final List functions) { + this.functions = functions; + } + + /** + * Get the names of the unrecognizable properties of the {@link CreateChatCompletionRequest}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link CreateChatCompletionRequest} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "CreateChatCompletionRequest has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link CreateChatCompletionRequest} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final CreateChatCompletionRequest createChatCompletionRequest = (CreateChatCompletionRequest) o; + return Objects.equals( + this.cloudSdkCustomFields, createChatCompletionRequest.cloudSdkCustomFields) + && Objects.equals(this.temperature, createChatCompletionRequest.temperature) + && Objects.equals(this.topP, createChatCompletionRequest.topP) + && Objects.equals(this.stream, createChatCompletionRequest.stream) + && Objects.equals(this.stop, createChatCompletionRequest.stop) + && Objects.equals(this.maxTokens, createChatCompletionRequest.maxTokens) + && Objects.equals(this.maxCompletionTokens, createChatCompletionRequest.maxCompletionTokens) + && Objects.equals(this.presencePenalty, createChatCompletionRequest.presencePenalty) + && Objects.equals(this.frequencyPenalty, createChatCompletionRequest.frequencyPenalty) + && Objects.equals(this.logitBias, createChatCompletionRequest.logitBias) + && Objects.equals(this.user, createChatCompletionRequest.user) + && Objects.equals(this.messages, createChatCompletionRequest.messages) + && Objects.equals(this.logprobs, createChatCompletionRequest.logprobs) + && Objects.equals(this.topLogprobs, createChatCompletionRequest.topLogprobs) + && Objects.equals(this.n, createChatCompletionRequest.n) + && Objects.equals(this.parallelToolCalls, createChatCompletionRequest.parallelToolCalls) + && Objects.equals(this.responseFormat, createChatCompletionRequest.responseFormat) + && Objects.equals(this.seed, createChatCompletionRequest.seed) + && Objects.equals(this.streamOptions, createChatCompletionRequest.streamOptions) + && Objects.equals(this.tools, createChatCompletionRequest.tools) + && Objects.equals(this.toolChoice, createChatCompletionRequest.toolChoice) + && Objects.equals(this.functionCall, createChatCompletionRequest.functionCall) + && Objects.equals(this.functions, createChatCompletionRequest.functions); + } + + @Override + public int hashCode() { + return Objects.hash( + temperature, + topP, + stream, + stop, + maxTokens, + maxCompletionTokens, + presencePenalty, + frequencyPenalty, + logitBias, + user, + messages, + logprobs, + topLogprobs, + n, + parallelToolCalls, + responseFormat, + seed, + streamOptions, + tools, + toolChoice, + functionCall, + functions, + cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class CreateChatCompletionRequest {\n"); + sb.append(" temperature: ").append(toIndentedString(temperature)).append("\n"); + sb.append(" topP: ").append(toIndentedString(topP)).append("\n"); + sb.append(" stream: ").append(toIndentedString(stream)).append("\n"); + sb.append(" stop: ").append(toIndentedString(stop)).append("\n"); + sb.append(" maxTokens: ").append(toIndentedString(maxTokens)).append("\n"); + sb.append(" maxCompletionTokens: ") + .append(toIndentedString(maxCompletionTokens)) + .append("\n"); + sb.append(" presencePenalty: ").append(toIndentedString(presencePenalty)).append("\n"); + sb.append(" frequencyPenalty: ").append(toIndentedString(frequencyPenalty)).append("\n"); + sb.append(" logitBias: ").append(toIndentedString(logitBias)).append("\n"); + sb.append(" user: ").append(toIndentedString(user)).append("\n"); + sb.append(" messages: ").append(toIndentedString(messages)).append("\n"); + sb.append(" logprobs: ").append(toIndentedString(logprobs)).append("\n"); + sb.append(" topLogprobs: ").append(toIndentedString(topLogprobs)).append("\n"); + sb.append(" n: ").append(toIndentedString(n)).append("\n"); + sb.append(" parallelToolCalls: ").append(toIndentedString(parallelToolCalls)).append("\n"); + sb.append(" responseFormat: ").append(toIndentedString(responseFormat)).append("\n"); + sb.append(" seed: ").append(toIndentedString(seed)).append("\n"); + sb.append(" streamOptions: ").append(toIndentedString(streamOptions)).append("\n"); + sb.append(" tools: ").append(toIndentedString(tools)).append("\n"); + sb.append(" toolChoice: ").append(toIndentedString(toolChoice)).append("\n"); + sb.append(" functionCall: ").append(toIndentedString(functionCall)).append("\n"); + sb.append(" functions: ").append(toIndentedString(functions)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionRequestAllOfFunctionCall.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionRequestAllOfFunctionCall.java new file mode 100644 index 000000000..79daa9136 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionRequestAllOfFunctionCall.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Deprecated in favor of `tool_choice`. Controls which (if any) function is called by the + * model. `none` means the model will not call a function and instead generates a message. + * `auto` means the model can pick between generating a message or calling a function. + * Specifying a particular function via `{\"name\": \"my_function\"}` + * forces the model to call that function. `none` is the default when no functions are + * present. `auto` is the default if functions are present. + * + * @deprecated + */ +@Deprecated +@com.google.common.annotations.Beta +public interface CreateChatCompletionRequestAllOfFunctionCall { + /** + * Helper class to create a ChatCompletionFunctionCallOption that implements {@link + * CreateChatCompletionRequestAllOfFunctionCall}. + */ + record InnerChatCompletionFunctionCallOption(@JsonValue ChatCompletionFunctionCallOption value) + implements CreateChatCompletionRequestAllOfFunctionCall {} + + /** + * Creator to enable deserialization of a ChatCompletionFunctionCallOption. + * + * @param val the value to use + * @return a new instance of {@link InnerChatCompletionFunctionCallOption}. + */ + @JsonCreator + static InnerChatCompletionFunctionCallOption create(ChatCompletionFunctionCallOption val) { + return new InnerChatCompletionFunctionCallOption(val); + } + + /** + * Helper class to create a String that implements {@link + * CreateChatCompletionRequestAllOfFunctionCall}. + */ + record InnerString(@JsonValue String value) + implements CreateChatCompletionRequestAllOfFunctionCall {} + + /** + * Creator to enable deserialization of a String. + * + * @param val the value to use + * @return a new instance of {@link InnerString}. + */ + @JsonCreator + static InnerString create(String val) { + return new InnerString(val); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionRequestAllOfResponseFormat.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionRequestAllOfResponseFormat.java new file mode 100644 index 000000000..4f2199bf5 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionRequestAllOfResponseFormat.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +/** + * An object specifying the format that the model must output. Compatible with + * [GPT-4o](https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models#gpt-4-and-gpt-4-turbo-models), + * [GPT-4o + * mini](https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models#gpt-4-and-gpt-4-turbo-models), + * [GPT-4 + * Turbo](https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models#gpt-4-and-gpt-4-turbo-models) + * and all + * [GPT-3.5](https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models#gpt-35) + * Turbo models newer than `gpt-3.5-turbo-1106`. Setting to `{ \"type\": + * \"json_schema\", \"json_schema\": {...} }` enables Structured Outputs + * which guarantees the model will match your supplied JSON schema. Setting to `{ + * \"type\": \"json_object\" }` enables JSON mode, which guarantees the + * message the model generates is valid JSON. **Important:** when using JSON mode, you **must** also + * instruct the model to produce JSON yourself via a system or user message. Without this, the model + * may generate an unending stream of whitespace until the generation reaches the token limit, + * resulting in a long-running and seemingly \"stuck\" request. Also note that the message + * content may be partially cut off if `finish_reason=\"length\"`, which + * indicates the generation exceeded `max_tokens` or the conversation exceeded the max + * context length. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION) +@JsonSubTypes({ + @JsonSubTypes.Type(value = ResponseFormatJsonObject.class), + @JsonSubTypes.Type(value = ResponseFormatJsonSchema.class), + @JsonSubTypes.Type(value = ResponseFormatText.class), +}) +@com.google.common.annotations.Beta +public interface CreateChatCompletionRequestAllOfResponseFormat {} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionRequestAllOfStop.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionRequestAllOfStop.java new file mode 100644 index 000000000..ab12653be --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionRequestAllOfStop.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import java.util.List; + +/** Up to 4 sequences where the API will stop generating further tokens. */ +@com.google.common.annotations.Beta +public interface CreateChatCompletionRequestAllOfStop { + /** + * Helper class to create a String that implements {@link CreateChatCompletionRequestAllOfStop}. + */ + record InnerString(@com.fasterxml.jackson.annotation.JsonValue String value) + implements CreateChatCompletionRequestAllOfStop {} + + /** + * Creator to enable deserialization of a String. + * + * @param val the value to use + * @return a new instance of {@link InnerString}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + static InnerString create(String val) { + return new InnerString(val); + } + + /** + * Helper class to create a list of String that implements {@link + * CreateChatCompletionRequestAllOfStop}. + */ + record InnerStrings(@com.fasterxml.jackson.annotation.JsonValue List values) + implements CreateChatCompletionRequestAllOfStop {} + + /** + * Creator to enable deserialization of a list of String. + * + * @param val the value to use + * @return a new instance of {@link InnerStrings}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + static InnerStrings create(List val) { + return new InnerStrings(val); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionResponse.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionResponse.java new file mode 100644 index 000000000..bc422a7f2 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionResponse.java @@ -0,0 +1,535 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** Represents a chat completion response returned by model, based on the provided input. */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class CreateChatCompletionResponse implements ChatCompletionsCreate200Response +// CHECKSTYLE:ON +{ + @JsonProperty("id") + private String id; + + @JsonProperty("prompt_filter_results") + private List promptFilterResults = new ArrayList<>(); + + @JsonProperty("choices") + private List choices = new ArrayList<>(); + + @JsonProperty("created") + private Integer created; + + @JsonProperty("model") + private String model; + + @JsonProperty("system_fingerprint") + private String systemFingerprint; + + /** The object type, which is always `chat.completion`. */ + public enum ObjectEnum { + /** The CHAT_COMPLETION option of this CreateChatCompletionResponse */ + CHAT_COMPLETION("chat.completion"), + /** The UNKNOWN_DEFAULT_OPEN_API option of this CreateChatCompletionResponse */ + UNKNOWN_DEFAULT_OPEN_API("unknown_default_open_api"); + ; + + private String value; + + ObjectEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type CreateChatCompletionResponse + */ + @JsonCreator + @Nonnull + public static ObjectEnum fromValue(@Nonnull final String value) { + for (ObjectEnum b : ObjectEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + return UNKNOWN_DEFAULT_OPEN_API; + } + } + + @JsonProperty("object") + private ObjectEnum _object; + + @JsonProperty("usage") + private CompletionUsage usage; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the id of this {@link CreateChatCompletionResponse} instance and return the same instance. + * + * @param id A unique identifier for the chat completion. + * @return The same instance of this {@link CreateChatCompletionResponse} class + */ + @Nonnull + public CreateChatCompletionResponse id(@Nonnull final String id) { + this.id = id; + return this; + } + + /** + * A unique identifier for the chat completion. + * + * @return id The id of this {@link CreateChatCompletionResponse} instance. + */ + @Nonnull + public String getId() { + return id; + } + + /** + * Set the id of this {@link CreateChatCompletionResponse} instance. + * + * @param id A unique identifier for the chat completion. + */ + public void setId(@Nonnull final String id) { + this.id = id; + } + + /** + * Set the promptFilterResults of this {@link CreateChatCompletionResponse} instance and return + * the same instance. + * + * @param promptFilterResults Content filtering results for zero or more prompts in the request. + * In a streaming request, results for different prompts may arrive at different times or in + * different orders. + * @return The same instance of this {@link CreateChatCompletionResponse} class + */ + @Nonnull + public CreateChatCompletionResponse promptFilterResults( + @Nullable final List promptFilterResults) { + this.promptFilterResults = promptFilterResults; + return this; + } + + /** + * Add one promptFilterResults instance to this {@link CreateChatCompletionResponse}. + * + * @param promptFilterResultsItem The promptFilterResults that should be added + * @return The same instance of type {@link CreateChatCompletionResponse} + */ + @Nonnull + public CreateChatCompletionResponse addPromptFilterResultsItem( + @Nonnull final PromptFilterResult promptFilterResultsItem) { + if (this.promptFilterResults == null) { + this.promptFilterResults = new ArrayList<>(); + } + this.promptFilterResults.add(promptFilterResultsItem); + return this; + } + + /** + * Content filtering results for zero or more prompts in the request. In a streaming request, + * results for different prompts may arrive at different times or in different orders. + * + * @return promptFilterResults The promptFilterResults of this {@link + * CreateChatCompletionResponse} instance. + */ + @Nonnull + public List getPromptFilterResults() { + return promptFilterResults; + } + + /** + * Set the promptFilterResults of this {@link CreateChatCompletionResponse} instance. + * + * @param promptFilterResults Content filtering results for zero or more prompts in the request. + * In a streaming request, results for different prompts may arrive at different times or in + * different orders. + */ + public void setPromptFilterResults(@Nullable final List promptFilterResults) { + this.promptFilterResults = promptFilterResults; + } + + /** + * Set the choices of this {@link CreateChatCompletionResponse} instance and return the same + * instance. + * + * @param choices A list of chat completion choices. Can be more than one if `n` is + * greater than 1. + * @return The same instance of this {@link CreateChatCompletionResponse} class + */ + @Nonnull + public CreateChatCompletionResponse choices( + @Nonnull final List choices) { + this.choices = choices; + return this; + } + + /** + * Add one choices instance to this {@link CreateChatCompletionResponse}. + * + * @param choicesItem The choices that should be added + * @return The same instance of type {@link CreateChatCompletionResponse} + */ + @Nonnull + public CreateChatCompletionResponse addChoicesItem( + @Nonnull final CreateChatCompletionResponseChoicesInner choicesItem) { + if (this.choices == null) { + this.choices = new ArrayList<>(); + } + this.choices.add(choicesItem); + return this; + } + + /** + * A list of chat completion choices. Can be more than one if `n` is greater than 1. + * + * @return choices The choices of this {@link CreateChatCompletionResponse} instance. + */ + @Nonnull + public List getChoices() { + return choices; + } + + /** + * Set the choices of this {@link CreateChatCompletionResponse} instance. + * + * @param choices A list of chat completion choices. Can be more than one if `n` is + * greater than 1. + */ + public void setChoices(@Nonnull final List choices) { + this.choices = choices; + } + + /** + * Set the created of this {@link CreateChatCompletionResponse} instance and return the same + * instance. + * + * @param created The Unix timestamp (in seconds) of when the chat completion was created. + * @return The same instance of this {@link CreateChatCompletionResponse} class + */ + @Nonnull + public CreateChatCompletionResponse created(@Nonnull final Integer created) { + this.created = created; + return this; + } + + /** + * The Unix timestamp (in seconds) of when the chat completion was created. + * + * @return created The created of this {@link CreateChatCompletionResponse} instance. + */ + @Nonnull + public Integer getCreated() { + return created; + } + + /** + * Set the created of this {@link CreateChatCompletionResponse} instance. + * + * @param created The Unix timestamp (in seconds) of when the chat completion was created. + */ + public void setCreated(@Nonnull final Integer created) { + this.created = created; + } + + /** + * Set the model of this {@link CreateChatCompletionResponse} instance and return the same + * instance. + * + * @param model The model used for the chat completion. + * @return The same instance of this {@link CreateChatCompletionResponse} class + */ + @Nonnull + public CreateChatCompletionResponse model(@Nonnull final String model) { + this.model = model; + return this; + } + + /** + * The model used for the chat completion. + * + * @return model The model of this {@link CreateChatCompletionResponse} instance. + */ + @Nonnull + public String getModel() { + return model; + } + + /** + * Set the model of this {@link CreateChatCompletionResponse} instance. + * + * @param model The model used for the chat completion. + */ + public void setModel(@Nonnull final String model) { + this.model = model; + } + + /** + * Set the systemFingerprint of this {@link CreateChatCompletionResponse} instance and return the + * same instance. + * + * @param systemFingerprint This fingerprint represents the backend configuration that the model + * runs with. Can be used in conjunction with the `seed` request parameter to + * understand when backend changes have been made that might impact determinism. + * @return The same instance of this {@link CreateChatCompletionResponse} class + */ + @Nonnull + public CreateChatCompletionResponse systemFingerprint(@Nullable final String systemFingerprint) { + this.systemFingerprint = systemFingerprint; + return this; + } + + /** + * This fingerprint represents the backend configuration that the model runs with. Can be used in + * conjunction with the `seed` request parameter to understand when backend changes have + * been made that might impact determinism. + * + * @return systemFingerprint The systemFingerprint of this {@link CreateChatCompletionResponse} + * instance. + */ + @Nonnull + public String getSystemFingerprint() { + return systemFingerprint; + } + + /** + * Set the systemFingerprint of this {@link CreateChatCompletionResponse} instance. + * + * @param systemFingerprint This fingerprint represents the backend configuration that the model + * runs with. Can be used in conjunction with the `seed` request parameter to + * understand when backend changes have been made that might impact determinism. + */ + public void setSystemFingerprint(@Nullable final String systemFingerprint) { + this.systemFingerprint = systemFingerprint; + } + + /** + * Set the _object of this {@link CreateChatCompletionResponse} instance and return the same + * instance. + * + * @param _object The object type, which is always `chat.completion`. + * @return The same instance of this {@link CreateChatCompletionResponse} class + */ + @Nonnull + public CreateChatCompletionResponse _object(@Nonnull final ObjectEnum _object) { + this._object = _object; + return this; + } + + /** + * The object type, which is always `chat.completion`. + * + * @return _object The _object of this {@link CreateChatCompletionResponse} instance. + */ + @Nonnull + public ObjectEnum getObject() { + return _object; + } + + /** + * Set the _object of this {@link CreateChatCompletionResponse} instance. + * + * @param _object The object type, which is always `chat.completion`. + */ + public void setObject(@Nonnull final ObjectEnum _object) { + this._object = _object; + } + + /** + * Set the usage of this {@link CreateChatCompletionResponse} instance and return the same + * instance. + * + * @param usage The usage of this {@link CreateChatCompletionResponse} + * @return The same instance of this {@link CreateChatCompletionResponse} class + */ + @Nonnull + public CreateChatCompletionResponse usage(@Nullable final CompletionUsage usage) { + this.usage = usage; + return this; + } + + /** + * Get usage + * + * @return usage The usage of this {@link CreateChatCompletionResponse} instance. + */ + @Nonnull + public CompletionUsage getUsage() { + return usage; + } + + /** + * Set the usage of this {@link CreateChatCompletionResponse} instance. + * + * @param usage The usage of this {@link CreateChatCompletionResponse} + */ + public void setUsage(@Nullable final CompletionUsage usage) { + this.usage = usage; + } + + /** + * Get the names of the unrecognizable properties of the {@link CreateChatCompletionResponse}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link CreateChatCompletionResponse} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "CreateChatCompletionResponse has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link CreateChatCompletionResponse} instance. If the + * map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final CreateChatCompletionResponse createChatCompletionResponse = + (CreateChatCompletionResponse) o; + return Objects.equals( + this.cloudSdkCustomFields, createChatCompletionResponse.cloudSdkCustomFields) + && Objects.equals(this.id, createChatCompletionResponse.id) + && Objects.equals( + this.promptFilterResults, createChatCompletionResponse.promptFilterResults) + && Objects.equals(this.choices, createChatCompletionResponse.choices) + && Objects.equals(this.created, createChatCompletionResponse.created) + && Objects.equals(this.model, createChatCompletionResponse.model) + && Objects.equals(this.systemFingerprint, createChatCompletionResponse.systemFingerprint) + && Objects.equals(this._object, createChatCompletionResponse._object) + && Objects.equals(this.usage, createChatCompletionResponse.usage); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + promptFilterResults, + choices, + created, + model, + systemFingerprint, + _object, + usage, + cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class CreateChatCompletionResponse {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" promptFilterResults: ") + .append(toIndentedString(promptFilterResults)) + .append("\n"); + sb.append(" choices: ").append(toIndentedString(choices)).append("\n"); + sb.append(" created: ").append(toIndentedString(created)).append("\n"); + sb.append(" model: ").append(toIndentedString(model)).append("\n"); + sb.append(" systemFingerprint: ").append(toIndentedString(systemFingerprint)).append("\n"); + sb.append(" _object: ").append(toIndentedString(_object)).append("\n"); + sb.append(" usage: ").append(toIndentedString(usage)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionResponseChoicesInner.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionResponseChoicesInner.java new file mode 100644 index 000000000..4631ffbe3 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionResponseChoicesInner.java @@ -0,0 +1,409 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** CreateChatCompletionResponseChoicesInner */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class CreateChatCompletionResponseChoicesInner +// CHECKSTYLE:ON +{ + /** + * The reason the model stopped generating tokens. This will be `stop` if the model hit + * a natural stop point or a provided stop sequence, `length` if the maximum number of + * tokens specified in the request was reached, `content_filter` if content was omitted + * due to a flag from our content filters, `tool_calls` if the model called a tool, or + * `function_call` (deprecated) if the model called a function. + */ + public enum FinishReasonEnum { + /** The STOP option of this CreateChatCompletionResponseChoicesInner */ + STOP("stop"), + + /** The LENGTH option of this CreateChatCompletionResponseChoicesInner */ + LENGTH("length"), + + /** The TOOL_CALLS option of this CreateChatCompletionResponseChoicesInner */ + TOOL_CALLS("tool_calls"), + + /** The CONTENT_FILTER option of this CreateChatCompletionResponseChoicesInner */ + CONTENT_FILTER("content_filter"), + + /** The FUNCTION_CALL option of this CreateChatCompletionResponseChoicesInner */ + FUNCTION_CALL("function_call"); + + private String value; + + FinishReasonEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type CreateChatCompletionResponseChoicesInner + */ + @JsonCreator + @Nonnull + public static FinishReasonEnum fromValue(@Nonnull final String value) { + for (FinishReasonEnum b : FinishReasonEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("finish_reason") + private FinishReasonEnum finishReason; + + @JsonProperty("index") + private Integer index; + + @JsonProperty("message") + private ChatCompletionResponseMessage message; + + @JsonProperty("content_filter_results") + private ContentFilterChoiceResults contentFilterResults; + + @JsonProperty("logprobs") + private CreateChatCompletionResponseChoicesInnerLogprobs logprobs; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the finishReason of this {@link CreateChatCompletionResponseChoicesInner} instance and + * return the same instance. + * + * @param finishReason The reason the model stopped generating tokens. This will be + * `stop` if the model hit a natural stop point or a provided stop sequence, + * `length` if the maximum number of tokens specified in the request was reached, + * `content_filter` if content was omitted due to a flag from our content filters, + * `tool_calls` if the model called a tool, or `function_call` + * (deprecated) if the model called a function. + * @return The same instance of this {@link CreateChatCompletionResponseChoicesInner} class + */ + @Nonnull + public CreateChatCompletionResponseChoicesInner finishReason( + @Nonnull final FinishReasonEnum finishReason) { + this.finishReason = finishReason; + return this; + } + + /** + * The reason the model stopped generating tokens. This will be `stop` if the model hit + * a natural stop point or a provided stop sequence, `length` if the maximum number of + * tokens specified in the request was reached, `content_filter` if content was omitted + * due to a flag from our content filters, `tool_calls` if the model called a tool, or + * `function_call` (deprecated) if the model called a function. + * + * @return finishReason The finishReason of this {@link CreateChatCompletionResponseChoicesInner} + * instance. + */ + @Nonnull + public FinishReasonEnum getFinishReason() { + return finishReason; + } + + /** + * Set the finishReason of this {@link CreateChatCompletionResponseChoicesInner} instance. + * + * @param finishReason The reason the model stopped generating tokens. This will be + * `stop` if the model hit a natural stop point or a provided stop sequence, + * `length` if the maximum number of tokens specified in the request was reached, + * `content_filter` if content was omitted due to a flag from our content filters, + * `tool_calls` if the model called a tool, or `function_call` + * (deprecated) if the model called a function. + */ + public void setFinishReason(@Nonnull final FinishReasonEnum finishReason) { + this.finishReason = finishReason; + } + + /** + * Set the index of this {@link CreateChatCompletionResponseChoicesInner} instance and return the + * same instance. + * + * @param index The index of the choice in the list of choices. + * @return The same instance of this {@link CreateChatCompletionResponseChoicesInner} class + */ + @Nonnull + public CreateChatCompletionResponseChoicesInner index(@Nonnull final Integer index) { + this.index = index; + return this; + } + + /** + * The index of the choice in the list of choices. + * + * @return index The index of this {@link CreateChatCompletionResponseChoicesInner} instance. + */ + @Nonnull + public Integer getIndex() { + return index; + } + + /** + * Set the index of this {@link CreateChatCompletionResponseChoicesInner} instance. + * + * @param index The index of the choice in the list of choices. + */ + public void setIndex(@Nonnull final Integer index) { + this.index = index; + } + + /** + * Set the message of this {@link CreateChatCompletionResponseChoicesInner} instance and return + * the same instance. + * + * @param message The message of this {@link CreateChatCompletionResponseChoicesInner} + * @return The same instance of this {@link CreateChatCompletionResponseChoicesInner} class + */ + @Nonnull + public CreateChatCompletionResponseChoicesInner message( + @Nonnull final ChatCompletionResponseMessage message) { + this.message = message; + return this; + } + + /** + * Get message + * + * @return message The message of this {@link CreateChatCompletionResponseChoicesInner} instance. + */ + @Nonnull + public ChatCompletionResponseMessage getMessage() { + return message; + } + + /** + * Set the message of this {@link CreateChatCompletionResponseChoicesInner} instance. + * + * @param message The message of this {@link CreateChatCompletionResponseChoicesInner} + */ + public void setMessage(@Nonnull final ChatCompletionResponseMessage message) { + this.message = message; + } + + /** + * Set the contentFilterResults of this {@link CreateChatCompletionResponseChoicesInner} instance + * and return the same instance. + * + * @param contentFilterResults The contentFilterResults of this {@link + * CreateChatCompletionResponseChoicesInner} + * @return The same instance of this {@link CreateChatCompletionResponseChoicesInner} class + */ + @Nonnull + public CreateChatCompletionResponseChoicesInner contentFilterResults( + @Nullable final ContentFilterChoiceResults contentFilterResults) { + this.contentFilterResults = contentFilterResults; + return this; + } + + /** + * Get contentFilterResults + * + * @return contentFilterResults The contentFilterResults of this {@link + * CreateChatCompletionResponseChoicesInner} instance. + */ + @Nonnull + public ContentFilterChoiceResults getContentFilterResults() { + return contentFilterResults; + } + + /** + * Set the contentFilterResults of this {@link CreateChatCompletionResponseChoicesInner} instance. + * + * @param contentFilterResults The contentFilterResults of this {@link + * CreateChatCompletionResponseChoicesInner} + */ + public void setContentFilterResults( + @Nullable final ContentFilterChoiceResults contentFilterResults) { + this.contentFilterResults = contentFilterResults; + } + + /** + * Set the logprobs of this {@link CreateChatCompletionResponseChoicesInner} instance and return + * the same instance. + * + * @param logprobs The logprobs of this {@link CreateChatCompletionResponseChoicesInner} + * @return The same instance of this {@link CreateChatCompletionResponseChoicesInner} class + */ + @Nonnull + public CreateChatCompletionResponseChoicesInner logprobs( + @Nullable final CreateChatCompletionResponseChoicesInnerLogprobs logprobs) { + this.logprobs = logprobs; + return this; + } + + /** + * Get logprobs + * + * @return logprobs The logprobs of this {@link CreateChatCompletionResponseChoicesInner} + * instance. + */ + @Nullable + public CreateChatCompletionResponseChoicesInnerLogprobs getLogprobs() { + return logprobs; + } + + /** + * Set the logprobs of this {@link CreateChatCompletionResponseChoicesInner} instance. + * + * @param logprobs The logprobs of this {@link CreateChatCompletionResponseChoicesInner} + */ + public void setLogprobs( + @Nullable final CreateChatCompletionResponseChoicesInnerLogprobs logprobs) { + this.logprobs = logprobs; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * CreateChatCompletionResponseChoicesInner}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * CreateChatCompletionResponseChoicesInner} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "CreateChatCompletionResponseChoicesInner has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link CreateChatCompletionResponseChoicesInner} + * instance. If the map previously contained a mapping for the key, the old value is replaced by + * the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final CreateChatCompletionResponseChoicesInner createChatCompletionResponseChoicesInner = + (CreateChatCompletionResponseChoicesInner) o; + return Objects.equals( + this.cloudSdkCustomFields, + createChatCompletionResponseChoicesInner.cloudSdkCustomFields) + && Objects.equals(this.finishReason, createChatCompletionResponseChoicesInner.finishReason) + && Objects.equals(this.index, createChatCompletionResponseChoicesInner.index) + && Objects.equals(this.message, createChatCompletionResponseChoicesInner.message) + && Objects.equals( + this.contentFilterResults, + createChatCompletionResponseChoicesInner.contentFilterResults) + && Objects.equals(this.logprobs, createChatCompletionResponseChoicesInner.logprobs); + } + + @Override + public int hashCode() { + return Objects.hash( + finishReason, index, message, contentFilterResults, logprobs, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class CreateChatCompletionResponseChoicesInner {\n"); + sb.append(" finishReason: ").append(toIndentedString(finishReason)).append("\n"); + sb.append(" index: ").append(toIndentedString(index)).append("\n"); + sb.append(" message: ").append(toIndentedString(message)).append("\n"); + sb.append(" contentFilterResults: ") + .append(toIndentedString(contentFilterResults)) + .append("\n"); + sb.append(" logprobs: ").append(toIndentedString(logprobs)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionResponseChoicesInnerLogprobs.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionResponseChoicesInnerLogprobs.java new file mode 100644 index 000000000..12626010e --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionResponseChoicesInnerLogprobs.java @@ -0,0 +1,240 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** Log probability information for the choice. */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class CreateChatCompletionResponseChoicesInnerLogprobs +// CHECKSTYLE:ON +{ + @JsonProperty("content") + private List content; + + @JsonProperty("refusal") + private List refusal; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the content of this {@link CreateChatCompletionResponseChoicesInnerLogprobs} instance and + * return the same instance. + * + * @param content A list of message content tokens with log probability information. + * @return The same instance of this {@link CreateChatCompletionResponseChoicesInnerLogprobs} + * class + */ + @Nonnull + public CreateChatCompletionResponseChoicesInnerLogprobs content( + @Nullable final List content) { + this.content = content; + return this; + } + + /** + * Add one content instance to this {@link CreateChatCompletionResponseChoicesInnerLogprobs}. + * + * @param contentItem The content that should be added + * @return The same instance of type {@link CreateChatCompletionResponseChoicesInnerLogprobs} + */ + @Nonnull + public CreateChatCompletionResponseChoicesInnerLogprobs addContentItem( + @Nonnull final ChatCompletionTokenLogprob contentItem) { + if (this.content == null) { + this.content = new ArrayList<>(); + } + this.content.add(contentItem); + return this; + } + + /** + * A list of message content tokens with log probability information. + * + * @return content The content of this {@link CreateChatCompletionResponseChoicesInnerLogprobs} + * instance. + */ + @Nullable + public List getContent() { + return content; + } + + /** + * Set the content of this {@link CreateChatCompletionResponseChoicesInnerLogprobs} instance. + * + * @param content A list of message content tokens with log probability information. + */ + public void setContent(@Nullable final List content) { + this.content = content; + } + + /** + * Set the refusal of this {@link CreateChatCompletionResponseChoicesInnerLogprobs} instance and + * return the same instance. + * + * @param refusal A list of message refusal tokens with log probability information. + * @return The same instance of this {@link CreateChatCompletionResponseChoicesInnerLogprobs} + * class + */ + @Nonnull + public CreateChatCompletionResponseChoicesInnerLogprobs refusal( + @Nullable final List refusal) { + this.refusal = refusal; + return this; + } + + /** + * Add one refusal instance to this {@link CreateChatCompletionResponseChoicesInnerLogprobs}. + * + * @param refusalItem The refusal that should be added + * @return The same instance of type {@link CreateChatCompletionResponseChoicesInnerLogprobs} + */ + @Nonnull + public CreateChatCompletionResponseChoicesInnerLogprobs addRefusalItem( + @Nonnull final ChatCompletionTokenLogprob refusalItem) { + if (this.refusal == null) { + this.refusal = new ArrayList<>(); + } + this.refusal.add(refusalItem); + return this; + } + + /** + * A list of message refusal tokens with log probability information. + * + * @return refusal The refusal of this {@link CreateChatCompletionResponseChoicesInnerLogprobs} + * instance. + */ + @Nullable + public List getRefusal() { + return refusal; + } + + /** + * Set the refusal of this {@link CreateChatCompletionResponseChoicesInnerLogprobs} instance. + * + * @param refusal A list of message refusal tokens with log probability information. + */ + public void setRefusal(@Nullable final List refusal) { + this.refusal = refusal; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * CreateChatCompletionResponseChoicesInnerLogprobs}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * CreateChatCompletionResponseChoicesInnerLogprobs} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "CreateChatCompletionResponseChoicesInnerLogprobs has no field with name '" + + name + + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link CreateChatCompletionResponseChoicesInnerLogprobs} + * instance. If the map previously contained a mapping for the key, the old value is replaced by + * the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final CreateChatCompletionResponseChoicesInnerLogprobs + createChatCompletionResponseChoicesInnerLogprobs = + (CreateChatCompletionResponseChoicesInnerLogprobs) o; + return Objects.equals( + this.cloudSdkCustomFields, + createChatCompletionResponseChoicesInnerLogprobs.cloudSdkCustomFields) + && Objects.equals(this.content, createChatCompletionResponseChoicesInnerLogprobs.content) + && Objects.equals(this.refusal, createChatCompletionResponseChoicesInnerLogprobs.refusal); + } + + @Override + public int hashCode() { + return Objects.hash(content, refusal, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class CreateChatCompletionResponseChoicesInnerLogprobs {\n"); + sb.append(" content: ").append(toIndentedString(content)).append("\n"); + sb.append(" refusal: ").append(toIndentedString(refusal)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionStreamResponse.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionStreamResponse.java new file mode 100644 index 000000000..6cd146506 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionStreamResponse.java @@ -0,0 +1,438 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Represents a streamed chunk of a chat completion response returned by model, based on the + * provided input. + */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class CreateChatCompletionStreamResponse implements ChatCompletionsCreate200Response +// CHECKSTYLE:ON +{ + @JsonProperty("id") + private String id; + + @JsonProperty("choices") + private List choices = new ArrayList<>(); + + @JsonProperty("created") + private Integer created; + + @JsonProperty("model") + private String model; + + @JsonProperty("system_fingerprint") + private String systemFingerprint; + + /** The object type, which is always `chat.completion.chunk`. */ + public enum ObjectEnum { + /** The CHAT_COMPLETION_CHUNK option of this CreateChatCompletionStreamResponse */ + CHAT_COMPLETION_CHUNK("chat.completion.chunk"), + /** The UNKNOWN_DEFAULT_OPEN_API option of this CreateChatCompletionResponse */ + UNKNOWN_DEFAULT_OPEN_API("unknown_default_open_api"); + + private String value; + + ObjectEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type CreateChatCompletionStreamResponse + */ + @JsonCreator + @Nonnull + public static ObjectEnum fromValue(@Nonnull final String value) { + for (ObjectEnum b : ObjectEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + return UNKNOWN_DEFAULT_OPEN_API; + } + } + + @JsonProperty("object") + private ObjectEnum _object; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the id of this {@link CreateChatCompletionStreamResponse} instance and return the same + * instance. + * + * @param id A unique identifier for the chat completion. Each chunk has the same ID. + * @return The same instance of this {@link CreateChatCompletionStreamResponse} class + */ + @Nonnull + public CreateChatCompletionStreamResponse id(@Nonnull final String id) { + this.id = id; + return this; + } + + /** + * A unique identifier for the chat completion. Each chunk has the same ID. + * + * @return id The id of this {@link CreateChatCompletionStreamResponse} instance. + */ + @Nonnull + public String getId() { + return id; + } + + /** + * Set the id of this {@link CreateChatCompletionStreamResponse} instance. + * + * @param id A unique identifier for the chat completion. Each chunk has the same ID. + */ + public void setId(@Nonnull final String id) { + this.id = id; + } + + /** + * Set the choices of this {@link CreateChatCompletionStreamResponse} instance and return the same + * instance. + * + * @param choices A list of chat completion choices. Can contain more than one elements if + * `n` is greater than 1. + * @return The same instance of this {@link CreateChatCompletionStreamResponse} class + */ + @Nonnull + public CreateChatCompletionStreamResponse choices( + @Nonnull final List choices) { + this.choices = choices; + return this; + } + + /** + * Add one choices instance to this {@link CreateChatCompletionStreamResponse}. + * + * @param choicesItem The choices that should be added + * @return The same instance of type {@link CreateChatCompletionStreamResponse} + */ + @Nonnull + public CreateChatCompletionStreamResponse addChoicesItem( + @Nonnull final CreateChatCompletionStreamResponseChoicesInner choicesItem) { + if (this.choices == null) { + this.choices = new ArrayList<>(); + } + this.choices.add(choicesItem); + return this; + } + + /** + * A list of chat completion choices. Can contain more than one elements if `n` is + * greater than 1. + * + * @return choices The choices of this {@link CreateChatCompletionStreamResponse} instance. + */ + @Nonnull + public List getChoices() { + return choices; + } + + /** + * Set the choices of this {@link CreateChatCompletionStreamResponse} instance. + * + * @param choices A list of chat completion choices. Can contain more than one elements if + * `n` is greater than 1. + */ + public void setChoices( + @Nonnull final List choices) { + this.choices = choices; + } + + /** + * Set the created of this {@link CreateChatCompletionStreamResponse} instance and return the same + * instance. + * + * @param created The Unix timestamp (in seconds) of when the chat completion was created. Each + * chunk has the same timestamp. + * @return The same instance of this {@link CreateChatCompletionStreamResponse} class + */ + @Nonnull + public CreateChatCompletionStreamResponse created(@Nonnull final Integer created) { + this.created = created; + return this; + } + + /** + * The Unix timestamp (in seconds) of when the chat completion was created. Each chunk has the + * same timestamp. + * + * @return created The created of this {@link CreateChatCompletionStreamResponse} instance. + */ + @Nonnull + public Integer getCreated() { + return created; + } + + /** + * Set the created of this {@link CreateChatCompletionStreamResponse} instance. + * + * @param created The Unix timestamp (in seconds) of when the chat completion was created. Each + * chunk has the same timestamp. + */ + public void setCreated(@Nonnull final Integer created) { + this.created = created; + } + + /** + * Set the model of this {@link CreateChatCompletionStreamResponse} instance and return the same + * instance. + * + * @param model The model to generate the completion. + * @return The same instance of this {@link CreateChatCompletionStreamResponse} class + */ + @Nonnull + public CreateChatCompletionStreamResponse model(@Nonnull final String model) { + this.model = model; + return this; + } + + /** + * The model to generate the completion. + * + * @return model The model of this {@link CreateChatCompletionStreamResponse} instance. + */ + @Nonnull + public String getModel() { + return model; + } + + /** + * Set the model of this {@link CreateChatCompletionStreamResponse} instance. + * + * @param model The model to generate the completion. + */ + public void setModel(@Nonnull final String model) { + this.model = model; + } + + /** + * Set the systemFingerprint of this {@link CreateChatCompletionStreamResponse} instance and + * return the same instance. + * + * @param systemFingerprint This fingerprint represents the backend configuration that the model + * runs with. Can be used in conjunction with the `seed` request parameter to + * understand when backend changes have been made that might impact determinism. + * @return The same instance of this {@link CreateChatCompletionStreamResponse} class + */ + @Nonnull + public CreateChatCompletionStreamResponse systemFingerprint( + @Nullable final String systemFingerprint) { + this.systemFingerprint = systemFingerprint; + return this; + } + + /** + * This fingerprint represents the backend configuration that the model runs with. Can be used in + * conjunction with the `seed` request parameter to understand when backend changes have + * been made that might impact determinism. + * + * @return systemFingerprint The systemFingerprint of this {@link + * CreateChatCompletionStreamResponse} instance. + */ + @Nonnull + public String getSystemFingerprint() { + return systemFingerprint; + } + + /** + * Set the systemFingerprint of this {@link CreateChatCompletionStreamResponse} instance. + * + * @param systemFingerprint This fingerprint represents the backend configuration that the model + * runs with. Can be used in conjunction with the `seed` request parameter to + * understand when backend changes have been made that might impact determinism. + */ + public void setSystemFingerprint(@Nullable final String systemFingerprint) { + this.systemFingerprint = systemFingerprint; + } + + /** + * Set the _object of this {@link CreateChatCompletionStreamResponse} instance and return the same + * instance. + * + * @param _object The object type, which is always `chat.completion.chunk`. + * @return The same instance of this {@link CreateChatCompletionStreamResponse} class + */ + @Nonnull + public CreateChatCompletionStreamResponse _object(@Nonnull final ObjectEnum _object) { + this._object = _object; + return this; + } + + /** + * The object type, which is always `chat.completion.chunk`. + * + * @return _object The _object of this {@link CreateChatCompletionStreamResponse} instance. + */ + @Nonnull + public ObjectEnum getObject() { + return _object; + } + + /** + * Set the _object of this {@link CreateChatCompletionStreamResponse} instance. + * + * @param _object The object type, which is always `chat.completion.chunk`. + */ + public void setObject(@Nonnull final ObjectEnum _object) { + this._object = _object; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * CreateChatCompletionStreamResponse}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link CreateChatCompletionStreamResponse} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "CreateChatCompletionStreamResponse has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link CreateChatCompletionStreamResponse} instance. If + * the map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final CreateChatCompletionStreamResponse createChatCompletionStreamResponse = + (CreateChatCompletionStreamResponse) o; + return Objects.equals( + this.cloudSdkCustomFields, createChatCompletionStreamResponse.cloudSdkCustomFields) + && Objects.equals(this.id, createChatCompletionStreamResponse.id) + && Objects.equals(this.choices, createChatCompletionStreamResponse.choices) + && Objects.equals(this.created, createChatCompletionStreamResponse.created) + && Objects.equals(this.model, createChatCompletionStreamResponse.model) + && Objects.equals( + this.systemFingerprint, createChatCompletionStreamResponse.systemFingerprint) + && Objects.equals(this._object, createChatCompletionStreamResponse._object); + } + + @Override + public int hashCode() { + return Objects.hash( + id, choices, created, model, systemFingerprint, _object, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class CreateChatCompletionStreamResponse {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" choices: ").append(toIndentedString(choices)).append("\n"); + sb.append(" created: ").append(toIndentedString(created)).append("\n"); + sb.append(" model: ").append(toIndentedString(model)).append("\n"); + sb.append(" systemFingerprint: ").append(toIndentedString(systemFingerprint)).append("\n"); + sb.append(" _object: ").append(toIndentedString(_object)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionStreamResponseChoicesInner.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionStreamResponseChoicesInner.java new file mode 100644 index 000000000..49c0c0f63 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/CreateChatCompletionStreamResponseChoicesInner.java @@ -0,0 +1,366 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** CreateChatCompletionStreamResponseChoicesInner */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class CreateChatCompletionStreamResponseChoicesInner +// CHECKSTYLE:ON +{ + @JsonProperty("delta") + private ChatCompletionStreamResponseDelta delta; + + @JsonProperty("logprobs") + private CreateChatCompletionResponseChoicesInnerLogprobs logprobs; + + /** + * The reason the model stopped generating tokens. This will be `stop` if the model hit + * a natural stop point or a provided stop sequence, `length` if the maximum number of + * tokens specified in the request was reached, `content_filter` if content was omitted + * due to a flag from our content filters, `tool_calls` if the model called a tool, or + * `function_call` (deprecated) if the model called a function. + */ + public enum FinishReasonEnum { + /** The STOP option of this CreateChatCompletionStreamResponseChoicesInner */ + STOP("stop"), + + /** The LENGTH option of this CreateChatCompletionStreamResponseChoicesInner */ + LENGTH("length"), + + /** The TOOL_CALLS option of this CreateChatCompletionStreamResponseChoicesInner */ + TOOL_CALLS("tool_calls"), + + /** The CONTENT_FILTER option of this CreateChatCompletionStreamResponseChoicesInner */ + CONTENT_FILTER("content_filter"), + + /** The FUNCTION_CALL option of this CreateChatCompletionStreamResponseChoicesInner */ + FUNCTION_CALL("function_call"); + + private String value; + + FinishReasonEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type CreateChatCompletionStreamResponseChoicesInner + */ + @JsonCreator + @Nonnull + public static FinishReasonEnum fromValue(@Nonnull final String value) { + for (FinishReasonEnum b : FinishReasonEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("finish_reason") + private FinishReasonEnum finishReason; + + @JsonProperty("index") + private Integer index; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the delta of this {@link CreateChatCompletionStreamResponseChoicesInner} instance and + * return the same instance. + * + * @param delta The delta of this {@link CreateChatCompletionStreamResponseChoicesInner} + * @return The same instance of this {@link CreateChatCompletionStreamResponseChoicesInner} class + */ + @Nonnull + public CreateChatCompletionStreamResponseChoicesInner delta( + @Nonnull final ChatCompletionStreamResponseDelta delta) { + this.delta = delta; + return this; + } + + /** + * Get delta + * + * @return delta The delta of this {@link CreateChatCompletionStreamResponseChoicesInner} + * instance. + */ + @Nonnull + public ChatCompletionStreamResponseDelta getDelta() { + return delta; + } + + /** + * Set the delta of this {@link CreateChatCompletionStreamResponseChoicesInner} instance. + * + * @param delta The delta of this {@link CreateChatCompletionStreamResponseChoicesInner} + */ + public void setDelta(@Nonnull final ChatCompletionStreamResponseDelta delta) { + this.delta = delta; + } + + /** + * Set the logprobs of this {@link CreateChatCompletionStreamResponseChoicesInner} instance and + * return the same instance. + * + * @param logprobs The logprobs of this {@link CreateChatCompletionStreamResponseChoicesInner} + * @return The same instance of this {@link CreateChatCompletionStreamResponseChoicesInner} class + */ + @Nonnull + public CreateChatCompletionStreamResponseChoicesInner logprobs( + @Nullable final CreateChatCompletionResponseChoicesInnerLogprobs logprobs) { + this.logprobs = logprobs; + return this; + } + + /** + * Get logprobs + * + * @return logprobs The logprobs of this {@link CreateChatCompletionStreamResponseChoicesInner} + * instance. + */ + @Nullable + public CreateChatCompletionResponseChoicesInnerLogprobs getLogprobs() { + return logprobs; + } + + /** + * Set the logprobs of this {@link CreateChatCompletionStreamResponseChoicesInner} instance. + * + * @param logprobs The logprobs of this {@link CreateChatCompletionStreamResponseChoicesInner} + */ + public void setLogprobs( + @Nullable final CreateChatCompletionResponseChoicesInnerLogprobs logprobs) { + this.logprobs = logprobs; + } + + /** + * Set the finishReason of this {@link CreateChatCompletionStreamResponseChoicesInner} instance + * and return the same instance. + * + * @param finishReason The reason the model stopped generating tokens. This will be + * `stop` if the model hit a natural stop point or a provided stop sequence, + * `length` if the maximum number of tokens specified in the request was reached, + * `content_filter` if content was omitted due to a flag from our content filters, + * `tool_calls` if the model called a tool, or `function_call` + * (deprecated) if the model called a function. + * @return The same instance of this {@link CreateChatCompletionStreamResponseChoicesInner} class + */ + @Nonnull + public CreateChatCompletionStreamResponseChoicesInner finishReason( + @Nullable final FinishReasonEnum finishReason) { + this.finishReason = finishReason; + return this; + } + + /** + * The reason the model stopped generating tokens. This will be `stop` if the model hit + * a natural stop point or a provided stop sequence, `length` if the maximum number of + * tokens specified in the request was reached, `content_filter` if content was omitted + * due to a flag from our content filters, `tool_calls` if the model called a tool, or + * `function_call` (deprecated) if the model called a function. + * + * @return finishReason The finishReason of this {@link + * CreateChatCompletionStreamResponseChoicesInner} instance. + */ + @Nullable + public FinishReasonEnum getFinishReason() { + return finishReason; + } + + /** + * Set the finishReason of this {@link CreateChatCompletionStreamResponseChoicesInner} instance. + * + * @param finishReason The reason the model stopped generating tokens. This will be + * `stop` if the model hit a natural stop point or a provided stop sequence, + * `length` if the maximum number of tokens specified in the request was reached, + * `content_filter` if content was omitted due to a flag from our content filters, + * `tool_calls` if the model called a tool, or `function_call` + * (deprecated) if the model called a function. + */ + public void setFinishReason(@Nullable final FinishReasonEnum finishReason) { + this.finishReason = finishReason; + } + + /** + * Set the index of this {@link CreateChatCompletionStreamResponseChoicesInner} instance and + * return the same instance. + * + * @param index The index of the choice in the list of choices. + * @return The same instance of this {@link CreateChatCompletionStreamResponseChoicesInner} class + */ + @Nonnull + public CreateChatCompletionStreamResponseChoicesInner index(@Nonnull final Integer index) { + this.index = index; + return this; + } + + /** + * The index of the choice in the list of choices. + * + * @return index The index of this {@link CreateChatCompletionStreamResponseChoicesInner} + * instance. + */ + @Nonnull + public Integer getIndex() { + return index; + } + + /** + * Set the index of this {@link CreateChatCompletionStreamResponseChoicesInner} instance. + * + * @param index The index of the choice in the list of choices. + */ + public void setIndex(@Nonnull final Integer index) { + this.index = index; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * CreateChatCompletionStreamResponseChoicesInner}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * CreateChatCompletionStreamResponseChoicesInner} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "CreateChatCompletionStreamResponseChoicesInner has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link CreateChatCompletionStreamResponseChoicesInner} + * instance. If the map previously contained a mapping for the key, the old value is replaced by + * the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final CreateChatCompletionStreamResponseChoicesInner + createChatCompletionStreamResponseChoicesInner = + (CreateChatCompletionStreamResponseChoicesInner) o; + return Objects.equals( + this.cloudSdkCustomFields, + createChatCompletionStreamResponseChoicesInner.cloudSdkCustomFields) + && Objects.equals(this.delta, createChatCompletionStreamResponseChoicesInner.delta) + && Objects.equals(this.logprobs, createChatCompletionStreamResponseChoicesInner.logprobs) + && Objects.equals( + this.finishReason, createChatCompletionStreamResponseChoicesInner.finishReason) + && Objects.equals(this.index, createChatCompletionStreamResponseChoicesInner.index); + } + + @Override + public int hashCode() { + return Objects.hash(delta, logprobs, finishReason, index, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class CreateChatCompletionStreamResponseChoicesInner {\n"); + sb.append(" delta: ").append(toIndentedString(delta)).append("\n"); + sb.append(" logprobs: ").append(toIndentedString(logprobs)).append("\n"); + sb.append(" finishReason: ").append(toIndentedString(finishReason)).append("\n"); + sb.append(" index: ").append(toIndentedString(index)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/EmbeddingsCreate200Response.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/EmbeddingsCreate200Response.java new file mode 100644 index 000000000..3109829e4 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/EmbeddingsCreate200Response.java @@ -0,0 +1,285 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** EmbeddingsCreate200Response */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class EmbeddingsCreate200Response +// CHECKSTYLE:ON +{ + @JsonProperty("object") + private String _object; + + @JsonProperty("model") + private String model; + + @JsonProperty("data") + private List data = new ArrayList<>(); + + @JsonProperty("usage") + private EmbeddingsCreate200ResponseUsage usage; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the _object of this {@link EmbeddingsCreate200Response} instance and return the same + * instance. + * + * @param _object The _object of this {@link EmbeddingsCreate200Response} + * @return The same instance of this {@link EmbeddingsCreate200Response} class + */ + @Nonnull + public EmbeddingsCreate200Response _object(@Nonnull final String _object) { + this._object = _object; + return this; + } + + /** + * Get _object + * + * @return _object The _object of this {@link EmbeddingsCreate200Response} instance. + */ + @Nonnull + public String getObject() { + return _object; + } + + /** + * Set the _object of this {@link EmbeddingsCreate200Response} instance. + * + * @param _object The _object of this {@link EmbeddingsCreate200Response} + */ + public void setObject(@Nonnull final String _object) { + this._object = _object; + } + + /** + * Set the model of this {@link EmbeddingsCreate200Response} instance and return the same + * instance. + * + * @param model The model of this {@link EmbeddingsCreate200Response} + * @return The same instance of this {@link EmbeddingsCreate200Response} class + */ + @Nonnull + public EmbeddingsCreate200Response model(@Nonnull final String model) { + this.model = model; + return this; + } + + /** + * Get model + * + * @return model The model of this {@link EmbeddingsCreate200Response} instance. + */ + @Nonnull + public String getModel() { + return model; + } + + /** + * Set the model of this {@link EmbeddingsCreate200Response} instance. + * + * @param model The model of this {@link EmbeddingsCreate200Response} + */ + public void setModel(@Nonnull final String model) { + this.model = model; + } + + /** + * Set the data of this {@link EmbeddingsCreate200Response} instance and return the same instance. + * + * @param data The data of this {@link EmbeddingsCreate200Response} + * @return The same instance of this {@link EmbeddingsCreate200Response} class + */ + @Nonnull + public EmbeddingsCreate200Response data( + @Nonnull final List data) { + this.data = data; + return this; + } + + /** + * Add one data instance to this {@link EmbeddingsCreate200Response}. + * + * @param dataItem The data that should be added + * @return The same instance of type {@link EmbeddingsCreate200Response} + */ + @Nonnull + public EmbeddingsCreate200Response addDataItem( + @Nonnull final EmbeddingsCreate200ResponseDataInner dataItem) { + if (this.data == null) { + this.data = new ArrayList<>(); + } + this.data.add(dataItem); + return this; + } + + /** + * Get data + * + * @return data The data of this {@link EmbeddingsCreate200Response} instance. + */ + @Nonnull + public List getData() { + return data; + } + + /** + * Set the data of this {@link EmbeddingsCreate200Response} instance. + * + * @param data The data of this {@link EmbeddingsCreate200Response} + */ + public void setData(@Nonnull final List data) { + this.data = data; + } + + /** + * Set the usage of this {@link EmbeddingsCreate200Response} instance and return the same + * instance. + * + * @param usage The usage of this {@link EmbeddingsCreate200Response} + * @return The same instance of this {@link EmbeddingsCreate200Response} class + */ + @Nonnull + public EmbeddingsCreate200Response usage(@Nonnull final EmbeddingsCreate200ResponseUsage usage) { + this.usage = usage; + return this; + } + + /** + * Get usage + * + * @return usage The usage of this {@link EmbeddingsCreate200Response} instance. + */ + @Nonnull + public EmbeddingsCreate200ResponseUsage getUsage() { + return usage; + } + + /** + * Set the usage of this {@link EmbeddingsCreate200Response} instance. + * + * @param usage The usage of this {@link EmbeddingsCreate200Response} + */ + public void setUsage(@Nonnull final EmbeddingsCreate200ResponseUsage usage) { + this.usage = usage; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingsCreate200Response}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingsCreate200Response} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "EmbeddingsCreate200Response has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link EmbeddingsCreate200Response} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final EmbeddingsCreate200Response embeddingsCreate200Response = (EmbeddingsCreate200Response) o; + return Objects.equals( + this.cloudSdkCustomFields, embeddingsCreate200Response.cloudSdkCustomFields) + && Objects.equals(this._object, embeddingsCreate200Response._object) + && Objects.equals(this.model, embeddingsCreate200Response.model) + && Objects.equals(this.data, embeddingsCreate200Response.data) + && Objects.equals(this.usage, embeddingsCreate200Response.usage); + } + + @Override + public int hashCode() { + return Objects.hash(_object, model, data, usage, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingsCreate200Response {\n"); + sb.append(" _object: ").append(toIndentedString(_object)).append("\n"); + sb.append(" model: ").append(toIndentedString(model)).append("\n"); + sb.append(" data: ").append(toIndentedString(data)).append("\n"); + sb.append(" usage: ").append(toIndentedString(usage)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/EmbeddingsCreate200ResponseDataInner.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/EmbeddingsCreate200ResponseDataInner.java new file mode 100644 index 000000000..20157a254 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/EmbeddingsCreate200ResponseDataInner.java @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** EmbeddingsCreate200ResponseDataInner */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class EmbeddingsCreate200ResponseDataInner +// CHECKSTYLE:ON +{ + @JsonProperty("index") + private Integer index; + + @JsonProperty("object") + private String _object; + + @JsonProperty("embedding") + private List embedding = new ArrayList<>(); // + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the index of this {@link EmbeddingsCreate200ResponseDataInner} instance and return the same + * instance. + * + * @param index The index of this {@link EmbeddingsCreate200ResponseDataInner} + * @return The same instance of this {@link EmbeddingsCreate200ResponseDataInner} class + */ + @Nonnull + public EmbeddingsCreate200ResponseDataInner index(@Nonnull final Integer index) { + this.index = index; + return this; + } + + /** + * Get index + * + * @return index The index of this {@link EmbeddingsCreate200ResponseDataInner} instance. + */ + @Nonnull + public Integer getIndex() { + return index; + } + + /** + * Set the index of this {@link EmbeddingsCreate200ResponseDataInner} instance. + * + * @param index The index of this {@link EmbeddingsCreate200ResponseDataInner} + */ + public void setIndex(@Nonnull final Integer index) { + this.index = index; + } + + /** + * Set the _object of this {@link EmbeddingsCreate200ResponseDataInner} instance and return the + * same instance. + * + * @param _object The _object of this {@link EmbeddingsCreate200ResponseDataInner} + * @return The same instance of this {@link EmbeddingsCreate200ResponseDataInner} class + */ + @Nonnull + public EmbeddingsCreate200ResponseDataInner _object(@Nonnull final String _object) { + this._object = _object; + return this; + } + + /** + * Get _object + * + * @return _object The _object of this {@link EmbeddingsCreate200ResponseDataInner} instance. + */ + @Nonnull + public String getObject() { + return _object; + } + + /** + * Set the _object of this {@link EmbeddingsCreate200ResponseDataInner} instance. + * + * @param _object The _object of this {@link EmbeddingsCreate200ResponseDataInner} + */ + public void setObject(@Nonnull final String _object) { + this._object = _object; + } + + /** + * Set the embedding of this {@link EmbeddingsCreate200ResponseDataInner} instance and return the + * same instance. + * + * @param embedding The embedding of this {@link EmbeddingsCreate200ResponseDataInner} + * @return The same instance of this {@link EmbeddingsCreate200ResponseDataInner} class + */ + @Nonnull + public EmbeddingsCreate200ResponseDataInner embedding(@Nonnull final List embedding) { + this.embedding = embedding; + return this; + } + + /** + * Add one embedding instance to this {@link EmbeddingsCreate200ResponseDataInner}. + * + * @param embeddingItem The embedding that should be added + * @return The same instance of type {@link EmbeddingsCreate200ResponseDataInner} + */ + @Nonnull + public EmbeddingsCreate200ResponseDataInner addEmbeddingItem( + @Nonnull final BigDecimal embeddingItem) { + if (this.embedding == null) { + this.embedding = new ArrayList<>(); + } + this.embedding.add(embeddingItem); + return this; + } + + /** + * Get embedding + * + * @return embedding The embedding of this {@link EmbeddingsCreate200ResponseDataInner} instance. + */ + @Nonnull + public List getEmbedding() { + return embedding; + } + + /** + * Set the embedding of this {@link EmbeddingsCreate200ResponseDataInner} instance. + * + * @param embedding The embedding of this {@link EmbeddingsCreate200ResponseDataInner} + */ + public void setEmbedding(@Nonnull final List embedding) { + this.embedding = embedding; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * EmbeddingsCreate200ResponseDataInner}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * EmbeddingsCreate200ResponseDataInner} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "EmbeddingsCreate200ResponseDataInner has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link EmbeddingsCreate200ResponseDataInner} instance. + * If the map previously contained a mapping for the key, the old value is replaced by the + * specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final EmbeddingsCreate200ResponseDataInner embeddingsCreate200ResponseDataInner = + (EmbeddingsCreate200ResponseDataInner) o; + return Objects.equals( + this.cloudSdkCustomFields, embeddingsCreate200ResponseDataInner.cloudSdkCustomFields) + && Objects.equals(this.index, embeddingsCreate200ResponseDataInner.index) + && Objects.equals(this._object, embeddingsCreate200ResponseDataInner._object) + && Objects.equals(this.embedding, embeddingsCreate200ResponseDataInner.embedding); + } + + @Override + public int hashCode() { + return Objects.hash(index, _object, embedding, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingsCreate200ResponseDataInner {\n"); + sb.append(" index: ").append(toIndentedString(index)).append("\n"); + sb.append(" _object: ").append(toIndentedString(_object)).append("\n"); + sb.append(" embedding: ").append(toIndentedString(embedding)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/EmbeddingsCreate200ResponseUsage.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/EmbeddingsCreate200ResponseUsage.java new file mode 100644 index 000000000..6ee775e3d --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/EmbeddingsCreate200ResponseUsage.java @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** EmbeddingsCreate200ResponseUsage */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class EmbeddingsCreate200ResponseUsage +// CHECKSTYLE:ON +{ + @JsonProperty("prompt_tokens") + private Integer promptTokens; + + @JsonProperty("total_tokens") + private Integer totalTokens; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the promptTokens of this {@link EmbeddingsCreate200ResponseUsage} instance and return the + * same instance. + * + * @param promptTokens The promptTokens of this {@link EmbeddingsCreate200ResponseUsage} + * @return The same instance of this {@link EmbeddingsCreate200ResponseUsage} class + */ + @Nonnull + public EmbeddingsCreate200ResponseUsage promptTokens(@Nonnull final Integer promptTokens) { + this.promptTokens = promptTokens; + return this; + } + + /** + * Get promptTokens + * + * @return promptTokens The promptTokens of this {@link EmbeddingsCreate200ResponseUsage} + * instance. + */ + @Nonnull + public Integer getPromptTokens() { + return promptTokens; + } + + /** + * Set the promptTokens of this {@link EmbeddingsCreate200ResponseUsage} instance. + * + * @param promptTokens The promptTokens of this {@link EmbeddingsCreate200ResponseUsage} + */ + public void setPromptTokens(@Nonnull final Integer promptTokens) { + this.promptTokens = promptTokens; + } + + /** + * Set the totalTokens of this {@link EmbeddingsCreate200ResponseUsage} instance and return the + * same instance. + * + * @param totalTokens The totalTokens of this {@link EmbeddingsCreate200ResponseUsage} + * @return The same instance of this {@link EmbeddingsCreate200ResponseUsage} class + */ + @Nonnull + public EmbeddingsCreate200ResponseUsage totalTokens(@Nonnull final Integer totalTokens) { + this.totalTokens = totalTokens; + return this; + } + + /** + * Get totalTokens + * + * @return totalTokens The totalTokens of this {@link EmbeddingsCreate200ResponseUsage} instance. + */ + @Nonnull + public Integer getTotalTokens() { + return totalTokens; + } + + /** + * Set the totalTokens of this {@link EmbeddingsCreate200ResponseUsage} instance. + * + * @param totalTokens The totalTokens of this {@link EmbeddingsCreate200ResponseUsage} + */ + public void setTotalTokens(@Nonnull final Integer totalTokens) { + this.totalTokens = totalTokens; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingsCreate200ResponseUsage}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingsCreate200ResponseUsage} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "EmbeddingsCreate200ResponseUsage has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link EmbeddingsCreate200ResponseUsage} instance. If + * the map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final EmbeddingsCreate200ResponseUsage embeddingsCreate200ResponseUsage = + (EmbeddingsCreate200ResponseUsage) o; + return Objects.equals( + this.cloudSdkCustomFields, embeddingsCreate200ResponseUsage.cloudSdkCustomFields) + && Objects.equals(this.promptTokens, embeddingsCreate200ResponseUsage.promptTokens) + && Objects.equals(this.totalTokens, embeddingsCreate200ResponseUsage.totalTokens); + } + + @Override + public int hashCode() { + return Objects.hash(promptTokens, totalTokens, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingsCreate200ResponseUsage {\n"); + sb.append(" promptTokens: ").append(toIndentedString(promptTokens)).append("\n"); + sb.append(" totalTokens: ").append(toIndentedString(totalTokens)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/EmbeddingsCreateRequest.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/EmbeddingsCreateRequest.java new file mode 100644 index 000000000..936a7aba7 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/EmbeddingsCreateRequest.java @@ -0,0 +1,311 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** EmbeddingsCreateRequest */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class EmbeddingsCreateRequest +// CHECKSTYLE:ON +{ + @JsonProperty("input") + private EmbeddingsCreateRequestInput input; + + @JsonProperty("user") + private String user; + + @JsonProperty("input_type") + private String inputType; + + @JsonProperty("encoding_format") + private String encodingFormat; + + @JsonProperty("dimensions") + private Integer dimensions; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the input of this {@link EmbeddingsCreateRequest} instance and return the same instance. + * + * @param input The input of this {@link EmbeddingsCreateRequest} + * @return The same instance of this {@link EmbeddingsCreateRequest} class + */ + @Nonnull + public EmbeddingsCreateRequest input(@Nonnull final EmbeddingsCreateRequestInput input) { + this.input = input; + return this; + } + + /** + * Get input + * + * @return input The input of this {@link EmbeddingsCreateRequest} instance. + */ + @Nonnull + public EmbeddingsCreateRequestInput getInput() { + return input; + } + + /** + * Set the input of this {@link EmbeddingsCreateRequest} instance. + * + * @param input The input of this {@link EmbeddingsCreateRequest} + */ + public void setInput(@Nonnull final EmbeddingsCreateRequestInput input) { + this.input = input; + } + + /** + * Set the user of this {@link EmbeddingsCreateRequest} instance and return the same instance. + * + * @param user A unique identifier representing your end-user, which can help monitoring and + * detecting abuse. + * @return The same instance of this {@link EmbeddingsCreateRequest} class + */ + @Nonnull + public EmbeddingsCreateRequest user(@Nullable final String user) { + this.user = user; + return this; + } + + /** + * A unique identifier representing your end-user, which can help monitoring and detecting abuse. + * + * @return user The user of this {@link EmbeddingsCreateRequest} instance. + */ + @Nonnull + public String getUser() { + return user; + } + + /** + * Set the user of this {@link EmbeddingsCreateRequest} instance. + * + * @param user A unique identifier representing your end-user, which can help monitoring and + * detecting abuse. + */ + public void setUser(@Nullable final String user) { + this.user = user; + } + + /** + * Set the inputType of this {@link EmbeddingsCreateRequest} instance and return the same + * instance. + * + * @param inputType input type of embedding search to use + * @return The same instance of this {@link EmbeddingsCreateRequest} class + */ + @Nonnull + public EmbeddingsCreateRequest inputType(@Nullable final String inputType) { + this.inputType = inputType; + return this; + } + + /** + * input type of embedding search to use + * + * @return inputType The inputType of this {@link EmbeddingsCreateRequest} instance. + */ + @Nonnull + public String getInputType() { + return inputType; + } + + /** + * Set the inputType of this {@link EmbeddingsCreateRequest} instance. + * + * @param inputType input type of embedding search to use + */ + public void setInputType(@Nullable final String inputType) { + this.inputType = inputType; + } + + /** + * Set the encodingFormat of this {@link EmbeddingsCreateRequest} instance and return the same + * instance. + * + * @param encodingFormat The format to return the embeddings in. Can be either `float` + * or `base64`. Defaults to `float`. + * @return The same instance of this {@link EmbeddingsCreateRequest} class + */ + @Nonnull + public EmbeddingsCreateRequest encodingFormat(@Nullable final String encodingFormat) { + this.encodingFormat = encodingFormat; + return this; + } + + /** + * The format to return the embeddings in. Can be either `float` or `base64`. + * Defaults to `float`. + * + * @return encodingFormat The encodingFormat of this {@link EmbeddingsCreateRequest} instance. + */ + @Nullable + public String getEncodingFormat() { + return encodingFormat; + } + + /** + * Set the encodingFormat of this {@link EmbeddingsCreateRequest} instance. + * + * @param encodingFormat The format to return the embeddings in. Can be either `float` + * or `base64`. Defaults to `float`. + */ + public void setEncodingFormat(@Nullable final String encodingFormat) { + this.encodingFormat = encodingFormat; + } + + /** + * Set the dimensions of this {@link EmbeddingsCreateRequest} instance and return the same + * instance. + * + * @param dimensions The number of dimensions the resulting output embeddings should have. Only + * supported in `text-embedding-3` and later models. + * @return The same instance of this {@link EmbeddingsCreateRequest} class + */ + @Nonnull + public EmbeddingsCreateRequest dimensions(@Nullable final Integer dimensions) { + this.dimensions = dimensions; + return this; + } + + /** + * The number of dimensions the resulting output embeddings should have. Only supported in + * `text-embedding-3` and later models. + * + * @return dimensions The dimensions of this {@link EmbeddingsCreateRequest} instance. + */ + @Nullable + public Integer getDimensions() { + return dimensions; + } + + /** + * Set the dimensions of this {@link EmbeddingsCreateRequest} instance. + * + * @param dimensions The number of dimensions the resulting output embeddings should have. Only + * supported in `text-embedding-3` and later models. + */ + public void setDimensions(@Nullable final Integer dimensions) { + this.dimensions = dimensions; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingsCreateRequest}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingsCreateRequest} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "EmbeddingsCreateRequest has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link EmbeddingsCreateRequest} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final EmbeddingsCreateRequest embeddingsCreateRequest = (EmbeddingsCreateRequest) o; + return Objects.equals(this.cloudSdkCustomFields, embeddingsCreateRequest.cloudSdkCustomFields) + && Objects.equals(this.input, embeddingsCreateRequest.input) + && Objects.equals(this.user, embeddingsCreateRequest.user) + && Objects.equals(this.inputType, embeddingsCreateRequest.inputType) + && Objects.equals(this.encodingFormat, embeddingsCreateRequest.encodingFormat) + && Objects.equals(this.dimensions, embeddingsCreateRequest.dimensions) + && super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash( + input, user, inputType, encodingFormat, dimensions, cloudSdkCustomFields, super.hashCode()); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingsCreateRequest {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" input: ").append(toIndentedString(input)).append("\n"); + sb.append(" user: ").append(toIndentedString(user)).append("\n"); + sb.append(" inputType: ").append(toIndentedString(inputType)).append("\n"); + sb.append(" encodingFormat: ").append(toIndentedString(encodingFormat)).append("\n"); + sb.append(" dimensions: ").append(toIndentedString(dimensions)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/EmbeddingsCreateRequestInput.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/EmbeddingsCreateRequestInput.java new file mode 100644 index 000000000..a2043736d --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/EmbeddingsCreateRequestInput.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import java.util.List; + +/** + * Input text to get embeddings for, encoded as a string. To get embeddings for multiple inputs in a + * single request, pass an array of strings. Each input must not exceed 2048 tokens in length. + * Unless you are embedding code, we suggest replacing newlines (\\n) in your input with a single + * space, as we have observed inferior results when newlines are present. + */ +@com.google.common.annotations.Beta +public interface EmbeddingsCreateRequestInput { + /** Helper class to create a String that implements {@link EmbeddingsCreateRequestInput}. */ + class InnerString implements EmbeddingsCreateRequestInput { + @com.fasterxml.jackson.annotation.JsonValue String value; + + InnerString(String value) { + this.value = value; + } + } + + /** + * Creator to enable deserialization of a String. + * + * @param val the value to use + * @return a new instance of {@link InnerString}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + static InnerString create(String val) { + return new InnerString(val); + } + + /** + * Helper class to create a list of String that implements {@link EmbeddingsCreateRequestInput}. + */ + record InnerStrings(@com.fasterxml.jackson.annotation.JsonValue List values) + implements EmbeddingsCreateRequestInput {} + + /** + * Creator to enable deserialization of a list of String. + * + * @param val the value to use + * @return a new instance of {@link InnerStrings}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + static InnerStrings create(List val) { + return new InnerStrings(val); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/Error.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/Error.java new file mode 100644 index 000000000..4d6bb21bf --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/Error.java @@ -0,0 +1,296 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** Error */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class Error +// CHECKSTYLE:ON +{ + @JsonProperty("param") + private String param; + + @JsonProperty("type") + private String type; + + @JsonProperty("inner_error") + private InnerError innerError; + + @JsonProperty("code") + private String code; + + @JsonProperty("message") + private String message; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the param of this {@link Error} instance and return the same instance. + * + * @param param The param of this {@link Error} + * @return The same instance of this {@link Error} class + */ + @Nonnull + public Error param(@Nullable final String param) { + this.param = param; + return this; + } + + /** + * Get param + * + * @return param The param of this {@link Error} instance. + */ + @Nonnull + public String getParam() { + return param; + } + + /** + * Set the param of this {@link Error} instance. + * + * @param param The param of this {@link Error} + */ + public void setParam(@Nullable final String param) { + this.param = param; + } + + /** + * Set the type of this {@link Error} instance and return the same instance. + * + * @param type The type of this {@link Error} + * @return The same instance of this {@link Error} class + */ + @Nonnull + public Error type(@Nullable final String type) { + this.type = type; + return this; + } + + /** + * Get type + * + * @return type The type of this {@link Error} instance. + */ + @Nonnull + public String getType() { + return type; + } + + /** + * Set the type of this {@link Error} instance. + * + * @param type The type of this {@link Error} + */ + public void setType(@Nullable final String type) { + this.type = type; + } + + /** + * Set the innerError of this {@link Error} instance and return the same instance. + * + * @param innerError The innerError of this {@link Error} + * @return The same instance of this {@link Error} class + */ + @Nonnull + public Error innerError(@Nullable final InnerError innerError) { + this.innerError = innerError; + return this; + } + + /** + * Get innerError + * + * @return innerError The innerError of this {@link Error} instance. + */ + @Nonnull + public InnerError getInnerError() { + return innerError; + } + + /** + * Set the innerError of this {@link Error} instance. + * + * @param innerError The innerError of this {@link Error} + */ + public void setInnerError(@Nullable final InnerError innerError) { + this.innerError = innerError; + } + + /** + * Set the code of this {@link Error} instance and return the same instance. + * + * @param code The code of this {@link Error} + * @return The same instance of this {@link Error} class + */ + @Nonnull + public Error code(@Nullable final String code) { + this.code = code; + return this; + } + + /** + * Get code + * + * @return code The code of this {@link Error} instance. + */ + @Nonnull + public String getCode() { + return code; + } + + /** + * Set the code of this {@link Error} instance. + * + * @param code The code of this {@link Error} + */ + public void setCode(@Nullable final String code) { + this.code = code; + } + + /** + * Set the message of this {@link Error} instance and return the same instance. + * + * @param message The message of this {@link Error} + * @return The same instance of this {@link Error} class + */ + @Nonnull + public Error message(@Nullable final String message) { + this.message = message; + return this; + } + + /** + * Get message + * + * @return message The message of this {@link Error} instance. + */ + @Nonnull + public String getMessage() { + return message; + } + + /** + * Set the message of this {@link Error} instance. + * + * @param message The message of this {@link Error} + */ + public void setMessage(@Nullable final String message) { + this.message = message; + } + + /** + * Get the names of the unrecognizable properties of the {@link Error}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link Error} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException("Error has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link Error} instance. If the map previously contained + * a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final Error error = (Error) o; + return Objects.equals(this.cloudSdkCustomFields, error.cloudSdkCustomFields) + && Objects.equals(this.param, error.param) + && Objects.equals(this.type, error.type) + && Objects.equals(this.innerError, error.innerError) + && Objects.equals(this.code, error.code) + && Objects.equals(this.message, error.message); + } + + @Override + public int hashCode() { + return Objects.hash(param, type, innerError, code, message, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class Error {\n"); + sb.append(" param: ").append(toIndentedString(param)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" innerError: ").append(toIndentedString(innerError)).append("\n"); + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" message: ").append(toIndentedString(message)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ErrorBase.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ErrorBase.java new file mode 100644 index 000000000..6cb109f0e --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ErrorBase.java @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ErrorBase */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ErrorBase +// CHECKSTYLE:ON +{ + @JsonProperty("code") + private String code; + + @JsonProperty("message") + private String message; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the code of this {@link ErrorBase} instance and return the same instance. + * + * @param code The code of this {@link ErrorBase} + * @return The same instance of this {@link ErrorBase} class + */ + @Nonnull + public ErrorBase code(@Nullable final String code) { + this.code = code; + return this; + } + + /** + * Get code + * + * @return code The code of this {@link ErrorBase} instance. + */ + @Nonnull + public String getCode() { + return code; + } + + /** + * Set the code of this {@link ErrorBase} instance. + * + * @param code The code of this {@link ErrorBase} + */ + public void setCode(@Nullable final String code) { + this.code = code; + } + + /** + * Set the message of this {@link ErrorBase} instance and return the same instance. + * + * @param message The message of this {@link ErrorBase} + * @return The same instance of this {@link ErrorBase} class + */ + @Nonnull + public ErrorBase message(@Nullable final String message) { + this.message = message; + return this; + } + + /** + * Get message + * + * @return message The message of this {@link ErrorBase} instance. + */ + @Nonnull + public String getMessage() { + return message; + } + + /** + * Set the message of this {@link ErrorBase} instance. + * + * @param message The message of this {@link ErrorBase} + */ + public void setMessage(@Nullable final String message) { + this.message = message; + } + + /** + * Get the names of the unrecognizable properties of the {@link ErrorBase}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ErrorBase} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException("ErrorBase has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ErrorBase} instance. If the map previously + * contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ErrorBase errorBase = (ErrorBase) o; + return Objects.equals(this.cloudSdkCustomFields, errorBase.cloudSdkCustomFields) + && Objects.equals(this.code, errorBase.code) + && Objects.equals(this.message, errorBase.message); + } + + @Override + public int hashCode() { + return Objects.hash(code, message, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ErrorBase {\n"); + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" message: ").append(toIndentedString(message)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ErrorResponse.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ErrorResponse.java new file mode 100644 index 000000000..896bacf0e --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ErrorResponse.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ErrorResponse */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ErrorResponse +// CHECKSTYLE:ON +{ + @JsonProperty("error") + private Error error; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the error of this {@link ErrorResponse} instance and return the same instance. + * + * @param error The error of this {@link ErrorResponse} + * @return The same instance of this {@link ErrorResponse} class + */ + @Nonnull + public ErrorResponse error(@Nullable final Error error) { + this.error = error; + return this; + } + + /** + * Get error + * + * @return error The error of this {@link ErrorResponse} instance. + */ + @Nonnull + public Error getError() { + return error; + } + + /** + * Set the error of this {@link ErrorResponse} instance. + * + * @param error The error of this {@link ErrorResponse} + */ + public void setError(@Nullable final Error error) { + this.error = error; + } + + /** + * Get the names of the unrecognizable properties of the {@link ErrorResponse}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ErrorResponse} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException("ErrorResponse has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ErrorResponse} instance. If the map previously + * contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ErrorResponse errorResponse = (ErrorResponse) o; + return Objects.equals(this.cloudSdkCustomFields, errorResponse.cloudSdkCustomFields) + && Objects.equals(this.error, errorResponse.error); + } + + @Override + public int hashCode() { + return Objects.hash(error, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ErrorResponse {\n"); + sb.append(" error: ").append(toIndentedString(error)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/FunctionObject.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/FunctionObject.java new file mode 100644 index 000000000..5b04827f3 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/FunctionObject.java @@ -0,0 +1,309 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** FunctionObject */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class FunctionObject +// CHECKSTYLE:ON +{ + @JsonProperty("description") + private String description; + + @JsonProperty("name") + private String name; + + @JsonProperty("parameters") + private Map parameters = new HashMap<>(); + + @JsonProperty("strict") + private Boolean strict = false; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the description of this {@link FunctionObject} instance and return the same instance. + * + * @param description A description of what the function does, used by the model to choose when + * and how to call the function. + * @return The same instance of this {@link FunctionObject} class + */ + @Nonnull + public FunctionObject description(@Nullable final String description) { + this.description = description; + return this; + } + + /** + * A description of what the function does, used by the model to choose when and how to call the + * function. + * + * @return description The description of this {@link FunctionObject} instance. + */ + @Nonnull + public String getDescription() { + return description; + } + + /** + * Set the description of this {@link FunctionObject} instance. + * + * @param description A description of what the function does, used by the model to choose when + * and how to call the function. + */ + public void setDescription(@Nullable final String description) { + this.description = description; + } + + /** + * Set the name of this {@link FunctionObject} instance and return the same instance. + * + * @param name The name of the function to be called. Must be a-z, A-Z, 0-9, or contain + * underscores and dashes, with a maximum length of 64. + * @return The same instance of this {@link FunctionObject} class + */ + @Nonnull + public FunctionObject name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and + * dashes, with a maximum length of 64. + * + * @return name The name of this {@link FunctionObject} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link FunctionObject} instance. + * + * @param name The name of the function to be called. Must be a-z, A-Z, 0-9, or contain + * underscores and dashes, with a maximum length of 64. + */ + public void setName(@Nonnull final String name) { + this.name = name; + } + + /** + * Set the parameters of this {@link FunctionObject} instance and return the same instance. + * + * @param parameters The parameters the functions accepts, described as a JSON Schema object. See + * the + * guide](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/function-calling) + * for examples, and the [JSON Schema + * reference](https://json-schema.org/understanding-json-schema/) for documentation about the + * format. Omitting `parameters` defines a function with an empty parameter list. + * @return The same instance of this {@link FunctionObject} class + */ + @Nonnull + public FunctionObject parameters(@Nullable final Map parameters) { + this.parameters = parameters; + return this; + } + + /** + * Put one parameters instance to this {@link FunctionObject} instance. + * + * @param key The String key of this parameters instance + * @param parametersItem The parameters that should be added under the given key + * @return The same instance of type {@link FunctionObject} + */ + @Nonnull + public FunctionObject putparametersItem( + @Nonnull final String key, @Nullable final Object parametersItem) { + if (this.parameters == null) { + this.parameters = new HashMap<>(); + } + this.parameters.put(key, parametersItem); + return this; + } + + /** + * The parameters the functions accepts, described as a JSON Schema object. See the + * guide](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/function-calling) for + * examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) + * for documentation about the format. Omitting `parameters` defines a function with an + * empty parameter list. + * + * @return parameters The parameters of this {@link FunctionObject} instance. + */ + @Nonnull + public Map getParameters() { + return parameters; + } + + /** + * Set the parameters of this {@link FunctionObject} instance. + * + * @param parameters The parameters the functions accepts, described as a JSON Schema object. See + * the + * guide](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/function-calling) + * for examples, and the [JSON Schema + * reference](https://json-schema.org/understanding-json-schema/) for documentation about the + * format. Omitting `parameters` defines a function with an empty parameter list. + */ + public void setParameters(@Nullable final Map parameters) { + this.parameters = parameters; + } + + /** + * Set the strict of this {@link FunctionObject} instance and return the same instance. + * + * @param strict Whether to enable strict schema adherence when generating the function call. If + * set to true, the model will follow the exact schema defined in the `parameters` + * field. Only a subset of JSON Schema is supported when `strict` is + * `true`. Learn more about Structured Outputs in the [function calling + * guide](docs/guides/function-calling). + * @return The same instance of this {@link FunctionObject} class + */ + @Nonnull + public FunctionObject strict(@Nullable final Boolean strict) { + this.strict = strict; + return this; + } + + /** + * Whether to enable strict schema adherence when generating the function call. If set to true, + * the model will follow the exact schema defined in the `parameters` field. Only a + * subset of JSON Schema is supported when `strict` is `true`. Learn more + * about Structured Outputs in the [function calling guide](docs/guides/function-calling). + * + * @return strict The strict of this {@link FunctionObject} instance. + */ + @Nullable + public Boolean isStrict() { + return strict; + } + + /** + * Set the strict of this {@link FunctionObject} instance. + * + * @param strict Whether to enable strict schema adherence when generating the function call. If + * set to true, the model will follow the exact schema defined in the `parameters` + * field. Only a subset of JSON Schema is supported when `strict` is + * `true`. Learn more about Structured Outputs in the [function calling + * guide](docs/guides/function-calling). + */ + public void setStrict(@Nullable final Boolean strict) { + this.strict = strict; + } + + /** + * Get the names of the unrecognizable properties of the {@link FunctionObject}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link FunctionObject} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException("FunctionObject has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link FunctionObject} instance. If the map previously + * contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final FunctionObject functionObject = (FunctionObject) o; + return Objects.equals(this.cloudSdkCustomFields, functionObject.cloudSdkCustomFields) + && Objects.equals(this.description, functionObject.description) + && Objects.equals(this.name, functionObject.name) + && Objects.equals(this.parameters, functionObject.parameters) + && Objects.equals(this.strict, functionObject.strict); + } + + @Override + public int hashCode() { + return Objects.hash(description, name, parameters, strict, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class FunctionObject {\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" parameters: ").append(toIndentedString(parameters)).append("\n"); + sb.append(" strict: ").append(toIndentedString(strict)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/InnerError.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/InnerError.java new file mode 100644 index 000000000..649d05acc --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/InnerError.java @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** Inner error with additional details. */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class InnerError +// CHECKSTYLE:ON +{ + @JsonProperty("code") + private InnerErrorCode code; + + @JsonProperty("content_filter_results") + private ContentFilterPromptResults contentFilterResults; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the code of this {@link InnerError} instance and return the same instance. + * + * @param code The code of this {@link InnerError} + * @return The same instance of this {@link InnerError} class + */ + @Nonnull + public InnerError code(@Nullable final InnerErrorCode code) { + this.code = code; + return this; + } + + /** + * Get code + * + * @return code The code of this {@link InnerError} instance. + */ + @Nonnull + public InnerErrorCode getCode() { + return code; + } + + /** + * Set the code of this {@link InnerError} instance. + * + * @param code The code of this {@link InnerError} + */ + public void setCode(@Nullable final InnerErrorCode code) { + this.code = code; + } + + /** + * Set the contentFilterResults of this {@link InnerError} instance and return the same instance. + * + * @param contentFilterResults The contentFilterResults of this {@link InnerError} + * @return The same instance of this {@link InnerError} class + */ + @Nonnull + public InnerError contentFilterResults( + @Nullable final ContentFilterPromptResults contentFilterResults) { + this.contentFilterResults = contentFilterResults; + return this; + } + + /** + * Get contentFilterResults + * + * @return contentFilterResults The contentFilterResults of this {@link InnerError} instance. + */ + @Nonnull + public ContentFilterPromptResults getContentFilterResults() { + return contentFilterResults; + } + + /** + * Set the contentFilterResults of this {@link InnerError} instance. + * + * @param contentFilterResults The contentFilterResults of this {@link InnerError} + */ + public void setContentFilterResults( + @Nullable final ContentFilterPromptResults contentFilterResults) { + this.contentFilterResults = contentFilterResults; + } + + /** + * Get the names of the unrecognizable properties of the {@link InnerError}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link InnerError} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException("InnerError has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link InnerError} instance. If the map previously + * contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final InnerError innerError = (InnerError) o; + return Objects.equals(this.cloudSdkCustomFields, innerError.cloudSdkCustomFields) + && Objects.equals(this.code, innerError.code) + && Objects.equals(this.contentFilterResults, innerError.contentFilterResults); + } + + @Override + public int hashCode() { + return Objects.hash(code, contentFilterResults, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class InnerError {\n"); + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" contentFilterResults: ") + .append(toIndentedString(contentFilterResults)) + .append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/InnerErrorCode.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/InnerErrorCode.java new file mode 100644 index 000000000..ee8144809 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/InnerErrorCode.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import javax.annotation.Nonnull; + +/** Error codes for the inner error object. */ +@com.google.common.annotations.Beta +public enum InnerErrorCode { + RESPONSIBLE_AI_POLICY_VIOLATION("ResponsibleAIPolicyViolation"); + + private final String value; + + InnerErrorCode(String value) { + this.value = value; + } + + /** + * @return The enum value. + */ + @JsonValue + public String getValue() { + return value; + } + + /** + * @return The String representation of the enum value. + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Converts the given value to its enum representation. + * + * @param value The input value. + * @return The enum representation of the given value. + */ + @JsonCreator + public static InnerErrorCode fromValue(@Nonnull final String value) { + for (final InnerErrorCode b : InnerErrorCode.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/PromptFilterResult.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/PromptFilterResult.java new file mode 100644 index 000000000..df44f3c38 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/PromptFilterResult.java @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** Content filtering results for a single prompt in the request. */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class PromptFilterResult +// CHECKSTYLE:ON +{ + @JsonProperty("prompt_index") + private Integer promptIndex; + + @JsonProperty("content_filter_results") + private ContentFilterPromptResults contentFilterResults; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the promptIndex of this {@link PromptFilterResult} instance and return the same instance. + * + * @param promptIndex The promptIndex of this {@link PromptFilterResult} + * @return The same instance of this {@link PromptFilterResult} class + */ + @Nonnull + public PromptFilterResult promptIndex(@Nullable final Integer promptIndex) { + this.promptIndex = promptIndex; + return this; + } + + /** + * Get promptIndex + * + * @return promptIndex The promptIndex of this {@link PromptFilterResult} instance. + */ + @Nonnull + public Integer getPromptIndex() { + return promptIndex; + } + + /** + * Set the promptIndex of this {@link PromptFilterResult} instance. + * + * @param promptIndex The promptIndex of this {@link PromptFilterResult} + */ + public void setPromptIndex(@Nullable final Integer promptIndex) { + this.promptIndex = promptIndex; + } + + /** + * Set the contentFilterResults of this {@link PromptFilterResult} instance and return the same + * instance. + * + * @param contentFilterResults The contentFilterResults of this {@link PromptFilterResult} + * @return The same instance of this {@link PromptFilterResult} class + */ + @Nonnull + public PromptFilterResult contentFilterResults( + @Nullable final ContentFilterPromptResults contentFilterResults) { + this.contentFilterResults = contentFilterResults; + return this; + } + + /** + * Get contentFilterResults + * + * @return contentFilterResults The contentFilterResults of this {@link PromptFilterResult} + * instance. + */ + @Nonnull + public ContentFilterPromptResults getContentFilterResults() { + return contentFilterResults; + } + + /** + * Set the contentFilterResults of this {@link PromptFilterResult} instance. + * + * @param contentFilterResults The contentFilterResults of this {@link PromptFilterResult} + */ + public void setContentFilterResults( + @Nullable final ContentFilterPromptResults contentFilterResults) { + this.contentFilterResults = contentFilterResults; + } + + /** + * Get the names of the unrecognizable properties of the {@link PromptFilterResult}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link PromptFilterResult} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException("PromptFilterResult has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link PromptFilterResult} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final PromptFilterResult promptFilterResult = (PromptFilterResult) o; + return Objects.equals(this.cloudSdkCustomFields, promptFilterResult.cloudSdkCustomFields) + && Objects.equals(this.promptIndex, promptFilterResult.promptIndex) + && Objects.equals(this.contentFilterResults, promptFilterResult.contentFilterResults); + } + + @Override + public int hashCode() { + return Objects.hash(promptIndex, contentFilterResults, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class PromptFilterResult {\n"); + sb.append(" promptIndex: ").append(toIndentedString(promptIndex)).append("\n"); + sb.append(" contentFilterResults: ") + .append(toIndentedString(contentFilterResults)) + .append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ResponseFormatJsonObject.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ResponseFormatJsonObject.java new file mode 100644 index 000000000..a3064b81d --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ResponseFormatJsonObject.java @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ResponseFormatJsonObject */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ResponseFormatJsonObject implements CreateChatCompletionRequestAllOfResponseFormat +// CHECKSTYLE:ON +{ + /** The type of response format being defined: `json_object` */ + public enum TypeEnum { + /** The JSON_OBJECT option of this ResponseFormatJsonObject */ + JSON_OBJECT("json_object"); + + private String value; + + TypeEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ResponseFormatJsonObject + */ + @JsonCreator + @Nonnull + public static TypeEnum fromValue(@Nonnull final String value) { + for (TypeEnum b : TypeEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("type") + private TypeEnum type; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the type of this {@link ResponseFormatJsonObject} instance and return the same instance. + * + * @param type The type of response format being defined: `json_object` + * @return The same instance of this {@link ResponseFormatJsonObject} class + */ + @Nonnull + public ResponseFormatJsonObject type(@Nonnull final TypeEnum type) { + this.type = type; + return this; + } + + /** + * The type of response format being defined: `json_object` + * + * @return type The type of this {@link ResponseFormatJsonObject} instance. + */ + @Nonnull + public TypeEnum getType() { + return type; + } + + /** + * Set the type of this {@link ResponseFormatJsonObject} instance. + * + * @param type The type of response format being defined: `json_object` + */ + public void setType(@Nonnull final TypeEnum type) { + this.type = type; + } + + /** + * Get the names of the unrecognizable properties of the {@link ResponseFormatJsonObject}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ResponseFormatJsonObject} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ResponseFormatJsonObject has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ResponseFormatJsonObject} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ResponseFormatJsonObject responseFormatJsonObject = (ResponseFormatJsonObject) o; + return Objects.equals(this.cloudSdkCustomFields, responseFormatJsonObject.cloudSdkCustomFields) + && Objects.equals(this.type, responseFormatJsonObject.type); + } + + @Override + public int hashCode() { + return Objects.hash(type, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ResponseFormatJsonObject {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ResponseFormatJsonSchema.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ResponseFormatJsonSchema.java new file mode 100644 index 000000000..ab62ebc5b --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ResponseFormatJsonSchema.java @@ -0,0 +1,244 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ResponseFormatJsonSchema */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ResponseFormatJsonSchema implements CreateChatCompletionRequestAllOfResponseFormat +// CHECKSTYLE:ON +{ + /** The type of response format being defined: `json_schema` */ + public enum TypeEnum { + /** The JSON_SCHEMA option of this ResponseFormatJsonSchema */ + JSON_SCHEMA("json_schema"); + + private String value; + + TypeEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ResponseFormatJsonSchema + */ + @JsonCreator + @Nonnull + public static TypeEnum fromValue(@Nonnull final String value) { + for (TypeEnum b : TypeEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("type") + private TypeEnum type; + + @JsonProperty("json_schema") + private ResponseFormatJsonSchemaJsonSchema jsonSchema; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the type of this {@link ResponseFormatJsonSchema} instance and return the same instance. + * + * @param type The type of response format being defined: `json_schema` + * @return The same instance of this {@link ResponseFormatJsonSchema} class + */ + @Nonnull + public ResponseFormatJsonSchema type(@Nonnull final TypeEnum type) { + this.type = type; + return this; + } + + /** + * The type of response format being defined: `json_schema` + * + * @return type The type of this {@link ResponseFormatJsonSchema} instance. + */ + @Nonnull + public TypeEnum getType() { + return type; + } + + /** + * Set the type of this {@link ResponseFormatJsonSchema} instance. + * + * @param type The type of response format being defined: `json_schema` + */ + public void setType(@Nonnull final TypeEnum type) { + this.type = type; + } + + /** + * Set the jsonSchema of this {@link ResponseFormatJsonSchema} instance and return the same + * instance. + * + * @param jsonSchema The jsonSchema of this {@link ResponseFormatJsonSchema} + * @return The same instance of this {@link ResponseFormatJsonSchema} class + */ + @Nonnull + public ResponseFormatJsonSchema jsonSchema( + @Nonnull final ResponseFormatJsonSchemaJsonSchema jsonSchema) { + this.jsonSchema = jsonSchema; + return this; + } + + /** + * Get jsonSchema + * + * @return jsonSchema The jsonSchema of this {@link ResponseFormatJsonSchema} instance. + */ + @Nonnull + public ResponseFormatJsonSchemaJsonSchema getJsonSchema() { + return jsonSchema; + } + + /** + * Set the jsonSchema of this {@link ResponseFormatJsonSchema} instance. + * + * @param jsonSchema The jsonSchema of this {@link ResponseFormatJsonSchema} + */ + public void setJsonSchema(@Nonnull final ResponseFormatJsonSchemaJsonSchema jsonSchema) { + this.jsonSchema = jsonSchema; + } + + /** + * Get the names of the unrecognizable properties of the {@link ResponseFormatJsonSchema}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ResponseFormatJsonSchema} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ResponseFormatJsonSchema has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ResponseFormatJsonSchema} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ResponseFormatJsonSchema responseFormatJsonSchema = (ResponseFormatJsonSchema) o; + return Objects.equals(this.cloudSdkCustomFields, responseFormatJsonSchema.cloudSdkCustomFields) + && Objects.equals(this.type, responseFormatJsonSchema.type) + && Objects.equals(this.jsonSchema, responseFormatJsonSchema.jsonSchema); + } + + @Override + public int hashCode() { + return Objects.hash(type, jsonSchema, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ResponseFormatJsonSchema {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" jsonSchema: ").append(toIndentedString(jsonSchema)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ResponseFormatJsonSchemaJsonSchema.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ResponseFormatJsonSchemaJsonSchema.java new file mode 100644 index 000000000..ba3dc31b9 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ResponseFormatJsonSchemaJsonSchema.java @@ -0,0 +1,303 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ResponseFormatJsonSchemaJsonSchema */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ResponseFormatJsonSchemaJsonSchema +// CHECKSTYLE:ON +{ + @JsonProperty("description") + private String description; + + @JsonProperty("name") + private String name; + + @JsonProperty("schema") + private Map schema = new HashMap<>(); + + @JsonProperty("strict") + private Boolean strict = false; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the description of this {@link ResponseFormatJsonSchemaJsonSchema} instance and return the + * same instance. + * + * @param description A description of what the response format is for, used by the model to + * determine how to respond in the format. + * @return The same instance of this {@link ResponseFormatJsonSchemaJsonSchema} class + */ + @Nonnull + public ResponseFormatJsonSchemaJsonSchema description(@Nullable final String description) { + this.description = description; + return this; + } + + /** + * A description of what the response format is for, used by the model to determine how to respond + * in the format. + * + * @return description The description of this {@link ResponseFormatJsonSchemaJsonSchema} + * instance. + */ + @Nonnull + public String getDescription() { + return description; + } + + /** + * Set the description of this {@link ResponseFormatJsonSchemaJsonSchema} instance. + * + * @param description A description of what the response format is for, used by the model to + * determine how to respond in the format. + */ + public void setDescription(@Nullable final String description) { + this.description = description; + } + + /** + * Set the name of this {@link ResponseFormatJsonSchemaJsonSchema} instance and return the same + * instance. + * + * @param name The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores and + * dashes, with a maximum length of 64. + * @return The same instance of this {@link ResponseFormatJsonSchemaJsonSchema} class + */ + @Nonnull + public ResponseFormatJsonSchemaJsonSchema name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with + * a maximum length of 64. + * + * @return name The name of this {@link ResponseFormatJsonSchemaJsonSchema} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link ResponseFormatJsonSchemaJsonSchema} instance. + * + * @param name The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores and + * dashes, with a maximum length of 64. + */ + public void setName(@Nonnull final String name) { + this.name = name; + } + + /** + * Set the schema of this {@link ResponseFormatJsonSchemaJsonSchema} instance and return the same + * instance. + * + * @param schema The schema for the response format, described as a JSON Schema object. + * @return The same instance of this {@link ResponseFormatJsonSchemaJsonSchema} class + */ + @Nonnull + public ResponseFormatJsonSchemaJsonSchema schema(@Nullable final Map schema) { + this.schema = schema; + return this; + } + + /** + * Put one schema instance to this {@link ResponseFormatJsonSchemaJsonSchema} instance. + * + * @param key The String key of this schema instance + * @param schemaItem The schema that should be added under the given key + * @return The same instance of type {@link ResponseFormatJsonSchemaJsonSchema} + */ + @Nonnull + public ResponseFormatJsonSchemaJsonSchema putschemaItem( + @Nonnull final String key, @Nullable final Object schemaItem) { + if (this.schema == null) { + this.schema = new HashMap<>(); + } + this.schema.put(key, schemaItem); + return this; + } + + /** + * The schema for the response format, described as a JSON Schema object. + * + * @return schema The schema of this {@link ResponseFormatJsonSchemaJsonSchema} instance. + */ + @Nonnull + public Map getSchema() { + return schema; + } + + /** + * Set the schema of this {@link ResponseFormatJsonSchemaJsonSchema} instance. + * + * @param schema The schema for the response format, described as a JSON Schema object. + */ + public void setSchema(@Nullable final Map schema) { + this.schema = schema; + } + + /** + * Set the strict of this {@link ResponseFormatJsonSchemaJsonSchema} instance and return the same + * instance. + * + * @param strict Whether to enable strict schema adherence when generating the output. If set to + * true, the model will always follow the exact schema defined in the `schema` + * field. Only a subset of JSON Schema is supported when `strict` is + * `true`. + * @return The same instance of this {@link ResponseFormatJsonSchemaJsonSchema} class + */ + @Nonnull + public ResponseFormatJsonSchemaJsonSchema strict(@Nullable final Boolean strict) { + this.strict = strict; + return this; + } + + /** + * Whether to enable strict schema adherence when generating the output. If set to true, the model + * will always follow the exact schema defined in the `schema` field. Only a subset of + * JSON Schema is supported when `strict` is `true`. + * + * @return strict The strict of this {@link ResponseFormatJsonSchemaJsonSchema} instance. + */ + @Nullable + public Boolean isStrict() { + return strict; + } + + /** + * Set the strict of this {@link ResponseFormatJsonSchemaJsonSchema} instance. + * + * @param strict Whether to enable strict schema adherence when generating the output. If set to + * true, the model will always follow the exact schema defined in the `schema` + * field. Only a subset of JSON Schema is supported when `strict` is + * `true`. + */ + public void setStrict(@Nullable final Boolean strict) { + this.strict = strict; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * ResponseFormatJsonSchemaJsonSchema}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ResponseFormatJsonSchemaJsonSchema} + * instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "ResponseFormatJsonSchemaJsonSchema has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ResponseFormatJsonSchemaJsonSchema} instance. If + * the map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ResponseFormatJsonSchemaJsonSchema responseFormatJsonSchemaJsonSchema = + (ResponseFormatJsonSchemaJsonSchema) o; + return Objects.equals( + this.cloudSdkCustomFields, responseFormatJsonSchemaJsonSchema.cloudSdkCustomFields) + && Objects.equals(this.description, responseFormatJsonSchemaJsonSchema.description) + && Objects.equals(this.name, responseFormatJsonSchemaJsonSchema.name) + && Objects.equals(this.schema, responseFormatJsonSchemaJsonSchema.schema) + && Objects.equals(this.strict, responseFormatJsonSchemaJsonSchema.strict); + } + + @Override + public int hashCode() { + return Objects.hash(description, name, schema, strict, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ResponseFormatJsonSchemaJsonSchema {\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" schema: ").append(toIndentedString(schema)).append("\n"); + sb.append(" strict: ").append(toIndentedString(strict)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ResponseFormatText.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ResponseFormatText.java new file mode 100644 index 000000000..880e34144 --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ResponseFormatText.java @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ResponseFormatText */ +// CHECKSTYLE:OFF +@com.google.common.annotations.Beta +public class ResponseFormatText implements CreateChatCompletionRequestAllOfResponseFormat +// CHECKSTYLE:ON +{ + /** The type of response format being defined: `text` */ + public enum TypeEnum { + /** The TEXT option of this ResponseFormatText */ + TEXT("text"); + + private String value; + + TypeEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type ResponseFormatText + */ + @JsonCreator + @Nonnull + public static TypeEnum fromValue(@Nonnull final String value) { + for (TypeEnum b : TypeEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("type") + private TypeEnum type; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the type of this {@link ResponseFormatText} instance and return the same instance. + * + * @param type The type of response format being defined: `text` + * @return The same instance of this {@link ResponseFormatText} class + */ + @Nonnull + public ResponseFormatText type(@Nonnull final TypeEnum type) { + this.type = type; + return this; + } + + /** + * The type of response format being defined: `text` + * + * @return type The type of this {@link ResponseFormatText} instance. + */ + @Nonnull + public TypeEnum getType() { + return type; + } + + /** + * Set the type of this {@link ResponseFormatText} instance. + * + * @param type The type of response format being defined: `text` + */ + public void setType(@Nonnull final TypeEnum type) { + this.type = type; + } + + /** + * Get the names of the unrecognizable properties of the {@link ResponseFormatText}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ResponseFormatText} instance. + * + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException("ResponseFormatText has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link ResponseFormatText} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ResponseFormatText responseFormatText = (ResponseFormatText) o; + return Objects.equals(this.cloudSdkCustomFields, responseFormatText.cloudSdkCustomFields) + && Objects.equals(this.type, responseFormatText.type); + } + + @Override + public int hashCode() { + return Objects.hash(type, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ResponseFormatText {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ToolCallType.java b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ToolCallType.java new file mode 100644 index 000000000..ae01f950b --- /dev/null +++ b/foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model2/ToolCallType.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Azure OpenAI Service API + * Azure OpenAI APIs for completions and search + * + * The version of the OpenAPI document: 2024-10-21 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.foundationmodels.openai.model2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import javax.annotation.Nonnull; + +/** The type of the tool call, in this case `function`. */ +@com.google.common.annotations.Beta +public enum ToolCallType { + FUNCTION("function"); + + private final String value; + + ToolCallType(String value) { + this.value = value; + } + + /** + * @return The enum value. + */ + @JsonValue + public String getValue() { + return value; + } + + /** + * @return The String representation of the enum value. + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Converts the given value to its enum representation. + * + * @param value The input value. + * @return The enum representation of the given value. + */ + @JsonCreator + public static ToolCallType fromValue(@Nonnull final String value) { + for (final ToolCallType b : ToolCallType.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} diff --git a/foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/BaseOpenAiClientTest.java b/foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/BaseOpenAiClientTest.java new file mode 100644 index 000000000..93dbc66e3 --- /dev/null +++ b/foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/BaseOpenAiClientTest.java @@ -0,0 +1,89 @@ +package com.sap.ai.sdk.foundationmodels.openai; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; +import com.github.tomakehurst.wiremock.junit5.WireMockTest; +import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor; +import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Cache; +import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import java.util.function.Function; +import org.apache.hc.client5.http.classic.HttpClient; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.io.entity.InputStreamEntity; +import org.apache.hc.core5.http.message.BasicClassicHttpResponse; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; + +@WireMockTest +abstract class BaseOpenAiClientTest { + + protected static final ObjectMapper MAPPER = new ObjectMapper(); + protected static OpenAiClient client; + protected final Function fileLoader = + filename -> Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(filename)); + + static void stubForChatCompletion() { + + stubFor( + post(urlPathEqualTo("/chat/completions")) + .withQueryParam("api-version", equalTo("2024-02-01")) + .willReturn( + aResponse() + .withBodyFile("chatCompletionResponse.json") + .withHeader("Content-Type", "application/json"))); + } + + static void stubForEmbedding() { + stubFor( + post(urlPathEqualTo("/embeddings")) + .willReturn( + aResponse() + .withBodyFile("embeddingResponse.json") + .withHeader("Content-Type", "application/json"))); + } + + @BeforeEach + void setup(WireMockRuntimeInfo server) { + final DefaultHttpDestination destination = + DefaultHttpDestination.builder(server.getHttpBaseUrl()).build(); + client = OpenAiClient.withCustomDestination(destination); + ApacheHttpClient5Accessor.setHttpClientCache(ApacheHttpClient5Cache.DISABLED); + } + + @AfterEach + void reset() { + ApacheHttpClient5Accessor.setHttpClientCache(null); + ApacheHttpClient5Accessor.setHttpClientFactory(null); + } + + InputStream stubChatCompletionDeltas(String responseFile) throws IOException { + var inputStream = spy(fileLoader.apply(responseFile)); + + final var httpClient = mock(HttpClient.class); + ApacheHttpClient5Accessor.setHttpClientFactory(destination -> httpClient); + + // Create a mock response + final var mockResponse = new BasicClassicHttpResponse(200, "OK"); + final var inputStreamEntity = new InputStreamEntity(inputStream, ContentType.TEXT_PLAIN); + mockResponse.setEntity(inputStreamEntity); + mockResponse.setHeader("Content-Type", "text/event-stream"); + + // Configure the HttpClient mock to return the mock response + doReturn(mockResponse).when(httpClient).executeOpen(any(), any(), any()); + + return inputStream; + } +} diff --git a/foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OldOpenAiClientTest.java b/foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OldOpenAiClientTest.java new file mode 100644 index 000000000..7694ece02 --- /dev/null +++ b/foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OldOpenAiClientTest.java @@ -0,0 +1,306 @@ +package com.sap.ai.sdk.foundationmodels.openai; + +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.times; + +import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionDelta; +import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionOutput; +import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionParameters; +import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatMessage; +import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiContentFilterPromptResults; +import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiEmbeddingParameters; +import java.io.IOException; +import java.util.List; +import java.util.stream.Stream; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +class OldOpenAiClientTest extends BaseOpenAiClientTest { + + @Test + void chatCompletion() { + + stubForChatCompletion(); + + final var systemMessage = + new OpenAiChatMessage.OpenAiChatSystemMessage().setContent("You are a helpful AI"); + final var userMessage = + new OpenAiChatMessage.OpenAiChatUserMessage() + .addText("Hello World! Why is this phrase so famous?"); + final var request = + new OpenAiChatCompletionParameters().addMessages(systemMessage, userMessage); + final var result = client.chatCompletion(request); + + assertThat(result).isNotNull(); + assertThat(result.getCreated()).isEqualTo(1727436279); + assertThat(result.getId()).isEqualTo("chatcmpl-AC3NPPYlxem8kRBBAX9EBObMMsrnf"); + assertThat(result.getModel()).isEqualTo("gpt-35-turbo"); + assertThat(result.getObject()).isEqualTo("chat.completion"); + assertThat(result.getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); + + assertThat(result.getUsage()).isNotNull(); + assertThat(result.getUsage().getCompletionTokens()).isEqualTo(20); + assertThat(result.getUsage().getPromptTokens()).isEqualTo(13); + assertThat(result.getUsage().getTotalTokens()).isEqualTo(33); + + assertThat(result.getPromptFilterResults()).hasSize(1); + assertThat(result.getPromptFilterResults().get(0).getPromptIndex()).isEqualTo(0); + + var promptFilterResults = result.getPromptFilterResults().get(0).getContentFilterResults(); + assertThat(promptFilterResults).isNotNull(); + assertThat(promptFilterResults.getSexual()).isNotNull(); + assertThat(promptFilterResults.getSexual().isFiltered()).isFalse(); + assertThat(promptFilterResults.getSexual().getSeverity().getValue()).isEqualTo("safe"); + assertThat(promptFilterResults.getViolence()).isNotNull(); + assertThat(promptFilterResults.getViolence().isFiltered()).isFalse(); + assertThat(promptFilterResults.getViolence().getSeverity().getValue()).isEqualTo("safe"); + assertThat(promptFilterResults.getHate()).isNotNull(); + assertThat(promptFilterResults.getHate().isFiltered()).isFalse(); + assertThat(promptFilterResults.getHate().getSeverity().getValue()).isEqualTo("safe"); + assertThat(promptFilterResults.getSelfHarm()).isNotNull(); + assertThat(promptFilterResults.getSelfHarm().getSeverity().getValue()).isEqualTo("safe"); + assertThat(promptFilterResults.getSelfHarm().isFiltered()).isFalse(); + assertThat(promptFilterResults.getProfanity()).isNull(); + assertThat(promptFilterResults.getError()).isNull(); + assertThat(promptFilterResults.getJailbreak()).isNull(); + + assertThat(result.getChoices()).hasSize(1); + + var choice = result.getChoices().get(0); + assertThat(choice.getFinishReason()).isEqualTo("stop"); + assertThat(choice.getIndex()).isZero(); + assertThat(choice.getMessage().getContent()) + .isEqualTo( + "I'm an AI and cannot answer that question as beauty is subjective and varies from person to person."); + assertThat(choice.getMessage().getRole()).isEqualTo("assistant"); + assertThat(choice.getMessage().getToolCalls()).isNull(); + + var contentFilterResults = choice.getContentFilterResults(); + assertThat(contentFilterResults).isNotNull(); + assertThat(contentFilterResults.getSexual()).isNotNull(); + assertThat(contentFilterResults.getSexual().isFiltered()).isFalse(); + assertThat(contentFilterResults.getSexual().getSeverity().getValue()).isEqualTo("safe"); + assertThat(contentFilterResults.getViolence()).isNotNull(); + assertThat(contentFilterResults.getViolence().isFiltered()).isFalse(); + assertThat(contentFilterResults.getViolence().getSeverity().getValue()).isEqualTo("safe"); + assertThat(contentFilterResults.getHate()).isNotNull(); + assertThat(contentFilterResults.getHate().isFiltered()).isFalse(); + assertThat(contentFilterResults.getHate().getSeverity().getValue()).isEqualTo("safe"); + assertThat(contentFilterResults.getSelfHarm()).isNotNull(); + assertThat(contentFilterResults.getSelfHarm().getSeverity().getValue()).isEqualTo("safe"); + assertThat(contentFilterResults.getSelfHarm().isFiltered()).isFalse(); + assertThat(contentFilterResults.getProfanity()).isNull(); + assertThat(contentFilterResults.getError()).isNull(); + assertThat(contentFilterResults.getJailbreak()).isNull(); + + verify( + postRequestedFor(urlPathEqualTo("/chat/completions")) + .withQueryParam("api-version", equalTo("2024-02-01")) + .withRequestBody( + equalToJson( + """ + { + "messages" : [ { + "role" : "system", + "content" : "You are a helpful AI" + }, { + "role" : "user", + "content" : [ { + "type" : "text", + "text" : "Hello World! Why is this phrase so famous?" + } ] + } ] + }"""))); + } + + @Test + void embedding() { + stubForEmbedding(); + + final var request = new OpenAiEmbeddingParameters().setInput("Hello World"); + final var result = client.embedding(request); + + assertThat(result).isNotNull(); + assertThat(result.getModel()).isEqualTo("ada"); + assertThat(result.getObject()).isEqualTo("list"); + + assertThat(result.getUsage()).isNotNull(); + assertThat(result.getUsage().getCompletionTokens()).isNull(); + assertThat(result.getUsage().getPromptTokens()).isEqualTo(2); + assertThat(result.getUsage().getTotalTokens()).isEqualTo(2); + + assertThat(result.getData()).isNotNull().hasSize(1); + var embeddingData = result.getData().get(0); + assertThat(embeddingData).isNotNull(); + assertThat(embeddingData.getObject()).isEqualTo("embedding"); + assertThat(embeddingData.getIndex()).isZero(); + assertThat(embeddingData.getEmbedding()) + .isNotNull() + .isNotEmpty() + .isEqualTo(new float[] {0.0f, 3.4028235E38f, 1.4E-45f, 1.23f, -4.56f}); + + verify( + postRequestedFor(urlPathEqualTo("/embeddings")) + .withRequestBody( + equalToJson( + """ + {"input": ["Hello World"]}"""))); + } + + @Test + void streamChatCompletionDeltasErrorHandling() throws IOException { + try (var inputStream = stubChatCompletionDeltas("streamChatCompletionError.txt")) { + + final var request = + new OpenAiChatCompletionParameters() + .addMessages( + new OpenAiChatMessage.OpenAiChatUserMessage() + .addText("Can you give me the first 100 numbers of the Fibonacci sequence?")); + + try (var stream = client.streamChatCompletionDeltas(request)) { + assertThatThrownBy(() -> stream.forEach(System.out::println)) + .isInstanceOf(OpenAiClientException.class) + .hasMessage("Failed to parse response and error message: 'exceeded token rate limit'"); + } + + Mockito.verify(inputStream, times(1)).close(); + } + } + + @Test + void streamChatCompletionDeltas() throws IOException { + try (var inputStream = stubChatCompletionDeltas("streamChatCompletion.txt")) { + + final var request = + new OpenAiChatCompletionParameters() + .addMessages( + new OpenAiChatMessage.OpenAiChatUserMessage() + .addText("Can you give me the first 100 numbers of the Fibonacci sequence?")); + + try (Stream stream = + client.streamChatCompletionDeltas(request)) { + + OpenAiChatCompletionOutput totalOutput = new OpenAiChatCompletionOutput(); + final List deltaList = + stream.peek(totalOutput::addDelta).toList(); + + assertThat(deltaList).hasSize(5); + // the first two and the last delta don't have any content + assertThat(deltaList.get(0).getDeltaContent()).isEmpty(); + assertThat(deltaList.get(1).getDeltaContent()).isEmpty(); + assertThat(deltaList.get(2).getDeltaContent()).isEqualTo("Sure"); + assertThat(deltaList.get(3).getDeltaContent()).isEqualTo("!"); + assertThat(deltaList.get(4).getDeltaContent()).isEmpty(); + + assertThat(deltaList.get(0).getSystemFingerprint()).isNull(); + assertThat(deltaList.get(1).getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); + assertThat(deltaList.get(2).getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); + assertThat(deltaList.get(3).getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); + assertThat(deltaList.get(4).getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); + + assertThat(deltaList.get(0).getUsage()).isNull(); + assertThat(deltaList.get(1).getUsage()).isNull(); + assertThat(deltaList.get(2).getUsage()).isNull(); + assertThat(deltaList.get(3).getUsage()).isNull(); + final var usage = deltaList.get(4).getUsage(); + assertThat(usage).isNotNull(); + assertThat(usage.getCompletionTokens()).isEqualTo(607); + assertThat(usage.getPromptTokens()).isEqualTo(21); + assertThat(usage.getTotalTokens()).isEqualTo(628); + + assertThat(deltaList.get(0).getChoices()).isEmpty(); + assertThat(deltaList.get(1).getChoices()).hasSize(1); + assertThat(deltaList.get(2).getChoices()).hasSize(1); + assertThat(deltaList.get(3).getChoices()).hasSize(1); + assertThat(deltaList.get(4).getChoices()).hasSize(1); + + final var delta0 = deltaList.get(0); + assertThat(delta0.getId()).isEmpty(); + assertThat(delta0.getCreated()).isZero(); + assertThat(delta0.getModel()).isEmpty(); + assertThat(delta0.getObject()).isEmpty(); + assertThat(delta0.getUsage()).isNull(); + assertThat(delta0.getChoices()).isEmpty(); + // prompt filter results are only present in delta 0 + assertThat(delta0.getPromptFilterResults()).isNotNull(); + assertThat(delta0.getPromptFilterResults().get(0).getPromptIndex()).isZero(); + final var promptFilter0 = delta0.getPromptFilterResults().get(0).getContentFilterResults(); + assertThat(promptFilter0).isNotNull(); + assertFilter(promptFilter0); + + final var delta2 = deltaList.get(2); + assertThat(delta2.getId()).isEqualTo("chatcmpl-A16EvnkgEm6AdxY0NoOmGPjsJucQ1"); + assertThat(delta2.getCreated()).isEqualTo(1724825677); + assertThat(delta2.getModel()).isEqualTo("gpt-35-turbo"); + assertThat(delta2.getObject()).isEqualTo("chat.completion.chunk"); + assertThat(delta2.getUsage()).isNull(); + assertThat(delta2.getPromptFilterResults()).isNull(); + final var choices2 = delta2.getChoices().get(0); + assertThat(choices2.getIndex()).isEqualTo(0); + assertThat(choices2.getFinishReason()).isNull(); + assertThat(choices2.getMessage()).isNotNull(); + // the role is only defined in delta 1, but it defaults to "assistant" for all deltas + assertThat(choices2.getMessage().getRole()).isEqualTo("assistant"); + assertThat(choices2.getMessage().getContent()).isEqualTo("Sure"); + assertThat(choices2.getMessage().getToolCalls()).isNull(); + final var filter2 = choices2.getContentFilterResults(); + assertFilter(filter2); + + final var delta3 = deltaList.get(3); + assertThat(delta3.getDeltaContent()).isEqualTo("!"); + + final var delta4Choice = deltaList.get(4).getChoices().get(0); + assertThat(delta4Choice.getFinishReason()).isEqualTo("stop"); + assertThat(delta4Choice.getMessage()).isNotNull(); + // the role is only defined in delta 1, but it defaults to "assistant" for all deltas + assertThat(delta4Choice.getMessage().getRole()).isEqualTo("assistant"); + assertThat(delta4Choice.getMessage().getContent()).isNull(); + assertThat(delta4Choice.getMessage().getToolCalls()).isNull(); + assertThat(totalOutput.getChoices()).hasSize(1); + final var choice = totalOutput.getChoices().get(0); + assertThat(choice.getFinishReason()).isEqualTo("stop"); + assertFilter(choice.getContentFilterResults()); + assertThat(choice.getFinishReason()).isEqualTo("stop"); + assertThat(choice.getMessage()).isNotNull(); + assertThat(choice.getMessage().getRole()).isEqualTo("assistant"); + assertThat(choice.getMessage().getContent()).isEqualTo("Sure!"); + assertThat(choice.getMessage().getToolCalls()).isNull(); + assertThat(totalOutput.getId()).isEqualTo("chatcmpl-A16EvnkgEm6AdxY0NoOmGPjsJucQ1"); + assertThat(totalOutput.getCreated()).isEqualTo(1724825677); + assertThat(totalOutput.getModel()).isEqualTo("gpt-35-turbo"); + assertThat(totalOutput.getObject()).isEqualTo("chat.completion.chunk"); + final var totalUsage = totalOutput.getUsage(); + assertThat(totalUsage).isNotNull(); + assertThat(totalUsage.getCompletionTokens()).isEqualTo(607); + assertThat(totalUsage.getPromptTokens()).isEqualTo(21); + assertThat(totalUsage.getTotalTokens()).isEqualTo(628); + assertThat(totalOutput.getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); + assertThat(totalOutput.getPromptFilterResults()).isNotNull(); + assertFilter(totalOutput.getPromptFilterResults().get(0).getContentFilterResults()); + } + + Mockito.verify(inputStream, times(1)).close(); + } + } + + void assertFilter(OpenAiContentFilterPromptResults filter) { + assertThat(filter).isNotNull(); + assertThat(filter.getHate()).isNotNull(); + assertThat(filter.getHate().isFiltered()).isFalse(); + assertThat(filter.getHate().getSeverity().getValue()).isEqualTo("safe"); + assertThat(filter.getSelfHarm()).isNotNull(); + assertThat(filter.getSelfHarm().isFiltered()).isFalse(); + assertThat(filter.getSelfHarm().getSeverity().getValue()).isEqualTo("safe"); + assertThat(filter.getSexual()).isNotNull(); + assertThat(filter.getSexual().isFiltered()).isFalse(); + assertThat(filter.getSexual().getSeverity().getValue()).isEqualTo("safe"); + assertThat(filter.getViolence()).isNotNull(); + assertThat(filter.getViolence().isFiltered()).isFalse(); + assertThat(filter.getViolence().getSeverity().getValue()).isEqualTo("safe"); + assertThat(filter.getJailbreak()).isNull(); + assertThat(filter.getProfanity()).isNull(); + assertThat(filter.getError()).isNull(); + } +} diff --git a/foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClientTest.java b/foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClientTest.java index 67c1c8a24..f58bb1130 100644 --- a/foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClientTest.java +++ b/foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClientTest.java @@ -1,103 +1,78 @@ package com.sap.ai.sdk.foundationmodels.openai; -import static com.github.tomakehurst.wiremock.client.WireMock.*; -import static com.sap.ai.sdk.foundationmodels.openai.model.OpenAiContentFilterSeverityResult.Severity.SAFE; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl; +import static com.github.tomakehurst.wiremock.client.WireMock.badRequest; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; +import static com.github.tomakehurst.wiremock.client.WireMock.exactly; +import static com.github.tomakehurst.wiremock.client.WireMock.noContent; +import static com.github.tomakehurst.wiremock.client.WireMock.okJson; +import static com.github.tomakehurst.wiremock.client.WireMock.okXml; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; +import static com.github.tomakehurst.wiremock.client.WireMock.serverError; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.verify; +import static com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionStreamResponse.ObjectEnum.CHAT_COMPLETION_CHUNK; +import static com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionStreamResponseChoicesInner.FinishReasonEnum.STOP; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.InstanceOfAssertFactories.MAP; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.when; import com.fasterxml.jackson.core.JsonParseException; -import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; -import com.github.tomakehurst.wiremock.junit5.WireMockTest; import com.github.tomakehurst.wiremock.stubbing.Scenario; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionChoice; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionDelta; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionOutput; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionParameters; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatMessage.OpenAiChatSystemMessage; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatMessage.OpenAiChatUserMessage; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiContentFilterPromptResults; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiEmbeddingParameters; -import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor; -import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Cache; -import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination; +import com.sap.ai.sdk.foundationmodels.openai.model2.CompletionUsage; +import com.sap.ai.sdk.foundationmodels.openai.model2.ContentFilterPromptResults; +import com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionRequest; +import com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionResponse; +import com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionStreamResponse; +import com.sap.ai.sdk.foundationmodels.openai.model2.PromptFilterResult; import io.vavr.control.Try; import java.io.IOException; -import java.io.InputStream; +import java.math.BigDecimal; import java.util.List; -import java.util.Objects; +import java.util.Map; +import java.util.NoSuchElementException; import java.util.concurrent.Callable; -import java.util.function.Function; import java.util.stream.Stream; import javax.annotation.Nonnull; import lombok.SneakyThrows; -import org.apache.hc.client5.http.classic.HttpClient; -import org.apache.hc.core5.http.ContentType; -import org.apache.hc.core5.http.io.entity.InputStreamEntity; -import org.apache.hc.core5.http.message.BasicClassicHttpResponse; import org.assertj.core.api.SoftAssertions; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mockito; -@WireMockTest -class OpenAiClientTest { - private static OpenAiClient client; - private final Function fileLoader = - filename -> Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(filename)); - - @BeforeEach - void setup(WireMockRuntimeInfo server) { - final DefaultHttpDestination destination = - DefaultHttpDestination.builder(server.getHttpBaseUrl()).build(); - client = OpenAiClient.withCustomDestination(destination); - ApacheHttpClient5Accessor.setHttpClientCache(ApacheHttpClient5Cache.DISABLED); - } - - @AfterEach - void reset() { - ApacheHttpClient5Accessor.setHttpClientCache(null); - ApacheHttpClient5Accessor.setHttpClientFactory(null); - } - - @Test - void apiVersion() { - stubFor(post(anyUrl()).willReturn(okJson("{}"))); - Try.of(() -> client.chatCompletion(new OpenAiChatCompletionParameters())); - - verify( - exactly(1), - postRequestedFor(anyUrl()).withQueryParam("api-version", equalTo("2024-02-01"))); +class OpenAiClientTest extends BaseOpenAiClientTest { - Try.of( - () -> client.withApiVersion("fooBar").chatCompletion(new OpenAiChatCompletionParameters())); - verify(exactly(1), postRequestedFor(anyUrl()).withQueryParam("api-version", equalTo("fooBar"))); - - assertThat(client) - .describedAs( - "withApiVersion should return a new object, the sut object should remain unchanged") - .isNotSameAs(client.withApiVersion("fooBar")); - Try.of(() -> client.chatCompletion(new OpenAiChatCompletionParameters())); - verify( - exactly(2), - postRequestedFor(anyUrl()).withQueryParam("api-version", equalTo("2024-02-01"))); + private static Callable[] chatCompletionCalls() { + return new Callable[] { + () -> { + final var systemMessage = OpenAiMessage.system("You are a helpful AI"); + final var userMessage = OpenAiMessage.user("Hello World! Why is this phrase so famous?"); + final var prompt = new OpenAiChatCompletionRequest(systemMessage, userMessage); + return client.chatCompletion(prompt); + }, + () -> + client + .withSystemPrompt("You are a helpful AI") + .chatCompletion("Hello World! Why is this phrase so famous?") + }; } private static Runnable[] errorHandlingCalls() { return new Runnable[] { - () -> client.chatCompletion(new OpenAiChatCompletionParameters()), + () -> client.chatCompletion(new OpenAiChatCompletionRequest("")), () -> client - .streamChatCompletionDeltas(new OpenAiChatCompletionParameters()) + .streamChatCompletionDeltas(new OpenAiChatCompletionRequest("")) // the stream needs to be consumed to parse the response .forEach(System.out::println) }; @@ -177,118 +152,114 @@ void chatCompletionErrorHandling(@Nonnull final Runnable request) { softly.assertAll(); } - private static Callable[] chatCompletionCalls() { - return new Callable[] { - () -> { - final var systemMessage = new OpenAiChatSystemMessage().setContent("You are a helpful AI"); - final var userMessage = - new OpenAiChatUserMessage().addText("Hello World! Why is this phrase so famous?"); - final var request = - new OpenAiChatCompletionParameters().addMessages(systemMessage, userMessage); - return client.chatCompletion(request); - }, - () -> - client - .withSystemPrompt("You are a helpful AI") - .chatCompletion("Hello World! Why is this phrase so famous?") - }; + @Test + void apiVersion() { + stubFor(post(anyUrl()).willReturn(okJson("{}"))); + Try.of(() -> client.chatCompletion(new OpenAiChatCompletionRequest(""))); + + verify( + exactly(1), + postRequestedFor(anyUrl()).withQueryParam("api-version", equalTo("2024-02-01"))); + + Try.of( + () -> client.withApiVersion("fooBar").chatCompletion(new OpenAiChatCompletionRequest(""))); + verify(exactly(1), postRequestedFor(anyUrl()).withQueryParam("api-version", equalTo("fooBar"))); + + assertThat(client) + .describedAs( + "withApiVersion should return a new object, the sut object should remain unchanged") + .isNotSameAs(client.withApiVersion("fooBar")); + Try.of(() -> client.chatCompletion(new OpenAiChatCompletionRequest(""))); + verify( + exactly(2), + postRequestedFor(anyUrl()).withQueryParam("api-version", equalTo("2024-02-01"))); } @SneakyThrows @ParameterizedTest @MethodSource("chatCompletionCalls") - void chatCompletion(@Nonnull final Callable request) { - try (var inputStream = fileLoader.apply("__files/chatCompletionResponse.json")) { - - final String response = new String(inputStream.readAllBytes()); - // with query parameter api-version=2024-02-01 - stubFor( - post(urlPathEqualTo("/chat/completions")) - .withQueryParam("api-version", equalTo("2024-02-01")) - .willReturn(okJson(response))); - - final OpenAiChatCompletionOutput result = request.call(); - - assertThat(result).isNotNull(); - assertThat(result.getCreated()).isEqualTo(1727436279); - assertThat(result.getId()).isEqualTo("chatcmpl-AC3NPPYlxem8kRBBAX9EBObMMsrnf"); - assertThat(result.getModel()).isEqualTo("gpt-35-turbo"); - assertThat(result.getObject()).isEqualTo("chat.completion"); - assertThat(result.getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); - - assertThat(result.getUsage()).isNotNull(); - assertThat(result.getUsage().getCompletionTokens()).isEqualTo(20); - assertThat(result.getUsage().getPromptTokens()).isEqualTo(13); - assertThat(result.getUsage().getTotalTokens()).isEqualTo(33); - - assertThat(result.getPromptFilterResults()).hasSize(1); - assertThat(result.getPromptFilterResults().get(0).getPromptIndex()).isEqualTo(0); - OpenAiContentFilterPromptResults promptFilterResults = - result.getPromptFilterResults().get(0).getContentFilterResults(); - assertThat(promptFilterResults).isNotNull(); - assertThat(promptFilterResults.getSexual()).isNotNull(); - assertThat(promptFilterResults.getSexual().isFiltered()).isFalse(); - assertThat(promptFilterResults.getSexual().getSeverity()).isEqualTo(SAFE); - assertThat(promptFilterResults.getViolence()).isNotNull(); - assertThat(promptFilterResults.getViolence().isFiltered()).isFalse(); - assertThat(promptFilterResults.getViolence().getSeverity()).isEqualTo(SAFE); - assertThat(promptFilterResults.getHate()).isNotNull(); - assertThat(promptFilterResults.getHate().isFiltered()).isFalse(); - assertThat(promptFilterResults.getHate().getSeverity()).isEqualTo(SAFE); - assertThat(promptFilterResults.getSelfHarm()).isNotNull(); - assertThat(promptFilterResults.getSelfHarm().getSeverity()).isEqualTo(SAFE); - assertThat(promptFilterResults.getSelfHarm().isFiltered()).isFalse(); - assertThat(promptFilterResults.getProfanity()).isNull(); - assertThat(promptFilterResults.getError()).isNull(); - assertThat(promptFilterResults.getJailbreak()).isNull(); - - assertThat(result.getChoices()).hasSize(1); - OpenAiChatCompletionChoice choice = result.getChoices().get(0); - assertThat(choice.getFinishReason()).isEqualTo("stop"); - assertThat(choice.getIndex()).isEqualTo(0); - assertThat(choice.getMessage().getContent()) - .isEqualTo( - "I'm an AI and cannot answer that question as beauty is subjective and varies from person to person."); - assertThat(choice.getMessage().getRole()).isEqualTo("assistant"); - assertThat(choice.getMessage().getToolCalls()).isNull(); - - OpenAiContentFilterPromptResults contentFilterResults = choice.getContentFilterResults(); - assertThat(contentFilterResults).isNotNull(); - assertThat(contentFilterResults.getSexual()).isNotNull(); - assertThat(contentFilterResults.getSexual().isFiltered()).isFalse(); - assertThat(contentFilterResults.getSexual().getSeverity()).isEqualTo(SAFE); - assertThat(contentFilterResults.getViolence()).isNotNull(); - assertThat(contentFilterResults.getViolence().isFiltered()).isFalse(); - assertThat(contentFilterResults.getViolence().getSeverity()).isEqualTo(SAFE); - assertThat(contentFilterResults.getHate()).isNotNull(); - assertThat(contentFilterResults.getHate().isFiltered()).isFalse(); - assertThat(contentFilterResults.getHate().getSeverity()).isEqualTo(SAFE); - assertThat(contentFilterResults.getSelfHarm()).isNotNull(); - assertThat(contentFilterResults.getSelfHarm().getSeverity()).isEqualTo(SAFE); - assertThat(contentFilterResults.getSelfHarm().isFiltered()).isFalse(); - assertThat(contentFilterResults.getProfanity()).isNull(); - assertThat(contentFilterResults.getError()).isNull(); - assertThat(contentFilterResults.getJailbreak()).isNull(); - - verify( - postRequestedFor(urlPathEqualTo("/chat/completions")) - .withQueryParam("api-version", equalTo("2024-02-01")) - .withRequestBody( - equalToJson( - """ - { - "messages" : [ { - "role" : "system", - "content" : "You are a helpful AI" - }, { - "role" : "user", - "content" : [ { - "type" : "text", - "text" : "Hello World! Why is this phrase so famous?" - } ] - } ] - }"""))); - } + void chatCompletion(@Nonnull final Callable request) { + + stubForChatCompletion(); + + final var result = (CreateChatCompletionResponse) request.call().getOriginalResponse(); + + assertThat(result).isNotNull(); + assertThat(result.getCreated()).isEqualTo(1727436279); + assertThat(result.getId()).isEqualTo("chatcmpl-AC3NPPYlxem8kRBBAX9EBObMMsrnf"); + assertThat(result.getModel()).isEqualTo("gpt-35-turbo"); + assertThat(result.getObject().getValue()).isEqualTo("chat.completion"); + assertThat(result.getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); + + assertThat(result.getUsage()).isNotNull(); + assertThat(result.getUsage().getCompletionTokens()).isEqualTo(20); + assertThat(result.getUsage().getPromptTokens()).isEqualTo(13); + assertThat(result.getUsage().getTotalTokens()).isEqualTo(33); + + assertThat(result.getPromptFilterResults()).hasSize(1); + assertThat(result.getPromptFilterResults().get(0).getPromptIndex()).isZero(); + + var promptFilterResults = result.getPromptFilterResults().get(0).getContentFilterResults(); + assertThat(promptFilterResults).isNotNull(); + assertThat(promptFilterResults.getSexual()).isNotNull(); + assertThat(promptFilterResults.getSexual().isFiltered()).isFalse(); + assertThat(promptFilterResults.getSexual().getSeverity().getValue()).isEqualTo("safe"); + assertThat(promptFilterResults.getViolence()).isNotNull(); + assertThat(promptFilterResults.getViolence().isFiltered()).isFalse(); + assertThat(promptFilterResults.getViolence().getSeverity().getValue()).isEqualTo("safe"); + assertThat(promptFilterResults.getHate()).isNotNull(); + assertThat(promptFilterResults.getHate().isFiltered()).isFalse(); + assertThat(promptFilterResults.getHate().getSeverity().getValue()).isEqualTo("safe"); + assertThat(promptFilterResults.getSelfHarm()).isNotNull(); + assertThat(promptFilterResults.getSelfHarm().getSeverity().getValue()).isEqualTo("safe"); + assertThat(promptFilterResults.getSelfHarm().isFiltered()).isFalse(); + assertThat(promptFilterResults.getProfanity()).isNull(); + assertThat(promptFilterResults.getError()).isNull(); + assertThat(promptFilterResults.getJailbreak()).isNull(); + + assertThat(result.getChoices()).hasSize(1); + + var choice = result.getChoices().get(0); + assertThat(choice.getFinishReason().getValue()).isEqualTo("stop"); + assertThat(choice.getIndex()).isZero(); + assertThat(choice.getMessage().getContent()) + .isEqualTo( + "I'm an AI and cannot answer that question as beauty is subjective and varies from person to person."); + assertThat(choice.getMessage().getRole().getValue()).isEqualTo("assistant"); + assertThat(choice.getMessage().getToolCalls()).isNull(); + + var contentFilterResults = choice.getContentFilterResults(); + assertThat(contentFilterResults).isNotNull(); + assertThat(contentFilterResults.getSexual()).isNotNull(); + assertThat(contentFilterResults.getSexual().isFiltered()).isFalse(); + assertThat(contentFilterResults.getSexual().getSeverity().getValue()).isEqualTo("safe"); + assertThat(contentFilterResults.getViolence()).isNotNull(); + assertThat(contentFilterResults.getViolence().isFiltered()).isFalse(); + assertThat(contentFilterResults.getViolence().getSeverity().getValue()).isEqualTo("safe"); + assertThat(contentFilterResults.getHate()).isNotNull(); + assertThat(contentFilterResults.getHate().isFiltered()).isFalse(); + assertThat(contentFilterResults.getHate().getSeverity().getValue()).isEqualTo("safe"); + assertThat(contentFilterResults.getSelfHarm()).isNotNull(); + assertThat(contentFilterResults.getSelfHarm().getSeverity().getValue()).isEqualTo("safe"); + assertThat(contentFilterResults.getSelfHarm().isFiltered()).isFalse(); + assertThat(contentFilterResults.getProfanity()).isNull(); + assertThat(contentFilterResults.getError()).isNull(); + + verify( + postRequestedFor(urlPathEqualTo("/chat/completions")) + .withQueryParam("api-version", equalTo("2024-02-01")) + .withRequestBody( + equalToJson( + """ + { + "messages" : [ { + "content" : "You are a helpful AI", + "role" : "system" + }, { + "content" : "Hello World! Why is this phrase so famous?", + "role" : "user" + } ] + }"""))); } @Test @@ -310,19 +281,21 @@ void history() { equalToJson( """ { - "messages" : [ { - "role" : "system", - "content" : "system prompt" - }, { - "role" : "user", - "content" : [ { - "type" : "text", - "text" : "chat completion 1" - } ] - } ] + "messages" : [ { + "content" : "system prompt", + "role" : "system" + }, { + "content" : "chat completion 1", + "role" : "user" + } ] }"""))); - client.withSystemPrompt("system prompt").chatCompletion("chat completion 2"); + var response = client.withSystemPrompt("system prompt").chatCompletion("chat completion 2"); + + assertThat(response.getContent()).isNotNull(); + assertThat(response.getContent()) + .isEqualTo( + "I'm an AI and cannot answer that question as beauty is subjective and varies from person to person."); verify( exactly(1), @@ -331,37 +304,28 @@ void history() { equalToJson( """ { - "messages" : [ { - "role" : "system", - "content" : "system prompt" - }, { - "role" : "user", - "content" : [ { - "type" : "text", - "text" : "chat completion 2" - } ] - } ] + "messages" : [ { + "content" : "system prompt", + "role" : "system" + }, { + "content" : "chat completion 2", + "role" : "user" + } ] }"""))); } @Test void embedding() { - stubFor( - post(urlPathEqualTo("/embeddings")) - .willReturn( - aResponse() - .withBodyFile("embeddingResponse.json") - .withHeader("Content-Type", "application/json"))); + stubForEmbedding(); - final var request = new OpenAiEmbeddingParameters().setInput("Hello World"); - final var result = client.embedding(request); + final var result = client.embedding("Hello World"); assertThat(result).isNotNull(); assertThat(result.getModel()).isEqualTo("ada"); assertThat(result.getObject()).isEqualTo("list"); assertThat(result.getUsage()).isNotNull(); - assertThat(result.getUsage().getCompletionTokens()).isNull(); + assertThat(result.getUsage().getCustomFieldNames()).doesNotContain("completion_tokens"); assertThat(result.getUsage().getPromptTokens()).isEqualTo(2); assertThat(result.getUsage().getTotalTokens()).isEqualTo(2); @@ -369,18 +333,23 @@ void embedding() { var embeddingData = result.getData().get(0); assertThat(embeddingData).isNotNull(); assertThat(embeddingData.getObject()).isEqualTo("embedding"); - assertThat(embeddingData.getIndex()).isEqualTo(0); + assertThat(embeddingData.getIndex()).isZero(); assertThat(embeddingData.getEmbedding()) .isNotNull() .isNotEmpty() - .isEqualTo(new float[] {0.0f, 3.4028235E38f, 1.4E-45f, 1.23f, -4.56f}); + .containsExactly( + new BigDecimal("0.0"), + new BigDecimal("3.4028235E+38"), + new BigDecimal("1.4E-45"), + new BigDecimal("1.23"), + new BigDecimal("-4.56")); verify( postRequestedFor(urlPathEqualTo("/embeddings")) .withRequestBody( equalToJson( """ - {"input":["Hello World"]}"""))); + {"input": "Hello World"}"""))); } @Test @@ -390,7 +359,8 @@ void testThrowsOnContentFilter() { var deltaWithContentFilter = mock(OpenAiChatCompletionDelta.class); when(deltaWithContentFilter.getFinishReason()).thenReturn("content_filter"); - when(mock.streamChatCompletionDeltas(any())).thenReturn(Stream.of(deltaWithContentFilter)); + when(mock.streamChatCompletionDeltas((CreateChatCompletionRequest) any())) + .thenReturn(Stream.of(deltaWithContentFilter)); // this must not throw, since the stream is lazily evaluated var stream = mock.streamChatCompletion(""); @@ -401,27 +371,13 @@ void testThrowsOnContentFilter() { @Test void streamChatCompletionDeltasErrorHandling() throws IOException { - try (var inputStream = spy(fileLoader.apply("streamChatCompletionError.txt"))) { - - final var httpClient = mock(HttpClient.class); - ApacheHttpClient5Accessor.setHttpClientFactory(destination -> httpClient); - - // Create a mock response - final var mockResponse = new BasicClassicHttpResponse(200, "OK"); - final var inputStreamEntity = new InputStreamEntity(inputStream, ContentType.TEXT_PLAIN); - mockResponse.setEntity(inputStreamEntity); - mockResponse.setHeader("Content-Type", "text/event-stream"); - - // Configure the HttpClient mock to return the mock response - doReturn(mockResponse).when(httpClient).executeOpen(any(), any(), any()); + try (var inputStream = stubChatCompletionDeltas("streamChatCompletionError.txt")) { final var request = - new OpenAiChatCompletionParameters() - .addMessages( - new OpenAiChatUserMessage() - .addText("Can you give me the first 100 numbers of the Fibonacci sequence?")); + new OpenAiChatCompletionRequest( + "Can you give me the first 100 numbers of the Fibonacci sequence?"); - try (Stream stream = client.streamChatCompletionDeltas(request)) { + try (var stream = client.streamChatCompletionDeltas(request)) { assertThatThrownBy(() -> stream.forEach(System.out::println)) .isInstanceOf(OpenAiClientException.class) .hasMessage("Failed to parse response and error message: 'exceeded token rate limit'"); @@ -433,145 +389,147 @@ void streamChatCompletionDeltasErrorHandling() throws IOException { @Test void streamChatCompletionDeltas() throws IOException { - try (var inputStream = spy(fileLoader.apply("streamChatCompletion.txt"))) { - - final var httpClient = mock(HttpClient.class); - ApacheHttpClient5Accessor.setHttpClientFactory(destination -> httpClient); - - // Create a mock response - final var mockResponse = new BasicClassicHttpResponse(200, "OK"); - final var inputStreamEntity = new InputStreamEntity(inputStream, ContentType.TEXT_PLAIN); - mockResponse.setEntity(inputStreamEntity); - mockResponse.setHeader("Content-Type", "text/event-stream"); - - // Configure the HttpClient mock to return the mock response - doReturn(mockResponse).when(httpClient).executeOpen(any(), any(), any()); + try (var inputStream = stubChatCompletionDeltas("streamChatCompletion.txt")) { final var request = - new OpenAiChatCompletionParameters() - .addMessages( - new OpenAiChatUserMessage() - .addText("Can you give me the first 100 numbers of the Fibonacci sequence?")); + new OpenAiChatCompletionRequest( + "Can you give me the first 100 numbers of the Fibonacci sequence?"); try (Stream stream = client.streamChatCompletionDeltas(request)) { - OpenAiChatCompletionOutput totalOutput = new OpenAiChatCompletionOutput(); - final List deltaList = - stream.peek(totalOutput::addDelta).toList(); + final List deltaList = stream.toList(); assertThat(deltaList).hasSize(5); // the first two and the last delta don't have any content - assertThat(deltaList.get(0).getDeltaContent()).isEqualTo(""); - assertThat(deltaList.get(1).getDeltaContent()).isEqualTo(""); + assertThat(deltaList.get(0).getDeltaContent()).isEmpty(); + assertThat(deltaList.get(1).getDeltaContent()).isEmpty(); assertThat(deltaList.get(2).getDeltaContent()).isEqualTo("Sure"); assertThat(deltaList.get(3).getDeltaContent()).isEqualTo("!"); - assertThat(deltaList.get(4).getDeltaContent()).isEqualTo(""); - - assertThat(deltaList.get(0).getSystemFingerprint()).isNull(); - assertThat(deltaList.get(1).getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); - assertThat(deltaList.get(2).getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); - assertThat(deltaList.get(3).getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); - assertThat(deltaList.get(4).getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); - - assertThat(deltaList.get(0).getUsage()).isNull(); - assertThat(deltaList.get(1).getUsage()).isNull(); - assertThat(deltaList.get(2).getUsage()).isNull(); - assertThat(deltaList.get(3).getUsage()).isNull(); - final var usage = deltaList.get(4).getUsage(); - assertThat(usage).isNotNull(); - assertThat(usage.getCompletionTokens()).isEqualTo(607); - assertThat(usage.getPromptTokens()).isEqualTo(21); - assertThat(usage.getTotalTokens()).isEqualTo(628); - - assertThat(deltaList.get(0).getChoices()).isEmpty(); - assertThat(deltaList.get(1).getChoices()).hasSize(1); - assertThat(deltaList.get(2).getChoices()).hasSize(1); - assertThat(deltaList.get(3).getChoices()).hasSize(1); - assertThat(deltaList.get(4).getChoices()).hasSize(1); - - final var delta0 = deltaList.get(0); - assertThat(delta0.getId()).isEqualTo(""); - assertThat(delta0.getCreated()).isEqualTo(0); - assertThat(delta0.getModel()).isEqualTo(""); - assertThat(delta0.getObject()).isEqualTo(""); - assertThat(delta0.getUsage()).isNull(); + assertThat(deltaList.get(4).getDeltaContent()).isEmpty(); + + assertThat(deltaList.get(3).getFinishReason()).isNull(); + assertThat(deltaList.get(4).getFinishReason()).isEqualTo(STOP.getValue()); + + final var delta0 = deltaList.get(0).getOriginalResponse(); + final var delta1 = deltaList.get(1).getOriginalResponse(); + final var delta2 = deltaList.get(2).getOriginalResponse(); + final var delta3 = deltaList.get(3).getOriginalResponse(); + final var delta4 = deltaList.get(4).getOriginalResponse(); + + assertThat(delta0.getSystemFingerprint()).isNull(); + assertThat(delta1.getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); + assertThat(delta2.getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); + assertThat(delta3.getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); + assertThat(delta4.getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); + + assertThatThrownBy(() -> delta0.getCustomField("usage")) + .isInstanceOf(NoSuchElementException.class); + assertThat(delta1.getCustomField("usage")).isNull(); + assertThat(delta1.getCustomField("usage")) + .isEqualTo(deltaList.get(1).getCompletionUsage(MAPPER)); + assertThat(delta2.getCustomField("usage")).isNull(); + assertThat(delta3.getCustomField("usage")).isNull(); + final Map delta4UsageRaw = (Map) delta4.getCustomField("usage"); + final var delta4Usage = MAPPER.convertValue(delta4UsageRaw, CompletionUsage.class); + assertThat(delta4Usage).isNotNull(); + assertThat(delta4Usage.getCompletionTokens()).isEqualTo(607); + assertThat(delta4Usage.getPromptTokens()).isEqualTo(21); + assertThat(delta4Usage.getTotalTokens()).isEqualTo(628); + assertThat(delta4Usage).isEqualTo(deltaList.get(4).getCompletionUsage(MAPPER)); + + // delta 0 + + assertThat(delta0.getId()).isEmpty(); + assertThat(delta0.getCreated()).isZero(); + assertThat(delta0.getModel()).isEmpty(); + assertThat(delta0.getObject()) + .isEqualTo(CreateChatCompletionStreamResponse.ObjectEnum.UNKNOWN_DEFAULT_OPEN_API); + assertThat(delta0.getChoices()).isEmpty(); - // prompt filter results are only present in delta 0 - assertThat(delta0.getPromptFilterResults()).isNotNull(); - assertThat(delta0.getPromptFilterResults().get(0).getPromptIndex()).isEqualTo(0); - final var promptFilter0 = delta0.getPromptFilterResults().get(0).getContentFilterResults(); - assertThat(promptFilter0).isNotNull(); - assertFilter(promptFilter0); - - final var delta2 = deltaList.get(2); + + var promptFilterResults = (List) delta0.getCustomField("prompt_filter_results"); + var promptFilter = + MAPPER.convertValue(promptFilterResults.get(0), PromptFilterResult.class); + + assertThat(promptFilter).isNotNull(); + assertThat(promptFilter.getPromptIndex()).isZero(); + final var contentFilterResults = promptFilter.getContentFilterResults(); + assertThat(contentFilterResults).isNotNull(); + assertFilter(contentFilterResults); + + // delta 1 + assertThat(delta1.getChoices()).hasSize(1); + + // delta 2 assertThat(delta2.getId()).isEqualTo("chatcmpl-A16EvnkgEm6AdxY0NoOmGPjsJucQ1"); assertThat(delta2.getCreated()).isEqualTo(1724825677); assertThat(delta2.getModel()).isEqualTo("gpt-35-turbo"); - assertThat(delta2.getObject()).isEqualTo("chat.completion.chunk"); - assertThat(delta2.getUsage()).isNull(); - assertThat(delta2.getPromptFilterResults()).isNull(); + assertThat(delta2.getObject()).isEqualTo(CHAT_COMPLETION_CHUNK); + assertThat(delta2.getCustomField("usage")).isNull(); + assertThat(delta2.getCustomFieldNames()).doesNotContain("prompt_filter_results"); + assertThat(delta2.getChoices()).hasSize(1); final var choices2 = delta2.getChoices().get(0); - assertThat(choices2.getIndex()).isEqualTo(0); + assertThat(choices2.getIndex()).isZero(); assertThat(choices2.getFinishReason()).isNull(); - assertThat(choices2.getMessage()).isNotNull(); - // the role is only defined in delta 1, but it defaults to "assistant" for all deltas - assertThat(choices2.getMessage().getRole()).isEqualTo("assistant"); - assertThat(choices2.getMessage().getContent()).isEqualTo("Sure"); - assertThat(choices2.getMessage().getToolCalls()).isNull(); - final var filter2 = choices2.getContentFilterResults(); + assertThat(choices2.getDelta()).isNotNull(); + // the role is only defined in delta 1 + assertThat(choices2.getDelta().getRole()).isNull(); + assertThat(choices2.getDelta().getContent()).isEqualTo("Sure"); + assertThat(choices2.getDelta().getToolCalls()).isNotNull().isEmpty(); + final Map filter2raw = (Map) choices2.getCustomField("content_filter_results"); + final var filter2 = MAPPER.convertValue(filter2raw, ContentFilterPromptResults.class); assertFilter(filter2); - final var delta3 = deltaList.get(3); - assertThat(delta3.getDeltaContent()).isEqualTo("!"); - - final var delta4Choice = deltaList.get(4).getChoices().get(0); - assertThat(delta4Choice.getFinishReason()).isEqualTo("stop"); - assertThat(delta4Choice.getMessage()).isNotNull(); - // the role is only defined in delta 1, but it defaults to "assistant" for all deltas - assertThat(delta4Choice.getMessage().getRole()).isEqualTo("assistant"); - assertThat(delta4Choice.getMessage().getContent()).isNull(); - assertThat(delta4Choice.getMessage().getToolCalls()).isNull(); - assertThat(totalOutput.getChoices()).hasSize(1); - final var choice = totalOutput.getChoices().get(0); - assertThat(choice.getFinishReason()).isEqualTo("stop"); - assertFilter(choice.getContentFilterResults()); - assertThat(choice.getFinishReason()).isEqualTo("stop"); - assertThat(choice.getMessage()).isNotNull(); - assertThat(choice.getMessage().getRole()).isEqualTo("assistant"); - assertThat(choice.getMessage().getContent()).isEqualTo("Sure!"); - assertThat(choice.getMessage().getToolCalls()).isNull(); - assertThat(totalOutput.getId()).isEqualTo("chatcmpl-A16EvnkgEm6AdxY0NoOmGPjsJucQ1"); - assertThat(totalOutput.getCreated()).isEqualTo(1724825677); - assertThat(totalOutput.getModel()).isEqualTo("gpt-35-turbo"); - assertThat(totalOutput.getObject()).isEqualTo("chat.completion.chunk"); - final var totalUsage = totalOutput.getUsage(); - assertThat(totalUsage).isNotNull(); - assertThat(totalUsage.getCompletionTokens()).isEqualTo(607); - assertThat(totalUsage.getPromptTokens()).isEqualTo(21); - assertThat(totalUsage.getTotalTokens()).isEqualTo(628); - assertThat(totalOutput.getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); - assertThat(totalOutput.getPromptFilterResults()).isNotNull(); - assertFilter(totalOutput.getPromptFilterResults().get(0).getContentFilterResults()); + // delta 3 + + assertThat(delta3.getChoices()).hasSize(1); + assertThat(deltaList.get(3).getDeltaContent()).isEqualTo("!"); + + // delta 4 + assertThat(delta4.getChoices()).hasSize(1); + final var delta4Choice = delta4.getChoices().get(0); + assertThat(delta4Choice.getFinishReason()).isEqualTo(STOP); + assertThat(delta4Choice.getDelta().getContent()).isNull(); + // the role is only defined in delta 1 + assertThat(delta4Choice.getDelta().getRole()).isNull(); + assertThat(delta4Choice.getDelta().getContent()).isNull(); + assertThat(delta4Choice.getDelta().getToolCalls()).isEmpty(); + assertThat(delta4.getChoices()).hasSize(1); + final var choice = delta4.getChoices().get(0); + assertThat(choice.getFinishReason()).isEqualTo(STOP); + final Map filterRaw = (Map) choice.getCustomField("content_filter_results"); + assertThat(filterRaw).isEmpty(); + assertThat(choice.getDelta()).isNotNull(); + assertThat(choice.getDelta().getRole()).isNull(); + assertThat(choice.getDelta().getContent()).isNull(); + assertThat(choice.getDelta().getToolCalls()).isNotNull().isEmpty(); + assertThat(delta4.getId()).isEqualTo("chatcmpl-A16EvnkgEm6AdxY0NoOmGPjsJucQ1"); + assertThat(delta4.getCreated()).isEqualTo(1724825677); + assertThat(delta4.getModel()).isEqualTo("gpt-35-turbo"); + assertThat(delta4.getObject()).isEqualTo(CHAT_COMPLETION_CHUNK); + assertThat(choice.getCustomField("content_filter_results")).asInstanceOf(MAP).isEmpty(); + assertThat(delta4.getSystemFingerprint()).isEqualTo("fp_e49e4201a9"); + assertThat(delta4.getCustomFieldNames()).doesNotContain("prompt_filter_results"); } Mockito.verify(inputStream, times(1)).close(); } } - void assertFilter(OpenAiContentFilterPromptResults filter) { + void assertFilter(ContentFilterPromptResults filter) { assertThat(filter).isNotNull(); assertThat(filter.getHate()).isNotNull(); assertThat(filter.getHate().isFiltered()).isFalse(); - assertThat(filter.getHate().getSeverity()).isEqualTo(SAFE); + assertThat(filter.getHate().getSeverity().getValue()).isEqualTo("safe"); assertThat(filter.getSelfHarm()).isNotNull(); assertThat(filter.getSelfHarm().isFiltered()).isFalse(); - assertThat(filter.getSelfHarm().getSeverity()).isEqualTo(SAFE); + assertThat(filter.getSelfHarm().getSeverity().getValue()).isEqualTo("safe"); assertThat(filter.getSexual()).isNotNull(); assertThat(filter.getSexual().isFiltered()).isFalse(); - assertThat(filter.getSexual().getSeverity()).isEqualTo(SAFE); + assertThat(filter.getSexual().getSeverity().getValue()).isEqualTo("safe"); assertThat(filter.getViolence()).isNotNull(); assertThat(filter.getViolence().isFiltered()).isFalse(); - assertThat(filter.getViolence().getSeverity()).isEqualTo(SAFE); + assertThat(filter.getViolence().getSeverity().getValue()).isEqualTo("safe"); assertThat(filter.getJailbreak()).isNull(); assertThat(filter.getProfanity()).isNull(); assertThat(filter.getError()).isNull(); diff --git a/pom.xml b/pom.xml index 78461f2cf..8601727bc 100644 --- a/pom.xml +++ b/pom.xml @@ -532,6 +532,7 @@ https://gitbox.apache.org/repos/asf?p=maven-pmd-plugin.git;a=blob_plain;f=src/ma com/sap/ai/sdk/core/client/* com/sap/ai/sdk/core/model/* + com/sap/ai/sdk/foundationmodels/openai/model2/* com/sap/ai/sdk/orchestration/model/* @@ -575,6 +576,7 @@ https://gitbox.apache.org/repos/asf?p=maven-pmd-plugin.git;a=blob_plain;f=src/ma com/sap/ai/sdk/core/client/* com/sap/ai/sdk/core/model/* com/sap/ai/sdk/orchestration/model/* + com/sap/ai/sdk/foundationmodels/openai/model2/* com/sap/ai/sdk/app/**/* diff --git a/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OpenAiController.java b/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OpenAiController.java index 26ea351bc..53aef5e29 100644 --- a/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OpenAiController.java +++ b/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OpenAiController.java @@ -1,9 +1,6 @@ package com.sap.ai.sdk.app.controllers; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import com.sap.ai.sdk.app.services.OpenAiService; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionOutput; import com.sap.cloud.sdk.cloudplatform.thread.ThreadContextExecutors; import java.io.IOException; import java.util.Arrays; @@ -26,6 +23,11 @@ public class OpenAiController { @Autowired private OpenAiService service; + /** + * Chat request to OpenAI + * + * @return a ResponseEntity with the response content + */ @GetMapping("/chatCompletion") @Nonnull Object chatCompletion( @@ -37,6 +39,11 @@ Object chatCompletion( return response.getContent(); } + /** + * Asynchronous stream of an OpenAI chat request + * + * @return the emitter that streams the assistant message response + */ @SuppressWarnings("unused") // The end-to-end test doesn't use this method @GetMapping("/streamChatCompletionDeltas") @Nonnull @@ -46,14 +53,10 @@ ResponseEntity streamChatCompletionDeltas() { final var emitter = new ResponseBodyEmitter(); final Runnable consumeStream = () -> { - final var totalOutput = new OpenAiChatCompletionOutput(); // try-with-resources ensures the stream is closed try (stream) { - stream - .peek(totalOutput::addDelta) - .forEach(delta -> send(emitter, delta.getDeltaContent())); + stream.forEach(delta -> send(emitter, delta.getDeltaContent())); } finally { - send(emitter, "\n\n-----Total Output-----\n\n" + objectToJson(totalOutput)); emitter.complete(); } }; @@ -63,6 +66,11 @@ ResponseEntity streamChatCompletionDeltas() { return ResponseEntity.ok().contentType(MediaType.TEXT_EVENT_STREAM).body(emitter); } + /** + * Asynchronous stream of an OpenAI chat request + * + * @return the emitter that streams the assistant message response + */ @SuppressWarnings("unused") // The end-to-end test doesn't use this method @GetMapping("/streamChatCompletion") @Nonnull @@ -101,19 +109,10 @@ public static void send(@Nonnull final ResponseBodyEmitter emitter, @Nonnull fin } /** - * Convert an object to JSON + * Chat request to OpenAI with an image * - * @param obj The object to convert - * @return The JSON representation of the object + * @return a ResponseEntity with the response content */ - private static String objectToJson(@Nonnull final Object obj) { - try { - return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(obj); - } catch (final JsonProcessingException ignored) { - return "Could not parse object to JSON"; - } - } - @GetMapping("/chatCompletionImage") @Nonnull Object chatCompletionImage( @@ -124,9 +123,14 @@ Object chatCompletionImage( if ("json".equals(format)) { return response; } - return response.getContent(); + return response.getChoices().get(0).getMessage(); } + /** + * Chat request to OpenAI with a tool. + * + * @return a ResponseEntity with the response content + */ @GetMapping("/chatCompletionTool") @Nonnull Object chatCompletionTools( @@ -139,12 +143,23 @@ Object chatCompletionTools( return response.getContent(); } + /** + * Get the embedding of a text + * + * @return a ResponseEntity with the response content + */ @GetMapping("/embedding") @Nonnull Object embedding() { return service.embedding("Hello world"); } + /** + * Chat request to OpenAI filtering by resource group + * + * @param resourceGroup The resource group to use + * @return a ResponseEntity with the response content + */ @GetMapping("/chatCompletion/{resourceGroup}") @Nonnull Object chatCompletionWithResource( diff --git a/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/OpenAiService.java b/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/OpenAiService.java index 5d5f26209..1fdb9be7a 100644 --- a/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/OpenAiService.java +++ b/sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/OpenAiService.java @@ -3,18 +3,33 @@ import static com.sap.ai.sdk.foundationmodels.openai.OpenAiModel.GPT_35_TURBO; import static com.sap.ai.sdk.foundationmodels.openai.OpenAiModel.GPT_4O; import static com.sap.ai.sdk.foundationmodels.openai.OpenAiModel.TEXT_EMBEDDING_ADA_002; -import static com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionTool.ToolType.FUNCTION; +import static com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestMessageContentPartImage.TypeEnum.IMAGE_URL; +import static com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestMessageContentPartImageImageUrl.DetailEnum.HIGH; +import static com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestMessageContentPartText.TypeEnum.TEXT; +import static com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestUserMessage.RoleEnum.USER; +import static com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionTool.TypeEnum.*; import com.sap.ai.sdk.core.AiCoreService; +import com.sap.ai.sdk.foundationmodels.openai.OpenAiChatCompletionDelta; +import com.sap.ai.sdk.foundationmodels.openai.OpenAiChatCompletionRequest; +import com.sap.ai.sdk.foundationmodels.openai.OpenAiChatCompletionResponse; import com.sap.ai.sdk.foundationmodels.openai.OpenAiClient; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionDelta; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionFunction; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionOutput; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionParameters; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionTool; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatMessage; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiEmbeddingOutput; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiEmbeddingParameters; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionNamedToolChoice; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionNamedToolChoiceFunction; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestMessageContentPartImage; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestMessageContentPartImageImageUrl; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestMessageContentPartText; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestUserMessage; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionRequestUserMessageContent; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionTool; +import com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionToolChoiceOption; +import com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionRequest; +import com.sap.ai.sdk.foundationmodels.openai.model2.CreateChatCompletionResponse; +import com.sap.ai.sdk.foundationmodels.openai.model2.EmbeddingsCreate200Response; +import com.sap.ai.sdk.foundationmodels.openai.model2.EmbeddingsCreateRequest; +import com.sap.ai.sdk.foundationmodels.openai.model2.EmbeddingsCreateRequestInput; +import com.sap.ai.sdk.foundationmodels.openai.model2.FunctionObject; +import java.net.URI; import java.util.List; import java.util.Map; import java.util.stream.Stream; @@ -34,7 +49,7 @@ public class OpenAiService { * @return the assistant message response */ @Nonnull - public OpenAiChatCompletionOutput chatCompletion(@Nonnull final String prompt) { + public OpenAiChatCompletionResponse chatCompletion(@Nonnull final String prompt) { return OpenAiClient.forModel(GPT_35_TURBO).chatCompletion(prompt); } @@ -47,8 +62,19 @@ public OpenAiChatCompletionOutput chatCompletion(@Nonnull final String prompt) { public Stream streamChatCompletionDeltas( @Nonnull final String message) { final var request = - new OpenAiChatCompletionParameters() - .addMessages(new OpenAiChatMessage.OpenAiChatUserMessage().addText(message)); + new CreateChatCompletionRequest() + .addMessagesItem( + new ChatCompletionRequestUserMessage() + .role(USER) + .content( + ChatCompletionRequestUserMessageContent.create( + List.of( + new ChatCompletionRequestMessageContentPartText() + .text(message) + .type(TEXT))))) + .tools(null) + .functions(null) + .parallelToolCalls(null); return OpenAiClient.forModel(GPT_35_TURBO).streamChatCompletionDeltas(request); } @@ -72,15 +98,27 @@ public Stream streamChatCompletion(@Nonnull final String message) { * @return the assistant message response */ @Nonnull - public OpenAiChatCompletionOutput chatCompletionImage(@Nonnull final String linkToImage) { + public CreateChatCompletionResponse chatCompletionImage(@Nonnull final String linkToImage) { + final var partText = + new ChatCompletionRequestMessageContentPartText() + .type(TEXT) + .text("Describe the following image."); + final var partImageUrl = + new ChatCompletionRequestMessageContentPartImageImageUrl() + .url(URI.create(linkToImage)) + .detail(HIGH); + final var partImage = + new ChatCompletionRequestMessageContentPartImage().type(IMAGE_URL).imageUrl(partImageUrl); + final var userMessage = + new ChatCompletionRequestUserMessage() + .role(USER) + .content(ChatCompletionRequestUserMessageContent.create(List.of(partText, partImage))); final var request = - new OpenAiChatCompletionParameters() - .addMessages( - new OpenAiChatMessage.OpenAiChatUserMessage() - .addText("Describe the following image.") - .addImage( - linkToImage, - OpenAiChatMessage.OpenAiChatUserMessage.ImageDetailLevel.HIGH)); + new CreateChatCompletionRequest() + .addMessagesItem(userMessage) + .functions(null) + .tools(null) + .parallelToolCalls(null); return OpenAiClient.forModel(GPT_4O).chatCompletion(request); } @@ -88,25 +126,31 @@ public OpenAiChatCompletionOutput chatCompletionImage(@Nonnull final String link /** * Chat request to OpenAI with a tool. * - * @param prompt The prompt to send to the assistant + * @param description of the function to be sent to the assistant * @return the assistant message response */ @Nonnull - public OpenAiChatCompletionOutput chatCompletionTools(@Nonnull final String prompt) { - final var question = - "A pair of rabbits is placed in a field. Each month, every pair produces one new pair, starting from the second month. How many rabbits will there be after 12 months?"; - final var par = Map.of("type", "object", "properties", Map.of("N", Map.of("type", "integer"))); - final var function = - new OpenAiChatCompletionFunction() - .setName("fibonacci") - .setDescription(prompt) - .setParameters(par); - final var tool = new OpenAiChatCompletionTool().setType(FUNCTION).setFunction(function); - final var request = - new OpenAiChatCompletionParameters() - .addMessages(new OpenAiChatMessage.OpenAiChatUserMessage().addText(question)) - .setTools(List.of(tool)) - .setToolChoiceFunction("fibonacci"); + public OpenAiChatCompletionResponse chatCompletionTools(@Nonnull final String description) { + var function = + new FunctionObject() + .name("fibonacci") + .description(description) + .parameters( + Map.of("type", "object", "properties", Map.of("N", Map.of("type", "integer")))); + + var tool = new ChatCompletionTool().type(FUNCTION).function(function); + + var toolChoice = + ChatCompletionToolChoiceOption.create( + new ChatCompletionNamedToolChoice() + .type(ChatCompletionNamedToolChoice.TypeEnum.FUNCTION) + .function(new ChatCompletionNamedToolChoiceFunction().name("fibonacci"))); + + var request = + new OpenAiChatCompletionRequest( + "A pair of rabbits is placed in a field. Each month, every pair produces one new pair, starting from the second month. How many rabbits will there be after 12 months?") + .tools(List.of(tool)) + .toolChoice(toolChoice); return OpenAiClient.forModel(GPT_35_TURBO).chatCompletion(request); } @@ -118,8 +162,9 @@ public OpenAiChatCompletionOutput chatCompletionTools(@Nonnull final String prom * @return the embedding response */ @Nonnull - public OpenAiEmbeddingOutput embedding(@Nonnull final String input) { - final var request = new OpenAiEmbeddingParameters().setInput(input); + public EmbeddingsCreate200Response embedding(@Nonnull final String input) { + final var request = + new EmbeddingsCreateRequest().input(EmbeddingsCreateRequestInput.create(input)); return OpenAiClient.forModel(TEXT_EMBEDDING_ADA_002).embedding(request); } @@ -132,7 +177,7 @@ public OpenAiEmbeddingOutput embedding(@Nonnull final String input) { * @return the assistant message response */ @Nonnull - public OpenAiChatCompletionOutput chatCompletionWithResource( + public OpenAiChatCompletionResponse chatCompletionWithResource( @Nonnull final String resourceGroup, @Nonnull final String prompt) { final var destination = diff --git a/sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/OpenAiTest.java b/sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/OpenAiTest.java index ec07fb037..6f33e4f4a 100644 --- a/sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/OpenAiTest.java +++ b/sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/OpenAiTest.java @@ -1,14 +1,17 @@ package com.sap.ai.sdk.app.controllers; import static com.sap.ai.sdk.foundationmodels.openai.OpenAiModel.GPT_35_TURBO; +import static com.sap.ai.sdk.foundationmodels.openai.model2.ChatCompletionResponseMessageRole.ASSISTANT; import static org.assertj.core.api.Assertions.assertThat; +import com.fasterxml.jackson.databind.ObjectMapper; import com.sap.ai.sdk.app.services.OpenAiService; +import com.sap.ai.sdk.foundationmodels.openai.OpenAiChatCompletionRequest; import com.sap.ai.sdk.foundationmodels.openai.OpenAiClient; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionOutput; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatCompletionParameters; -import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiChatMessage.OpenAiChatUserMessage; +import com.sap.ai.sdk.foundationmodels.openai.OpenAiMessage; +import com.sap.ai.sdk.foundationmodels.openai.model2.CompletionUsage; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -26,9 +29,8 @@ void setUp() { void chatCompletion() { final var completion = service.chatCompletion("Who is the prettiest"); - final var message = completion.getChoices().get(0).getMessage(); - assertThat(message.getRole()).isEqualTo("assistant"); - assertThat(message.getContent()).isNotEmpty(); + assertThat(completion.getChoice().getMessage().getRole()).isEqualTo(ASSISTANT); + assertThat(completion.getContent()).isNotEmpty(); } @Test @@ -38,24 +40,24 @@ void chatCompletionImage() { "https://upload.wikimedia.org/wikipedia/commons/thumb/5/59/SAP_2011_logo.svg/440px-SAP_2011_logo.svg.png"); final var message = completion.getChoices().get(0).getMessage(); - assertThat(message.getRole()).isEqualTo("assistant"); + assertThat(message.getRole()).isEqualTo(ASSISTANT); assertThat(message.getContent()).isNotEmpty(); } @Test void streamChatCompletion() { - final var request = - new OpenAiChatCompletionParameters() - .addMessages(new OpenAiChatUserMessage().addText("Who is the prettiest?")); + final var userMessage = OpenAiMessage.user("Who is the prettiest?"); + final var prompt = new OpenAiChatCompletionRequest(userMessage); - final var totalOutput = new OpenAiChatCompletionOutput(); + final var totalOutput = new AtomicReference(); final var filledDeltaCount = new AtomicInteger(0); OpenAiClient.forModel(GPT_35_TURBO) - .streamChatCompletionDeltas(request) - .peek(totalOutput::addDelta) + .streamChatCompletionDeltas(prompt) // foreach consumes all elements, closing the stream at the end .forEach( delta -> { + final var usage = delta.getCompletionUsage(new ObjectMapper()); + totalOutput.compareAndExchange(null, usage); final String deltaContent = delta.getDeltaContent(); log.info("delta: {}", delta); if (!deltaContent.isEmpty()) { @@ -67,10 +69,9 @@ void streamChatCompletion() { // see OpenAiChatCompletionDelta#getDeltaContent assertThat(filledDeltaCount.get()).isGreaterThan(0); - assertThat(totalOutput.getChoices()).isNotEmpty(); - assertThat(totalOutput.getChoices().get(0).getMessage().getContent()).isNotEmpty(); - assertThat(totalOutput.getPromptFilterResults()).isNotNull(); - assertThat(totalOutput.getChoices().get(0).getContentFilterResults()).isNotNull(); + assertThat(totalOutput.get().getTotalTokens()).isGreaterThan(0); + assertThat(totalOutput.get().getPromptTokens()).isEqualTo(14); + assertThat(totalOutput.get().getCompletionTokens()).isGreaterThan(0); } @Test @@ -78,8 +79,8 @@ void chatCompletionTools() { final var completion = service.chatCompletionTools("Calculate the Fibonacci number for given sequence index."); - final var message = completion.getChoices().get(0).getMessage(); - assertThat(message.getRole()).isEqualTo("assistant"); + final var message = completion.getChoice().getMessage(); + assertThat(message.getRole()).isEqualTo(ASSISTANT); assertThat(message.getToolCalls()).isNotNull(); assertThat(message.getToolCalls().get(0).getFunction().getName()).isEqualTo("fibonacci"); } @@ -98,8 +99,7 @@ void chatCompletionWithResource() { final var completion = service.chatCompletionWithResource("ai-sdk-java-e2e", "Where is the nearest coffee shop?"); - final var message = completion.getChoices().get(0).getMessage(); - assertThat(message.getRole()).isEqualTo("assistant"); - assertThat(message.getContent()).isNotEmpty(); + assertThat(completion.getChoice().getMessage().getRole()).isEqualTo(ASSISTANT); + assertThat(completion.getContent()).isNotEmpty(); } }