diff --git a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/OpenAIServiceVersion.java b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/OpenAIServiceVersion.java index 8d15584caf4d..6a0186a342c1 100644 --- a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/OpenAIServiceVersion.java +++ b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/OpenAIServiceVersion.java @@ -15,7 +15,10 @@ public enum OpenAIServiceVersion implements ServiceVersion { V2023_05_15("2023-05-15"), /** Enum value 2023-06-01-preview. */ - V2023_06_01_PREVIEW("2023-06-01-preview"); + V2023_06_01_PREVIEW("2023-06-01-preview"), + + /** Enum value 2023-07-01-preview. */ + V2023_07_01_PREVIEW("2023-07-01-preview"); private final String version; @@ -35,6 +38,6 @@ public String getVersion() { * @return The latest {@link OpenAIServiceVersion}. */ public static OpenAIServiceVersion getLatest() { - return V2023_06_01_PREVIEW; + return V2023_07_01_PREVIEW; } } diff --git a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/implementation/OpenAIClientImpl.java b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/implementation/OpenAIClientImpl.java index 788bf745dcae..914334796541 100644 --- a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/implementation/OpenAIClientImpl.java +++ b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/implementation/OpenAIClientImpl.java @@ -546,7 +546,7 @@ public Response getEmbeddingsWithResponse( * int (Required) * ] * } - * finish_reason: String(stop/length/content_filter) (Required) + * finish_reason: String(stop/length/content_filter/function_call) (Required) * } * ] * usage (Required): { @@ -643,7 +643,7 @@ public Mono> getCompletionsWithResponseAsync( * int (Required) * ] * } - * finish_reason: String(stop/length/content_filter) (Required) + * finish_reason: String(stop/length/content_filter/function_call) (Required) * } * ] * usage (Required): { @@ -689,10 +689,23 @@ public Response getCompletionsWithResponse( * { * messages (Required): [ * (Required){ - * role: String(system/assistant/user) (Required) + * role: String(system/assistant/user/function) (Required) * content: String (Optional) + * name: String (Optional) + * function_call (Optional): { + * name: String (Required) + * arguments: String (Required) + * } + * } + * ] + * functions (Optional): [ + * (Optional){ + * name: String (Required) + * description: String (Optional) + * parameters: Object (Optional) * } * ] + * function_call: FunctionCallModelBase (Optional) * max_tokens: Integer (Optional) * temperature: Double (Optional) * top_p: Double (Optional) @@ -720,11 +733,16 @@ public Response getCompletionsWithResponse( * choices (Required): [ * (Required){ * message (Optional): { - * role: String(system/assistant/user) (Required) + * role: String(system/assistant/user/function) (Required) * content: String (Optional) + * name: String (Optional) + * function_call (Optional): { + * name: String (Required) + * arguments: String (Required) + * } * } * index: int (Required) - * finish_reason: String(stop/length/content_filter) (Required) + * finish_reason: String(stop/length/content_filter/function_call) (Required) * delta (Optional): (recursive schema, see delta above) * } * ] @@ -774,10 +792,23 @@ public Mono> getChatCompletionsWithResponseAsync( * { * messages (Required): [ * (Required){ - * role: String(system/assistant/user) (Required) + * role: String(system/assistant/user/function) (Required) * content: String (Optional) + * name: String (Optional) + * function_call (Optional): { + * name: String (Required) + * arguments: String (Required) + * } + * } + * ] + * functions (Optional): [ + * (Optional){ + * name: String (Required) + * description: String (Optional) + * parameters: Object (Optional) * } * ] + * function_call: FunctionCallModelBase (Optional) * max_tokens: Integer (Optional) * temperature: Double (Optional) * top_p: Double (Optional) @@ -805,11 +836,16 @@ public Mono> getChatCompletionsWithResponseAsync( * choices (Required): [ * (Required){ * message (Optional): { - * role: String(system/assistant/user) (Required) + * role: String(system/assistant/user/function) (Required) * content: String (Optional) + * name: String (Optional) + * function_call (Optional): { + * name: String (Required) + * arguments: String (Required) + * } * } * index: int (Required) - * finish_reason: String(stop/length/content_filter) (Required) + * finish_reason: String(stop/length/content_filter/function_call) (Required) * delta (Optional): (recursive schema, see delta above) * } * ] diff --git a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatCompletionsOptions.java b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatCompletionsOptions.java index 7df28d9666c7..eaf04039f1d6 100644 --- a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatCompletionsOptions.java +++ b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatCompletionsOptions.java @@ -429,4 +429,71 @@ public ChatCompletionsOptions setModel(String model) { this.model = model; return this; } + + /* + * A list of functions the model may generate JSON inputs for. + */ + @Generated + @JsonProperty(value = "functions") + private List functions; + + /* + * Controls how the model responds to function calls. "none" means the model does not call a function, + * and responds to the end-user. "auto" means the model can pick between an end-user 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. + */ + @Generated + @JsonProperty(value = "function_call") + private FunctionCallModelBase functionCall; + + /** + * Get the functions property: A list of functions the model may generate JSON inputs for. + * + * @return the functions value. + */ + @Generated + public List getFunctions() { + return this.functions; + } + + /** + * Set the functions property: A list of functions the model may generate JSON inputs for. + * + * @param functions the functions value to set. + * @return the ChatCompletionsOptions object itself. + */ + @Generated + public ChatCompletionsOptions setFunctions(List functions) { + this.functions = functions; + return this; + } + + /** + * Get the functionCall property: Controls how the model responds to function calls. "none" means the model does not + * call a function, and responds to the end-user. "auto" means the model can pick between an end-user 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. + * + * @return the functionCall value. + */ + @Generated + public FunctionCallModelBase getFunctionCall() { + return this.functionCall; + } + + /** + * Set the functionCall property: Controls how the model responds to function calls. "none" means the model does not + * call a function, and responds to the end-user. "auto" means the model can pick between an end-user 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. + * + * @param functionCall the functionCall value to set. + * @return the ChatCompletionsOptions object itself. + */ + @Generated + public ChatCompletionsOptions setFunctionCall(FunctionCallModelBase functionCall) { + this.functionCall = functionCall; + return this; + } } diff --git a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatMessage.java b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatMessage.java index 2ad4cfd18b97..2594743f63f7 100644 --- a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatMessage.java +++ b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatMessage.java @@ -68,4 +68,72 @@ public ChatMessage setContent(String content) { this.content = content; return this; } + + /* + * The name of the author of this message. `name` is required if role is `function`, and it should be the name of + * the + * function whose response is in the `content`. May contain a-z, A-Z, 0-9, and underscores, with a maximum length + * of + * 64 characters. + */ + @Generated + @JsonProperty(value = "name") + private String name; + + /* + * The name and arguments of a function that should be called, as generated by the model. + */ + @Generated + @JsonProperty(value = "function_call") + private FunctionCall functionCall; + + /** + * Get the name property: The name of the author of this message. `name` is required if role is `function`, and it + * should be the name of the function whose response is in the `content`. May contain a-z, A-Z, 0-9, and + * underscores, with a maximum length of 64 characters. + * + * @return the name value. + */ + @Generated + public String getName() { + return this.name; + } + + /** + * Set the name property: The name of the author of this message. `name` is required if role is `function`, and it + * should be the name of the function whose response is in the `content`. May contain a-z, A-Z, 0-9, and + * underscores, with a maximum length of 64 characters. + * + * @param name the name value to set. + * @return the ChatMessage object itself. + */ + @Generated + public ChatMessage setName(String name) { + this.name = name; + return this; + } + + /** + * Get the functionCall property: The name and arguments of a function that should be called, as generated by the + * model. + * + * @return the functionCall value. + */ + @Generated + public FunctionCall getFunctionCall() { + return this.functionCall; + } + + /** + * Set the functionCall property: The name and arguments of a function that should be called, as generated by the + * model. + * + * @param functionCall the functionCall value to set. + * @return the ChatMessage object itself. + */ + @Generated + public ChatMessage setFunctionCall(FunctionCall functionCall) { + this.functionCall = functionCall; + return this; + } } diff --git a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatRole.java b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatRole.java index dcf8fe55f839..621ea748768e 100644 --- a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatRole.java +++ b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatRole.java @@ -50,4 +50,7 @@ public static ChatRole fromString(String name) { public static Collection values() { return values(ChatRole.class); } + + /** The role that provides function results for char completions. */ + @Generated public static final ChatRole FUNCTION = fromString("function"); } diff --git a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/CompletionsFinishReason.java b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/CompletionsFinishReason.java index c267098eca5b..b16c05f00c3f 100644 --- a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/CompletionsFinishReason.java +++ b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/CompletionsFinishReason.java @@ -52,4 +52,7 @@ public static CompletionsFinishReason fromString(String name) { public static Collection values() { return values(CompletionsFinishReason.class); } + + /** Completion ended normally, with the model requesting a function to be called. */ + @Generated public static final CompletionsFinishReason FUNCTION_CALL = fromString("function_call"); } diff --git a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionCall.java b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionCall.java new file mode 100644 index 000000000000..0d87182bd586 --- /dev/null +++ b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionCall.java @@ -0,0 +1,67 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.ai.openai.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** The name and arguments of a function that should be called, as generated by the model. */ +@Immutable +public final class FunctionCall { + /* + * The name of the function to call. + */ + @Generated + @JsonProperty(value = "name") + private String name; + + /* + * 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. + */ + @Generated + @JsonProperty(value = "arguments") + private String arguments; + + /** + * Creates an instance of FunctionCall class. + * + * @param name the name value to set. + * @param arguments the arguments value to set. + */ + @Generated + @JsonCreator + public FunctionCall( + @JsonProperty(value = "name") String name, @JsonProperty(value = "arguments") String arguments) { + this.name = name; + this.arguments = arguments; + } + + /** + * Get the name property: The name of the function to call. + * + * @return the name value. + */ + @Generated + public String getName() { + return this.name; + } + + /** + * Get the arguments property: 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 arguments value. + */ + @Generated + public String getArguments() { + return this.arguments; + } +} diff --git a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionCallModelBase.java b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionCallModelBase.java new file mode 100644 index 000000000000..25beabc48f37 --- /dev/null +++ b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionCallModelBase.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.ai.openai.models; + +/** The FunctionCallModelBase model. */ +public abstract class FunctionCallModelBase { + /** Creates an instance of FunctionCallModelBase class. */ + protected FunctionCallModelBase() {} +} diff --git a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionCallPreset.java b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionCallPreset.java new file mode 100644 index 000000000000..e3b693141724 --- /dev/null +++ b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionCallPreset.java @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.ai.openai.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.util.ExpandableStringEnum; +import com.fasterxml.jackson.annotation.JsonCreator; +import java.util.Collection; + +/** + * The collection of predefined behaviors for handling request-provided function information in a chat completions + * operation. + */ +public final class FunctionCallPreset extends ExpandableStringEnum { + /** + * Specifies that the model may either use any of the functions provided in this chat completions request or instead + * return a standard chat completions response as if no functions were provided. + */ + @Generated public static final FunctionCallPreset AUTO = fromString("auto"); + + /** + * Specifies that the model should not respond with a function call and should instead provide a standard chat + * completions response. Response content may still be influenced by the provided function information. + */ + @Generated public static final FunctionCallPreset NONE = fromString("none"); + + /** + * Creates a new instance of FunctionCallPreset value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Generated + @Deprecated + public FunctionCallPreset() {} + + /** + * Creates or finds a FunctionCallPreset from its string representation. + * + * @param name a name to look for. + * @return the corresponding FunctionCallPreset. + */ + @Generated + @JsonCreator + public static FunctionCallPreset fromString(String name) { + return fromString(name, FunctionCallPreset.class); + } + + /** + * Gets known FunctionCallPreset values. + * + * @return known FunctionCallPreset values. + */ + @Generated + public static Collection values() { + return values(FunctionCallPreset.class); + } +} diff --git a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionCallPresetFunctionCallModel.java b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionCallPresetFunctionCallModel.java new file mode 100644 index 000000000000..9bcabdf0def9 --- /dev/null +++ b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionCallPresetFunctionCallModel.java @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.ai.openai.models; + +import com.azure.core.annotation.Immutable; +import com.fasterxml.jackson.annotation.JsonValue; + +/** The FunctionCallPresetFunctionCallModel model. */ +@Immutable +public final class FunctionCallPresetFunctionCallModel extends FunctionCallModelBase { + private final FunctionCallPreset value; + + /** + * Creates an instance of FunctionCallPresetFunctionCallModel class. + * + * @param value the value. + */ + public FunctionCallPresetFunctionCallModel(FunctionCallPreset value) { + this.value = value; + } + + /** + * Gets the value. + * + * @return the value. + */ + @JsonValue + public FunctionCallPreset getValue() { + return this.value; + } +} diff --git a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionDefinition.java b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionDefinition.java new file mode 100644 index 000000000000..379a5adb4eba --- /dev/null +++ b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionDefinition.java @@ -0,0 +1,105 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.ai.openai.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.annotation.Generated; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The definition of a caller-specified function that chat completions may invoke in response to matching user input. + */ +@Fluent +public final class FunctionDefinition { + /* + * The name of the function to be called. + */ + @Generated + @JsonProperty(value = "name") + private String name; + + /* + * A description of what the function does. The model will use this description when selecting the function and + * interpreting its parameters. + */ + @Generated + @JsonProperty(value = "description") + private String description; + + /* + * The parameters the functions accepts, described as a JSON Schema object. + */ + @Generated + @JsonProperty(value = "parameters") + private Object parameters; + + /** + * Creates an instance of FunctionDefinition class. + * + * @param name the name value to set. + */ + @Generated + @JsonCreator + public FunctionDefinition(@JsonProperty(value = "name") String name) { + this.name = name; + } + + /** + * Get the name property: The name of the function to be called. + * + * @return the name value. + */ + @Generated + public String getName() { + return this.name; + } + + /** + * Get the description property: A description of what the function does. The model will use this description when + * selecting the function and interpreting its parameters. + * + * @return the description value. + */ + @Generated + public String getDescription() { + return this.description; + } + + /** + * Set the description property: A description of what the function does. The model will use this description when + * selecting the function and interpreting its parameters. + * + * @param description the description value to set. + * @return the FunctionDefinition object itself. + */ + @Generated + public FunctionDefinition setDescription(String description) { + this.description = description; + return this; + } + + /** + * Get the parameters property: The parameters the functions accepts, described as a JSON Schema object. + * + * @return the parameters value. + */ + @Generated + public Object getParameters() { + return this.parameters; + } + + /** + * Set the parameters property: The parameters the functions accepts, described as a JSON Schema object. + * + * @param parameters the parameters value to set. + * @return the FunctionDefinition object itself. + */ + @Generated + public FunctionDefinition setParameters(Object parameters) { + this.parameters = parameters; + return this; + } +} diff --git a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionName.java b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionName.java new file mode 100644 index 000000000000..2db5ead3f1ce --- /dev/null +++ b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionName.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.ai.openai.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A structure that specifies the exact name of a specific, request-provided function to use when processing a chat + * completions operation. + */ +@Immutable +public final class FunctionName { + /* + * The name of the function to call. + */ + @Generated + @JsonProperty(value = "name") + private String name; + + /** + * Creates an instance of FunctionName class. + * + * @param name the name value to set. + */ + @Generated + @JsonCreator + public FunctionName(@JsonProperty(value = "name") String name) { + this.name = name; + } + + /** + * Get the name property: The name of the function to call. + * + * @return the name value. + */ + @Generated + public String getName() { + return this.name; + } +} diff --git a/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionNameFunctionCallModel.java b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionNameFunctionCallModel.java new file mode 100644 index 000000000000..df40077ac3ea --- /dev/null +++ b/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/FunctionNameFunctionCallModel.java @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) AutoRest Code Generator. + +package com.azure.ai.openai.models; + +import com.azure.core.annotation.Immutable; +import com.fasterxml.jackson.annotation.JsonValue; + +/** The FunctionNameFunctionCallModel model. */ +@Immutable +public final class FunctionNameFunctionCallModel extends FunctionCallModelBase { + private final FunctionName value; + + /** + * Creates an instance of FunctionNameFunctionCallModel class. + * + * @param value the value. + */ + public FunctionNameFunctionCallModel(FunctionName value) { + this.value = value; + } + + /** + * Gets the value. + * + * @return the value. + */ + @JsonValue + public FunctionName getValue() { + return this.value; + } +} diff --git a/sdk/openai/azure-ai-openai/tsp-location.yaml b/sdk/openai/azure-ai-openai/tsp-location.yaml index 4eba2fde995a..7683ed4fc521 100644 --- a/sdk/openai/azure-ai-openai/tsp-location.yaml +++ b/sdk/openai/azure-ai-openai/tsp-location.yaml @@ -1,5 +1,5 @@ -directory: specification/cognitiveservices/OpenAI.Inference -additionalDirectories: - - specification/cognitiveservices/OpenAI.Authoring -commit: db23874c147db173933476b3b352cbf12abe84a9 +commit: 05aa13f0a2433b0c15627cbb668a12b4e70aa7d0 repo: Azure/azure-rest-api-specs +additionalDirectories: [] +directory: specification/cognitiveservices/OpenAI.Inference +