Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 12 additions & 1 deletion audio/models.tsp
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
namespace OpenAI;
import "../versions.tsp";

namespace ModelDefinitions;

using TypeSpec.OpenAPI;
using TypeSpec.Versioning;

model CreateTranscriptionRequest {
@azure
@TypeSpec.Http.path deploymentId: string;

/**
* The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4,
* mpeg, mpga, m4a, ogg, wav, or webm.
Expand Down Expand Up @@ -50,6 +57,9 @@ model CreateTranscriptionResponse {
}

model CreateTranslationRequest {
@azure
@TypeSpec.Http.path deploymentId: string;

/**
* The audio file object (not file name) to translate, in one of these formats: flac, mp3, mp4,
* mpeg, mpga, m4a, ogg, wav, or webm.
Expand Down Expand Up @@ -83,6 +93,7 @@ model CreateTranslationRequest {
*/
@minValue(0)
@maxValue(1)
@azure
temperature?: float64 = 0;
}

Expand Down
3 changes: 3 additions & 0 deletions audio/operations.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ using TypeSpec.Http;
using TypeSpec.OpenAPI;

namespace OpenAI;

using ModelDefinitions;

@route("/audio")
namespace Audio {
@route("transcriptions")
Expand Down
88 changes: 88 additions & 0 deletions azuremain.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import "@typespec/http";
import "@typespec/openapi3";
import "@typespec/openapi";
import "@typespec/versioning";

import "./audio";
import "./completions";
import "./edits";
import "./embeddings";
import "./files";
import "./fine-tuning";
import "./images";
import "./moderation";
import "./versions.tsp";

import "./main.tsp";

using TypeSpec.Http;

/** The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details. */
@service({
title: "Azure OpenAI API",
termsOfService: "https://openai.com/policies/terms-of-use",
contact: {
name: "OpenAI Support",
url: "https://help.openai.com",
},
license: {
name: "MIT",
url: "https://github.com/openai/openai-openapi/blob/master/LICENSE",
},
})
@server("{base_url}/openai", "OpenAI Endpoint", {
base_url: url;
})
@useAuth(BearerAuth)
@TypeSpec.Versioning.useDependency(ModelDefinitions.OpenAIFlavors.Azure)
namespace AzureOpenAI {
@route("deployments/{deploymentId}/chat")
namespace Chat {
interface Completions {
@route("completions")
op createCompletion is OpenAI.Chat.Completions.createChatCompletion;
};
}

@route("deployments/{deploymentId}/extensions/chat")
namespace ChatExtensions {
@route("completions")
op createCompletionOnYourOwnData(... ModelDefinitions.CreateChatCompletionRequest, dataSources: DataSource[]): ModelDefinitions.CreateChatCompletionResponse;
}

@route("deployments/{deploymentId}/completions")
namespace Completions {
op createCompletion is OpenAI.Completions.createCompletion;
}

@route("deployments/{deploymentId}/embeddings")
namespace Embeddings {
op createEmbedding is OpenAI.Embeddings.createEmbedding;
}

@route("deployments/{deploymentId}/audio")
namespace Audio {
@route("transcriptions")
op transcriptions is OpenAI.Audio.Transcriptions.createTranscription;

@route("translations")
op translations is OpenAI.Audio.Translations.createTranslation;
}

@route("/files")
interface Files extends OpenAI.Files {};

@route("/fine-tunes")
interface FineTunes extends OpenAI.FineTunes {};

@route("/fine-tuning")
interface FineTuning extends OpenAI.FineTunes {};

@route("/models")
interface Models extends OpenAI.Models {};

@route("/models")
interface Images extends OpenAI.Images {};

model DataSource {};
}
2 changes: 1 addition & 1 deletion common/models.tsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OpenAI;
namespace ModelDefinitions;
using TypeSpec.OpenAPI;

model ListModelsResponse {
Expand Down
27 changes: 27 additions & 0 deletions completions/azuremodels.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import "../versions.tsp";

namespace ModelDefinitions;

using TypeSpec.Versioning;

@azure
model ContentFilterResult {
severity: "safe" | "low" | "medium" | "high";
filtered: boolean;
}

@azure
model ErrorBase {
code?: string;
message?: string;
};

@azure
model ContentFilterResults {
sexual: ContentFilterResult;
violence: ContentFilterResult;
hate: ContentFilterResult;
self_harm: ContentFilterResult;
error: ErrorBase;
}

36 changes: 34 additions & 2 deletions completions/models.tsp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
namespace OpenAI;
import "../versions.tsp";
import "./azuremodels.tsp";

namespace ModelDefinitions;

using TypeSpec.OpenAPI;
using TypeSpec.Versioning;

alias CHAT_COMPLETION_MODELS =
| "gpt4"
Expand Down Expand Up @@ -142,6 +147,10 @@ scalar N extends safeint;
scalar MaxTokens extends safeint;

model CreateChatCompletionRequest {
@azure
@TypeSpec.Http.path
deploymentId: string;

/**
* ID of the model to use. See the [model endpoint compatibility](/docs/models/model-endpoint-compatibility)
* table for details on which models work with the Chat API.
Expand Down Expand Up @@ -204,6 +213,10 @@ model ChatCompletionFunctions {
model ChatCompletionFunctionParameters is Record<unknown>;

model ChatCompletionRequestMessage {
@azure
@TypeSpec.Http.path
deploymentId: string;

/** The role of the messages author. One of `system`, `user`, `assistant`, or `function`. */
role: "system" | "user" | "assistant" | "function";

Expand Down Expand Up @@ -259,6 +272,9 @@ model CreateChatCompletionResponse {
/** The model used for the chat completion. */
`model`: string;

@azure
promp_filter_results: ContentFilterResult[];

/** A list of chat completion choices. Can be more than one if `n` is greater than 1. */
choices: {
/** The index of the choice in the list of choices. */
Expand All @@ -273,6 +289,9 @@ model CreateChatCompletionResponse {
* a flag from our content filters, or `function_call` if the model called a function.
*/
finish_reason: "stop" | "length" | "function_call" | "content_filter";

@azure
content_filter_results?: ContentFilterResult;
}[];

usage?: CompletionUsage;
Expand Down Expand Up @@ -309,9 +328,16 @@ model ChatCompletionResponseMessage {
*/
arguments: string;
};

@azure
content_filter_results?: ContentFilterResults
}

model CreateCompletionRequest {
@azure
@TypeSpec.Http.path
deploymentId: string;

/**
* ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to
* see all of your available models, or see our [Model overview](/docs/models/overview) for
Expand Down Expand Up @@ -359,6 +385,9 @@ model CreateCompletionRequest {
* quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop`.
*/
best_of?: safeint | null = 1;

@azure
completion_config?: string | null;
}

@oneOf
Expand Down Expand Up @@ -417,4 +446,7 @@ model CreateCompletionResponse {
}[];

usage?: CompletionUsage;
}

@azure
content_filter_results?: ContentFilterResults
}
2 changes: 2 additions & 0 deletions completions/operations.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ using TypeSpec.OpenAPI;

namespace OpenAI;

using ModelDefinitions;

@route("/chat")
namespace Chat {
@route("/completions")
Expand Down
3 changes: 2 additions & 1 deletion edits/models.tsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace OpenAI;
namespace ModelDefinitions;

using TypeSpec.OpenAPI;

model CreateEditRequest {
Expand Down
2 changes: 2 additions & 0 deletions edits/operations.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ using TypeSpec.OpenAPI;

namespace OpenAI;

using ModelDefinitions;

@route("/edits")
interface Edits {
#deprecated "deprecated"
Expand Down
10 changes: 9 additions & 1 deletion embeddings/models.tsp
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import "../common/models.tsp";
import "../versions.tsp";

namespace OpenAI;
namespace ModelDefinitions;
using TypeSpec.OpenAPI;
using TypeSpec.Versioning;

model CreateEmbeddingRequest {
@azure
@TypeSpec.Http.path deploymentId: string;

/** ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](/docs/models/overview) for descriptions of them. */
@extension("x-oaiTypeLabel", "string")
`model`: string | "text-embedding-ada-002";
Expand All @@ -18,6 +23,9 @@ model CreateEmbeddingRequest {
input: string | string[] | TokenArray | TokenArrayArray;

user?: User;

@azure
input_type?: string;
}
model CreateEmbeddingResponse {
/** The object type, which is always "embedding". */
Expand Down
2 changes: 2 additions & 0 deletions embeddings/operations.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ using TypeSpec.OpenAPI;

namespace OpenAI;

using ModelDefinitions;

@route("/embeddings")
interface Embeddings {
@tag("OpenAI")
Expand Down
2 changes: 1 addition & 1 deletion files/models.tsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OpenAI;
namespace ModelDefinitions;
using TypeSpec.OpenAPI;

model ListFilesResponse {
Expand Down
2 changes: 2 additions & 0 deletions files/operations.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ using TypeSpec.OpenAPI;

namespace OpenAI;

using ModelDefinitions;

@route("/files")
interface Files {
@tag("OpenAI")
Expand Down
2 changes: 1 addition & 1 deletion fine-tuning/models.tsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OpenAI;
namespace ModelDefinitions;
using TypeSpec.OpenAPI;

model FineTuningJob {
Expand Down
2 changes: 2 additions & 0 deletions fine-tuning/operations.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ using TypeSpec.OpenAPI;

namespace OpenAI;

using ModelDefinitions;

@route("/fine_tuning")
namespace FineTuning {
@route("jobs")
Expand Down
2 changes: 1 addition & 1 deletion images/models.tsp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "../common/models.tsp";

namespace OpenAI;
namespace ModelDefinitions;
using TypeSpec.OpenAPI;

alias SharedImageProperties = {
Expand Down
2 changes: 2 additions & 0 deletions images/operations.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ using TypeSpec.OpenAPI;

namespace OpenAI;

using ModelDefinitions;

@route("/images")
interface Images {
@route("generations")
Expand Down
9 changes: 7 additions & 2 deletions main.tsp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "@typespec/http";
import "@typespec/openapi3";
import "@typespec/openapi";
import "@typespec/versioning";

import "./audio";
import "./completions";
Expand All @@ -10,8 +11,11 @@ import "./files";
import "./fine-tuning";
import "./images";
import "./moderation";
import "./versions.tsp";

using TypeSpec.Http;
using TypeSpec.Versioning;


/** The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details. */
@service({
Expand All @@ -24,9 +28,10 @@ using TypeSpec.Http;
license: {
name: "MIT",
url: "https://github.com/openai/openai-openapi/blob/master/LICENSE",
},
version: "2.0.0",
}
})
@server("https://api.openai.com/v1", "OpenAI Endpoint")
@useAuth(BearerAuth)
@useDependency(ModelDefinitions.OpenAIFlavors.OpenAI)
namespace OpenAI;

Loading