-
Notifications
You must be signed in to change notification settings - Fork 861
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[azopenai] Updating to the 2023-07-01 API surface (#21169)
* Updating to the 2023-07-01 API surface - Adding in functions support and example. - Added in accomodation for content filtering info. - Make it so we can use separate service instances for some tests so we can test against the latest upcoming fixes/changes.
- Loading branch information
1 parent
c39ac95
commit 9f67e71
Showing
25 changed files
with
1,426 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,8 @@ go: true | |
use: "@autorest/[email protected]" | ||
title: "OpenAI" | ||
slice-elements-byval: true | ||
remove-non-reference-schema: true | ||
# can't use this since it removes an innererror type that we want () | ||
# remove-non-reference-schema: true | ||
``` | ||
|
||
## Transformations | ||
|
@@ -81,7 +82,7 @@ directive: | |
where: $.components.schemas["ImageOperation"].properties.status | ||
transform: $["$ref"] = $.anyOf[0]["$ref"];delete $.anyOf; | ||
- from: openapi-document | ||
where: $.components.schemas["ImageGenerationOptions"].properties | ||
where: $.components.schemas.ImageGenerationOptions.properties | ||
transform: | | ||
$.size["$ref"] = "#/components/schemas/ImageSize"; delete $.allOf; | ||
$.response_format["$ref"] = "#/components/schemas/ImageGenerationResponseFormat"; delete $.allOf; | ||
|
@@ -93,11 +94,12 @@ directive: | |
- from: openapi-document | ||
where: $.components.schemas["ImageOperationStatus"].properties.status | ||
transform: $["$ref"] = "#/components/schemas/State"; delete $.allOf; | ||
- from: openapi-document | ||
where: $.components.schemas["ContentFilterResult"].properties.severity | ||
transform: $["$ref"] = "#/components/schemas/ContentFilterSeverity"; delete $.allOf; | ||
- from: openapi-document | ||
where: $.components.schemas["ChatChoice"].properties.finish_reason | ||
transform: > | ||
delete $.oneOf; | ||
$["$ref"] = "#/components/schemas/CompletionsFinishReason"; | ||
transform: $["$ref"] = "#/components/schemas/CompletionsFinishReason"; delete $.oneOf; | ||
# Fix "AutoGenerated" models | ||
- from: openapi-document | ||
where: $.components.schemas["ChatCompletions"].properties.usage | ||
|
@@ -163,7 +165,7 @@ directive: | |
- client.go | ||
- models.go | ||
- options.go | ||
- response_types.go | ||
- response_types.go | ||
where: $ | ||
transform: return $.replace(/Client(\w+)((?:Options|Response))/g, "$1$2"); | ||
|
||
|
@@ -172,10 +174,19 @@ directive: | |
where: $ | ||
transform: return $.replace(/runtime\.JoinPaths\(client.endpoint, urlPath\)/g, "client.formatURL(urlPath)"); | ||
|
||
# Some ImageGenerations hackery to represent the ImageLocation/ImagePayload polymorphism. | ||
# - Remove the auto-generated ImageGenerationsDataItem. | ||
# - Replace the ImageGenerations.Data type with []ImageGenerationDataItem | ||
# - from: models.go | ||
# where: $ | ||
# transform: | | ||
# return $.replace(/type ImageGenerationsDataItem struct {[^}]+}/, "// ImageGenerationsDataItem represents an image URL or payload\ntype ImageGenerationsDataItem struct{\nImageLocation\nImagePayload\n}") | ||
# $.replace(/(type ImageGenerations struct.+?)Data any/g, "$1Data []ImageGenerationsDataItem") | ||
|
||
- from: models.go | ||
where: $ | ||
transform: | | ||
return $.replace(/type ImageGenerationsDataItem struct {[^}]+}/, "// ImageGenerationsDataItem represents an image URL or payload\ntype ImageGenerationsDataItem struct{\nImageLocation\nImagePayload\n}"); | ||
return $.replace(/(type ImageGenerations struct.+?)Data any/sg, "$1Data []ImageGenerationsDataItem") | ||
# delete the auto-generated ImageGenerationsDataItem, we handle that custom | ||
- from: models.go | ||
|
@@ -218,6 +229,17 @@ directive: | |
.replace(/BeginAzureBatchImageGenerationInternal/g, "beginAzureBatchImageGeneration") | ||
.replace(/BatchImageGenerationOperationResponse/g, "batchImageGenerationOperationResponse"); | ||
# BUG: ChatCompletionsOptionsFunctionCall is another one of those "here's mutually exclusive values" options... | ||
- from: | ||
- models.go | ||
- models_serde.go | ||
where: $ | ||
transform: | | ||
return $ | ||
.replace(/populateAny\(objectMap, "function_call", c.FunctionCall\)/, 'populate(objectMap, "function_call", c.FunctionCall)') | ||
.replace(/\/\/ ChatCompletionsOptionsFunctionCall.+?\n}/, "") | ||
.replace(/FunctionCall any/, "FunctionCall *ChatCompletionsOptionsFunctionCall"); | ||
# fix some casing | ||
- from: | ||
- client.go | ||
|
@@ -228,8 +250,30 @@ directive: | |
where: $ | ||
transform: return $.replace(/Logprobs/g, "LogProbs") | ||
|
||
# remove PossibleazureOpenAIOperationStateValues, since we don't expose the poller | ||
# delete ContentFilterResult in favor of our custom representation. | ||
- from: | ||
- models.go | ||
- models_serde.go | ||
where: $ | ||
transform: | | ||
return $.replace(/\/\/ ContentFilterResult.+?\n}/s, "") | ||
.replace(/\/\/ MarshalJSON implements the json.Marshaller interface for type ContentFilterResult.+?\n}/s, "") | ||
.replace(/\/\/ UnmarshalJSON implements the json.Unmarshaller interface for type ContentFilterResult.+?\n}/s, ""); | ||
- from: constants.go | ||
where: $ | ||
transform: return $.replace(/\/\/ PossibleazureOpenAIOperationStateValues returns.+?\n}/s, ""); | ||
|
||
# fix incorrect property name for content filtering | ||
# TODO: I imagine we should able to fix this in the tsp? | ||
- from: models_serde.go | ||
where: $ | ||
transform: | | ||
return $ | ||
.replace(/ case "selfHarm":/g, ' case "self_harm":') | ||
.replace(/populate\(objectMap, "selfHarm", c.SelfHarm\)/g, 'populate(objectMap, "self_harm", c.SelfHarm)'); | ||
- from: client.go | ||
where: $ | ||
transform: return $.replace(/runtime\.NewResponseError/sg, "client.newError"); | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.