Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAI Functions #35748

Merged
merged 26 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cdee6e0
Added preliminary support for OpenAI Functions
jpalvarezl Jul 5, 2023
cc124c2
WIP: serialization still fails
jpalvarezl Jul 7, 2023
f492635
Tests are passing, requests go through to nonAzure OAI
jpalvarezl Jul 8, 2023
b87df26
Moved gened classes with polymorphism to impl package
jpalvarezl Jul 8, 2023
0dfb11f
Added assertion for function call
jpalvarezl Jul 10, 2023
0573d73
Added test for usage of function not supplied in the request
jpalvarezl Jul 10, 2023
10c4696
Renamed test for clarity
jpalvarezl Jul 10, 2023
2bbb6ff
Addressed most of the PR comments
jpalvarezl Jul 10, 2023
c9f4280
Added sync version of the tests
jpalvarezl Jul 10, 2023
71e48bf
Renamed runner method
jpalvarezl Jul 10, 2023
a1340cb
Added Azure sync/async tests
jpalvarezl Jul 10, 2023
00d6762
Added docs for FunctionCall
jpalvarezl Jul 10, 2023
72101cb
Removed unused files from samples package
jpalvarezl Jul 10, 2023
abe5ff3
Preparing release notes
jpalvarezl Jul 10, 2023
c9a4fde
Renamed static member
jpalvarezl Jul 11, 2023
14a12af
Moved the exception handling one level up in the call stack
jpalvarezl Jul 11, 2023
aed004b
code regened
jpalvarezl Jul 11, 2023
a5eada6
Moved custom models under their own package
jpalvarezl Jul 12, 2023
2619f35
Updated test records
jpalvarezl Jul 12, 2023
19a9c2c
Addressed most of the style checks
jpalvarezl Jul 12, 2023
5334715
removed unused import
jpalvarezl Jul 12, 2023
671cf53
Merge branch 'main' into jpalvarezl/aoai_functions
jpalvarezl Jul 13, 2023
1411a63
Renamed type
jpalvarezl Jul 13, 2023
d827c17
Added spell checker exception for DALL-E
jpalvarezl Jul 13, 2023
4eca3e9
Updated commit hash and re-ran code gen
jpalvarezl Jul 13, 2023
3dff5f4
Renamed param
jpalvarezl Jul 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/openai/azure-ai-openai/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/openai/azure-ai-openai",
"Tag": "java/openai/azure-ai-openai_2a6e71fe2e"
"Tag": "java/openai/azure-ai-openai_94811d7537"
}
1 change: 1 addition & 0 deletions sdk/openai/azure-ai-openai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
--add-exports com.azure.core/com.azure.core.implementation.util=ALL-UNNAMED
--add-opens com.azure.ai.openai/com.azure.ai.openai=ALL-UNNAMED
--add-opens com.azure.ai.openai/com.azure.ai.openai.implementation=com.fasterxml.jackson.databind
--add-opens com.azure.ai.openai/com.azure.ai.openai.functions=com.fasterxml.jackson.databind
</javaModulesSurefireArgLine>
<jacoco.skip>true</jacoco.skip>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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.implementation;

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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.implementation;


import com.fasterxml.jackson.annotation.JsonSubTypes;

@JsonSubTypes({
@JsonSubTypes.Type(name="preset", value = FunctionCallPresetFunctionCallModel.class),
@JsonSubTypes.Type(name="custom", value = FunctionNameFunctionCallModel.class)
})
/** The FunctionCallModelBase model. */
public class FunctionCallModelBase {
/** Creates an instance of FunctionCallModelBase class. */
protected FunctionCallModelBase() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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.implementation;

import com.azure.core.annotation.Generated;
import com.azure.core.util.ExpandableStringEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import java.util.Collection;

/** Preset values to control how the mode; responds to function calls. */
public final class FunctionCallPreset extends ExpandableStringEnum<FunctionCallPreset> {
/** Means the model can pick between an end-user or calling a function. */
@Generated public static final FunctionCallPreset AUTO = fromString("auto");

/** Means the model does not call a function, and responds to the end-user. */
@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<FunctionCallPreset> values() {
return values(FunctionCallPreset.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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.implementation;

import com.azure.core.annotation.Immutable;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;

/** The FunctionCallPresetFunctionCallModel model. */
@Immutable
@JsonTypeName("preset")
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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// 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.implementation;

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 function that can be called by the model. See the [guide](/docs/guides/gpt/function-calling) for
* examples.
*/
@Fluent
public final class FunctionDefinition {
/*
* 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.
*/
@Generated
@JsonProperty(value = "name")
private String name;

/*
* The description of what the function does.
*/
@Generated
@JsonProperty(value = "description")
private String description;

/*
* The parameters the functions accepts, described as a JSON Schema object.
* See the [guide](/docs/guides/gpt/function-calling) for examples, and the [JSON Schema
* reference](https://json-schema.org/understanding-json-schema/)
* for documentation about the format.
*/
@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. Must be a-z, A-Z, 0-9, or contain underscores and
* dashes, with a maximum length of 64.
*
* @return the name value.
*/
@Generated
public String getName() {
return this.name;
}

/**
* Get the description property: The description of what the function does.
*
* @return the description value.
*/
@Generated
public String getDescription() {
return this.description;
}

/**
* Set the description property: The description of what the function does.
*
* @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. See the
* [guide](/docs/guides/gpt/function-calling) for examples, and the [JSON Schema
* reference](https://json-schema.org/understanding-json-schema/) for documentation about the format.
*
* @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. See the
* [guide](/docs/guides/gpt/function-calling) for examples, and the [JSON Schema
* reference](https://json-schema.org/understanding-json-schema/) for documentation about the format.
*
* @param parameters the parameters value to set.
* @return the FunctionDefinition object itself.
*/
@Generated
public FunctionDefinition setParameters(Object parameters) {
this.parameters = parameters;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.implementation;

import com.azure.ai.openai.models.FunctionName;
import com.azure.core.annotation.Immutable;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;

/**
* The FunctionNameFunctionCallModel model.
*/
@Immutable
@JsonTypeName("custom")
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;
}
}
Loading