From a62282a56e5986d75b432ea697fa10355e6774bc Mon Sep 17 00:00:00 2001 From: "Nadheesh Jihan, nadheesh@wso2.com" Date: Tue, 30 Jan 2024 17:13:59 +0530 Subject: [PATCH 1/4] Update openai chat connector --- openapi/openai.chat/Ballerina.toml | 4 +- openapi/openai.chat/Module.md | 39 +- openapi/openai.chat/client.bal | 22 +- openapi/openai.chat/openapi.yaml | 1458 ++- openapi/openai.chat/original-openapi.yaml | 10497 +++++++++++++++----- openapi/openai.chat/types.bal | 405 +- openapi/openai.chat/utils.bal | 18 +- 7 files changed, 9793 insertions(+), 2650 deletions(-) diff --git a/openapi/openai.chat/Ballerina.toml b/openapi/openai.chat/Ballerina.toml index 613e5d835..95fa2c008 100644 --- a/openapi/openai.chat/Ballerina.toml +++ b/openapi/openai.chat/Ballerina.toml @@ -4,9 +4,9 @@ keywords = ["AI/Chat", "OpenAI", "Cost/Paid", "GPT-3.5", "ChatGPT", "Vendor/Open org = "ballerinax" name = "openai.chat" icon = "icon.png" -distribution = "2201.4.1" +distribution = "2201.8.4" repository = "https://github.com/ballerina-platform/openapi-connectors/tree/main/openapi/openai.chat" -version = "1.1.3" +version = "2.0.0" authors = ["Ballerina"] [build-options] observabilityIncluded = true diff --git a/openapi/openai.chat/Module.md b/openapi/openai.chat/Module.md index 2238ab8fe..5c33be2b8 100644 --- a/openapi/openai.chat/Module.md +++ b/openapi/openai.chat/Module.md @@ -31,7 +31,9 @@ chat:Client chatClient = check new ({ ``` ### Step 3: Invoke the connector operation -1. Now you can use the operations available within the connector. Following is an example on creating a conversation with the GPT-3.5 model. +1. Now you can use the operations available within the connector. + +Following is an example on creating a conversation with the GPT-3.5 model. ```ballerina public function main() returns error? { chat:CreateChatCompletionRequest req = { @@ -42,4 +44,39 @@ chat:Client chatClient = check new ({ } ``` +Following is an example of using OpenAI vision capabilities when chatting. + + ```ballerina + public function main() returns error? { + chat:CreateChatCompletionResponse response = check chatClient->/chat/completions.post( + { + model: "gpt-4-vision-preview", + messages: [ + { + "role": "system", + "content": "You are a helpful assistant." + }, + { + "role": "user", + "content": [ + { + "type": "text", + "text": "Describe the image." + }, + { + "type": "image_url", + "image_url": { + "url": "" + } + } + ] + + } + ] + } + ); + chat:CreateChatCompletionResponse_choices[] choices = response.choices; + io:println(choices[0].message?.content); + } + ``` 2. Use `bal run` command to compile and run the Ballerina program. diff --git a/openapi/openai.chat/client.bal b/openapi/openai.chat/client.bal index a79bffcc0..c73de05ee 100644 --- a/openapi/openai.chat/client.bal +++ b/openapi/openai.chat/client.bal @@ -1,27 +1,11 @@ -// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - +// AUTO-GENERATED FILE. DO NOT MODIFY. +// This file is auto-generated by the Ballerina OpenAPI tool. import ballerina/http; -# This is a generated connector for the [OpenAI API] (https://platform.openai.com/docs/api-reference/introduction) specification. Use the OpenAI API to access the state-of-the-art language models that can complete sentences, transcribe audio, and generate images. The API also supports natural language processing tasks such as text classification, entity recognition, and sentiment analysis. By using the OpenAI API, you can incorporate advanced AI capabilities into your own applications and services. -@display {label: "OpenAI Chat", iconPath: "icon.png"} +# The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details. public isolated client class Client { final http:Client clientEp; # Gets invoked to initialize the `connector`. - # To use the OpenAI API, you will need an API key. You can sign up for an API key by creating an [account](https://beta.openai.com/signup/) on the OpenAI website and following the [provided instructions](https://platform.openai.com/docs/api-reference/authentication). # # + config - The configurations to be used when initializing the `connector` # + serviceUrl - URL of the target service diff --git a/openapi/openai.chat/openapi.yaml b/openapi/openai.chat/openapi.yaml index 230824965..4ed78c4e9 100644 --- a/openapi/openai.chat/openapi.yaml +++ b/openapi/openai.chat/openapi.yaml @@ -1,28 +1,26 @@ openapi: 3.0.0 info: title: OpenAI API - version: '2.0.0' - x-ballerina-display: - label: OpenAI Chat - iconPath: "icon.png" - description: >- - This is a generated connector for the [OpenAI API] (https://platform.openai.com/docs/api-reference/introduction) specification. Use the OpenAI API to access the state-of-the-art language models that can complete sentences, transcribe audio, and generate images. The API also supports natural language processing tasks such as text classification, entity recognition, and sentiment analysis. By using the OpenAI API, you can incorporate advanced AI capabilities into your own applications and services. - x-ballerina-init-description: >- - To use the OpenAI API, you will need an API key. You can sign up for an API key by creating an [account](https://beta.openai.com/signup/) on the OpenAI website and following the [provided instructions](https://platform.openai.com/docs/api-reference/authentication). + description: The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details. + version: 2.0.0 + 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 servers: - url: https://api.openai.com/v1 tags: - - name: OpenAI - description: The OpenAI REST API -security: - - BearerAuth: [] + - name: Chat + description: Given a list of messages comprising a conversation, the model will return a response. paths: /chat/completions: post: operationId: createChatCompletion tags: - - OpenAI - - chat + - Chat summary: Creates a model response for the given chat conversation. requestBody: required: true @@ -31,147 +29,932 @@ paths: schema: $ref: '#/components/schemas/CreateChatCompletionRequest' responses: - "200": + '200': description: OK content: application/json: schema: $ref: '#/components/schemas/CreateChatCompletionResponse' - x-oaiMeta: name: Create chat completion group: chat + returns: | + Returns a [chat completion](/docs/api-reference/chat/object) object, or a streamed sequence of [chat completion chunk](/docs/api-reference/chat/streaming) objects if the request is streamed. path: create - beta: true examples: - curl: | - curl https://api.openai.com/v1/chat/completions \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "model": "gpt-3.5-turbo", - "messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"}] - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - - completion = openai.ChatCompletion.create( - model="gpt-3.5-turbo", - messages=[ - {"role": "system", "content": "You are a helpful assistant."}, - {"role": "user", "content": "Hello!"} - ] - ) - - print(completion.choices[0].message) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - - const completion = await openai.createChatCompletion({ - model: "gpt-3.5-turbo", - messages: [{"role": "system", "content": "You are a helpful assistant."}, {role: "user", content: "Hello world"}], - }); - console.log(completion.data.choices[0].message); - parameters: | - { - "model": "gpt-3.5-turbo", - "messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"}] - } - response: | - { - "id": "chatcmpl-123", - "object": "chat.completion", - "created": 1677652288, - "choices": [{ - "index": 0, - "message": { - "role": "assistant", - "content": "\n\nHello there, how may I assist you today?", - }, - "finish_reason": "stop" - }], - "usage": { - "prompt_tokens": 9, - "completion_tokens": 12, - "total_tokens": 21 - } - } + - title: Default + request: + curl: | + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "VAR_model_id", + "messages": [ + { + "role": "system", + "content": "You are a helpful assistant." + }, + { + "role": "user", + "content": "Hello!" + } + ] + }' + python: | + from openai import OpenAI + client = OpenAI() + + completion = client.chat.completions.create( + model="VAR_model_id", + messages=[ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": "Hello!"} + ] + ) + + print(completion.choices[0].message) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const completion = await openai.chat.completions.create({ + messages: [{ role: "system", content: "You are a helpful assistant." }], + model: "VAR_model_id", + }); + + console.log(completion.choices[0]); + } + + main(); + response: | + { + "id": "chatcmpl-123", + "object": "chat.completion", + "created": 1677652288, + "model": "gpt-3.5-turbo-0613", + "system_fingerprint": "fp_44709d6fcb", + "choices": [{ + "index": 0, + "message": { + "role": "assistant", + "content": "\n\nHello there, how may I assist you today?", + }, + "logprobs": null, + "finish_reason": "stop" + }], + "usage": { + "prompt_tokens": 9, + "completion_tokens": 12, + "total_tokens": 21 + } + } + - title: Image input + request: + curl: | + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "gpt-4-vision-preview", + "messages": [ + { + "role": "user", + "content": [ + { + "type": "text", + "text": "What’s in this image?" + }, + { + "type": "image_url", + "image_url": { + "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg" + } + } + ] + } + ], + "max_tokens": 300 + }' + python: | + from openai import OpenAI + + client = OpenAI() + + response = client.chat.completions.create( + model="gpt-4-vision-preview", + messages=[ + { + "role": "user", + "content": [ + {"type": "text", "text": "What’s in this image?"}, + { + "type": "image_url", + "image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", + }, + ], + } + ], + max_tokens=300, + ) + + print(response.choices[0]) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const response = await openai.chat.completions.create({ + model: "gpt-4-vision-preview", + messages: [ + { + role: "user", + content: [ + { type: "text", text: "What’s in this image?" }, + { + type: "image_url", + image_url: + "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", + }, + ], + }, + ], + }); + console.log(response.choices[0]); + } + main(); + response: | + { + "id": "chatcmpl-123", + "object": "chat.completion", + "created": 1677652288, + "model": "gpt-3.5-turbo-0613", + "system_fingerprint": "fp_44709d6fcb", + "choices": [{ + "index": 0, + "message": { + "role": "assistant", + "content": "\n\nHello there, how may I assist you today?", + }, + "logprobs": null, + "finish_reason": "stop" + }], + "usage": { + "prompt_tokens": 9, + "completion_tokens": 12, + "total_tokens": 21 + } + } + - title: Streaming + request: + curl: | + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "VAR_model_id", + "messages": [ + { + "role": "system", + "content": "You are a helpful assistant." + }, + { + "role": "user", + "content": "Hello!" + } + ], + "stream": true + }' + python: | + from openai import OpenAI + client = OpenAI() + + completion = client.chat.completions.create( + model="VAR_model_id", + messages=[ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": "Hello!"} + ], + stream=True + ) + + for chunk in completion: + print(chunk.choices[0].delta) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const completion = await openai.chat.completions.create({ + model: "VAR_model_id", + messages: [ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": "Hello!"} + ], + stream: true, + }); + + for await (const chunk of completion) { + console.log(chunk.choices[0].delta.content); + } + } + + main(); + response: | + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]} + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"Hello"},"logprobs":null,"finish_reason":null}]} + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"!"},"logprobs":null,"finish_reason":null}]} + + .... + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":" today"},"logprobs":null,"finish_reason":null}]} + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"?"},"logprobs":null,"finish_reason":null}]} + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]} + - title: Functions + request: + curl: | + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "gpt-3.5-turbo", + "messages": [ + { + "role": "user", + "content": "What is the weather like in Boston?" + } + ], + "tools": [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA" + }, + "unit": { + "type": "string", + "enum": ["celsius", "fahrenheit"] + } + }, + "required": ["location"] + } + } + } + ], + "tool_choice": "auto" + }' + python: | + from openai import OpenAI + client = OpenAI() + + tools = [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA", + }, + "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, + }, + "required": ["location"], + }, + } + } + ] + messages = [{"role": "user", "content": "What's the weather like in Boston today?"}] + completion = client.chat.completions.create( + model="VAR_model_id", + messages=messages, + tools=tools, + tool_choice="auto" + ) + + print(completion) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const messages = [{"role": "user", "content": "What's the weather like in Boston today?"}]; + const tools = [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA", + }, + "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, + }, + "required": ["location"], + }, + } + } + ]; + const response = await openai.chat.completions.create({ + model: "gpt-3.5-turbo", + messages: messages, + tools: tools, + tool_choice: "auto", + }); + + console.log(response); + } + + main(); + response: | + { + "id": "chatcmpl-abc123", + "object": "chat.completion", + "created": 1699896916, + "model": "gpt-3.5-turbo-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": null, + "tool_calls": [ + { + "id": "call_abc123", + "type": "function", + "function": { + "name": "get_current_weather", + "arguments": "{\n\"location\": \"Boston, MA\"\n}" + } + } + ] + }, + "logprobs": null, + "finish_reason": "tool_calls" + } + ], + "usage": { + "prompt_tokens": 82, + "completion_tokens": 17, + "total_tokens": 99 + } + } + - title: Logprobs + request: + curl: | + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "VAR_model_id", + "messages": [ + { + "role": "user", + "content": "Hello!" + } + ], + "logprobs": true, + "top_logprobs": 2 + }' + python: | + from openai import OpenAI + client = OpenAI() + + completion = client.chat.completions.create( + model="VAR_model_id", + messages=[ + {"role": "user", "content": "Hello!"} + ], + logprobs=True, + top_logprobs=2 + ) + + print(completion.choices[0].message) + print(completion.choices[0].logprobs) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const completion = await openai.chat.completions.create({ + messages: [{ role: "user", content: "Hello!" }], + model: "VAR_model_id", + logprobs: true, + top_logprobs: 2, + }); + + console.log(completion.choices[0]); + } + + main(); + response: | + { + "id": "chatcmpl-123", + "object": "chat.completion", + "created": 1702685778, + "model": "gpt-3.5-turbo-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "Hello! How can I assist you today?" + }, + "logprobs": { + "content": [ + { + "token": "Hello", + "logprob": -0.31725305, + "bytes": [72, 101, 108, 108, 111], + "top_logprobs": [ + { + "token": "Hello", + "logprob": -0.31725305, + "bytes": [72, 101, 108, 108, 111] + }, + { + "token": "Hi", + "logprob": -1.3190403, + "bytes": [72, 105] + } + ] + }, + { + "token": "!", + "logprob": -0.02380986, + "bytes": [ + 33 + ], + "top_logprobs": [ + { + "token": "!", + "logprob": -0.02380986, + "bytes": [33] + }, + { + "token": " there", + "logprob": -3.787621, + "bytes": [32, 116, 104, 101, 114, 101] + } + ] + }, + { + "token": " How", + "logprob": -0.000054669687, + "bytes": [32, 72, 111, 119], + "top_logprobs": [ + { + "token": " How", + "logprob": -0.000054669687, + "bytes": [32, 72, 111, 119] + }, + { + "token": "<|end|>", + "logprob": -10.953937, + "bytes": null + } + ] + }, + { + "token": " can", + "logprob": -0.015801601, + "bytes": [32, 99, 97, 110], + "top_logprobs": [ + { + "token": " can", + "logprob": -0.015801601, + "bytes": [32, 99, 97, 110] + }, + { + "token": " may", + "logprob": -4.161023, + "bytes": [32, 109, 97, 121] + } + ] + }, + { + "token": " I", + "logprob": -3.7697225e-6, + "bytes": [ + 32, + 73 + ], + "top_logprobs": [ + { + "token": " I", + "logprob": -3.7697225e-6, + "bytes": [32, 73] + }, + { + "token": " assist", + "logprob": -13.596657, + "bytes": [32, 97, 115, 115, 105, 115, 116] + } + ] + }, + { + "token": " assist", + "logprob": -0.04571125, + "bytes": [32, 97, 115, 115, 105, 115, 116], + "top_logprobs": [ + { + "token": " assist", + "logprob": -0.04571125, + "bytes": [32, 97, 115, 115, 105, 115, 116] + }, + { + "token": " help", + "logprob": -3.1089056, + "bytes": [32, 104, 101, 108, 112] + } + ] + }, + { + "token": " you", + "logprob": -5.4385737e-6, + "bytes": [32, 121, 111, 117], + "top_logprobs": [ + { + "token": " you", + "logprob": -5.4385737e-6, + "bytes": [32, 121, 111, 117] + }, + { + "token": " today", + "logprob": -12.807695, + "bytes": [32, 116, 111, 100, 97, 121] + } + ] + }, + { + "token": " today", + "logprob": -0.0040071653, + "bytes": [32, 116, 111, 100, 97, 121], + "top_logprobs": [ + { + "token": " today", + "logprob": -0.0040071653, + "bytes": [32, 116, 111, 100, 97, 121] + }, + { + "token": "?", + "logprob": -5.5247097, + "bytes": [63] + } + ] + }, + { + "token": "?", + "logprob": -0.0008108172, + "bytes": [63], + "top_logprobs": [ + { + "token": "?", + "logprob": -0.0008108172, + "bytes": [63] + }, + { + "token": "?\n", + "logprob": -7.184561, + "bytes": [63, 10] + } + ] + } + ] + }, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 9, + "completion_tokens": 9, + "total_tokens": 18 + }, + "system_fingerprint": null + } components: securitySchemes: - BearerAuth: + ApiKeyAuth: type: http scheme: bearer schemas: + ChatCompletionRequestMessageContentPart: + oneOf: + - $ref: '#/components/schemas/ChatCompletionRequestMessageContentPartText' + - $ref: '#/components/schemas/ChatCompletionRequestMessageContentPartImage' + x-oaiExpandable: true + ChatCompletionRequestMessageContentPartImage: + type: object + title: Image content part + properties: + type: + type: string + enum: + - image_url + description: The type of the content part. + image_url: + type: object + properties: + url: + type: string + description: Either a URL of the image or the base64 encoded image data. + format: uri + detail: + type: string + description: Specifies the detail level of the image. Learn more in the [Vision guide](/docs/guides/vision/low-or-high-fidelity-image-understanding). + enum: + - auto + - low + - high + default: auto + required: + - url + required: + - type + - image_url + ChatCompletionRequestMessageContentPartText: + type: object + title: Text content part + properties: + type: + type: string + enum: + - text + description: The type of the content part. + text: + type: string + description: The text content. + required: + - type + - text ChatCompletionRequestMessage: + oneOf: + - $ref: '#/components/schemas/ChatCompletionRequestSystemMessage' + - $ref: '#/components/schemas/ChatCompletionRequestUserMessage' + - $ref: '#/components/schemas/ChatCompletionRequestAssistantMessage' + - $ref: '#/components/schemas/ChatCompletionRequestToolMessage' + - $ref: '#/components/schemas/ChatCompletionRequestFunctionMessage' + x-oaiExpandable: true + ChatCompletionRequestSystemMessage: type: object + title: System message properties: + content: + description: The contents of the system message. + type: string role: type: string - enum: ["system", "user", "assistant", "function"] - description: The role of the messages author. One of `system`, `user`, `assistant`, or `function`. + enum: + - system + description: The role of the messages author, in this case `system`. + name: + type: string + description: An optional name for the participant. Provides the model information to differentiate between participants of the same role. + required: + - content + - role + ChatCompletionRequestUserMessage: + type: object + title: User message + properties: content: + description: | + The contents of the user message. + oneOf: + - type: string + description: The text contents of the message. + title: Text content + - type: array + description: An array of content parts with a defined type, each can be of type `text` or `image_url` when passing in images. You can pass multiple images by adding multiple `image_url` content parts. Image input is only supported when using the `gpt-4-visual-preview` model. + title: Array of content parts + items: + $ref: '#/components/schemas/ChatCompletionRequestMessageContentPart' + minItems: 1 + x-oaiExpandable: true + role: + type: string + enum: + - user + description: The role of the messages author, in this case `user`. + name: type: string - description: The contents of the message. `content` is required for all messages except assistant messages with function calls. + description: An optional name for the participant. Provides the model information to differentiate between participants of the same role. + required: + - content + - role + ChatCompletionRequestAssistantMessage: + type: object + title: Assistant message + properties: + content: nullable: true + type: string + description: | + The contents of the assistant message. Required unless `tool_calls` or `function_call` is specified. + role: + type: string + enum: + - assistant + description: The role of the messages author, in this case `assistant`. name: type: string - description: 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. + description: An optional name for the participant. Provides the model information to differentiate between participants of the same role. + tool_calls: + $ref: '#/components/schemas/ChatCompletionMessageToolCalls' function_call: type: object - description: The name and arguments of a function that should be called, as generated by the model. + deprecated: true + description: Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. properties: - name: - type: string - description: The name of the function to call. arguments: type: string description: 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. - required: + name: + type: string + description: The name of the function to call. + required: + - arguments + - name + required: + - role + ChatCompletionRequestToolMessage: + type: object + title: Tool message + properties: + role: + type: string + enum: + - tool + description: The role of the messages author, in this case `tool`. + content: + type: string + description: The contents of the tool message. + tool_call_id: + type: string + description: Tool call that this message is responding to. + required: - role - content - - ChatCompletionFunctionParameters: + - tool_call_id + ChatCompletionRequestFunctionMessage: type: object - 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. - # TODO type this as json schema - additionalProperties: true + title: Function message + deprecated: true + properties: + role: + type: string + enum: + - function + description: The role of the messages author, in this case `function`. + content: + nullable: true + type: string + description: The contents of the function message. + name: + type: string + description: The name of the function to call. + required: + - role + - content + - name + FunctionParameters: + type: object + description: |- + The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/text-generation/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. + additionalProperties: true ChatCompletionFunctions: type: object + deprecated: true properties: + description: + type: string + description: A description of what the function does, used by the model to choose when and how to call the function. name: type: string description: 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. + parameters: + $ref: '#/components/schemas/FunctionParameters' + required: + - name + ChatCompletionFunctionCallOption: + type: object + description: | + Specifying a particular function via `{"name": "my_function"}` forces the model to call that function. + properties: + name: + type: string + description: The name of the function to call. + required: + - name + ChatCompletionTool: + type: object + properties: + type: + type: string + enum: + - function + description: The type of the tool. Currently, only `function` is supported. + function: + $ref: '#/components/schemas/FunctionObject' + required: + - type + - function + FunctionObject: + type: object + properties: description: type: string - description: The description of what the function does. + description: A description of what the function does, used by the model to choose when and how to call the function. + name: + type: string + description: 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. parameters: - $ref: '#/components/schemas/ChatCompletionFunctionParameters' - required: + $ref: '#/components/schemas/FunctionParameters' + required: - name + ChatCompletionToolChoiceOption: + description: | + 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 `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that function. - ChatCompletionResponseMessage: + `none` is the default when no functions are present. `auto` is the default if functions are present. + oneOf: + - type: string + description: | + `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. + enum: + - none + - auto + - $ref: '#/components/schemas/ChatCompletionNamedToolChoice' + x-oaiExpandable: true + ChatCompletionNamedToolChoice: type: object + description: Specifies a tool the model should use. Use to force the model to call a specific function. properties: - role: + type: type: string - enum: ["system", "user", "assistant", "function"] - description: The role of the author of this message. - content: + enum: + - function + description: The type of the tool. Currently, only `function` is supported. + function: + type: object + description: The function that should be called. + properties: + name: + type: string + description: The name of the function to call. + required: + - name + required: + - type + - function + ChatCompletionMessageToolCalls: + type: array + description: The tool calls generated by the model, such as function calls. + items: + $ref: '#/components/schemas/ChatCompletionMessageToolCall' + ChatCompletionMessageToolCall: + type: object + properties: + id: type: string - description: The contents of the message. - nullable: true - function_call: + description: The ID of the tool call. + type: + type: string + enum: + - function + description: The type of the tool. Currently, only `function` is supported. + function: type: object - description: The name and arguments of a function that should be called, as generated by the model. + description: The function that the model called. properties: name: type: string @@ -179,106 +962,174 @@ components: arguments: type: string description: 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. - required: - - role - - ChatCompletionStreamResponseDelta: + required: + - name + - arguments + required: + - id + - type + - function + ChatCompletionRole: + type: string + description: The role of the author of a message + enum: + - system + - user + - assistant + - tool + - function + ChatCompletionResponseMessage: type: object + description: A chat completion message generated by the model. properties: - role: - type: string - enum: ["system", "user", "assistant", "function"] - description: The role of the author of this message. content: type: string - description: The contents of the chunk message. + description: The contents of the message. nullable: true + tool_calls: + $ref: '#/components/schemas/ChatCompletionMessageToolCalls' + role: + type: string + enum: + - assistant + description: The role of the author of this message. function_call: type: object - description: The name and arguments of a function that should be called, as generated by the model. + deprecated: true + description: Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. properties: - name: - type: string - description: The name of the function to call. arguments: type: string description: 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. - + name: + type: string + description: The name of the function to call. + required: + - name + - arguments + required: + - role + - content CreateChatCompletionRequest: type: object properties: - model: - description: 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. - example: "gpt-3.5-turbo" - oneOf: - - type: string - - type: string - enum: ["gpt-4","gpt-4-0613","gpt-4-32k","gpt-4-32k-0613","gpt-3.5-turbo","gpt-3.5-turbo-16k","gpt-3.5-turbo-0613","gpt-3.5-turbo-16k-0613"] messages: - description: 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). + description: A list of messages comprising the conversation so far. [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models). type: array minItems: 1 items: $ref: '#/components/schemas/ChatCompletionRequestMessage' - functions: - description: A list of functions the model may generate JSON inputs for. - type: array - minItems: 1 - items: - $ref: '#/components/schemas/ChatCompletionFunctions' - function_call: - description: 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. - oneOf: + model: + description: 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. + example: gpt-3.5-turbo + anyOf: - type: string - enum: [none, auto] - - type: object - properties: - name: - type: string - description: The name of the function to call. - required: - - name - temperature: + - type: string + enum: + - gpt-4-0125-preview + - gpt-4-turbo-preview + - gpt-4-1106-preview + - gpt-4-vision-preview + - gpt-4 + - gpt-4-0314 + - gpt-4-0613 + - gpt-4-32k + - gpt-4-32k-0314 + - gpt-4-32k-0613 + - gpt-3.5-turbo + - gpt-3.5-turbo-16k + - gpt-3.5-turbo-0301 + - gpt-3.5-turbo-0613 + - gpt-3.5-turbo-1106 + - gpt-3.5-turbo-16k-0613 + x-oaiTypeLabel: string + frequency_penalty: type: number - minimum: 0 + default: 0 + minimum: -2 maximum: 2 - default: 1 - example: 1 nullable: true description: | - 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. + 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. - We generally recommend altering this or `top_p` but not both. - top_p: - type: number + [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) + logit_bias: + type: object + x-oaiTypeLabel: map + nullable: true + additionalProperties: + type: integer + description: | + 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. + logprobs: + description: 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`. This option is currently not available on the `gpt-4-vision-preview` model. + type: boolean + nullable: true + top_logprobs: + description: An integer between 0 and 5 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. + type: integer minimum: 0 - maximum: 1 - default: 1 - example: 1 + maximum: 5 nullable: true + max_tokens: description: | - 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. + The maximum number of [tokens](/tokenizer) that can be generated in the chat completion. - We generally recommend altering this or `temperature` but not both. - n: + 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. + type: integer + nullable: true + 'n': type: integer minimum: 1 maximum: 128 default: 1 example: 1 nullable: true - description: How many chat completion choices to generate for each input message. - stream: - description: > - 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://github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb). - type: boolean + description: 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. + presence_penalty: + type: number + default: 0 + minimum: -2 + maximum: 2 nullable: true - default: false + description: | + 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. + + [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) + response_format: + type: object + description: | + An object specifying the format that the model must output. Compatible with [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and `gpt-3.5-turbo-1106`. + + 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. + properties: + type: + type: string + enum: + - text + - json_object + example: json_object + default: text + description: Must be one of `text` or `json_object`. + seed: + type: integer + minimum: -9223372036854776000 + maximum: 9223372036854776000 + nullable: true + description: | + 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. + x-oaiMeta: + beta: true stop: description: | Up to 4 sequences where the API will stop generating further tokens. - # default: null + default: null oneOf: - type: string nullable: true @@ -287,132 +1138,255 @@ components: maxItems: 4 items: type: string - max_tokens: + stream: description: | - The maximum number of [tokens](/tokenizer) to generate 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://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) for counting tokens. - default: inf - type: integer - presence_penalty: + 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). + type: boolean + nullable: true + default: false + temperature: type: number - default: 0 - minimum: -2 + minimum: 0 maximum: 2 + default: 1 + example: 1 nullable: true description: | - 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. + 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. - [See more information about frequency and presence penalties.](/docs/api-reference/parameter-details) - frequency_penalty: + We generally recommend altering this or `top_p` but not both. + top_p: type: number - default: 0 - minimum: -2 - maximum: 2 + minimum: 0 + maximum: 1 + default: 1 + example: 1 nullable: true description: | - 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. + 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. - [See more information about frequency and presence penalties.](/docs/api-reference/parameter-details) - logit_bias: - type: object - x-oaiTypeLabel: map - # default: null - nullable: true + We generally recommend altering this or `temperature` but not both. + tools: + type: array description: | - 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. + 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. + items: + $ref: '#/components/schemas/ChatCompletionTool' + tool_choice: + $ref: '#/components/schemas/ChatCompletionToolChoiceOption' user: type: string example: user-1234 description: | A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids). + function_call: + deprecated: true + description: | + 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. + oneOf: + - type: string + description: | + `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. + enum: + - none + - auto + - $ref: '#/components/schemas/ChatCompletionFunctionCallOption' + x-oaiExpandable: true + functions: + deprecated: true + description: | + Deprecated in favor of `tools`. + + A list of functions the model may generate JSON inputs for. + type: array + minItems: 1 + maxItems: 128 + items: + $ref: '#/components/schemas/ChatCompletionFunctions' required: - model - messages - CreateChatCompletionResponse: type: object + description: Represents a chat completion response returned by model, based on the provided input. properties: id: type: string - object: - type: string - created: - type: integer - model: - type: string + description: A unique identifier for the chat completion. choices: type: array + description: A list of chat completion choices. Can be more than one if `n` is greater than 1. items: type: object + required: + - finish_reason + - index + - message properties: + finish_reason: + type: string + description: | + 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. + enum: + - stop + - length + - tool_calls + - content_filter + - function_call index: type: integer + description: The index of the choice in the list of choices. message: $ref: '#/components/schemas/ChatCompletionResponseMessage' - finish_reason: - type: string - enum: ["stop", "length", "function_call"] + logprobs: + description: Log probability information for the choice. + type: object + nullable: true + properties: + content: + description: A list of message content tokens with log probability information. + type: array + items: + $ref: '#/components/schemas/ChatCompletionTokenLogprob' + nullable: true + required: + - content + created: + type: integer + description: The Unix timestamp (in seconds) of when the chat completion was created. + model: + type: string + description: The model used for the chat completion. + system_fingerprint: + type: string + description: | + 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. + object: + type: string + description: The object type, which is always `chat.completion`. + enum: + - chat.completion usage: - type: object - properties: - prompt_tokens: - type: integer - completion_tokens: - type: integer - total_tokens: - type: integer - required: - - prompt_tokens - - completion_tokens - - total_tokens - required: - - id - - object + $ref: '#/components/schemas/CompletionUsage' + required: + - choices - created + - id - model - - choices - - CreateChatCompletionStreamResponse: + - object + x-oaiMeta: + name: The chat completion object + group: chat + example: | + { + "id": "chatcmpl-123", + "object": "chat.completion", + "created": 1677652288, + "model": "gpt-3.5-turbo-0613", + "system_fingerprint": "fp_44709d6fcb", + "choices": [{ + "index": 0, + "message": { + "role": "assistant", + "content": "\n\nHello there, how may I assist you today?", + }, + "logprobs": null, + "finish_reason": "stop" + }], + "usage": { + "prompt_tokens": 9, + "completion_tokens": 12, + "total_tokens": 21 + } + } + ChatCompletionTokenLogprob: type: object properties: - id: - type: string - object: - type: string - created: - type: integer - model: + token: + description: The token. type: string - choices: + logprob: + description: The log probability of this token. + type: number + bytes: + description: 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. + type: array + items: + type: integer + nullable: true + top_logprobs: + description: 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. type: array items: type: object properties: - index: - type: integer - delta: - $ref: '#/components/schemas/ChatCompletionStreamResponseDelta' - finish_reason: + token: + description: The token. type: string - enum: ["stop", "length", "function_call"] - required: - - id - - object - - created - - model - - choices - + logprob: + description: The log probability of this token. + type: number + bytes: + description: 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. + type: array + items: + type: integer + nullable: true + required: + - token + - logprob + - bytes + required: + - token + - logprob + - bytes + - top_logprobs + CompletionUsage: + type: object + description: Usage statistics for the completion request. + properties: + completion_tokens: + type: integer + description: Number of tokens in the generated completion. + prompt_tokens: + type: integer + description: Number of tokens in the prompt. + total_tokens: + type: integer + description: Total number of tokens used in the request (prompt + completion). + required: + - prompt_tokens + - completion_tokens + - total_tokens +security: + - ApiKeyAuth: [] x-oaiMeta: groups: - - id: completions - title: Completions - description: | - Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position. - id: chat title: Chat description: | Given a list of messages comprising a conversation, the model will return a response. + + Related guide: [Chat Completions](/docs/guides/text-generation) + sections: + - type: endpoint + key: createChatCompletion + path: create + - type: object + key: CreateChatCompletionResponse + path: object + - type: object + key: CreateChatCompletionStreamResponse + path: streaming diff --git a/openapi/openai.chat/original-openapi.yaml b/openapi/openai.chat/original-openapi.yaml index 550ae33cf..2d7d1a778 100644 --- a/openapi/openai.chat/original-openapi.yaml +++ b/openapi/openai.chat/original-openapi.yaml @@ -1,780 +1,1449 @@ openapi: 3.0.0 info: title: OpenAI API - description: APIs for sampling from and fine-tuning language models - version: '2.0.0' + description: The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details. + version: "2.0.0" + 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 servers: - url: https://api.openai.com/v1 tags: -- name: OpenAI - description: The OpenAI REST API + - name: Assistants + description: Build Assistants that can call models and use tools. + - name: Audio + description: Learn how to turn audio into text or text into audio. + - name: Chat + description: Given a list of messages comprising a conversation, the model will return a response. + - name: Completions + description: Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position. + - name: Embeddings + description: Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms. + - name: Fine-tuning + description: Manage fine-tuning jobs to tailor a model to your specific training data. + - name: Files + description: Files are used to upload documents that can be used with features like Assistants and Fine-tuning. + - name: Images + description: Given a prompt and/or an input image, the model will generate a new image. + - name: Models + description: List and describe the various models available in the API. + - name: Moderations + description: Given a input text, outputs if the model classifies it as violating OpenAI's content policy. paths: + # Note: When adding an endpoint, make sure you also add it in the `groups` section, in the end of this file, + # under the appropriate group /chat/completions: post: operationId: createChatCompletion tags: - - OpenAI + - Chat summary: Creates a model response for the given chat conversation. requestBody: required: true content: application/json: schema: - $ref: '#/components/schemas/CreateChatCompletionRequest' + $ref: "#/components/schemas/CreateChatCompletionRequest" responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/CreateChatCompletionResponse' + $ref: "#/components/schemas/CreateChatCompletionResponse" x-oaiMeta: name: Create chat completion group: chat + returns: | + Returns a [chat completion](/docs/api-reference/chat/object) object, or a streamed sequence of [chat completion chunk](/docs/api-reference/chat/streaming) objects if the request is streamed. path: create - beta: true examples: - curl: | - curl https://api.openai.com/v1/chat/completions \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "model": "gpt-3.5-turbo", - "messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"}] - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - - completion = openai.ChatCompletion.create( - model="gpt-3.5-turbo", - messages=[ - {"role": "system", "content": "You are a helpful assistant."}, - {"role": "user", "content": "Hello!"} - ] - ) - - print(completion.choices[0].message) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - - const completion = await openai.createChatCompletion({ - model: "gpt-3.5-turbo", - messages: [{"role": "system", "content": "You are a helpful assistant."}, {role: "user", content: "Hello world"}], - }); - console.log(completion.data.choices[0].message); - parameters: | - { - "model": "gpt-3.5-turbo", - "messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"}] - } - response: | - { - "id": "chatcmpl-123", - "object": "chat.completion", - "created": 1677652288, - "choices": [{ - "index": 0, - "message": { - "role": "assistant", - "content": "\n\nHello there, how may I assist you today?", - }, - "finish_reason": "stop" - }], - "usage": { - "prompt_tokens": 9, - "completion_tokens": 12, - "total_tokens": 21 - } - } + - title: Default + request: + curl: | + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "VAR_model_id", + "messages": [ + { + "role": "system", + "content": "You are a helpful assistant." + }, + { + "role": "user", + "content": "Hello!" + } + ] + }' + python: | + from openai import OpenAI + client = OpenAI() + + completion = client.chat.completions.create( + model="VAR_model_id", + messages=[ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": "Hello!"} + ] + ) + + print(completion.choices[0].message) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const completion = await openai.chat.completions.create({ + messages: [{ role: "system", content: "You are a helpful assistant." }], + model: "VAR_model_id", + }); + + console.log(completion.choices[0]); + } + + main(); + response: &chat_completion_example | + { + "id": "chatcmpl-123", + "object": "chat.completion", + "created": 1677652288, + "model": "gpt-3.5-turbo-0613", + "system_fingerprint": "fp_44709d6fcb", + "choices": [{ + "index": 0, + "message": { + "role": "assistant", + "content": "\n\nHello there, how may I assist you today?", + }, + "logprobs": null, + "finish_reason": "stop" + }], + "usage": { + "prompt_tokens": 9, + "completion_tokens": 12, + "total_tokens": 21 + } + } + - title: Image input + request: + curl: | + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "gpt-4-vision-preview", + "messages": [ + { + "role": "user", + "content": [ + { + "type": "text", + "text": "What’s in this image?" + }, + { + "type": "image_url", + "image_url": { + "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg" + } + } + ] + } + ], + "max_tokens": 300 + }' + python: | + from openai import OpenAI + + client = OpenAI() + + response = client.chat.completions.create( + model="gpt-4-vision-preview", + messages=[ + { + "role": "user", + "content": [ + {"type": "text", "text": "What’s in this image?"}, + { + "type": "image_url", + "image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", + }, + ], + } + ], + max_tokens=300, + ) + + print(response.choices[0]) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const response = await openai.chat.completions.create({ + model: "gpt-4-vision-preview", + messages: [ + { + role: "user", + content: [ + { type: "text", text: "What’s in this image?" }, + { + type: "image_url", + image_url: + "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg", + }, + ], + }, + ], + }); + console.log(response.choices[0]); + } + main(); + response: &chat_completion_image_example | + { + "id": "chatcmpl-123", + "object": "chat.completion", + "created": 1677652288, + "model": "gpt-3.5-turbo-0613", + "system_fingerprint": "fp_44709d6fcb", + "choices": [{ + "index": 0, + "message": { + "role": "assistant", + "content": "\n\nHello there, how may I assist you today?", + }, + "logprobs": null, + "finish_reason": "stop" + }], + "usage": { + "prompt_tokens": 9, + "completion_tokens": 12, + "total_tokens": 21 + } + } + - title: Streaming + request: + curl: | + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "VAR_model_id", + "messages": [ + { + "role": "system", + "content": "You are a helpful assistant." + }, + { + "role": "user", + "content": "Hello!" + } + ], + "stream": true + }' + python: | + from openai import OpenAI + client = OpenAI() + + completion = client.chat.completions.create( + model="VAR_model_id", + messages=[ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": "Hello!"} + ], + stream=True + ) + + for chunk in completion: + print(chunk.choices[0].delta) + + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const completion = await openai.chat.completions.create({ + model: "VAR_model_id", + messages: [ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": "Hello!"} + ], + stream: true, + }); + + for await (const chunk of completion) { + console.log(chunk.choices[0].delta.content); + } + } + + main(); + response: &chat_completion_chunk_example | + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]} + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"Hello"},"logprobs":null,"finish_reason":null}]} + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"!"},"logprobs":null,"finish_reason":null}]} + + .... + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":" today"},"logprobs":null,"finish_reason":null}]} + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"?"},"logprobs":null,"finish_reason":null}]} + + {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-3.5-turbo-0613", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]} + - title: Functions + request: + curl: | + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "gpt-3.5-turbo", + "messages": [ + { + "role": "user", + "content": "What is the weather like in Boston?" + } + ], + "tools": [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA" + }, + "unit": { + "type": "string", + "enum": ["celsius", "fahrenheit"] + } + }, + "required": ["location"] + } + } + } + ], + "tool_choice": "auto" + }' + python: | + from openai import OpenAI + client = OpenAI() + + tools = [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA", + }, + "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, + }, + "required": ["location"], + }, + } + } + ] + messages = [{"role": "user", "content": "What's the weather like in Boston today?"}] + completion = client.chat.completions.create( + model="VAR_model_id", + messages=messages, + tools=tools, + tool_choice="auto" + ) + + print(completion) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const messages = [{"role": "user", "content": "What's the weather like in Boston today?"}]; + const tools = [ + { + "type": "function", + "function": { + "name": "get_current_weather", + "description": "Get the current weather in a given location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state, e.g. San Francisco, CA", + }, + "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, + }, + "required": ["location"], + }, + } + } + ]; + + const response = await openai.chat.completions.create({ + model: "gpt-3.5-turbo", + messages: messages, + tools: tools, + tool_choice: "auto", + }); + + console.log(response); + } + + main(); + response: &chat_completion_function_example | + { + "id": "chatcmpl-abc123", + "object": "chat.completion", + "created": 1699896916, + "model": "gpt-3.5-turbo-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": null, + "tool_calls": [ + { + "id": "call_abc123", + "type": "function", + "function": { + "name": "get_current_weather", + "arguments": "{\n\"location\": \"Boston, MA\"\n}" + } + } + ] + }, + "logprobs": null, + "finish_reason": "tool_calls" + } + ], + "usage": { + "prompt_tokens": 82, + "completion_tokens": 17, + "total_tokens": 99 + } + } + - title: Logprobs + request: + curl: | + curl https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "VAR_model_id", + "messages": [ + { + "role": "user", + "content": "Hello!" + } + ], + "logprobs": true, + "top_logprobs": 2 + }' + python: | + from openai import OpenAI + client = OpenAI() + + completion = client.chat.completions.create( + model="VAR_model_id", + messages=[ + {"role": "user", "content": "Hello!"} + ], + logprobs=True, + top_logprobs=2 + ) + + print(completion.choices[0].message) + print(completion.choices[0].logprobs) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const completion = await openai.chat.completions.create({ + messages: [{ role: "user", content: "Hello!" }], + model: "VAR_model_id", + logprobs: true, + top_logprobs: 2, + }); + + console.log(completion.choices[0]); + } + + main(); + response: | + { + "id": "chatcmpl-123", + "object": "chat.completion", + "created": 1702685778, + "model": "gpt-3.5-turbo-0613", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "Hello! How can I assist you today?" + }, + "logprobs": { + "content": [ + { + "token": "Hello", + "logprob": -0.31725305, + "bytes": [72, 101, 108, 108, 111], + "top_logprobs": [ + { + "token": "Hello", + "logprob": -0.31725305, + "bytes": [72, 101, 108, 108, 111] + }, + { + "token": "Hi", + "logprob": -1.3190403, + "bytes": [72, 105] + } + ] + }, + { + "token": "!", + "logprob": -0.02380986, + "bytes": [ + 33 + ], + "top_logprobs": [ + { + "token": "!", + "logprob": -0.02380986, + "bytes": [33] + }, + { + "token": " there", + "logprob": -3.787621, + "bytes": [32, 116, 104, 101, 114, 101] + } + ] + }, + { + "token": " How", + "logprob": -0.000054669687, + "bytes": [32, 72, 111, 119], + "top_logprobs": [ + { + "token": " How", + "logprob": -0.000054669687, + "bytes": [32, 72, 111, 119] + }, + { + "token": "<|end|>", + "logprob": -10.953937, + "bytes": null + } + ] + }, + { + "token": " can", + "logprob": -0.015801601, + "bytes": [32, 99, 97, 110], + "top_logprobs": [ + { + "token": " can", + "logprob": -0.015801601, + "bytes": [32, 99, 97, 110] + }, + { + "token": " may", + "logprob": -4.161023, + "bytes": [32, 109, 97, 121] + } + ] + }, + { + "token": " I", + "logprob": -3.7697225e-6, + "bytes": [ + 32, + 73 + ], + "top_logprobs": [ + { + "token": " I", + "logprob": -3.7697225e-6, + "bytes": [32, 73] + }, + { + "token": " assist", + "logprob": -13.596657, + "bytes": [32, 97, 115, 115, 105, 115, 116] + } + ] + }, + { + "token": " assist", + "logprob": -0.04571125, + "bytes": [32, 97, 115, 115, 105, 115, 116], + "top_logprobs": [ + { + "token": " assist", + "logprob": -0.04571125, + "bytes": [32, 97, 115, 115, 105, 115, 116] + }, + { + "token": " help", + "logprob": -3.1089056, + "bytes": [32, 104, 101, 108, 112] + } + ] + }, + { + "token": " you", + "logprob": -5.4385737e-6, + "bytes": [32, 121, 111, 117], + "top_logprobs": [ + { + "token": " you", + "logprob": -5.4385737e-6, + "bytes": [32, 121, 111, 117] + }, + { + "token": " today", + "logprob": -12.807695, + "bytes": [32, 116, 111, 100, 97, 121] + } + ] + }, + { + "token": " today", + "logprob": -0.0040071653, + "bytes": [32, 116, 111, 100, 97, 121], + "top_logprobs": [ + { + "token": " today", + "logprob": -0.0040071653, + "bytes": [32, 116, 111, 100, 97, 121] + }, + { + "token": "?", + "logprob": -5.5247097, + "bytes": [63] + } + ] + }, + { + "token": "?", + "logprob": -0.0008108172, + "bytes": [63], + "top_logprobs": [ + { + "token": "?", + "logprob": -0.0008108172, + "bytes": [63] + }, + { + "token": "?\n", + "logprob": -7.184561, + "bytes": [63, 10] + } + ] + } + ] + }, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 9, + "completion_tokens": 9, + "total_tokens": 18 + }, + "system_fingerprint": null + } + /completions: post: operationId: createCompletion tags: - - OpenAI + - Completions summary: Creates a completion for the provided prompt and parameters. requestBody: required: true content: application/json: schema: - $ref: '#/components/schemas/CreateCompletionRequest' + $ref: "#/components/schemas/CreateCompletionRequest" responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/CreateCompletionResponse' + $ref: "#/components/schemas/CreateCompletionResponse" x-oaiMeta: name: Create completion group: completions - path: create + returns: | + Returns a [completion](/docs/api-reference/completions/object) object, or a sequence of completion objects if the request is streamed. + legacy: true examples: - curl: | - curl https://api.openai.com/v1/completions \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "model": "VAR_model_id", - "prompt": "Say this is a test", - "max_tokens": 7, - "temperature": 0 - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Completion.create( - model="VAR_model_id", - prompt="Say this is a test", - max_tokens=7, - temperature=0 - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createCompletion({ - model: "VAR_model_id", - prompt: "Say this is a test", - max_tokens: 7, - temperature: 0, - }); - parameters: | - { - "model": "VAR_model_id", - "prompt": "Say this is a test", - "max_tokens": 7, - "temperature": 0, - "top_p": 1, - "n": 1, - "stream": false, - "logprobs": null, - "stop": "\n" - } - response: | - { - "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7", - "object": "text_completion", - "created": 1589478378, - "model": "VAR_model_id", - "choices": [ + - title: No streaming + request: + curl: | + curl https://api.openai.com/v1/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "VAR_model_id", + "prompt": "Say this is a test", + "max_tokens": 7, + "temperature": 0 + }' + python: | + from openai import OpenAI + client = OpenAI() + + client.completions.create( + model="VAR_model_id", + prompt="Say this is a test", + max_tokens=7, + temperature=0 + ) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const completion = await openai.completions.create({ + model: "VAR_model_id", + prompt: "Say this is a test.", + max_tokens: 7, + temperature: 0, + }); + + console.log(completion); + } + main(); + response: | { - "text": "\n\nThis is indeed a test", - "index": 0, - "logprobs": null, - "finish_reason": "length" - } - ], - "usage": { - "prompt_tokens": 5, - "completion_tokens": 7, - "total_tokens": 12 - } - } - /edits: - post: - operationId: createEdit - tags: - - OpenAI - summary: Creates a new edit for the provided input, instruction, and parameters. - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/CreateEditRequest' - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/CreateEditResponse' - x-oaiMeta: - name: Create edit - group: edits - path: create - examples: - curl: | - curl https://api.openai.com/v1/edits \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ + "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7", + "object": "text_completion", + "created": 1589478378, "model": "VAR_model_id", - "input": "What day of the wek is it?", - "instruction": "Fix the spelling mistakes" - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Edit.create( - model="VAR_model_id", - input="What day of the wek is it?", - instruction="Fix the spelling mistakes" - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createEdit({ - model: "VAR_model_id", - input: "What day of the wek is it?", - instruction: "Fix the spelling mistakes", - }); - parameters: | - { - "model": "VAR_model_id", - "input": "What day of the wek is it?", - "instruction": "Fix the spelling mistakes" - } - response: | - { - "object": "edit", - "created": 1589478378, - "choices": [ + "system_fingerprint": "fp_44709d6fcb", + "choices": [ + { + "text": "\n\nThis is indeed a test", + "index": 0, + "logprobs": null, + "finish_reason": "length" + } + ], + "usage": { + "prompt_tokens": 5, + "completion_tokens": 7, + "total_tokens": 12 + } + } + - title: Streaming + request: + curl: | + curl https://api.openai.com/v1/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "VAR_model_id", + "prompt": "Say this is a test", + "max_tokens": 7, + "temperature": 0, + "stream": true + }' + python: | + from openai import OpenAI + client = OpenAI() + + for chunk in client.completions.create( + model="VAR_model_id", + prompt="Say this is a test", + max_tokens=7, + temperature=0, + stream=True + ): + print(chunk.choices[0].text) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const stream = await openai.completions.create({ + model: "VAR_model_id", + prompt: "Say this is a test.", + stream: true, + }); + + for await (const chunk of stream) { + console.log(chunk.choices[0].text) + } + } + main(); + response: | { - "text": "What day of the week is it?", - "index": 0, + "id": "cmpl-7iA7iJjj8V2zOkCGvWF2hAkDWBQZe", + "object": "text_completion", + "created": 1690759702, + "choices": [ + { + "text": "This", + "index": 0, + "logprobs": null, + "finish_reason": null + } + ], + "model": "gpt-3.5-turbo-instruct" + "system_fingerprint": "fp_44709d6fcb", } - ], - "usage": { - "prompt_tokens": 25, - "completion_tokens": 32, - "total_tokens": 57 - } - } /images/generations: post: operationId: createImage tags: - - OpenAI + - Images summary: Creates an image given a prompt. requestBody: required: true content: application/json: schema: - $ref: '#/components/schemas/CreateImageRequest' + $ref: "#/components/schemas/CreateImageRequest" responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/ImagesResponse' + $ref: "#/components/schemas/ImagesResponse" x-oaiMeta: name: Create image group: images - path: create - beta: true + returns: Returns a list of [image](/docs/api-reference/images/object) objects. examples: - curl: | - curl https://api.openai.com/v1/images/generations \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "prompt": "A cute baby sea otter", - "n": 2, - "size": "1024x1024" - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Image.create( - prompt="A cute baby sea otter", - n=2, - size="1024x1024" - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createImage({ - prompt: "A cute baby sea otter", - n: 2, - size: "1024x1024", - }); - parameters: | - { - "prompt": "A cute baby sea otter", - "n": 2, - "size": "1024x1024" - } - response: | - { - "created": 1589478378, - "data": [ - { - "url": "https://..." - }, - { - "url": "https://..." - } - ] - } + request: + curl: | + curl https://api.openai.com/v1/images/generations \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "dall-e-3", + "prompt": "A cute baby sea otter", + "n": 1, + "size": "1024x1024" + }' + python: | + from openai import OpenAI + client = OpenAI() + + client.images.generate( + model="dall-e-3", + prompt="A cute baby sea otter", + n=1, + size="1024x1024" + ) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const image = await openai.images.generate({ model: "dall-e-3", prompt: "A cute baby sea otter" }); + console.log(image.data); + } + main(); + response: | + { + "created": 1589478378, + "data": [ + { + "url": "https://..." + }, + { + "url": "https://..." + } + ] + } /images/edits: post: operationId: createImageEdit tags: - - OpenAI + - Images summary: Creates an edited or extended image given an original image and a prompt. requestBody: required: true content: multipart/form-data: schema: - $ref: '#/components/schemas/CreateImageEditRequest' + $ref: "#/components/schemas/CreateImageEditRequest" responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/ImagesResponse' + $ref: "#/components/schemas/ImagesResponse" x-oaiMeta: name: Create image edit group: images - path: create-edit - beta: true + returns: Returns a list of [image](/docs/api-reference/images/object) objects. examples: - curl: | - curl https://api.openai.com/v1/images/edits \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -F image="@otter.png" \ - -F mask="@mask.png" \ - -F prompt="A cute baby sea otter wearing a beret" \ - -F n=2 \ - -F size="1024x1024" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Image.create_edit( - image=open("otter.png", "rb"), - mask=open("mask.png", "rb"), - prompt="A cute baby sea otter wearing a beret", - n=2, - size="1024x1024" - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createImageEdit( - fs.createReadStream("otter.png"), - fs.createReadStream("mask.png"), - "A cute baby sea otter wearing a beret", - 2, - "1024x1024" - ); - response: | - { - "created": 1589478378, - "data": [ - { - "url": "https://..." - }, - { - "url": "https://..." - } - ] - } + request: + curl: | + curl https://api.openai.com/v1/images/edits \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -F image="@otter.png" \ + -F mask="@mask.png" \ + -F prompt="A cute baby sea otter wearing a beret" \ + -F n=2 \ + -F size="1024x1024" + python: | + from openai import OpenAI + client = OpenAI() + + client.images.edit( + image=open("otter.png", "rb"), + mask=open("mask.png", "rb"), + prompt="A cute baby sea otter wearing a beret", + n=2, + size="1024x1024" + ) + node.js: |- + import fs from "fs"; + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const image = await openai.images.edit({ + image: fs.createReadStream("otter.png"), + mask: fs.createReadStream("mask.png"), + prompt: "A cute baby sea otter wearing a beret", + }); + console.log(image.data); + } + main(); + response: | + { + "created": 1589478378, + "data": [ + { + "url": "https://..." + }, + { + "url": "https://..." + } + ] + } /images/variations: post: operationId: createImageVariation tags: - - OpenAI + - Images summary: Creates a variation of a given image. requestBody: required: true content: multipart/form-data: schema: - $ref: '#/components/schemas/CreateImageVariationRequest' + $ref: "#/components/schemas/CreateImageVariationRequest" responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/ImagesResponse' + $ref: "#/components/schemas/ImagesResponse" x-oaiMeta: name: Create image variation group: images - path: create-variation - beta: true + returns: Returns a list of [image](/docs/api-reference/images/object) objects. examples: - curl: | - curl https://api.openai.com/v1/images/variations \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -F image="@otter.png" \ - -F n=2 \ - -F size="1024x1024" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Image.create_variation( - image=open("otter.png", "rb"), - n=2, - size="1024x1024" - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createImageVariation( - fs.createReadStream("otter.png"), - 2, - "1024x1024" - ); - response: | - { - "created": 1589478378, - "data": [ - { - "url": "https://..." - }, - { - "url": "https://..." + request: + curl: | + curl https://api.openai.com/v1/images/variations \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -F image="@otter.png" \ + -F n=2 \ + -F size="1024x1024" + python: | + from openai import OpenAI + client = OpenAI() + + response = client.images.create_variation( + image=open("image_edit_original.png", "rb"), + n=2, + size="1024x1024" + ) + node.js: |- + import fs from "fs"; + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const image = await openai.images.createVariation({ + image: fs.createReadStream("otter.png"), + }); + + console.log(image.data); } - ] - } + main(); + response: | + { + "created": 1589478378, + "data": [ + { + "url": "https://..." + }, + { + "url": "https://..." + } + ] + } /embeddings: post: operationId: createEmbedding tags: - - OpenAI + - Embeddings summary: Creates an embedding vector representing the input text. requestBody: required: true content: application/json: schema: - $ref: '#/components/schemas/CreateEmbeddingRequest' + $ref: "#/components/schemas/CreateEmbeddingRequest" responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/CreateEmbeddingResponse' + $ref: "#/components/schemas/CreateEmbeddingResponse" x-oaiMeta: name: Create embeddings group: embeddings - path: create + returns: A list of [embedding](/docs/api-reference/embeddings/object) objects. examples: - curl: | - curl https://api.openai.com/v1/embeddings \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: application/json" \ - -d '{ - "input": "The food was delicious and the waiter...", - "model": "text-embedding-ada-002" - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Embedding.create( - model="text-embedding-ada-002", - input="The food was delicious and the waiter..." - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createEmbedding({ - model: "text-embedding-ada-002", - input: "The food was delicious and the waiter...", - }); - parameters: | - { - "model": "text-embedding-ada-002", - "input": "The food was delicious and the waiter..." - } - response: | - { - "object": "list", - "data": [ - { - "object": "embedding", - "embedding": [ - 0.0023064255, - -0.009327292, - .... (1536 floats total for ada-002) - -0.0028842222, - ], - "index": 0 + request: + curl: | + curl https://api.openai.com/v1/embeddings \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "input": "The food was delicious and the waiter...", + "model": "text-embedding-ada-002", + "encoding_format": "float" + }' + python: | + from openai import OpenAI + client = OpenAI() + + client.embeddings.create( + model="text-embedding-ada-002", + input="The food was delicious and the waiter...", + encoding_format="float" + ) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const embedding = await openai.embeddings.create({ + model: "text-embedding-ada-002", + input: "The quick brown fox jumped over the lazy dog", + encoding_format: "float", + }); + + console.log(embedding); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "object": "embedding", + "embedding": [ + 0.0023064255, + -0.009327292, + .... (1536 floats total for ada-002) + -0.0028842222, + ], + "index": 0 + } + ], + "model": "text-embedding-ada-002", + "usage": { + "prompt_tokens": 8, + "total_tokens": 8 } - ], - "model": "text-embedding-ada-002", - "usage": { - "prompt_tokens": 8, - "total_tokens": 8 } - } + /audio/speech: + post: + operationId: createSpeech + tags: + - Audio + summary: Generates audio from the input text. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CreateSpeechRequest" + responses: + "200": + description: OK + headers: + Transfer-Encoding: + schema: + type: string + description: chunked + content: + application/octet-stream: + schema: + type: string + format: binary + x-oaiMeta: + name: Create speech + group: audio + returns: The audio file content. + examples: + request: + curl: | + curl https://api.openai.com/v1/audio/speech \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "model": "tts-1", + "input": "The quick brown fox jumped over the lazy dog.", + "voice": "alloy" + }' \ + --output speech.mp3 + python: | + from pathlib import Path + import openai + + speech_file_path = Path(__file__).parent / "speech.mp3" + response = openai.audio.speech.create( + model="tts-1", + voice="alloy", + input="The quick brown fox jumped over the lazy dog." + ) + response.stream_to_file(speech_file_path) + node: | + import fs from "fs"; + import path from "path"; + import OpenAI from "openai"; + + const openai = new OpenAI(); + + const speechFile = path.resolve("./speech.mp3"); + + async function main() { + const mp3 = await openai.audio.speech.create({ + model: "tts-1", + voice: "alloy", + input: "Today is a wonderful day to build something people love!", + }); + console.log(speechFile); + const buffer = Buffer.from(await mp3.arrayBuffer()); + await fs.promises.writeFile(speechFile, buffer); + } + main(); /audio/transcriptions: post: operationId: createTranscription tags: - - OpenAI + - Audio summary: Transcribes audio into the input language. requestBody: required: true content: multipart/form-data: schema: - $ref: '#/components/schemas/CreateTranscriptionRequest' + $ref: "#/components/schemas/CreateTranscriptionRequest" responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/CreateTranscriptionResponse' + $ref: "#/components/schemas/CreateTranscriptionResponse" x-oaiMeta: name: Create transcription group: audio - path: create - beta: true + returns: The transcribed text. examples: - curl: | - curl https://api.openai.com/v1/audio/transcriptions \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: multipart/form-data" \ - -F file="@/path/to/file/audio.mp3" \ - -F model="whisper-1" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - audio_file = open("audio.mp3", "rb") - transcript = openai.Audio.transcribe("whisper-1", audio_file) - node: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const resp = await openai.createTranscription( - fs.createReadStream("audio.mp3"), - "whisper-1" - ); - parameters: | - { - "file": "audio.mp3", - "model": "whisper-1" - } - response: | - { - "text": "Imagine the wildest idea that you've ever had, and you're curious about how it might scale to something that's a 100, a 1,000 times bigger. This is a place where you can get to do that." - } + request: + curl: | + curl https://api.openai.com/v1/audio/transcriptions \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: multipart/form-data" \ + -F file="@/path/to/file/audio.mp3" \ + -F model="whisper-1" + python: | + from openai import OpenAI + client = OpenAI() + + audio_file = open("speech.mp3", "rb") + transcript = client.audio.transcriptions.create( + model="whisper-1", + file=audio_file + ) + node: | + import fs from "fs"; + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const transcription = await openai.audio.transcriptions.create({ + file: fs.createReadStream("audio.mp3"), + model: "whisper-1", + }); + + console.log(transcription.text); + } + main(); + response: | + { + "text": "Imagine the wildest idea that you've ever had, and you're curious about how it might scale to something that's a 100, a 1,000 times bigger. This is a place where you can get to do that." + } /audio/translations: post: operationId: createTranslation tags: - - OpenAI + - Audio summary: Translates audio into English. requestBody: required: true content: multipart/form-data: schema: - $ref: '#/components/schemas/CreateTranslationRequest' + $ref: "#/components/schemas/CreateTranslationRequest" responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/CreateTranslationResponse' + $ref: "#/components/schemas/CreateTranslationResponse" x-oaiMeta: name: Create translation group: audio - path: create - beta: true + returns: The translated text. examples: - curl: | - curl https://api.openai.com/v1/audio/translations \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -H "Content-Type: multipart/form-data" \ - -F file="@/path/to/file/german.m4a" \ - -F model="whisper-1" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - audio_file = open("german.m4a", "rb") - transcript = openai.Audio.translate("whisper-1", audio_file) - node: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const resp = await openai.createTranslation( - fs.createReadStream("audio.mp3"), - "whisper-1" - ); - parameters: | - { - "file": "german.m4a", - "model": "whisper-1" - } - response: | - { - "text": "Hello, my name is Wolfgang and I come from Germany. Where are you heading today?" - } + request: + curl: | + curl https://api.openai.com/v1/audio/translations \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: multipart/form-data" \ + -F file="@/path/to/file/german.m4a" \ + -F model="whisper-1" + python: | + from openai import OpenAI + client = OpenAI() + + audio_file = open("speech.mp3", "rb") + transcript = client.audio.translations.create( + model="whisper-1", + file=audio_file + ) + node: | + import fs from "fs"; + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const translation = await openai.audio.translations.create({ + file: fs.createReadStream("speech.mp3"), + model: "whisper-1", + }); + + console.log(translation.text); + } + main(); + response: | + { + "text": "Hello, my name is Wolfgang and I come from Germany. Where are you heading today?" + } /files: get: operationId: listFiles tags: - - OpenAI + - Files summary: Returns a list of files that belong to the user's organization. + parameters: + - in: query + name: purpose + required: false + schema: + type: string + description: Only return files with the given purpose. responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/ListFilesResponse' + $ref: "#/components/schemas/ListFilesResponse" x-oaiMeta: name: List files group: files - path: list + returns: A list of [File](/docs/api-reference/files/object) objects. examples: - curl: | - curl https://api.openai.com/v1/files \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.File.list() - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.listFiles(); - response: | - { - "data": [ - { - "id": "file-ccdDZrC3iZVNiQVeEA6Z66wf", - "object": "file", - "bytes": 175, - "created_at": 1613677385, - "filename": "train.jsonl", - "purpose": "search" - }, - { - "id": "file-XjGxS3KTG0uNmNOK362iJua3", - "object": "file", - "bytes": 140, - "created_at": 1613779121, - "filename": "puppy.jsonl", - "purpose": "search" + request: + curl: | + curl https://api.openai.com/v1/files \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.files.list() + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const list = await openai.files.list(); + + for await (const file of list) { + console.log(file); + } } - ], - "object": "list" - } + + main(); + response: | + { + "data": [ + { + "id": "file-abc123", + "object": "file", + "bytes": 175, + "created_at": 1613677385, + "filename": "salesOverview.pdf", + "purpose": "assistants", + }, + { + "id": "file-abc123", + "object": "file", + "bytes": 140, + "created_at": 1613779121, + "filename": "puppy.jsonl", + "purpose": "fine-tune", + } + ], + "object": "list" + } post: operationId: createFile tags: - - OpenAI + - Files summary: | - Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact us if you need to increase the storage limit. + Upload a file that can be used across various endpoints. The size of all the files uploaded by one organization can be up to 100 GB. + The size of individual files can be a maximum of 512 MB or 2 million tokens for Assistants. See the [Assistants Tools guide](/docs/assistants/tools) to learn more about the types of files supported. The Fine-tuning API only supports `.jsonl` files. + + Please [contact us](https://help.openai.com/) if you need to increase these storage limits. requestBody: required: true content: multipart/form-data: schema: - $ref: '#/components/schemas/CreateFileRequest' + $ref: "#/components/schemas/CreateFileRequest" responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/OpenAIFile' + $ref: "#/components/schemas/OpenAIFile" x-oaiMeta: name: Upload file group: files - path: upload + returns: The uploaded [File](/docs/api-reference/files/object) object. examples: - curl: | - curl https://api.openai.com/v1/files \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -F purpose="fine-tune" \ - -F file="@mydata.jsonl" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.File.create( - file=open("mydata.jsonl", "rb"), - purpose='fine-tune' - ) - node.js: | - const fs = require("fs"); - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createFile( - fs.createReadStream("mydata.jsonl"), - "fine-tune" - ); - response: | - { - "id": "file-XjGxS3KTG0uNmNOK362iJua3", - "object": "file", - "bytes": 140, - "created_at": 1613779121, - "filename": "mydata.jsonl", - "purpose": "fine-tune" - } + request: + curl: | + curl https://api.openai.com/v1/files \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -F purpose="fine-tune" \ + -F file="@mydata.jsonl" + python: | + from openai import OpenAI + client = OpenAI() + + client.files.create( + file=open("mydata.jsonl", "rb"), + purpose="fine-tune" + ) + node.js: |- + import fs from "fs"; + import OpenAI from "openai"; + + const openai = new OpenAI(); + async function main() { + const file = await openai.files.create({ + file: fs.createReadStream("mydata.jsonl"), + purpose: "fine-tune", + }); + + console.log(file); + } + + main(); + response: | + { + "id": "file-abc123", + "object": "file", + "bytes": 120000, + "created_at": 1677610602, + "filename": "mydata.jsonl", + "purpose": "fine-tune", + } /files/{file_id}: delete: operationId: deleteFile tags: - - OpenAI + - Files summary: Delete a file. parameters: - in: path @@ -782,45 +1451,51 @@ paths: required: true schema: type: string - description: The ID of the file to use for this request + description: The ID of the file to use for this request. responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/DeleteFileResponse' + $ref: "#/components/schemas/DeleteFileResponse" x-oaiMeta: name: Delete file group: files - path: delete + returns: Deletion status. examples: - curl: | - curl https://api.openai.com/v1/files/file-XjGxS3KTG0uNmNOK362iJua3 \ - -X DELETE \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.File.delete("file-XjGxS3KTG0uNmNOK362iJua3") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.deleteFile("file-XjGxS3KTG0uNmNOK362iJua3"); - response: | - { - "id": "file-XjGxS3KTG0uNmNOK362iJua3", - "object": "file", - "deleted": true - } + request: + curl: | + curl https://api.openai.com/v1/files/file-abc123 \ + -X DELETE \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.files.delete("file-abc123") + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const file = await openai.files.del("file-abc123"); + + console.log(file); + } + + main(); + response: | + { + "id": "file-abc123", + "object": "file", + "deleted": true + } get: operationId: retrieveFile tags: - - OpenAI + - Files summary: Returns information about a specific file. parameters: - in: path @@ -828,57 +1503,62 @@ paths: required: true schema: type: string - description: The ID of the file to use for this request + description: The ID of the file to use for this request. responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/OpenAIFile' + $ref: "#/components/schemas/OpenAIFile" x-oaiMeta: name: Retrieve file group: files - path: retrieve + returns: The [File](/docs/api-reference/files/object) object matching the specified ID. examples: - curl: | - curl https://api.openai.com/v1/files/file-XjGxS3KTG0uNmNOK362iJua3 \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.File.retrieve("file-XjGxS3KTG0uNmNOK362iJua3") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.retrieveFile("file-XjGxS3KTG0uNmNOK362iJua3"); - response: | - { - "id": "file-XjGxS3KTG0uNmNOK362iJua3", - "object": "file", - "bytes": 140, - "created_at": 1613779657, - "filename": "mydata.jsonl", - "purpose": "fine-tune" - } + request: + curl: | + curl https://api.openai.com/v1/files/file-abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.files.retrieve("file-abc123") + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const file = await openai.files.retrieve("file-abc123"); + console.log(file); + } + + main(); + response: | + { + "id": "file-abc123", + "object": "file", + "bytes": 120000, + "created_at": 1677610602, + "filename": "mydata.jsonl", + "purpose": "fine-tune", + } /files/{file_id}/content: get: operationId: downloadFile tags: - - OpenAI - summary: Returns the contents of the specified file + - Files + summary: Returns the contents of the specified file. parameters: - in: path name: file_id required: true schema: type: string - description: The ID of the file to use for this request + description: The ID of the file to use for this request. responses: "200": description: OK @@ -889,455 +1569,511 @@ paths: x-oaiMeta: name: Retrieve file content group: files - path: retrieve-content + returns: The file content. examples: - curl: | - curl https://api.openai.com/v1/files/file-XjGxS3KTG0uNmNOK362iJua3/content \ - -H "Authorization: Bearer $OPENAI_API_KEY" > file.jsonl - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - content = openai.File.download("file-XjGxS3KTG0uNmNOK362iJua3") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.downloadFile("file-XjGxS3KTG0uNmNOK362iJua3"); - - /fine-tunes: + request: + curl: | + curl https://api.openai.com/v1/files/file-abc123/content \ + -H "Authorization: Bearer $OPENAI_API_KEY" > file.jsonl + python: | + from openai import OpenAI + client = OpenAI() + + content = client.files.retrieve_content("file-abc123") + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const file = await openai.files.retrieveContent("file-abc123"); + + console.log(file); + } + + main(); + + /fine_tuning/jobs: post: - operationId: createFineTune + operationId: createFineTuningJob tags: - - OpenAI + - Fine-tuning summary: | - Creates a job that fine-tunes a specified model from a given dataset. + Creates a fine-tuning job which begins the process of creating a new model from a given dataset. Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete. - [Learn more about Fine-tuning](/docs/guides/fine-tuning) + [Learn more about fine-tuning](/docs/guides/fine-tuning) requestBody: required: true content: application/json: schema: - $ref: '#/components/schemas/CreateFineTuneRequest' + $ref: "#/components/schemas/CreateFineTuningJobRequest" responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/FineTune' + $ref: "#/components/schemas/FineTuningJob" x-oaiMeta: - name: Create fine-tune - group: fine-tunes - path: create + name: Create fine-tuning job + group: fine-tuning + returns: A [fine-tuning.job](/docs/api-reference/fine-tuning/object) object. examples: - curl: | - curl https://api.openai.com/v1/fine-tunes \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "training_file": "file-XGinujblHPwGLSztz8cPS8XY" - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTune.create(training_file="file-XGinujblHPwGLSztz8cPS8XY") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createFineTune({ - training_file: "file-XGinujblHPwGLSztz8cPS8XY", - }); - response: | - { - "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F", - "object": "fine-tune", - "model": "curie", - "created_at": 1614807352, - "events": [ + - title: Default + request: + curl: | + curl https://api.openai.com/v1/fine_tuning/jobs \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "training_file": "file-BK7bzQj3FfZFXr7DbL6xJwfo", + "model": "gpt-3.5-turbo" + }' + python: | + from openai import OpenAI + client = OpenAI() + + client.fine_tuning.jobs.create( + training_file="file-abc123", + model="gpt-3.5-turbo" + ) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const fineTune = await openai.fineTuning.jobs.create({ + training_file: "file-abc123" + }); + + console.log(fineTune); + } + + main(); + response: | { - "object": "fine-tune-event", + "object": "fine_tuning.job", + "id": "ftjob-abc123", + "model": "gpt-3.5-turbo-0613", "created_at": 1614807352, - "level": "info", - "message": "Job enqueued. Waiting for jobs ahead to complete. Queue number: 0." + "fine_tuned_model": null, + "organization_id": "org-123", + "result_files": [], + "status": "queued", + "validation_file": null, + "training_file": "file-abc123", } - ], - "fine_tuned_model": null, - "hyperparams": { - "batch_size": 4, - "learning_rate_multiplier": 0.1, - "n_epochs": 4, - "prompt_loss_weight": 0.1, - }, - "organization_id": "org-...", - "result_files": [], - "status": "pending", - "validation_files": [], - "training_files": [ + - title: Epochs + request: + curl: | + curl https://api.openai.com/v1/fine_tuning/jobs \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "training_file": "file-abc123", + "model": "gpt-3.5-turbo", + "hyperparameters": { + "n_epochs": 2 + } + }' + python: | + from openai import OpenAI + client = OpenAI() + + client.fine_tuning.jobs.create( + training_file="file-abc123", + model="gpt-3.5-turbo", + hyperparameters={ + "n_epochs":2 + } + ) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const fineTune = await openai.fineTuning.jobs.create({ + training_file: "file-abc123", + model: "gpt-3.5-turbo", + hyperparameters: { n_epochs: 2 } + }); + + console.log(fineTune); + } + + main(); + response: | { - "id": "file-XGinujblHPwGLSztz8cPS8XY", - "object": "file", - "bytes": 1547276, - "created_at": 1610062281, - "filename": "my-data-train.jsonl", - "purpose": "fine-tune-train" + "object": "fine_tuning.job", + "id": "ftjob-abc123", + "model": "gpt-3.5-turbo-0613", + "created_at": 1614807352, + "fine_tuned_model": null, + "organization_id": "org-123", + "result_files": [], + "status": "queued", + "validation_file": null, + "training_file": "file-abc123", + "hyperparameters": {"n_epochs": 2}, + } + - title: Validation file + request: + curl: | + curl https://api.openai.com/v1/fine_tuning/jobs \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "training_file": "file-abc123", + "validation_file": "file-abc123", + "model": "gpt-3.5-turbo" + }' + python: | + from openai import OpenAI + client = OpenAI() + + client.fine_tuning.jobs.create( + training_file="file-abc123", + validation_file="file-def456", + model="gpt-3.5-turbo" + ) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const fineTune = await openai.fineTuning.jobs.create({ + training_file: "file-abc123", + validation_file: "file-abc123" + }); + + console.log(fineTune); + } + + main(); + response: | + { + "object": "fine_tuning.job", + "id": "ftjob-abc123", + "model": "gpt-3.5-turbo-0613", + "created_at": 1614807352, + "fine_tuned_model": null, + "organization_id": "org-123", + "result_files": [], + "status": "queued", + "validation_file": "file-abc123", + "training_file": "file-abc123", } - ], - "updated_at": 1614807352, - } get: - operationId: listFineTunes + operationId: listPaginatedFineTuningJobs tags: - - OpenAI + - Fine-tuning summary: | List your organization's fine-tuning jobs + parameters: + - name: after + in: query + description: Identifier for the last job from the previous pagination request. + required: false + schema: + type: string + - name: limit + in: query + description: Number of fine-tuning jobs to retrieve. + required: false + schema: + type: integer + default: 20 responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/ListFineTunesResponse' + $ref: "#/components/schemas/ListPaginatedFineTuningJobsResponse" x-oaiMeta: - name: List fine-tunes - group: fine-tunes - path: list + name: List fine-tuning jobs + group: fine-tuning + returns: A list of paginated [fine-tuning job](/docs/api-reference/fine-tuning/object) objects. examples: - curl: | - curl https://api.openai.com/v1/fine-tunes \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTune.list() - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.listFineTunes(); - response: | - { - "object": "list", - "data": [ - { - "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F", - "object": "fine-tune", - "model": "curie", - "created_at": 1614807352, - "fine_tuned_model": null, - "hyperparams": { ... }, - "organization_id": "org-...", - "result_files": [], - "status": "pending", - "validation_files": [], - "training_files": [ { ... } ], - "updated_at": 1614807352, - }, - { ... }, - { ... } - ] - } + request: + curl: | + curl https://api.openai.com/v1/fine_tuning/jobs?limit=2 \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.fine_tuning.jobs.list() + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); - /fine-tunes/{fine_tune_id}: + async function main() { + const list = await openai.fineTuning.jobs.list(); + + for await (const fineTune of list) { + console.log(fineTune); + } + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "object": "fine_tuning.job.event", + "id": "ft-event-TjX0lMfOniCZX64t9PUQT5hn", + "created_at": 1689813489, + "level": "warn", + "message": "Fine tuning process stopping due to job cancellation", + "data": null, + "type": "message" + }, + { ... }, + { ... } + ], "has_more": true + } + /fine_tuning/jobs/{fine_tuning_job_id}: get: - operationId: retrieveFineTune + operationId: retrieveFineTuningJob tags: - - OpenAI + - Fine-tuning summary: | - Gets info about the fine-tune job. + Get info about a fine-tuning job. - [Learn more about Fine-tuning](/docs/guides/fine-tuning) + [Learn more about fine-tuning](/docs/guides/fine-tuning) parameters: - in: path - name: fine_tune_id + name: fine_tuning_job_id required: true schema: type: string - example: - ft-AF1WoRqd3aJAHsqc9NY7iL8F + example: ft-AF1WoRqd3aJAHsqc9NY7iL8F description: | - The ID of the fine-tune job + The ID of the fine-tuning job. responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/FineTune' + $ref: "#/components/schemas/FineTuningJob" x-oaiMeta: - name: Retrieve fine-tune - group: fine-tunes - path: retrieve + name: Retrieve fine-tuning job + group: fine-tuning + returns: The [fine-tuning](/docs/api-reference/fine-tuning/object) object with the given ID. examples: - curl: | - curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTune.retrieve(id="ft-AF1WoRqd3aJAHsqc9NY7iL8F") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.retrieveFineTune("ft-AF1WoRqd3aJAHsqc9NY7iL8F"); - response: | - { - "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F", - "object": "fine-tune", - "model": "curie", - "created_at": 1614807352, - "events": [ - { - "object": "fine-tune-event", - "created_at": 1614807352, - "level": "info", - "message": "Job enqueued. Waiting for jobs ahead to complete. Queue number: 0." - }, - { - "object": "fine-tune-event", - "created_at": 1614807356, - "level": "info", - "message": "Job started." - }, - { - "object": "fine-tune-event", - "created_at": 1614807861, - "level": "info", - "message": "Uploaded snapshot: curie:ft-acmeco-2021-03-03-21-44-20." - }, - { - "object": "fine-tune-event", - "created_at": 1614807864, - "level": "info", - "message": "Uploaded result files: file-QQm6ZpqdNwAaVC3aSz5sWwLT." - }, - { - "object": "fine-tune-event", - "created_at": 1614807864, - "level": "info", - "message": "Job succeeded." - } - ], - "fine_tuned_model": "curie:ft-acmeco-2021-03-03-21-44-20", - "hyperparams": { - "batch_size": 4, - "learning_rate_multiplier": 0.1, - "n_epochs": 4, - "prompt_loss_weight": 0.1, - }, - "organization_id": "org-...", - "result_files": [ - { - "id": "file-QQm6ZpqdNwAaVC3aSz5sWwLT", - "object": "file", - "bytes": 81509, - "created_at": 1614807863, - "filename": "compiled_results.csv", - "purpose": "fine-tune-results" - } - ], - "status": "succeeded", - "validation_files": [], - "training_files": [ - { - "id": "file-XGinujblHPwGLSztz8cPS8XY", - "object": "file", - "bytes": 1547276, - "created_at": 1610062281, - "filename": "my-data-train.jsonl", - "purpose": "fine-tune-train" + request: + curl: | + curl https://api.openai.com/v1/fine_tuning/jobs/ft-AF1WoRqd3aJAHsqc9NY7iL8F \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.fine_tuning.jobs.retrieve("ftjob-abc123") + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const fineTune = await openai.fineTuning.jobs.retrieve("ftjob-abc123"); + + console.log(fineTune); } - ], - "updated_at": 1614807865, - } - /fine-tunes/{fine_tune_id}/cancel: - post: - operationId: cancelFineTune + main(); + response: &fine_tuning_example | + { + "object": "fine_tuning.job", + "id": "ftjob-abc123", + "model": "davinci-002", + "created_at": 1692661014, + "finished_at": 1692661190, + "fine_tuned_model": "ft:davinci-002:my-org:custom_suffix:7q8mpxmy", + "organization_id": "org-123", + "result_files": [ + "file-abc123" + ], + "status": "succeeded", + "validation_file": null, + "training_file": "file-abc123", + "hyperparameters": { + "n_epochs": 4, + }, + "trained_tokens": 5768 + } + /fine_tuning/jobs/{fine_tuning_job_id}/events: + get: + operationId: listFineTuningEvents tags: - - OpenAI + - Fine-tuning summary: | - Immediately cancel a fine-tune job. + Get status updates for a fine-tuning job. parameters: - in: path - name: fine_tune_id + name: fine_tuning_job_id required: true schema: type: string - example: - ft-AF1WoRqd3aJAHsqc9NY7iL8F + example: ft-AF1WoRqd3aJAHsqc9NY7iL8F description: | - The ID of the fine-tune job to cancel + The ID of the fine-tuning job to get events for. + - name: after + in: query + description: Identifier for the last event from the previous pagination request. + required: false + schema: + type: string + - name: limit + in: query + description: Number of events to retrieve. + required: false + schema: + type: integer + default: 20 responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/FineTune' + $ref: "#/components/schemas/ListFineTuningJobEventsResponse" x-oaiMeta: - name: Cancel fine-tune - group: fine-tunes - path: cancel + name: List fine-tuning events + group: fine-tuning + returns: A list of fine-tuning event objects. examples: - curl: | - curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F/cancel \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTune.cancel(id="ft-AF1WoRqd3aJAHsqc9NY7iL8F") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.cancelFineTune("ft-AF1WoRqd3aJAHsqc9NY7iL8F"); - response: | - { - "id": "ft-xhrpBbvVUzYGo8oUO1FY4nI7", - "object": "fine-tune", - "model": "curie", - "created_at": 1614807770, - "events": [ { ... } ], - "fine_tuned_model": null, - "hyperparams": { ... }, - "organization_id": "org-...", - "result_files": [], - "status": "cancelled", - "validation_files": [], - "training_files": [ - { - "id": "file-XGinujblHPwGLSztz8cPS8XY", - "object": "file", - "bytes": 1547276, - "created_at": 1610062281, - "filename": "my-data-train.jsonl", - "purpose": "fine-tune-train" + request: + curl: | + curl https://api.openai.com/v1/fine_tuning/jobs/ftjob-abc123/events \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.fine_tuning.jobs.list_events( + fine_tuning_job_id="ftjob-abc123", + limit=2 + ) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const list = await openai.fineTuning.list_events(id="ftjob-abc123", limit=2); + + for await (const fineTune of list) { + console.log(fineTune); + } } - ], - "updated_at": 1614807789, - } - /fine-tunes/{fine_tune_id}/events: - get: - operationId: listFineTuneEvents + main(); + response: | + { + "object": "list", + "data": [ + { + "object": "fine_tuning.job.event", + "id": "ft-event-ddTJfwuMVpfLXseO0Am0Gqjm", + "created_at": 1692407401, + "level": "info", + "message": "Fine tuning job successfully completed", + "data": null, + "type": "message" + }, + { + "object": "fine_tuning.job.event", + "id": "ft-event-tyiGuB72evQncpH87xe505Sv", + "created_at": 1692407400, + "level": "info", + "message": "New fine-tuned model created: ft:gpt-3.5-turbo:openai::7p4lURel", + "data": null, + "type": "message" + } + ], + "has_more": true + } + /fine_tuning/jobs/{fine_tuning_job_id}/cancel: + post: + operationId: cancelFineTuningJob tags: - - OpenAI + - Fine-tuning summary: | - Get fine-grained status updates for a fine-tune job. + Immediately cancel a fine-tune job. parameters: - in: path - name: fine_tune_id + name: fine_tuning_job_id required: true schema: type: string - example: - ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - The ID of the fine-tune job to get events for. - - in: query - name: stream - required: false - schema: - type: boolean - default: false + example: ft-AF1WoRqd3aJAHsqc9NY7iL8F description: | - Whether to stream events for the fine-tune job. If set to true, - events 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. The stream will terminate with a - `data: [DONE]` message when the job is finished (succeeded, cancelled, - or failed). - - If set to false, only events generated so far will be returned. + The ID of the fine-tuning job to cancel. responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/ListFineTuneEventsResponse' + $ref: "#/components/schemas/FineTuningJob" x-oaiMeta: - name: List fine-tune events - group: fine-tunes - path: events + name: Cancel fine-tuning + group: fine-tuning + returns: The cancelled [fine-tuning](/docs/api-reference/fine-tuning/object) object. examples: - curl: | - curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F/events \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.FineTune.list_events(id="ft-AF1WoRqd3aJAHsqc9NY7iL8F") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.listFineTuneEvents("ft-AF1WoRqd3aJAHsqc9NY7iL8F"); - response: | - { - "object": "list", - "data": [ - { - "object": "fine-tune-event", - "created_at": 1614807352, - "level": "info", - "message": "Job enqueued. Waiting for jobs ahead to complete. Queue number: 0." - }, - { - "object": "fine-tune-event", - "created_at": 1614807356, - "level": "info", - "message": "Job started." - }, - { - "object": "fine-tune-event", - "created_at": 1614807861, - "level": "info", - "message": "Uploaded snapshot: curie:ft-acmeco-2021-03-03-21-44-20." - }, - { - "object": "fine-tune-event", - "created_at": 1614807864, - "level": "info", - "message": "Uploaded result files: file-QQm6ZpqdNwAaVC3aSz5sWwLT." - }, - { - "object": "fine-tune-event", - "created_at": 1614807864, - "level": "info", - "message": "Job succeeded." + request: + curl: | + curl -X POST https://api.openai.com/v1/fine_tuning/jobs/ftjob-abc123/cancel \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.fine_tuning.jobs.cancel("ftjob-abc123") + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const fineTune = await openai.fineTuning.jobs.cancel("ftjob-abc123"); + + console.log(fineTune); } - ] - } + main(); + response: | + { + "object": "fine_tuning.job", + "id": "ftjob-abc123", + "model": "gpt-3.5-turbo-0613", + "created_at": 1689376978, + "fine_tuned_model": null, + "organization_id": "org-123", + "result_files": [], + "hyperparameters": { + "n_epochs": "auto" + }, + "status": "cancelled", + "validation_file": "file-abc123", + "training_file": "file-abc123" + } /models: get: operationId: listModels tags: - - OpenAI + - Models summary: Lists the currently available models, and provides basic information about each one such as the owner and availability. responses: "200": @@ -1345,57 +2081,64 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ListModelsResponse' + $ref: "#/components/schemas/ListModelsResponse" x-oaiMeta: name: List models group: models - path: list + returns: A list of [model](/docs/api-reference/models/object) objects. examples: - curl: | - curl https://api.openai.com/v1/models \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Model.list() - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.listModels(); - response: | - { - "data": [ - { - "id": "model-id-0", - "object": "model", - "owned_by": "organization-owner", - "permission": [...] - }, - { - "id": "model-id-1", - "object": "model", - "owned_by": "organization-owner", - "permission": [...] - }, - { - "id": "model-id-2", - "object": "model", - "owned_by": "openai", - "permission": [...] - }, - ], - "object": "list" - } + request: + curl: | + curl https://api.openai.com/v1/models \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.models.list() + node.js: |- + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const list = await openai.models.list(); + + for await (const model of list) { + console.log(model); + } + } + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "model-id-0", + "object": "model", + "created": 1686935002, + "owned_by": "organization-owner" + }, + { + "id": "model-id-1", + "object": "model", + "created": 1686935002, + "owned_by": "organization-owner", + }, + { + "id": "model-id-2", + "object": "model", + "created": 1686935002, + "owned_by": "openai" + }, + ], + "object": "list" + } /models/{model}: get: operationId: retrieveModel tags: - - OpenAI + - Models summary: Retrieves a model instance, providing basic information about the model such as the owner and permissioning. parameters: - in: path @@ -1404,56 +2147,60 @@ paths: schema: type: string # ideally this will be an actual ID, so this will always work from browser - example: - text-davinci-001 - description: - The ID of the model to use for this request + example: gpt-3.5-turbo + description: The ID of the model to use for this request responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/Model' + $ref: "#/components/schemas/Model" x-oaiMeta: name: Retrieve model group: models - path: retrieve + returns: The [model](/docs/api-reference/models/object) object matching the specified ID. examples: - curl: | - curl https://api.openai.com/v1/models/VAR_model_id \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Model.retrieve("VAR_model_id") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.retrieveModel("VAR_model_id"); - response: | - { - "id": "VAR_model_id", - "object": "model", - "owned_by": "openai", - "permission": [...] - } + request: + curl: | + curl https://api.openai.com/v1/models/VAR_model_id \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.models.retrieve("VAR_model_id") + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const model = await openai.models.retrieve("gpt-3.5-turbo"); + + console.log(model); + } + + main(); + response: &retrieve_model_response | + { + "id": "VAR_model_id", + "object": "model", + "created": 1686935002, + "owned_by": "openai" + } delete: operationId: deleteModel tags: - - OpenAI - summary: Delete a fine-tuned model. You must have the Owner role in your organization. + - Models + summary: Delete a fine-tuned model. You must have the Owner role in your organization to delete a model. parameters: - in: path name: model required: true schema: type: string - example: curie:ft-acmeco-2021-03-03-21-44-20 + example: ft:gpt-3.5-turbo:acemeco:suffix:abc123 description: The model to delete responses: "200": @@ -1461,1562 +2208,6784 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/DeleteModelResponse' + $ref: "#/components/schemas/DeleteModelResponse" x-oaiMeta: - name: Delete fine-tune model - group: fine-tunes - path: delete-model + name: Delete a fine-tuned model + group: models + returns: Deletion status. examples: - curl: | - curl https://api.openai.com/v1/models/curie:ft-acmeco-2021-03-03-21-44-20 \ - -X DELETE \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Model.delete("curie:ft-acmeco-2021-03-03-21-44-20") - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.deleteModel('curie:ft-acmeco-2021-03-03-21-44-20'); - response: | - { - "id": "curie:ft-acmeco-2021-03-03-21-44-20", - "object": "model", - "deleted": true - } + request: + curl: | + curl https://api.openai.com/v1/models/ft:gpt-3.5-turbo:acemeco:suffix:abc123 \ + -X DELETE \ + -H "Authorization: Bearer $OPENAI_API_KEY" + python: | + from openai import OpenAI + client = OpenAI() + + client.models.delete("ft:gpt-3.5-turbo:acemeco:suffix:abc123") + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const model = await openai.models.del("ft:gpt-3.5-turbo:acemeco:suffix:abc123"); + + console.log(model); + } + main(); + response: | + { + "id": "ft:gpt-3.5-turbo:acemeco:suffix:abc123", + "object": "model", + "deleted": true + } /moderations: post: operationId: createModeration tags: - - OpenAI + - Moderations summary: Classifies if text violates OpenAI's Content Policy requestBody: required: true content: application/json: schema: - $ref: '#/components/schemas/CreateModerationRequest' + $ref: "#/components/schemas/CreateModerationRequest" responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/CreateModerationResponse' + $ref: "#/components/schemas/CreateModerationResponse" x-oaiMeta: name: Create moderation group: moderations - path: create + returns: A [moderation](/docs/api-reference/moderations/object) object. examples: - curl: | - curl https://api.openai.com/v1/moderations \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "input": "I want to kill them." - }' - python: | - import os - import openai - openai.api_key = os.getenv("OPENAI_API_KEY") - openai.Moderation.create( - input="I want to kill them.", - ) - node.js: | - const { Configuration, OpenAIApi } = require("openai"); - const configuration = new Configuration({ - apiKey: process.env.OPENAI_API_KEY, - }); - const openai = new OpenAIApi(configuration); - const response = await openai.createModeration({ - input: "I want to kill them.", - }); - parameters: | - { - "input": "I want to kill them." - } - response: | - { - "id": "modr-5MWoLO", - "model": "text-moderation-001", - "results": [ - { - "categories": { - "hate": false, - "hate/threatening": true, - "self-harm": false, - "sexual": false, - "sexual/minors": false, - "violence": true, - "violence/graphic": false - }, - "category_scores": { - "hate": 0.22714105248451233, - "hate/threatening": 0.4132447838783264, - "self-harm": 0.005232391878962517, - "sexual": 0.01407341007143259, - "sexual/minors": 0.0038522258400917053, - "violence": 0.9223177433013916, - "violence/graphic": 0.036865197122097015 - }, - "flagged": true - } - ] - } - -components: - schemas: - Error: - type: object - properties: - type: - type: string - nullable: false - message: - type: string - nullable: false - param: - type: string - nullable: true - code: - type: string - nullable: true - required: - - type - - message - - param - - code - - ErrorResponse: - type: object - properties: - error: - $ref: '#/components/schemas/Error' - required: - - error + request: + curl: | + curl https://api.openai.com/v1/moderations \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "input": "I want to kill them." + }' + python: | + from openai import OpenAI + client = OpenAI() - ListModelsResponse: - type: object - properties: - object: - type: string - data: - type: array - items: - $ref: '#/components/schemas/Model' - required: - - object - - data + client.moderations.create(input="I want to kill them.") + node.js: | + import OpenAI from "openai"; - DeleteModelResponse: - type: object - properties: - id: - type: string - object: - type: string - deleted: - type: boolean - required: - - id - - object - - deleted + const openai = new OpenAI(); - CreateCompletionRequest: - type: object - properties: - model: - description: &model_description | - 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. - oneOf: - - type: string - - type: string - enum: ["text-davinci-003","text-davinci-002","text-davinci-001","code-davinci-002","text-curie-001","text-babbage-001","text-ada-001"] - prompt: - description: &completions_prompt_description | - The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays. + async function main() { + const moderation = await openai.moderations.create({ input: "I want to kill them." }); + + console.log(moderation); + } + main(); + response: &moderation_example | + { + "id": "modr-XXXXX", + "model": "text-moderation-005", + "results": [ + { + "flagged": true, + "categories": { + "sexual": false, + "hate": false, + "harassment": false, + "self-harm": false, + "sexual/minors": false, + "hate/threatening": false, + "violence/graphic": false, + "self-harm/intent": false, + "self-harm/instructions": false, + "harassment/threatening": true, + "violence": true, + }, + "category_scores": { + "sexual": 1.2282071e-06, + "hate": 0.010696256, + "harassment": 0.29842457, + "self-harm": 1.5236925e-08, + "sexual/minors": 5.7246268e-08, + "hate/threatening": 0.0060676364, + "violence/graphic": 4.435014e-06, + "self-harm/intent": 8.098441e-10, + "self-harm/instructions": 2.8498655e-11, + "harassment/threatening": 0.63055265, + "violence": 0.99011886, + } + } + ] + } + + /assistants: + get: + operationId: listAssistants + tags: + - Assistants + summary: Returns a list of assistants. + parameters: + - name: limit + in: query + description: &pagination_limit_param_description | + A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. + required: false + schema: + type: integer + default: 20 + - name: order + in: query + description: &pagination_order_param_description | + Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order. + schema: + type: string + default: desc + enum: ["asc", "desc"] + - name: after + in: query + description: &pagination_after_param_description | + A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. + schema: + type: string + - name: before + in: query + description: &pagination_before_param_description | + A cursor for use in pagination. `before` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/ListAssistantsResponse" + x-oaiMeta: + name: List assistants + group: assistants + beta: true + returns: A list of [assistant](/docs/api-reference/assistants/object) objects. + examples: + request: + curl: | + curl "https://api.openai.com/v1/assistants?order=desc&limit=20" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" + python: | + from openai import OpenAI + client = OpenAI() + + my_assistants = client.beta.assistants.list( + order="desc", + limit="20", + ) + print(my_assistants.data) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const myAssistants = await openai.beta.assistants.list({ + order: "desc", + limit: "20", + }); + + console.log(myAssistants.data); + } + + main(); + response: &list_assistants_example | + { + "object": "list", + "data": [ + { + "id": "asst_abc123", + "object": "assistant", + "created_at": 1698982736, + "name": "Coding Tutor", + "description": null, + "model": "gpt-4", + "instructions": "You are a helpful assistant designed to make me better at coding!", + "tools": [], + "file_ids": [], + "metadata": {} + }, + { + "id": "asst_abc456", + "object": "assistant", + "created_at": 1698982718, + "name": "My Assistant", + "description": null, + "model": "gpt-4", + "instructions": "You are a helpful assistant designed to make me better at coding!", + "tools": [], + "file_ids": [], + "metadata": {} + }, + { + "id": "asst_abc789", + "object": "assistant", + "created_at": 1698982643, + "name": null, + "description": null, + "model": "gpt-4", + "instructions": null, + "tools": [], + "file_ids": [], + "metadata": {} + } + ], + "first_id": "asst_abc123", + "last_id": "asst_abc789", + "has_more": false + } + post: + operationId: createAssistant + tags: + - Assistants + summary: Create an assistant with a model and instructions. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CreateAssistantRequest" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/AssistantObject" + x-oaiMeta: + name: Create assistant + group: assistants + beta: true + returns: An [assistant](/docs/api-reference/assistants/object) object. + examples: + - title: Code Interpreter + request: + curl: | + curl "https://api.openai.com/v1/assistants" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" \ + -d '{ + "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.", + "name": "Math Tutor", + "tools": [{"type": "code_interpreter"}], + "model": "gpt-4" + }' + + python: | + from openai import OpenAI + client = OpenAI() + + my_assistant = client.beta.assistants.create( + instructions="You are a personal math tutor. When asked a question, write and run Python code to answer the question.", + name="Math Tutor", + tools=[{"type": "code_interpreter"}], + model="gpt-4", + ) + print(my_assistant) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const myAssistant = await openai.beta.assistants.create({ + instructions: + "You are a personal math tutor. When asked a question, write and run Python code to answer the question.", + name: "Math Tutor", + tools: [{ type: "code_interpreter" }], + model: "gpt-4", + }); + + console.log(myAssistant); + } + + main(); + response: &create_assistants_example | + { + "id": "asst_abc123", + "object": "assistant", + "created_at": 1698984975, + "name": "Math Tutor", + "description": null, + "model": "gpt-4", + "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.", + "tools": [ + { + "type": "code_interpreter" + } + ], + "file_ids": [], + "metadata": {} + } + - title: Files + request: + curl: | + curl https://api.openai.com/v1/assistants \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" \ + -d '{ + "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies.", + "tools": [{"type": "retrieval"}], + "model": "gpt-4", + "file_ids": ["file-abc123"] + }' + python: | + from openai import OpenAI + client = OpenAI() + + my_assistant = client.beta.assistants.create( + instructions="You are an HR bot, and you have access to files to answer employee questions about company policies.", + name="HR Helper", + tools=[{"type": "retrieval"}], + model="gpt-4", + file_ids=["file-abc123"], + ) + print(my_assistant) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const myAssistant = await openai.beta.assistants.create({ + instructions: + "You are an HR bot, and you have access to files to answer employee questions about company policies.", + name: "HR Helper", + tools: [{ type: "retrieval" }], + model: "gpt-4", + file_ids: ["file-abc123"], + }); + + console.log(myAssistant); + } + + main(); + response: | + { + "id": "asst_abc123", + "object": "assistant", + "created_at": 1699009403, + "name": "HR Helper", + "description": null, + "model": "gpt-4", + "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies.", + "tools": [ + { + "type": "retrieval" + } + ], + "file_ids": [ + "file-abc123" + ], + "metadata": {} + } + + /assistants/{assistant_id}: + get: + operationId: getAssistant + tags: + - Assistants + summary: Retrieves an assistant. + parameters: + - in: path + name: assistant_id + required: true + schema: + type: string + description: The ID of the assistant to retrieve. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/AssistantObject" + x-oaiMeta: + name: Retrieve assistant + group: assistants + beta: true + returns: The [assistant](/docs/api-reference/assistants/object) object matching the specified ID. + examples: + request: + curl: | + curl https://api.openai.com/v1/assistants/asst_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" + python: | + from openai import OpenAI + client = OpenAI() + + my_assistant = client.beta.assistants.retrieve("asst_abc123") + print(my_assistant) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const myAssistant = await openai.beta.assistants.retrieve( + "asst_abc123" + ); + + console.log(myAssistant); + } + + main(); + response: | + { + "id": "asst_abc123", + "object": "assistant", + "created_at": 1699009709, + "name": "HR Helper", + "description": null, + "model": "gpt-4", + "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies.", + "tools": [ + { + "type": "retrieval" + } + ], + "file_ids": [ + "file-abc123" + ], + "metadata": {} + } + post: + operationId: modifyAssistant + tags: + - Assistants + summary: Modifies an assistant. + parameters: + - in: path + name: assistant_id + required: true + schema: + type: string + description: The ID of the assistant to modify. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/ModifyAssistantRequest" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/AssistantObject" + x-oaiMeta: + name: Modify assistant + group: assistants + beta: true + returns: The modified [assistant](/docs/api-reference/assistants/object) object. + examples: + request: + curl: | + curl https://api.openai.com/v1/assistants/asst_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" \ + -d '{ + "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files.", + "tools": [{"type": "retrieval"}], + "model": "gpt-4", + "file_ids": ["file-abc123", "file-abc456"] + }' + python: | + from openai import OpenAI + client = OpenAI() + + my_updated_assistant = client.beta.assistants.update( + "asst_abc123", + instructions="You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files.", + name="HR Helper", + tools=[{"type": "retrieval"}], + model="gpt-4", + file_ids=["file-abc123", "file-abc456"], + ) + + print(my_updated_assistant) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const myUpdatedAssistant = await openai.beta.assistants.update( + "asst_abc123", + { + instructions: + "You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files.", + name: "HR Helper", + tools: [{ type: "retrieval" }], + model: "gpt-4", + file_ids: [ + "file-abc123", + "file-abc456", + ], + } + ); + + console.log(myUpdatedAssistant); + } + + main(); + response: | + { + "id": "asst_abc123", + "object": "assistant", + "created_at": 1699009709, + "name": "HR Helper", + "description": null, + "model": "gpt-4", + "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files.", + "tools": [ + { + "type": "retrieval" + } + ], + "file_ids": [ + "file-abc123", + "file-abc456" + ], + "metadata": {} + } + delete: + operationId: deleteAssistant + tags: + - Assistants + summary: Delete an assistant. + parameters: + - in: path + name: assistant_id + required: true + schema: + type: string + description: The ID of the assistant to delete. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/DeleteAssistantResponse" + x-oaiMeta: + name: Delete assistant + group: assistants + beta: true + returns: Deletion status + examples: + request: + curl: | + curl https://api.openai.com/v1/assistants/asst_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" \ + -X DELETE + python: | + from openai import OpenAI + client = OpenAI() + + response = client.beta.assistants.delete("asst_abc123") + print(response) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const response = await openai.beta.assistants.del("asst_abc123"); + + console.log(response); + } + main(); + response: | + { + "id": "asst_abc123", + "object": "assistant.deleted", + "deleted": true + } + + /threads: + post: + operationId: createThread + tags: + - Assistants + summary: Create a thread. + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/CreateThreadRequest" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/ThreadObject" + x-oaiMeta: + name: Create thread + group: threads + beta: true + returns: A [thread](/docs/api-reference/threads) object. + examples: + - title: Empty + request: + curl: | + curl https://api.openai.com/v1/threads \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" \ + -d '' + python: | + from openai import OpenAI + client = OpenAI() + + empty_thread = client.beta.threads.create() + print(empty_thread) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const emptyThread = await openai.beta.threads.create(); + + console.log(emptyThread); + } + + main(); + response: | + { + "id": "thread_abc123", + "object": "thread", + "created_at": 1699012949, + "metadata": {} + } + - title: Messages + request: + curl: | + curl https://api.openai.com/v1/threads \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" \ + -d '{ + "messages": [{ + "role": "user", + "content": "Hello, what is AI?", + "file_ids": ["file-abc123"] + }, { + "role": "user", + "content": "How does AI work? Explain it in simple terms." + }] + }' + python: | + from openai import OpenAI + client = OpenAI() + + message_thread = client.beta.threads.create( + messages=[ + { + "role": "user", + "content": "Hello, what is AI?", + "file_ids": ["file-abc123"], + }, + { + "role": "user", + "content": "How does AI work? Explain it in simple terms." + }, + ] + ) + + print(message_thread) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const messageThread = await openai.beta.threads.create({ + messages: [ + { + role: "user", + content: "Hello, what is AI?", + file_ids: ["file-abc123"], + }, + { + role: "user", + content: "How does AI work? Explain it in simple terms.", + }, + ], + }); + + console.log(messageThread); + } + + main(); + response: | + { + id: 'thread_abc123', + object: 'thread', + created_at: 1699014083, + metadata: {} + } + + /threads/{thread_id}: + get: + operationId: getThread + tags: + - Assistants + summary: Retrieves a thread. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + description: The ID of the thread to retrieve. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/ThreadObject" + x-oaiMeta: + name: Retrieve thread + group: threads + beta: true + returns: The [thread](/docs/api-reference/threads/object) object matching the specified ID. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" + python: | + from openai import OpenAI + client = OpenAI() + + my_thread = client.beta.threads.retrieve("thread_abc123") + print(my_thread) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const myThread = await openai.beta.threads.retrieve( + "thread_abc123" + ); + + console.log(myThread); + } + + main(); + response: | + { + "id": "thread_abc123", + "object": "thread", + "created_at": 1699014083, + "metadata": {} + } + post: + operationId: modifyThread + tags: + - Assistants + summary: Modifies a thread. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + description: The ID of the thread to modify. Only the `metadata` can be modified. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/ModifyThreadRequest" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/ThreadObject" + x-oaiMeta: + name: Modify thread + group: threads + beta: true + returns: The modified [thread](/docs/api-reference/threads/object) object matching the specified ID. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" \ + -d '{ + "metadata": { + "modified": "true", + "user": "abc123" + } + }' + python: | + from openai import OpenAI + client = OpenAI() + + my_updated_thread = client.beta.threads.update( + "thread_abc123", + metadata={ + "modified": "true", + "user": "abc123" + } + ) + print(my_updated_thread) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const updatedThread = await openai.beta.threads.update( + "thread_abc123", + { + metadata: { modified: "true", user: "abc123" }, + } + ); + + console.log(updatedThread); + } + + main(); + response: | + { + "id": "thread_abc123", + "object": "thread", + "created_at": 1699014083, + "metadata": { + "modified": "true", + "user": "abc123" + } + } + delete: + operationId: deleteThread + tags: + - Assistants + summary: Delete a thread. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + description: The ID of the thread to delete. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/DeleteThreadResponse" + x-oaiMeta: + name: Delete thread + group: threads + beta: true + returns: Deletion status + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" \ + -X DELETE + python: | + from openai import OpenAI + client = OpenAI() + + response = client.beta.threads.delete("thread_abc123") + print(response) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const response = await openai.beta.threads.del("thread_abc123"); + + console.log(response); + } + main(); + response: | + { + "id": "thread_abc123", + "object": "thread.deleted", + "deleted": true + } + + /threads/{thread_id}/messages: + get: + operationId: listMessages + tags: + - Assistants + summary: Returns a list of messages for a given thread. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + description: The ID of the [thread](/docs/api-reference/threads) the messages belong to. + - name: limit + in: query + description: *pagination_limit_param_description + required: false + schema: + type: integer + default: 20 + - name: order + in: query + description: *pagination_order_param_description + schema: + type: string + default: desc + enum: ["asc", "desc"] + - name: after + in: query + description: *pagination_after_param_description + schema: + type: string + - name: before + in: query + description: *pagination_before_param_description + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/ListMessagesResponse" + x-oaiMeta: + name: List messages + group: threads + beta: true + returns: A list of [message](/docs/api-reference/messages) objects. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/messages \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" + python: | + from openai import OpenAI + client = OpenAI() + + thread_messages = client.beta.threads.messages.list("thread_abc123") + print(thread_messages.data) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const threadMessages = await openai.beta.threads.messages.list( + "thread_abc123" + ); + + console.log(threadMessages.data); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "msg_abc123", + "object": "thread.message", + "created_at": 1699016383, + "thread_id": "thread_abc123", + "role": "user", + "content": [ + { + "type": "text", + "text": { + "value": "How does AI work? Explain it in simple terms.", + "annotations": [] + } + } + ], + "file_ids": [], + "assistant_id": null, + "run_id": null, + "metadata": {} + }, + { + "id": "msg_abc456", + "object": "thread.message", + "created_at": 1699016383, + "thread_id": "thread_abc123", + "role": "user", + "content": [ + { + "type": "text", + "text": { + "value": "Hello, what is AI?", + "annotations": [] + } + } + ], + "file_ids": [ + "file-abc123" + ], + "assistant_id": null, + "run_id": null, + "metadata": {} + } + ], + "first_id": "msg_abc123", + "last_id": "msg_abc456", + "has_more": false + } + post: + operationId: createMessage + tags: + - Assistants + summary: Create a message. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + description: The ID of the [thread](/docs/api-reference/threads) to create a message for. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CreateMessageRequest" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/MessageObject" + x-oaiMeta: + name: Create message + group: threads + beta: true + returns: A [message](/docs/api-reference/messages/object) object. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/messages \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" \ + -d '{ + "role": "user", + "content": "How does AI work? Explain it in simple terms." + }' + python: | + from openai import OpenAI + client = OpenAI() + + thread_message = client.beta.threads.messages.create( + "thread_abc123", + role="user", + content="How does AI work? Explain it in simple terms.", + ) + print(thread_message) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const threadMessages = await openai.beta.threads.messages.create( + "thread_abc123", + { role: "user", content: "How does AI work? Explain it in simple terms." } + ); + + console.log(threadMessages); + } + + main(); + response: | + { + "id": "msg_abc123", + "object": "thread.message", + "created_at": 1699017614, + "thread_id": "thread_abc123", + "role": "user", + "content": [ + { + "type": "text", + "text": { + "value": "How does AI work? Explain it in simple terms.", + "annotations": [] + } + } + ], + "file_ids": [], + "assistant_id": null, + "run_id": null, + "metadata": {} + } + + /threads/{thread_id}/messages/{message_id}: + get: + operationId: getMessage + tags: + - Assistants + summary: Retrieve a message. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + description: The ID of the [thread](/docs/api-reference/threads) to which this message belongs. + - in: path + name: message_id + required: true + schema: + type: string + description: The ID of the message to retrieve. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/MessageObject" + x-oaiMeta: + name: Retrieve message + group: threads + beta: true + returns: The [message](/docs/api-reference/threads/messages/object) object matching the specified ID. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" + python: | + from openai import OpenAI + client = OpenAI() + + message = client.beta.threads.messages.retrieve( + message_id="msg_abc123", + thread_id="thread_abc123", + ) + print(message) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const message = await openai.beta.threads.messages.retrieve( + "thread_abc123", + "msg_abc123" + ); + + console.log(message); + } + + main(); + response: | + { + "id": "msg_abc123", + "object": "thread.message", + "created_at": 1699017614, + "thread_id": "thread_abc123", + "role": "user", + "content": [ + { + "type": "text", + "text": { + "value": "How does AI work? Explain it in simple terms.", + "annotations": [] + } + } + ], + "file_ids": [], + "assistant_id": null, + "run_id": null, + "metadata": {} + } + post: + operationId: modifyMessage + tags: + - Assistants + summary: Modifies a message. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + description: The ID of the thread to which this message belongs. + - in: path + name: message_id + required: true + schema: + type: string + description: The ID of the message to modify. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/ModifyMessageRequest" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/MessageObject" + x-oaiMeta: + name: Modify message + group: threads + beta: true + returns: The modified [message](/docs/api-reference/threads/messages/object) object. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123 \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" \ + -d '{ + "metadata": { + "modified": "true", + "user": "abc123" + } + }' + python: | + from openai import OpenAI + client = OpenAI() + + message = client.beta.threads.messages.update( + message_id="msg_abc12", + thread_id="thread_abc123", + metadata={ + "modified": "true", + "user": "abc123", + }, + ) + print(message) + node.js: |- + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const message = await openai.beta.threads.messages.update( + "thread_abc123", + "msg_abc123", + { + metadata: { + modified: "true", + user: "abc123", + }, + } + }' + response: | + { + "id": "msg_abc123", + "object": "thread.message", + "created_at": 1699017614, + "thread_id": "thread_abc123", + "role": "user", + "content": [ + { + "type": "text", + "text": { + "value": "How does AI work? Explain it in simple terms.", + "annotations": [] + } + } + ], + "file_ids": [], + "assistant_id": null, + "run_id": null, + "metadata": { + "modified": "true", + "user": "abc123" + } + } + + /threads/runs: + post: + operationId: createThreadAndRun + tags: + - Assistants + summary: Create a thread and run it in one request. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CreateThreadAndRunRequest" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/RunObject" + x-oaiMeta: + name: Create thread and run + group: threads + beta: true + returns: A [run](/docs/api-reference/runs/object) object. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/runs \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" \ + -d '{ + "assistant_id": "asst_abc123", + "thread": { + "messages": [ + {"role": "user", "content": "Explain deep learning to a 5 year old."} + ] + } + }' + python: | + from openai import OpenAI + client = OpenAI() + + run = client.beta.threads.create_and_run( + assistant_id="asst_abc123", + thread={ + "messages": [ + {"role": "user", "content": "Explain deep learning to a 5 year old."} + ] + } + ) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const run = await openai.beta.threads.createAndRun({ + assistant_id: "asst_abc123", + thread: { + messages: [ + { role: "user", content: "Explain deep learning to a 5 year old." }, + ], + }, + }); + + console.log(run); + } + + main(); + response: | + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1699076792, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "queued", + "started_at": null, + "expires_at": 1699077392, + "cancelled_at": null, + "failed_at": null, + "completed_at": null, + "last_error": null, + "model": "gpt-4", + "instructions": "You are a helpful assistant.", + "tools": [], + "file_ids": [], + "metadata": {}, + "usage": null + } + + /threads/{thread_id}/runs: + get: + operationId: listRuns + tags: + - Assistants + summary: Returns a list of runs belonging to a thread. + parameters: + - name: thread_id + in: path + required: true + schema: + type: string + description: The ID of the thread the run belongs to. + - name: limit + in: query + description: *pagination_limit_param_description + required: false + schema: + type: integer + default: 20 + - name: order + in: query + description: *pagination_order_param_description + schema: + type: string + default: desc + enum: ["asc", "desc"] + - name: after + in: query + description: *pagination_after_param_description + schema: + type: string + - name: before + in: query + description: *pagination_before_param_description + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/ListRunsResponse" + x-oaiMeta: + name: List runs + group: threads + beta: true + returns: A list of [run](/docs/api-reference/runs/object) objects. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" + python: | + from openai import OpenAI + client = OpenAI() + + runs = client.beta.threads.runs.list( + "thread_abc123" + ) + print(runs) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const runs = await openai.beta.threads.runs.list( + "thread_abc123" + ); + + console.log(runs); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1699075072, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "completed", + "started_at": 1699075072, + "expires_at": null, + "cancelled_at": null, + "failed_at": null, + "completed_at": 1699075073, + "last_error": null, + "model": "gpt-3.5-turbo", + "instructions": null, + "tools": [ + { + "type": "code_interpreter" + } + ], + "file_ids": [ + "file-abc123", + "file-abc456" + ], + "metadata": {}, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + }, + { + "id": "run_abc456", + "object": "thread.run", + "created_at": 1699063290, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "completed", + "started_at": 1699063290, + "expires_at": null, + "cancelled_at": null, + "failed_at": null, + "completed_at": 1699063291, + "last_error": null, + "model": "gpt-3.5-turbo", + "instructions": null, + "tools": [ + { + "type": "code_interpreter" + } + ], + "file_ids": [ + "file-abc123", + "file-abc456" + ], + "metadata": {}, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + } + ], + "first_id": "run_abc123", + "last_id": "run_abc456", + "has_more": false + } + post: + operationId: createRun + tags: + - Assistants + summary: Create a run. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + description: The ID of the thread to run. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CreateRunRequest" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/RunObject" + x-oaiMeta: + name: Create run + group: threads + beta: true + returns: A [run](/docs/api-reference/runs/object) object. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" \ + -d '{ + "assistant_id": "asst_abc123" + }' + python: | + from openai import OpenAI + client = OpenAI() + + run = client.beta.threads.runs.create( + thread_id="thread_abc123", + assistant_id="asst_abc123" + ) + print(run) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const run = await openai.beta.threads.runs.create( + "thread_abc123", + { assistant_id: "asst_abc123" } + ); + + console.log(run); + } + + main(); + response: &run_object_example | + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1699063290, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "queued", + "started_at": 1699063290, + "expires_at": null, + "cancelled_at": null, + "failed_at": null, + "completed_at": 1699063291, + "last_error": null, + "model": "gpt-4", + "instructions": null, + "tools": [ + { + "type": "code_interpreter" + } + ], + "file_ids": [ + "file-abc123", + "file-abc456" + ], + "metadata": {}, + "usage": null + } + + /threads/{thread_id}/runs/{run_id}: + get: + operationId: getRun + tags: + - Assistants + summary: Retrieves a run. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + description: The ID of the [thread](/docs/api-reference/threads) that was run. + - in: path + name: run_id + required: true + schema: + type: string + description: The ID of the run to retrieve. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/RunObject" + x-oaiMeta: + name: Retrieve run + group: threads + beta: true + returns: The [run](/docs/api-reference/runs/object) object matching the specified ID. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" + python: | + from openai import OpenAI + client = OpenAI() + + run = client.beta.threads.runs.retrieve( + thread_id="thread_abc123", + run_id="run_abc123" + ) + print(run) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const run = await openai.beta.threads.runs.retrieve( + "thread_abc123", + "run_abc123" + ); + + console.log(run); + } + + main(); + response: | + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1699075072, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "completed", + "started_at": 1699075072, + "expires_at": null, + "cancelled_at": null, + "failed_at": null, + "completed_at": 1699075073, + "last_error": null, + "model": "gpt-3.5-turbo", + "instructions": null, + "tools": [ + { + "type": "code_interpreter" + } + ], + "file_ids": [ + "file-abc123", + "file-abc456" + ], + "metadata": {}, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + } + post: + operationId: modifyRun + tags: + - Assistants + summary: Modifies a run. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + description: The ID of the [thread](/docs/api-reference/threads) that was run. + - in: path + name: run_id + required: true + schema: + type: string + description: The ID of the run to modify. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/ModifyRunRequest" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/RunObject" + x-oaiMeta: + name: Modify run + group: threads + beta: true + returns: The modified [run](/docs/api-reference/runs/object) object matching the specified ID. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" \ + -d '{ + "metadata": { + "user_id": "user_abc123" + } + }' + python: | + from openai import OpenAI + client = OpenAI() + + run = client.beta.threads.runs.update( + thread_id="thread_abc123", + run_id="run_abc123", + metadata={"user_id": "user_abc123"}, + ) + print(run) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const run = await openai.beta.threads.runs.update( + "thread_abc123", + "run_abc123", + { + metadata: { + user_id: "user_abc123", + }, + } + ); + + console.log(run); + } + + main(); + response: | + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1699075072, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "completed", + "started_at": 1699075072, + "expires_at": null, + "cancelled_at": null, + "failed_at": null, + "completed_at": 1699075073, + "last_error": null, + "model": "gpt-3.5-turbo", + "instructions": null, + "tools": [ + { + "type": "code_interpreter" + } + ], + "file_ids": [ + "file-abc123", + "file-abc456" + ], + "metadata": { + "user_id": "user_abc123" + }, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + } + + /threads/{thread_id}/runs/{run_id}/submit_tool_outputs: + post: + operationId: submitToolOuputsToRun + tags: + - Assistants + summary: | + When a run has the `status: "requires_action"` and `required_action.type` is `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + description: The ID of the [thread](/docs/api-reference/threads) to which this run belongs. + - in: path + name: run_id + required: true + schema: + type: string + description: The ID of the run that requires the tool output submission. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/SubmitToolOutputsRunRequest" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/RunObject" + x-oaiMeta: + name: Submit tool outputs to run + group: threads + beta: true + returns: The modified [run](/docs/api-reference/runs/object) object matching the specified ID. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/submit_tool_outputs \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" \ + -d '{ + "tool_outputs": [ + { + "tool_call_id": "call_abc123", + "output": "28C" + } + ] + }' + python: | + from openai import OpenAI + client = OpenAI() + + run = client.beta.threads.runs.submit_tool_outputs( + thread_id="thread_abc123", + run_id="run_abc123", + tool_outputs=[ + { + "tool_call_id": "call_abc123", + "output": "28C" + } + ] + ) + print(run) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const run = await openai.beta.threads.runs.submitToolOutputs( + "thread_abc123", + "run_abc123", + { + tool_outputs: [ + { + tool_call_id: "call_abc123", + output: "28C", + }, + ], + } + ); + + console.log(run); + } + + main(); + response: | + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1699075592, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "queued", + "started_at": 1699075592, + "expires_at": 1699076192, + "cancelled_at": null, + "failed_at": null, + "completed_at": null, + "last_error": null, + "model": "gpt-4", + "instructions": "You tell the weather.", + "tools": [ + { + "type": "function", + "function": { + "name": "get_weather", + "description": "Determine weather in my location", + "parameters": { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state e.g. San Francisco, CA" + }, + "unit": { + "type": "string", + "enum": [ + "c", + "f" + ] + } + }, + "required": [ + "location" + ] + } + } + } + ], + "file_ids": [], + "metadata": {}, + "usage": null + } + + /threads/{thread_id}/runs/{run_id}/cancel: + post: + operationId: cancelRun + tags: + - Assistants + summary: Cancels a run that is `in_progress`. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + description: The ID of the thread to which this run belongs. + - in: path + name: run_id + required: true + schema: + type: string + description: The ID of the run to cancel. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/RunObject" + x-oaiMeta: + name: Cancel a run + group: threads + beta: true + returns: The modified [run](/docs/api-reference/runs/object) object matching the specified ID. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/cancel \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "OpenAI-Beta: assistants=v1" \ + -X POST + python: | + from openai import OpenAI + client = OpenAI() + + run = client.beta.threads.runs.cancel( + thread_id="thread_abc123", + run_id="run_abc123" + ) + print(run) + node.js: | + import OpenAI from "openai"; + + const openai = new OpenAI(); + + async function main() { + const run = await openai.beta.threads.runs.cancel( + "thread_abc123", + "run_abc123" + ); + + console.log(run); + } + + main(); + response: | + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1699076126, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "cancelling", + "started_at": 1699076126, + "expires_at": 1699076726, + "cancelled_at": null, + "failed_at": null, + "completed_at": null, + "last_error": null, + "model": "gpt-4", + "instructions": "You summarize books.", + "tools": [ + { + "type": "retrieval" + } + ], + "file_ids": [], + "metadata": {}, + "usage": null + } + + /threads/{thread_id}/runs/{run_id}/steps: + get: + operationId: listRunSteps + tags: + - Assistants + summary: Returns a list of run steps belonging to a run. + parameters: + - name: thread_id + in: path + required: true + schema: + type: string + description: The ID of the thread the run and run steps belong to. + - name: run_id + in: path + required: true + schema: + type: string + description: The ID of the run the run steps belong to. + - name: limit + in: query + description: *pagination_limit_param_description + required: false + schema: + type: integer + default: 20 + - name: order + in: query + description: *pagination_order_param_description + schema: + type: string + default: desc + enum: ["asc", "desc"] + - name: after + in: query + description: *pagination_after_param_description + schema: + type: string + - name: before + in: query + description: *pagination_before_param_description + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/ListRunStepsResponse" + x-oaiMeta: + name: List run steps + group: threads + beta: true + returns: A list of [run step](/docs/api-reference/runs/step-object) objects. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/steps \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" + python: | + from openai import OpenAI + client = OpenAI() + + run_steps = client.beta.threads.runs.steps.list( + thread_id="thread_abc123", + run_id="run_abc123" + ) + print(run_steps) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const runStep = await openai.beta.threads.runs.steps.list( + "thread_abc123", + "run_abc123" + ); + console.log(runStep); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "step_abc123", + "object": "thread.run.step", + "created_at": 1699063291, + "run_id": "run_abc123", + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "type": "message_creation", + "status": "completed", + "cancelled_at": null, + "completed_at": 1699063291, + "expired_at": null, + "failed_at": null, + "last_error": null, + "step_details": { + "type": "message_creation", + "message_creation": { + "message_id": "msg_abc123" + } + }, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + } + ], + "first_id": "step_abc123", + "last_id": "step_abc456", + "has_more": false + } + + /threads/{thread_id}/runs/{run_id}/steps/{step_id}: + get: + operationId: getRunStep + tags: + - Assistants + summary: Retrieves a run step. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + description: The ID of the thread to which the run and run step belongs. + - in: path + name: run_id + required: true + schema: + type: string + description: The ID of the run to which the run step belongs. + - in: path + name: step_id + required: true + schema: + type: string + description: The ID of the run step to retrieve. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/RunStepObject" + x-oaiMeta: + name: Retrieve run step + group: threads + beta: true + returns: The [run step](/docs/api-reference/runs/step-object) object matching the specified ID. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/steps/step_abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" + python: | + from openai import OpenAI + client = OpenAI() + + run_step = client.beta.threads.runs.steps.retrieve( + thread_id="thread_abc123", + run_id="run_abc123", + step_id="step_abc123" + ) + print(run_step) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const runStep = await openai.beta.threads.runs.steps.retrieve( + "thread_abc123", + "run_abc123", + "step_abc123" + ); + console.log(runStep); + } + + main(); + response: &run_step_object_example | + { + "id": "step_abc123", + "object": "thread.run.step", + "created_at": 1699063291, + "run_id": "run_abc123", + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "type": "message_creation", + "status": "completed", + "cancelled_at": null, + "completed_at": 1699063291, + "expired_at": null, + "failed_at": null, + "last_error": null, + "step_details": { + "type": "message_creation", + "message_creation": { + "message_id": "msg_abc123" + } + }, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + } + + /assistants/{assistant_id}/files: + get: + operationId: listAssistantFiles + tags: + - Assistants + summary: Returns a list of assistant files. + parameters: + - name: assistant_id + in: path + description: The ID of the assistant the file belongs to. + required: true + schema: + type: string + - name: limit + in: query + description: *pagination_limit_param_description + required: false + schema: + type: integer + default: 20 + - name: order + in: query + description: *pagination_order_param_description + schema: + type: string + default: desc + enum: ["asc", "desc"] + - name: after + in: query + description: *pagination_after_param_description + schema: + type: string + - name: before + in: query + description: *pagination_before_param_description + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/ListAssistantFilesResponse" + x-oaiMeta: + name: List assistant files + group: assistants + beta: true + returns: A list of [assistant file](/docs/api-reference/assistants/file-object) objects. + examples: + request: + curl: | + curl https://api.openai.com/v1/assistants/asst_abc123/files \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" + python: | + from openai import OpenAI + client = OpenAI() + + assistant_files = client.beta.assistants.files.list( + assistant_id="asst_abc123" + ) + print(assistant_files) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const assistantFiles = await openai.beta.assistants.files.list( + "asst_abc123" + ); + console.log(assistantFiles); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "file-abc123", + "object": "assistant.file", + "created_at": 1699060412, + "assistant_id": "asst_abc123" + }, + { + "id": "file-abc456", + "object": "assistant.file", + "created_at": 1699060412, + "assistant_id": "asst_abc123" + } + ], + "first_id": "file-abc123", + "last_id": "file-abc456", + "has_more": false + } + post: + operationId: createAssistantFile + tags: + - Assistants + summary: Create an assistant file by attaching a [File](/docs/api-reference/files) to an [assistant](/docs/api-reference/assistants). + parameters: + - in: path + name: assistant_id + required: true + schema: + type: string + example: file-abc123 + description: | + The ID of the assistant for which to create a File. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CreateAssistantFileRequest" + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/AssistantFileObject" + x-oaiMeta: + name: Create assistant file + group: assistants + beta: true + returns: An [assistant file](/docs/api-reference/assistants/file-object) object. + examples: + request: + curl: | + curl https://api.openai.com/v1/assistants/asst_abc123/files \ + -H 'Authorization: Bearer $OPENAI_API_KEY"' \ + -H 'Content-Type: application/json' \ + -H 'OpenAI-Beta: assistants=v1' \ + -d '{ + "file_id": "file-abc123" + }' + python: | + from openai import OpenAI + client = OpenAI() + + assistant_file = client.beta.assistants.files.create( + assistant_id="asst_abc123", + file_id="file-abc123" + ) + print(assistant_file) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const myAssistantFile = await openai.beta.assistants.files.create( + "asst_abc123", + { + file_id: "file-abc123" + } + ); + console.log(myAssistantFile); + } + + main(); + response: &assistant_file_object | + { + "id": "file-abc123", + "object": "assistant.file", + "created_at": 1699055364, + "assistant_id": "asst_abc123" + } + + /assistants/{assistant_id}/files/{file_id}: + get: + operationId: getAssistantFile + tags: + - Assistants + summary: Retrieves an AssistantFile. + parameters: + - in: path + name: assistant_id + required: true + schema: + type: string + description: The ID of the assistant who the file belongs to. + - in: path + name: file_id + required: true + schema: + type: string + description: The ID of the file we're getting. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/AssistantFileObject" + x-oaiMeta: + name: Retrieve assistant file + group: assistants + beta: true + returns: The [assistant file](/docs/api-reference/assistants/file-object) object matching the specified ID. + examples: + request: + curl: | + curl https://api.openai.com/v1/assistants/asst_abc123/files/file-abc123 \ + -H 'Authorization: Bearer $OPENAI_API_KEY"' \ + -H 'Content-Type: application/json' \ + -H 'OpenAI-Beta: assistants=v1' + python: | + from openai import OpenAI + client = OpenAI() + + assistant_file = client.beta.assistants.files.retrieve( + assistant_id="asst_abc123", + file_id="file-abc123" + ) + print(assistant_file) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const myAssistantFile = await openai.beta.assistants.files.retrieve( + "asst_abc123", + "file-abc123" + ); + console.log(myAssistantFile); + } + + main(); + response: *assistant_file_object + delete: + operationId: deleteAssistantFile + tags: + - Assistants + summary: Delete an assistant file. + parameters: + - in: path + name: assistant_id + required: true + schema: + type: string + description: The ID of the assistant that the file belongs to. + - in: path + name: file_id + required: true + schema: + type: string + description: The ID of the file to delete. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/DeleteAssistantFileResponse" + x-oaiMeta: + name: Delete assistant file + group: assistants + beta: true + returns: Deletion status + examples: + request: + curl: | + curl https://api.openai.com/v1/assistants/asst_abc123/files/file-abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" \ + -X DELETE + python: | + from openai import OpenAI + client = OpenAI() + + deleted_assistant_file = client.beta.assistants.files.delete( + assistant_id="asst_abc123", + file_id="file-abc123" + ) + print(deleted_assistant_file) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const deletedAssistantFile = await openai.beta.assistants.files.del( + "asst_abc123", + "file-abc123" + ); + console.log(deletedAssistantFile); + } + + main(); + response: | + { + id: "file-abc123", + object: "assistant.file.deleted", + deleted: true + } + + /threads/{thread_id}/messages/{message_id}/files: + get: + operationId: listMessageFiles + tags: + - Assistants + summary: Returns a list of message files. + parameters: + - name: thread_id + in: path + description: The ID of the thread that the message and files belong to. + required: true + schema: + type: string + - name: message_id + in: path + description: The ID of the message that the files belongs to. + required: true + schema: + type: string + - name: limit + in: query + description: *pagination_limit_param_description + required: false + schema: + type: integer + default: 20 + - name: order + in: query + description: *pagination_order_param_description + schema: + type: string + default: desc + enum: ["asc", "desc"] + - name: after + in: query + description: *pagination_after_param_description + schema: + type: string + - name: before + in: query + description: *pagination_before_param_description + schema: + type: string + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/ListMessageFilesResponse" + x-oaiMeta: + name: List message files + group: threads + beta: true + returns: A list of [message file](/docs/api-reference/messages/file-object) objects. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123/files \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" + python: | + from openai import OpenAI + client = OpenAI() + + message_files = client.beta.threads.messages.files.list( + thread_id="thread_abc123", + message_id="msg_abc123" + ) + print(message_files) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const messageFiles = await openai.beta.threads.messages.files.list( + "thread_abc123", + "msg_abc123" + ); + console.log(messageFiles); + } + + main(); + response: | + { + "object": "list", + "data": [ + { + "id": "file-abc123", + "object": "thread.message.file", + "created_at": 1699061776, + "message_id": "msg_abc123" + }, + { + "id": "file-abc123", + "object": "thread.message.file", + "created_at": 1699061776, + "message_id": "msg_abc123" + } + ], + "first_id": "file-abc123", + "last_id": "file-abc123", + "has_more": false + } + + /threads/{thread_id}/messages/{message_id}/files/{file_id}: + get: + operationId: getMessageFile + tags: + - Assistants + summary: Retrieves a message file. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + example: thread_abc123 + description: The ID of the thread to which the message and File belong. + - in: path + name: message_id + required: true + schema: + type: string + example: msg_abc123 + description: The ID of the message the file belongs to. + - in: path + name: file_id + required: true + schema: + type: string + example: file-abc123 + description: The ID of the file being retrieved. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/MessageFileObject" + x-oaiMeta: + name: Retrieve message file + group: threads + beta: true + returns: The [message file](/docs/api-reference/messages/file-object) object. + examples: + request: + curl: | + curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123/files/file-abc123 \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -H "Content-Type: application/json" \ + -H "OpenAI-Beta: assistants=v1" + python: | + from openai import OpenAI + client = OpenAI() + + message_files = client.beta.threads.messages.files.retrieve( + thread_id="thread_abc123", + message_id="msg_abc123", + file_id="file-abc123" + ) + print(message_files) + node.js: | + import OpenAI from "openai"; + const openai = new OpenAI(); + + async function main() { + const messageFile = await openai.beta.threads.messages.files.retrieve( + "thread_abc123", + "msg_abc123", + "file-abc123" + ); + console.log(messageFile); + } + + main(); + response: | + { + "id": "file-abc123", + "object": "thread.message.file", + "created_at": 1699061776, + "message_id": "msg_abc123" + } + +components: + securitySchemes: + ApiKeyAuth: + type: http + scheme: "bearer" + + schemas: + Error: + type: object + properties: + code: + type: string + nullable: true + message: + type: string + nullable: false + param: + type: string + nullable: true + type: + type: string + nullable: false + required: + - type + - message + - param + - code + ErrorResponse: + type: object + properties: + error: + $ref: "#/components/schemas/Error" + required: + - error + + ListModelsResponse: + type: object + properties: + object: + type: string + enum: [list] + data: + type: array + items: + $ref: "#/components/schemas/Model" + required: + - object + - data + DeleteModelResponse: + type: object + properties: + id: + type: string + deleted: + type: boolean + object: + type: string + required: + - id + - object + - deleted + + CreateCompletionRequest: + type: object + properties: + model: + description: &model_description | + 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. + anyOf: + - type: string + - type: string + enum: ["gpt-3.5-turbo-instruct", "davinci-002", "babbage-002"] + x-oaiTypeLabel: string + prompt: + description: &completions_prompt_description | + The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays. Note that <|endoftext|> is the document separator that the model sees during training, so if a prompt is not specified the model will generate as if from the beginning of a new document. - default: '<|endoftext|>' + default: "<|endoftext|>" + nullable: true + oneOf: + - type: string + default: "" + example: "This is a test." + - type: array + items: + type: string + default: "" + example: "This is a test." + - type: array + minItems: 1 + items: + type: integer + example: "[1212, 318, 257, 1332, 13]" + - type: array + minItems: 1 + items: + type: array + minItems: 1 + items: + type: integer + example: "[[1212, 318, 257, 1332, 13]]" + best_of: + type: integer + default: 1 + minimum: 0 + maximum: 20 + nullable: true + description: &completions_best_of_description | + Generates `best_of` completions server-side and returns the "best" (the one with the highest log probability per token). Results cannot be streamed. + + When used with `n`, `best_of` controls the number of candidate completions and `n` specifies how many to return – `best_of` must be greater than `n`. + + **Note:** Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop`. + echo: + type: boolean + default: false + nullable: true + description: &completions_echo_description > + Echo back the prompt in addition to the completion + frequency_penalty: + type: number + default: 0 + minimum: -2 + maximum: 2 + nullable: true + description: &completions_frequency_penalty_description | + 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. + + [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) + logit_bias: &completions_logit_bias + type: object + x-oaiTypeLabel: map + default: null + nullable: true + additionalProperties: + type: integer + description: &completions_logit_bias_description | + Modify the likelihood of specified tokens appearing in the completion. + + Accepts a JSON object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100. You can use this [tokenizer tool](/tokenizer?view=bpe) to convert text to token IDs. 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. + + As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being generated. + logprobs: &completions_logprobs_configuration + type: integer + minimum: 0 + maximum: 5 + default: null + nullable: true + description: &completions_logprobs_description | + Include the log probabilities on the `logprobs` most likely output tokens, as well the chosen tokens. For example, if `logprobs` is 5, the API will return a list of the 5 most likely tokens. The API will always return the `logprob` of the sampled token, so there may be up to `logprobs+1` elements in the response. + + The maximum value for `logprobs` is 5. + max_tokens: + type: integer + minimum: 0 + default: 16 + example: 16 + nullable: true + description: &completions_max_tokens_description | + The maximum number of [tokens](/tokenizer) that can be generated in the completion. + + The token count of your prompt plus `max_tokens` cannot exceed the model's context length. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens. + n: + type: integer + minimum: 1 + maximum: 128 + default: 1 + example: 1 + nullable: true + description: &completions_completions_description | + How many completions to generate for each prompt. + + **Note:** Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop`. + presence_penalty: + type: number + default: 0 + minimum: -2 + maximum: 2 + nullable: true + description: &completions_presence_penalty_description | + 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. + + [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) + seed: &completions_seed_param + type: integer + minimum: -9223372036854775808 + maximum: 9223372036854775807 + nullable: true + description: | + 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. + stop: + description: &completions_stop_description > + Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence. + default: null + nullable: true + oneOf: + - type: string + default: <|endoftext|> + example: "\n" + nullable: true + - type: array + minItems: 1 + maxItems: 4 + items: + type: string + example: '["\n"]' + stream: + description: > + Whether to stream back partial progress. If set, 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). + type: boolean + nullable: true + default: false + suffix: + description: The suffix that comes after a completion of inserted text. + default: null + nullable: true + type: string + example: "test." + temperature: + type: number + minimum: 0 + maximum: 2 + default: 1 + example: 1 + nullable: true + description: &completions_temperature_description | + 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. + top_p: + type: number + minimum: 0 + maximum: 1 + default: 1 + example: 1 + nullable: true + description: &completions_top_p_description | + 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. + user: &end_user_param_configuration + type: string + example: user-1234 + description: | + A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids). + required: + - model + - prompt + + CreateCompletionResponse: + type: object + description: | + Represents a completion response from the API. Note: both the streamed and non-streamed response objects share the same shape (unlike the chat endpoint). + properties: + id: + type: string + description: A unique identifier for the completion. + choices: + type: array + description: The list of completion choices the model generated for the input prompt. + items: + type: object + required: + - finish_reason + - index + - logprobs + - text + properties: + finish_reason: + type: string + description: &completion_finish_reason_description | + 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, + or `content_filter` if content was omitted due to a flag from our content filters. + enum: ["stop", "length", "content_filter"] + index: + type: integer + logprobs: + type: object + nullable: true + properties: + text_offset: + type: array + items: + type: integer + token_logprobs: + type: array + items: + type: number + tokens: + type: array + items: + type: string + top_logprobs: + type: array + items: + type: object + additionalProperties: + type: number + text: + type: string + created: + type: integer + description: The Unix timestamp (in seconds) of when the completion was created. + model: + type: string + description: The model used for completion. + system_fingerprint: + type: string + description: | + 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. + object: + type: string + description: The object type, which is always "text_completion" + enum: [text_completion] + usage: + $ref: "#/components/schemas/CompletionUsage" + required: + - id + - object + - created + - model + - choices + x-oaiMeta: + name: The completion object + legacy: true + example: | + { + "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7", + "object": "text_completion", + "created": 1589478378, + "model": "gpt-3.5-turbo", + "choices": [ + { + "text": "\n\nThis is indeed a test", + "index": 0, + "logprobs": null, + "finish_reason": "length" + } + ], + "usage": { + "prompt_tokens": 5, + "completion_tokens": 7, + "total_tokens": 12 + } + } + + ChatCompletionRequestMessageContentPart: + oneOf: + - $ref: "#/components/schemas/ChatCompletionRequestMessageContentPartText" + - $ref: "#/components/schemas/ChatCompletionRequestMessageContentPartImage" + x-oaiExpandable: true + + ChatCompletionRequestMessageContentPartImage: + type: object + title: Image content part + properties: + type: + type: string + enum: ["image_url"] + description: The type of the content part. + image_url: + type: object + properties: + url: + type: string + description: Either a URL of the image or the base64 encoded image data. + format: uri + detail: + type: string + description: Specifies the detail level of the image. Learn more in the [Vision guide](/docs/guides/vision/low-or-high-fidelity-image-understanding). + enum: ["auto", "low", "high"] + default: "auto" + required: + - url + required: + - type + - image_url + + ChatCompletionRequestMessageContentPartText: + type: object + title: Text content part + properties: + type: + type: string + enum: ["text"] + description: The type of the content part. + text: + type: string + description: The text content. + required: + - type + - text + + ChatCompletionRequestMessage: + oneOf: + - $ref: "#/components/schemas/ChatCompletionRequestSystemMessage" + - $ref: "#/components/schemas/ChatCompletionRequestUserMessage" + - $ref: "#/components/schemas/ChatCompletionRequestAssistantMessage" + - $ref: "#/components/schemas/ChatCompletionRequestToolMessage" + - $ref: "#/components/schemas/ChatCompletionRequestFunctionMessage" + x-oaiExpandable: true + + ChatCompletionRequestSystemMessage: + type: object + title: System message + properties: + content: + description: The contents of the system message. + type: string + role: + type: string + enum: ["system"] + description: The role of the messages author, in this case `system`. + name: + type: string + description: An optional name for the participant. Provides the model information to differentiate between participants of the same role. + required: + - content + - role + + ChatCompletionRequestUserMessage: + type: object + title: User message + properties: + content: + description: | + The contents of the user message. + oneOf: + - type: string + description: The text contents of the message. + title: Text content + - type: array + description: An array of content parts with a defined type, each can be of type `text` or `image_url` when passing in images. You can pass multiple images by adding multiple `image_url` content parts. Image input is only supported when using the `gpt-4-visual-preview` model. + title: Array of content parts + items: + $ref: "#/components/schemas/ChatCompletionRequestMessageContentPart" + minItems: 1 + x-oaiExpandable: true + role: + type: string + enum: ["user"] + description: The role of the messages author, in this case `user`. + name: + type: string + description: An optional name for the participant. Provides the model information to differentiate between participants of the same role. + required: + - content + - role + + ChatCompletionRequestAssistantMessage: + type: object + title: Assistant message + properties: + content: + nullable: true + type: string + description: | + The contents of the assistant message. Required unless `tool_calls` or `function_call` is specified. + role: + type: string + enum: ["assistant"] + description: The role of the messages author, in this case `assistant`. + name: + type: string + description: An optional name for the participant. Provides the model information to differentiate between participants of the same role. + tool_calls: + $ref: "#/components/schemas/ChatCompletionMessageToolCalls" + function_call: + type: object + deprecated: true + description: "Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model." + properties: + arguments: + type: string + description: 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. + name: + type: string + description: The name of the function to call. + required: + - arguments + - name + required: + - role + + ChatCompletionRequestToolMessage: + type: object + title: Tool message + properties: + role: + type: string + enum: ["tool"] + description: The role of the messages author, in this case `tool`. + content: + type: string + description: The contents of the tool message. + tool_call_id: + type: string + description: Tool call that this message is responding to. + required: + - role + - content + - tool_call_id + + ChatCompletionRequestFunctionMessage: + type: object + title: Function message + deprecated: true + properties: + role: + type: string + enum: ["function"] + description: The role of the messages author, in this case `function`. + content: + nullable: true + type: string + description: The contents of the function message. + name: + type: string + description: The name of the function to call. + required: + - role + - content + - name + + FunctionParameters: + type: object + description: "The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/text-generation/function-calling) for examples, and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation about the format. \n\nOmitting `parameters` defines a function with an empty parameter list." + additionalProperties: true + + ChatCompletionFunctions: + type: object + deprecated: true + properties: + description: + type: string + description: A description of what the function does, used by the model to choose when and how to call the function. + name: + type: string + description: 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. + parameters: + $ref: "#/components/schemas/FunctionParameters" + required: + - name + + ChatCompletionFunctionCallOption: + type: object + description: > + Specifying a particular function via `{"name": "my_function"}` forces the model to call that function. + properties: + name: + type: string + description: The name of the function to call. + required: + - name + + ChatCompletionTool: + type: object + properties: + type: + type: string + enum: ["function"] + description: The type of the tool. Currently, only `function` is supported. + function: + $ref: "#/components/schemas/FunctionObject" + required: + - type + - function + + FunctionObject: + type: object + properties: + description: + type: string + description: A description of what the function does, used by the model to choose when and how to call the function. + name: + type: string + description: 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. + parameters: + $ref: "#/components/schemas/FunctionParameters" + required: + - name + + ChatCompletionToolChoiceOption: + description: | + 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 `{"type": "function", "function": {"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. + oneOf: + - type: string + description: > + `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. + enum: [none, auto] + - $ref: "#/components/schemas/ChatCompletionNamedToolChoice" + x-oaiExpandable: true + + ChatCompletionNamedToolChoice: + type: object + description: Specifies a tool the model should use. Use to force the model to call a specific function. + properties: + type: + type: string + enum: ["function"] + description: The type of the tool. Currently, only `function` is supported. + function: + type: object + properties: + name: + type: string + description: The name of the function to call. + required: + - name + required: + - type + - function + + ChatCompletionMessageToolCalls: + type: array + description: The tool calls generated by the model, such as function calls. + items: + $ref: "#/components/schemas/ChatCompletionMessageToolCall" + + ChatCompletionMessageToolCall: + type: object + properties: + # TODO: index included when streaming + id: + type: string + description: The ID of the tool call. + type: + type: string + enum: ["function"] + description: The type of the tool. Currently, only `function` is supported. + function: + type: object + description: The function that the model called. + properties: + name: + type: string + description: The name of the function to call. + arguments: + type: string + description: 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. + required: + - name + - arguments + required: + - id + - type + - function + + ChatCompletionMessageToolCallChunk: + type: object + properties: + index: + type: integer + id: + type: string + description: The ID of the tool call. + type: + type: string + enum: ["function"] + description: The type of the tool. Currently, only `function` is supported. + function: + type: object + properties: + name: + type: string + description: The name of the function to call. + arguments: + type: string + description: 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. + required: + - index + + # Note, this isn't referenced anywhere, but is kept as a convenience to record all possible roles in one place. + ChatCompletionRole: + type: string + description: The role of the author of a message + enum: + - system + - user + - assistant + - tool + - function + + ChatCompletionResponseMessage: + type: object + description: A chat completion message generated by the model. + properties: + content: + type: string + description: The contents of the message. + nullable: true + tool_calls: + $ref: "#/components/schemas/ChatCompletionMessageToolCalls" + role: + type: string + enum: ["assistant"] + description: The role of the author of this message. + function_call: + type: object + deprecated: true + description: "Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model." + properties: + arguments: + type: string + description: 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. + name: + type: string + description: The name of the function to call. + required: + - name + - arguments + required: + - role + - content + + ChatCompletionStreamResponseDelta: + type: object + description: A chat completion delta generated by streamed model responses. + properties: + content: + type: string + description: The contents of the chunk message. + nullable: true + function_call: + deprecated: true + type: object + description: "Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model." + properties: + arguments: + type: string + description: 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. + name: + type: string + description: The name of the function to call. + tool_calls: + type: array + items: + $ref: "#/components/schemas/ChatCompletionMessageToolCallChunk" + role: + type: string + enum: ["system", "user", "assistant", "tool"] + description: The role of the author of this message. + + CreateChatCompletionRequest: + type: object + properties: + messages: + description: A list of messages comprising the conversation so far. [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models). + type: array + minItems: 1 + items: + $ref: "#/components/schemas/ChatCompletionRequestMessage" + model: + description: 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. + example: "gpt-3.5-turbo" + anyOf: + - type: string + - type: string + enum: + [ + "gpt-4-0125-preview", + "gpt-4-turbo-preview", + "gpt-4-1106-preview", + "gpt-4-vision-preview", + "gpt-4", + "gpt-4-0314", + "gpt-4-0613", + "gpt-4-32k", + "gpt-4-32k-0314", + "gpt-4-32k-0613", + "gpt-3.5-turbo", + "gpt-3.5-turbo-16k", + "gpt-3.5-turbo-0301", + "gpt-3.5-turbo-0613", + "gpt-3.5-turbo-1106", + "gpt-3.5-turbo-16k-0613", + ] + x-oaiTypeLabel: string + frequency_penalty: + type: number + default: 0 + minimum: -2 + maximum: 2 + nullable: true + description: *completions_frequency_penalty_description + logit_bias: + type: object + x-oaiTypeLabel: map + default: null + nullable: true + additionalProperties: + type: integer + description: | + 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. + logprobs: + description: 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`. This option is currently not available on the `gpt-4-vision-preview` model. + type: boolean + default: false + nullable: true + top_logprobs: + description: An integer between 0 and 5 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. + type: integer + minimum: 0 + maximum: 5 + nullable: true + max_tokens: + description: | + 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. + type: integer + nullable: true + n: + type: integer + minimum: 1 + maximum: 128 + default: 1 + example: 1 + nullable: true + description: 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. + presence_penalty: + type: number + default: 0 + minimum: -2 + maximum: 2 + nullable: true + description: *completions_presence_penalty_description + response_format: + type: object + description: | + An object specifying the format that the model must output. Compatible with [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and `gpt-3.5-turbo-1106`. + + 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. + properties: + type: + type: string + enum: ["text", "json_object"] + example: "json_object" + default: "text" + description: Must be one of `text` or `json_object`. + seed: + type: integer + minimum: -9223372036854775808 + maximum: 9223372036854775807 + nullable: true + description: | + 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. + x-oaiMeta: + beta: true + stop: + description: | + Up to 4 sequences where the API will stop generating further tokens. + default: null + oneOf: + - type: string + nullable: true + - type: array + minItems: 1 + maxItems: 4 + items: + type: string + stream: + description: > + 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). + type: boolean + nullable: true + default: false + temperature: + type: number + minimum: 0 + maximum: 2 + default: 1 + example: 1 + nullable: true + description: *completions_temperature_description + top_p: + type: number + minimum: 0 + maximum: 1 + default: 1 + example: 1 + nullable: true + description: *completions_top_p_description + tools: + type: array + description: > + 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. + items: + $ref: "#/components/schemas/ChatCompletionTool" + tool_choice: + $ref: "#/components/schemas/ChatCompletionToolChoiceOption" + user: *end_user_param_configuration + function_call: + deprecated: true + description: | + 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. + oneOf: + - type: string + description: > + `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. + enum: [none, auto] + - $ref: "#/components/schemas/ChatCompletionFunctionCallOption" + x-oaiExpandable: true + functions: + deprecated: true + description: | + Deprecated in favor of `tools`. + + A list of functions the model may generate JSON inputs for. + type: array + minItems: 1 + maxItems: 128 + items: + $ref: "#/components/schemas/ChatCompletionFunctions" + + required: + - model + - messages + + CreateChatCompletionResponse: + type: object + description: Represents a chat completion response returned by model, based on the provided input. + properties: + id: + type: string + description: A unique identifier for the chat completion. + choices: + type: array + description: A list of chat completion choices. Can be more than one if `n` is greater than 1. + items: + type: object + required: + - finish_reason + - index + - message + - logprobs + properties: + finish_reason: + type: string + description: &chat_completion_finish_reason_description | + 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. + enum: + [ + "stop", + "length", + "tool_calls", + "content_filter", + "function_call", + ] + index: + type: integer + description: The index of the choice in the list of choices. + message: + $ref: "#/components/schemas/ChatCompletionResponseMessage" + logprobs: &chat_completion_response_logprobs + description: Log probability information for the choice. + type: object + nullable: true + properties: + content: + description: A list of message content tokens with log probability information. + type: array + items: + $ref: "#/components/schemas/ChatCompletionTokenLogprob" + nullable: true + required: + - content + created: + type: integer + description: The Unix timestamp (in seconds) of when the chat completion was created. + model: + type: string + description: The model used for the chat completion. + system_fingerprint: + type: string + description: | + 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. + object: + type: string + description: The object type, which is always `chat.completion`. + enum: [chat.completion] + usage: + $ref: "#/components/schemas/CompletionUsage" + required: + - choices + - created + - id + - model + - object + x-oaiMeta: + name: The chat completion object + group: chat + example: *chat_completion_example + + CreateChatCompletionFunctionResponse: + type: object + description: Represents a chat completion response returned by model, based on the provided input. + properties: + id: + type: string + description: A unique identifier for the chat completion. + choices: + type: array + description: A list of chat completion choices. Can be more than one if `n` is greater than 1. + items: + type: object + required: + - finish_reason + - index + - message + - logprobs + properties: + finish_reason: + type: string + description: + &chat_completion_function_finish_reason_description | + 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, or `function_call` if the model called a function. + enum: ["stop", "length", "function_call", "content_filter"] + index: + type: integer + description: The index of the choice in the list of choices. + message: + $ref: "#/components/schemas/ChatCompletionResponseMessage" + created: + type: integer + description: The Unix timestamp (in seconds) of when the chat completion was created. + model: + type: string + description: The model used for the chat completion. + system_fingerprint: + type: string + description: | + 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. + object: + type: string + description: The object type, which is always `chat.completion`. + enum: [chat.completion] + usage: + $ref: "#/components/schemas/CompletionUsage" + required: + - choices + - created + - id + - model + - object + x-oaiMeta: + name: The chat completion object + group: chat + example: *chat_completion_function_example + + ChatCompletionTokenLogprob: + type: object + properties: + token: &chat_completion_response_logprobs_token + description: The token. + type: string + logprob: &chat_completion_response_logprobs_token_logprob + description: The log probability of this token. + type: number + bytes: &chat_completion_response_logprobs_bytes + description: 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. + type: array + items: + type: integer + nullable: true + top_logprobs: + description: 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. + type: array + items: + type: object + properties: + token: *chat_completion_response_logprobs_token + logprob: *chat_completion_response_logprobs_token_logprob + bytes: *chat_completion_response_logprobs_bytes + required: + - token + - logprob + - bytes + required: + - token + - logprob + - bytes + - top_logprobs + + ListPaginatedFineTuningJobsResponse: + type: object + properties: + data: + type: array + items: + $ref: "#/components/schemas/FineTuningJob" + has_more: + type: boolean + object: + type: string + enum: [list] + required: + - object + - data + - has_more + + CreateChatCompletionStreamResponse: + type: object + description: Represents a streamed chunk of a chat completion response returned by model, based on the provided input. + properties: + id: + type: string + description: A unique identifier for the chat completion. Each chunk has the same ID. + choices: + type: array + description: A list of chat completion choices. Can be more than one if `n` is greater than 1. + items: + type: object + required: + - delta + - finish_reason + - index + properties: + delta: + $ref: "#/components/schemas/ChatCompletionStreamResponseDelta" + logprobs: *chat_completion_response_logprobs + finish_reason: + type: string + description: *chat_completion_finish_reason_description + enum: + [ + "stop", + "length", + "tool_calls", + "content_filter", + "function_call", + ] + nullable: true + index: + type: integer + description: The index of the choice in the list of choices. + created: + type: integer + description: The Unix timestamp (in seconds) of when the chat completion was created. Each chunk has the same timestamp. + model: + type: string + description: The model to generate the completion. + system_fingerprint: + type: string + description: | + 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. + object: + type: string + description: The object type, which is always `chat.completion.chunk`. + enum: [chat.completion.chunk] + required: + - choices + - created + - id + - model + - object + x-oaiMeta: + name: The chat completion chunk object + group: chat + example: *chat_completion_chunk_example + + CreateChatCompletionImageResponse: + type: object + description: Represents a streamed chunk of a chat completion response returned by model, based on the provided input. + x-oaiMeta: + name: The chat completion chunk object + group: chat + example: *chat_completion_image_example + + CreateImageRequest: + type: object + properties: + prompt: + description: A text description of the desired image(s). The maximum length is 1000 characters for `dall-e-2` and 4000 characters for `dall-e-3`. + type: string + example: "A cute baby sea otter" + model: + anyOf: + - type: string + - type: string + enum: ["dall-e-2", "dall-e-3"] + x-oaiTypeLabel: string + default: "dall-e-2" + example: "dall-e-3" + nullable: true + description: The model to use for image generation. + n: &images_n + type: integer + minimum: 1 + maximum: 10 + default: 1 + example: 1 + nullable: true + description: The number of images to generate. Must be between 1 and 10. For `dall-e-3`, only `n=1` is supported. + quality: + type: string + enum: ["standard", "hd"] + default: "standard" + example: "standard" + description: The quality of the image that will be generated. `hd` creates images with finer details and greater consistency across the image. This param is only supported for `dall-e-3`. + response_format: &images_response_format + type: string + enum: ["url", "b64_json"] + default: "url" + example: "url" + nullable: true + description: The format in which the generated images are returned. Must be one of `url` or `b64_json`. + size: &images_size + type: string + enum: ["256x256", "512x512", "1024x1024", "1792x1024", "1024x1792"] + default: "1024x1024" + example: "1024x1024" + nullable: true + description: The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`. Must be one of `1024x1024`, `1792x1024`, or `1024x1792` for `dall-e-3` models. + style: + type: string + enum: ["vivid", "natural"] + default: "vivid" + example: "vivid" + nullable: true + description: The style of the generated images. Must be one of `vivid` or `natural`. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images. This param is only supported for `dall-e-3`. + user: *end_user_param_configuration + required: + - prompt + + ImagesResponse: + properties: + created: + type: integer + data: + type: array + items: + $ref: "#/components/schemas/Image" + required: + - created + - data + + Image: + type: object + description: Represents the url or the content of an image generated by the OpenAI API. + properties: + b64_json: + type: string + description: The base64-encoded JSON of the generated image, if `response_format` is `b64_json`. + url: + type: string + description: The URL of the generated image, if `response_format` is `url` (default). + revised_prompt: + type: string + description: The prompt that was used to generate the image, if there was any revision to the prompt. + x-oaiMeta: + name: The image object + example: | + { + "url": "...", + "revised_prompt": "..." + } + + CreateImageEditRequest: + type: object + properties: + image: + description: The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask. + type: string + format: binary + prompt: + description: A text description of the desired image(s). The maximum length is 1000 characters. + type: string + example: "A cute baby sea otter wearing a beret" + mask: + description: An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where `image` should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as `image`. + type: string + format: binary + model: + anyOf: + - type: string + - type: string + enum: ["dall-e-2"] + x-oaiTypeLabel: string + default: "dall-e-2" + example: "dall-e-2" + nullable: true + description: The model to use for image generation. Only `dall-e-2` is supported at this time. + n: + type: integer + minimum: 1 + maximum: 10 + default: 1 + example: 1 + nullable: true + description: The number of images to generate. Must be between 1 and 10. + size: &dalle2_images_size + type: string + enum: ["256x256", "512x512", "1024x1024"] + default: "1024x1024" + example: "1024x1024" + nullable: true + description: The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. + response_format: *images_response_format + user: *end_user_param_configuration + required: + - prompt + - image + + CreateImageVariationRequest: + type: object + properties: + image: + description: The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square. + type: string + format: binary + model: + anyOf: + - type: string + - type: string + enum: ["dall-e-2"] + x-oaiTypeLabel: string + default: "dall-e-2" + example: "dall-e-2" + nullable: true + description: The model to use for image generation. Only `dall-e-2` is supported at this time. + n: *images_n + response_format: *images_response_format + size: *dalle2_images_size + user: *end_user_param_configuration + required: + - image + + CreateModerationRequest: + type: object + properties: + input: + description: The input text to classify + oneOf: + - type: string + default: "" + example: "I want to kill them." + - type: array + items: + type: string + default: "" + example: "I want to kill them." + model: + description: | + Two content moderations models are available: `text-moderation-stable` and `text-moderation-latest`. + + The default is `text-moderation-latest` which will be automatically upgraded over time. This ensures you are always using our most accurate model. If you use `text-moderation-stable`, we will provide advanced notice before updating the model. Accuracy of `text-moderation-stable` may be slightly lower than for `text-moderation-latest`. + nullable: false + default: "text-moderation-latest" + example: "text-moderation-stable" + anyOf: + - type: string + - type: string + enum: ["text-moderation-latest", "text-moderation-stable"] + x-oaiTypeLabel: string + required: + - input + + CreateModerationResponse: + type: object + description: Represents policy compliance report by OpenAI's content moderation model against a given input. + properties: + id: + type: string + description: The unique identifier for the moderation request. + model: + type: string + description: The model used to generate the moderation results. + results: + type: array + description: A list of moderation objects. + items: + type: object + properties: + flagged: + type: boolean + description: Whether the content violates [OpenAI's usage policies](/policies/usage-policies). + categories: + type: object + description: A list of the categories, and whether they are flagged or not. + properties: + hate: + type: boolean + description: Content that expresses, incites, or promotes hate based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste. Hateful content aimed at non-protected groups (e.g., chess players) is harassment. + hate/threatening: + type: boolean + description: Hateful content that also includes violence or serious harm towards the targeted group based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste. + harassment: + type: boolean + description: Content that expresses, incites, or promotes harassing language towards any target. + harassment/threatening: + type: boolean + description: Harassment content that also includes violence or serious harm towards any target. + self-harm: + type: boolean + description: Content that promotes, encourages, or depicts acts of self-harm, such as suicide, cutting, and eating disorders. + self-harm/intent: + type: boolean + description: Content where the speaker expresses that they are engaging or intend to engage in acts of self-harm, such as suicide, cutting, and eating disorders. + self-harm/instructions: + type: boolean + description: Content that encourages performing acts of self-harm, such as suicide, cutting, and eating disorders, or that gives instructions or advice on how to commit such acts. + sexual: + type: boolean + description: Content meant to arouse sexual excitement, such as the description of sexual activity, or that promotes sexual services (excluding sex education and wellness). + sexual/minors: + type: boolean + description: Sexual content that includes an individual who is under 18 years old. + violence: + type: boolean + description: Content that depicts death, violence, or physical injury. + violence/graphic: + type: boolean + description: Content that depicts death, violence, or physical injury in graphic detail. + required: + - hate + - hate/threatening + - harassment + - harassment/threatening + - self-harm + - self-harm/intent + - self-harm/instructions + - sexual + - sexual/minors + - violence + - violence/graphic + category_scores: + type: object + description: A list of the categories along with their scores as predicted by model. + properties: + hate: + type: number + description: The score for the category 'hate'. + hate/threatening: + type: number + description: The score for the category 'hate/threatening'. + harassment: + type: number + description: The score for the category 'harassment'. + harassment/threatening: + type: number + description: The score for the category 'harassment/threatening'. + self-harm: + type: number + description: The score for the category 'self-harm'. + self-harm/intent: + type: number + description: The score for the category 'self-harm/intent'. + self-harm/instructions: + type: number + description: The score for the category 'self-harm/instructions'. + sexual: + type: number + description: The score for the category 'sexual'. + sexual/minors: + type: number + description: The score for the category 'sexual/minors'. + violence: + type: number + description: The score for the category 'violence'. + violence/graphic: + type: number + description: The score for the category 'violence/graphic'. + required: + - hate + - hate/threatening + - harassment + - harassment/threatening + - self-harm + - self-harm/intent + - self-harm/instructions + - sexual + - sexual/minors + - violence + - violence/graphic + required: + - flagged + - categories + - category_scores + required: + - id + - model + - results + x-oaiMeta: + name: The moderation object + example: *moderation_example + + ListFilesResponse: + type: object + properties: + data: + type: array + items: + $ref: "#/components/schemas/OpenAIFile" + object: + type: string + enum: [list] + required: + - object + - data + + CreateFileRequest: + type: object + additionalProperties: false + properties: + file: + description: | + The File object (not file name) to be uploaded. + type: string + format: binary + purpose: + description: | + The intended purpose of the uploaded file. + + Use "fine-tune" for [Fine-tuning](/docs/api-reference/fine-tuning) and "assistants" for [Assistants](/docs/api-reference/assistants) and [Messages](/docs/api-reference/messages). This allows us to validate the format of the uploaded file is correct for fine-tuning. + type: string + enum: ["fine-tune", "assistants"] + required: + - file + - purpose + + DeleteFileResponse: + type: object + properties: + id: + type: string + object: + type: string + enum: [file] + deleted: + type: boolean + required: + - id + - object + - deleted + + CreateFineTuningJobRequest: + type: object + properties: + model: + description: | + The name of the model to fine-tune. You can select one of the + [supported models](/docs/guides/fine-tuning/what-models-can-be-fine-tuned). + example: "gpt-3.5-turbo" + anyOf: + - type: string + - type: string + enum: ["babbage-002", "davinci-002", "gpt-3.5-turbo"] + x-oaiTypeLabel: string + training_file: + description: | + The ID of an uploaded file that contains training data. + + See [upload file](/docs/api-reference/files/upload) for how to upload a file. + + Your dataset must be formatted as a JSONL file. Additionally, you must upload your file with the purpose `fine-tune`. + + See the [fine-tuning guide](/docs/guides/fine-tuning) for more details. + type: string + example: "file-abc123" + hyperparameters: + type: object + description: The hyperparameters used for the fine-tuning job. + properties: + batch_size: + description: | + Number of examples in each batch. A larger batch size means that model parameters + are updated less frequently, but with lower variance. + oneOf: + - type: string + enum: [auto] + - type: integer + minimum: 1 + maximum: 256 + default: auto + learning_rate_multiplier: + description: | + Scaling factor for the learning rate. A smaller learning rate may be useful to avoid + overfitting. + oneOf: + - type: string + enum: [auto] + - type: number + minimum: 0 + exclusiveMinimum: true + default: auto + n_epochs: + description: | + The number of epochs to train the model for. An epoch refers to one full cycle + through the training dataset. + oneOf: + - type: string + enum: [auto] + - type: integer + minimum: 1 + maximum: 50 + default: auto + suffix: + description: | + A string of up to 18 characters that will be added to your fine-tuned model name. + + For example, a `suffix` of "custom-model-name" would produce a model name like `ft:gpt-3.5-turbo:openai:custom-model-name:7p4lURel`. + type: string + minLength: 1 + maxLength: 40 + default: null + nullable: true + validation_file: + description: | + The ID of an uploaded file that contains validation data. + + If you provide this file, the data is used to generate validation + metrics periodically during fine-tuning. These metrics can be viewed in + the fine-tuning results file. + The same data should not be present in both train and validation files. + + Your dataset must be formatted as a JSONL file. You must upload your file with the purpose `fine-tune`. + + See the [fine-tuning guide](/docs/guides/fine-tuning) for more details. + type: string nullable: true + example: "file-abc123" + required: + - model + - training_file + + ListFineTuningJobEventsResponse: + type: object + properties: + data: + type: array + items: + $ref: "#/components/schemas/FineTuningJobEvent" + object: + type: string + enum: [list] + required: + - object + - data + + CreateEmbeddingRequest: + type: object + additionalProperties: false + properties: + input: + description: | + Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays. The input must not exceed the max input tokens for the model (8192 tokens for `text-embedding-ada-002`), cannot be an empty string, and any array must be 2048 dimensions or less. [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens. + example: "The quick brown fox jumped over the lazy dog" oneOf: - type: string - default: '' + title: string + description: The string that will be turned into an embedding. + default: "" example: "This is a test." - type: array + title: array + description: The array of strings that will be turned into an embedding. + minItems: 1 + maxItems: 2048 items: type: string - default: '' - example: "This is a test." + default: "" + example: "['This is a test.']" - type: array + title: array + description: The array of integers that will be turned into an embedding. minItems: 1 + maxItems: 2048 items: type: integer example: "[1212, 318, 257, 1332, 13]" - type: array + title: array + description: The array of arrays containing integers that will be turned into an embedding. minItems: 1 + maxItems: 2048 items: type: array minItems: 1 items: type: integer example: "[[1212, 318, 257, 1332, 13]]" - suffix: - description: - The suffix that comes after a completion of inserted text. - default: null - nullable: true + x-oaiExpandable: true + model: + description: *model_description + example: "text-embedding-3-small" + anyOf: + - type: string + - type: string + enum: ["text-embedding-ada-002", "text-embedding-3-small", "text-embedding-3-large"] + x-oaiTypeLabel: string + encoding_format: + description: "The format to return the embeddings in. Can be either `float` or [`base64`](https://pypi.org/project/pybase64/)." + example: "float" + default: "float" type: string - example: "test." - max_tokens: + enum: ["float", "base64"] + dimensions: + description: | + The number of dimensions the resulting output embeddings should have. Only supported in `text-embedding-3` and later models. type: integer - minimum: 0 - default: 16 - example: 16 - nullable: true - description: &completions_max_tokens_description | - The maximum number of [tokens](/tokenizer) to generate in the completion. + minimum: 1 + user: *end_user_param_configuration + required: + - model + - input + + CreateEmbeddingResponse: + type: object + properties: + data: + type: array + description: The list of embeddings generated by the model. + items: + $ref: "#/components/schemas/Embedding" + model: + type: string + description: The name of the model used to generate the embedding. + object: + type: string + description: The object type, which is always "list". + enum: [list] + usage: + type: object + description: The usage information for the request. + properties: + prompt_tokens: + type: integer + description: The number of tokens used by the prompt. + total_tokens: + type: integer + description: The total number of tokens used by the request. + required: + - prompt_tokens + - total_tokens + required: + - object + - model + - data + - usage + + CreateTranscriptionRequest: + type: object + additionalProperties: false + properties: + file: + description: | + The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm. + type: string + x-oaiTypeLabel: file + format: binary + model: + description: | + ID of the model to use. Only `whisper-1` is currently available. + example: whisper-1 + anyOf: + - type: string + - type: string + enum: ["whisper-1"] + x-oaiTypeLabel: string + language: + description: | + The language of the input audio. Supplying the input language in [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) format will improve accuracy and latency. + type: string + prompt: + description: | + An optional text to guide the model's style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should match the audio language. + type: string + response_format: + description: | + The format of the transcript output, in one of these options: `json`, `text`, `srt`, `verbose_json`, or `vtt`. + type: string + enum: + - json + - text + - srt + - verbose_json + - vtt + default: json + temperature: + description: | + The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. + type: number + default: 0 + required: + - file + - model + + # Note: This does not currently support the non-default response format types. + CreateTranscriptionResponse: + type: object + properties: + text: + type: string + required: + - text - The token count of your prompt plus `max_tokens` cannot exceed the model's context length. [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) for counting tokens. + CreateTranslationRequest: + type: object + additionalProperties: false + properties: + file: + description: | + The audio file object (not file name) translate, in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm. + type: string + x-oaiTypeLabel: file + format: binary + model: + description: | + ID of the model to use. Only `whisper-1` is currently available. + example: whisper-1 + anyOf: + - type: string + - type: string + enum: ["whisper-1"] + x-oaiTypeLabel: string + prompt: + description: | + An optional text to guide the model's style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should be in English. + type: string + response_format: + description: | + The format of the transcript output, in one of these options: `json`, `text`, `srt`, `verbose_json`, or `vtt`. + type: string + default: json temperature: + description: | + The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. type: number - minimum: 0 - maximum: 2 - default: 1 - example: 1 - nullable: true - description: &completions_temperature_description | - 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. + default: 0 + required: + - file + - model - We generally recommend altering this or `top_p` but not both. - top_p: + # Note: This does not currently support the non-default response format types. + CreateTranslationResponse: + type: object + properties: + text: + type: string + required: + - text + + CreateSpeechRequest: + type: object + additionalProperties: false + properties: + model: + description: | + One of the available [TTS models](/docs/models/tts): `tts-1` or `tts-1-hd` + anyOf: + - type: string + - type: string + enum: ["tts-1", "tts-1-hd"] + x-oaiTypeLabel: string + input: + type: string + description: The text to generate audio for. The maximum length is 4096 characters. + maxLength: 4096 + voice: + description: The voice to use when generating the audio. Supported voices are `alloy`, `echo`, `fable`, `onyx`, `nova`, and `shimmer`. Previews of the voices are available in the [Text to speech guide](/docs/guides/text-to-speech/voice-options). + type: string + enum: ["alloy", "echo", "fable", "onyx", "nova", "shimmer"] + response_format: + description: "The format to audio in. Supported formats are `mp3`, `opus`, `aac`, and `flac`." + default: "mp3" + type: string + enum: ["mp3", "opus", "aac", "flac"] + speed: + description: "The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the default." type: number - minimum: 0 - maximum: 1 - default: 1 - example: 1 - nullable: true - description: &completions_top_p_description | - 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. + default: 1.0 + minimum: 0.25 + maximum: 4.0 + required: + - model + - input + - voice - We generally recommend altering this or `temperature` but not both. - n: + Model: + title: Model + description: Describes an OpenAI model offering that can be used with the API. + properties: + id: + type: string + description: The model identifier, which can be referenced in the API endpoints. + created: type: integer - minimum: 1 - maximum: 128 - default: 1 - example: 1 - nullable: true - description: &completions_completions_description | - How many completions to generate for each prompt. + description: The Unix timestamp (in seconds) when the model was created. + object: + type: string + description: The object type, which is always "model". + enum: [model] + owned_by: + type: string + description: The organization that owns the model. + required: + - id + - object + - created + - owned_by + x-oaiMeta: + name: The model object + example: *retrieve_model_response - **Note:** Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop`. - stream: - description: > - Whether to stream back partial progress. If set, 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://github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb). - type: boolean - nullable: true - default: false - logprobs: &completions_logprobs_configuration + OpenAIFile: + title: OpenAIFile + description: The `File` object represents a document that has been uploaded to OpenAI. + properties: + id: + type: string + description: The file identifier, which can be referenced in the API endpoints. + bytes: type: integer - minimum: 0 - maximum: 5 - default: null - nullable: true - description: &completions_logprobs_description | - Include the log probabilities on the `logprobs` most likely tokens, as well the chosen tokens. For example, if `logprobs` is 5, the API will return a list of the 5 most likely tokens. The API will always return the `logprob` of the sampled token, so there may be up to `logprobs+1` elements in the response. + description: The size of the file, in bytes. + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the file was created. + filename: + type: string + description: The name of the file. + object: + type: string + description: The object type, which is always `file`. + enum: ["file"] + purpose: + type: string + description: The intended purpose of the file. Supported values are `fine-tune`, `fine-tune-results`, `assistants`, and `assistants_output`. + enum: + [ + "fine-tune", + "fine-tune-results", + "assistants", + "assistants_output", + ] + status: + type: string + deprecated: true + description: Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`. + enum: ["uploaded", "processed", "error"] + status_details: + type: string + deprecated: true + description: Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`. + required: + - id + - object + - bytes + - created_at + - filename + - purpose + - status + x-oaiMeta: + name: The file object + example: | + { + "id": "file-abc123", + "object": "file", + "bytes": 120000, + "created_at": 1677610602, + "filename": "salesOverview.pdf", + "purpose": "assistants", + } + Embedding: + type: object + description: | + Represents an embedding vector returned by embedding endpoint. + properties: + index: + type: integer + description: The index of the embedding in the list of embeddings. + embedding: + type: array + description: | + The embedding vector, which is a list of floats. The length of vector depends on the model as listed in the [embedding guide](/docs/guides/embeddings). + items: + type: number + object: + type: string + description: The object type, which is always "embedding". + enum: [embedding] + required: + - index + - object + - embedding + x-oaiMeta: + name: The embedding object + example: | + { + "object": "embedding", + "embedding": [ + 0.0023064255, + -0.009327292, + .... (1536 floats total for ada-002) + -0.0028842222, + ], + "index": 0 + } - The maximum value for `logprobs` is 5. - echo: - type: boolean - default: false - nullable: true - description: &completions_echo_description > - Echo back the prompt in addition to the completion - stop: - description: &completions_stop_description > - Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence. - default: null + FineTuningJob: + type: object + title: FineTuningJob + description: | + The `fine_tuning.job` object represents a fine-tuning job that has been created through the API. + properties: + id: + type: string + description: The object identifier, which can be referenced in the API endpoints. + created_at: + type: integer + description: The Unix timestamp (in seconds) for when the fine-tuning job was created. + error: + type: object nullable: true - oneOf: - - type: string - default: <|endoftext|> - example: "\n" + description: For fine-tuning jobs that have `failed`, this will contain more information on the cause of the failure. + properties: + code: + type: string + description: A machine-readable error code. + message: + type: string + description: A human-readable error message. + param: + type: string + description: The parameter that was invalid, usually `training_file` or `validation_file`. This field will be null if the failure was not parameter-specific. nullable: true - - type: array - minItems: 1 - maxItems: 4 - items: - type: string - example: '["\n"]' - presence_penalty: - type: number - default: 0 - minimum: -2 - maximum: 2 - nullable: true - description: &completions_presence_penalty_description | - 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. - - [See more information about frequency and presence penalties.](/docs/api-reference/parameter-details) - frequency_penalty: - type: number - default: 0 - minimum: -2 - maximum: 2 + required: + - code + - message + - param + fine_tuned_model: + type: string nullable: true - description: &completions_frequency_penalty_description | - 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. - - [See more information about frequency and presence penalties.](/docs/api-reference/parameter-details) - best_of: + description: The name of the fine-tuned model that is being created. The value will be null if the fine-tuning job is still running. + finished_at: type: integer - default: 1 - minimum: 0 - maximum: 20 nullable: true - description: &completions_best_of_description | - Generates `best_of` completions server-side and returns the "best" (the one with the highest log probability per token). Results cannot be streamed. - - When used with `n`, `best_of` controls the number of candidate completions and `n` specifies how many to return – `best_of` must be greater than `n`. - - **Note:** Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop`. - logit_bias: &completions_logit_bias + description: The Unix timestamp (in seconds) for when the fine-tuning job was finished. The value will be null if the fine-tuning job is still running. + hyperparameters: type: object - x-oaiTypeLabel: map - default: null - nullable: true - description: &completions_logit_bias_description | - Modify the likelihood of specified tokens appearing in the completion. - - Accepts a json object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100. You can use this [tokenizer tool](/tokenizer?view=bpe) (which works for both GPT-2 and GPT-3) to convert text to token IDs. 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. + description: The hyperparameters used for the fine-tuning job. See the [fine-tuning guide](/docs/guides/fine-tuning) for more details. + properties: + n_epochs: + oneOf: + - type: string + enum: [auto] + - type: integer + minimum: 1 + maximum: 50 + default: auto + description: + The number of epochs to train the model for. An epoch refers to one full cycle through the training dataset. - As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being generated. - user: &end_user_param_configuration + "auto" decides the optimal number of epochs based on the size of the dataset. If setting the number manually, we support any number between 1 and 50 epochs. + required: + - n_epochs + model: type: string - example: user-1234 - description: | - A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids). + description: The base model that is being fine-tuned. + object: + type: string + description: The object type, which is always "fine_tuning.job". + enum: [fine_tuning.job] + organization_id: + type: string + description: The organization that owns the fine-tuning job. + result_files: + type: array + description: The compiled results file ID(s) for the fine-tuning job. You can retrieve the results with the [Files API](/docs/api-reference/files/retrieve-contents). + items: + type: string + example: file-abc123 + status: + type: string + description: The current status of the fine-tuning job, which can be either `validating_files`, `queued`, `running`, `succeeded`, `failed`, or `cancelled`. + enum: + [ + "validating_files", + "queued", + "running", + "succeeded", + "failed", + "cancelled", + ] + trained_tokens: + type: integer + nullable: true + description: The total number of billable tokens processed by this fine-tuning job. The value will be null if the fine-tuning job is still running. + training_file: + type: string + description: The file ID used for training. You can retrieve the training data with the [Files API](/docs/api-reference/files/retrieve-contents). + validation_file: + type: string + nullable: true + description: The file ID used for validation. You can retrieve the validation results with the [Files API](/docs/api-reference/files/retrieve-contents). required: + - created_at + - error + - finished_at + - fine_tuned_model + - hyperparameters + - id - model - - prompt - - CreateCompletionResponse: + - object + - organization_id + - result_files + - status + - trained_tokens + - training_file + - validation_file + x-oaiMeta: + name: The fine-tuning job object + example: *fine_tuning_example + + FineTuningJobEvent: type: object + description: Fine-tuning job event object properties: id: type: string - object: - type: string - created: + created_at: type: integer - model: + level: type: string - choices: - type: array - items: - type: object - required: - - text - - index - - logprobs - - finish_reason - properties: - text: - type: string - index: - type: integer - logprobs: - type: object - nullable: true - properties: - tokens: - type: array - items: - type: string - token_logprobs: - type: array - items: - type: number - top_logprobs: - type: array - items: - type: object - text_offset: - type: array - items: - type: integer - finish_reason: - type: string - enum: ["stop", "length"] - usage: - type: object - properties: - prompt_tokens: - type: integer - completion_tokens: - type: integer - total_tokens: - type: integer - required: - - prompt_tokens - - completion_tokens - - total_tokens - required: + enum: ["info", "warn", "error"] + message: + type: string + object: + type: string + enum: [fine_tuning.job.event] + required: - id - object - - created - - model - - choices + - created_at + - level + - message + x-oaiMeta: + name: The fine-tuning job event object + example: | + { + "object": "fine_tuning.job.event", + "id": "ftevent-abc123" + "created_at": 1677610602, + "level": "info", + "message": "Created fine-tuning job" + } - ChatCompletionRequestMessage: + CompletionUsage: type: object + description: Usage statistics for the completion request. properties: - role: - type: string - enum: ["system", "user", "assistant", "function"] - description: The role of the messages author. One of `system`, `user`, `assistant`, or `function`. - content: - type: string - description: The contents of the message. `content` is required for all messages except assistant messages with function calls. - name: - type: string - description: 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. - function_call: - type: object - description: The name and arguments of a function that should be called, as generated by the model. - properties: - name: - type: string - description: The name of the function to call. - arguments: - type: string - description: 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. - required: - - role - - ChatCompletionFunctionParameters: + completion_tokens: + type: integer + description: Number of tokens in the generated completion. + prompt_tokens: + type: integer + description: Number of tokens in the prompt. + total_tokens: + type: integer + description: Total number of tokens used in the request (prompt + completion). + required: + - prompt_tokens + - completion_tokens + - total_tokens + + RunCompletionUsage: type: object - 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. - # TODO type this as json schema - additionalProperties: true + description: Usage statistics related to the run. This value will be `null` if the run is not in a terminal state (i.e. `in_progress`, `queued`, etc.). + properties: + completion_tokens: + type: integer + description: Number of completion tokens used over the course of the run. + prompt_tokens: + type: integer + description: Number of prompt tokens used over the course of the run. + total_tokens: + type: integer + description: Total number of tokens used (prompt + completion). + required: + - prompt_tokens + - completion_tokens + - total_tokens + nullable: true - ChatCompletionFunctions: + RunStepCompletionUsage: type: object + description: Usage statistics related to the run step. This value will be `null` while the run step's status is `in_progress`. properties: - name: - type: string - description: 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. - description: - type: string - description: The description of what the function does. - parameters: - $ref: '#/components/schemas/ChatCompletionFunctionParameters' - required: - - name + completion_tokens: + type: integer + description: Number of completion tokens used over the course of the run step. + prompt_tokens: + type: integer + description: Number of prompt tokens used over the course of the run step. + total_tokens: + type: integer + description: Total number of tokens used (prompt + completion). + required: + - prompt_tokens + - completion_tokens + - total_tokens + nullable: true - ChatCompletionResponseMessage: + AssistantObject: type: object + title: Assistant + description: Represents an `assistant` that can call the model and use tools. properties: - role: + id: + description: The identifier, which can be referenced in API endpoints. type: string - enum: ["system", "user", "assistant", "function"] - description: The role of the author of this message. - content: + object: + description: The object type, which is always `assistant`. type: string - description: The contents of the message. - nullable: true - function_call: - type: object - description: The name and arguments of a function that should be called, as generated by the model. - properties: - name: - type: string - description: The name of the function to call. - arguments: - type: string - description: 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. - required: - - role - - ChatCompletionStreamResponseDelta: - type: object - properties: - role: + enum: [assistant] + created_at: + description: The Unix timestamp (in seconds) for when the assistant was created. + type: integer + name: + description: &assistant_name_param_description | + The name of the assistant. The maximum length is 256 characters. type: string - enum: ["system", "user", "assistant", "function"] - description: The role of the author of this message. - content: + maxLength: 256 + nullable: true + description: + description: &assistant_description_param_description | + The description of the assistant. The maximum length is 512 characters. type: string - description: The contents of the chunk message. + maxLength: 512 nullable: true - function_call: - type: object - description: The name and arguments of a function that should be called, as generated by the model. - properties: - name: - type: string - description: The name of the function to call. - arguments: - type: string - description: 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. - - CreateChatCompletionRequest: - type: object - properties: model: - description: 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. - example: "gpt-3.5-turbo" - oneOf: - - type: string - - type: string - enum: ["gpt-4","gpt-4-0613","gpt-4-32k","gpt-4-32k-0613","gpt-3.5-turbo","gpt-3.5-turbo-16k","gpt-3.5-turbo-0613","gpt-3.5-turbo-16k-0613"] - messages: - description: 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). + description: *model_description + type: string + instructions: + description: &assistant_instructions_param_description | + The system instructions that the assistant uses. The maximum length is 32768 characters. + type: string + maxLength: 32768 + nullable: true + tools: + description: &assistant_tools_param_description | + A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `retrieval`, or `function`. + default: [] type: array - minItems: 1 + maxItems: 128 items: - $ref: '#/components/schemas/ChatCompletionRequestMessage' - functions: - description: A list of functions the model may generate JSON inputs for. + oneOf: + - $ref: "#/components/schemas/AssistantToolsCode" + - $ref: "#/components/schemas/AssistantToolsRetrieval" + - $ref: "#/components/schemas/AssistantToolsFunction" + x-oaiExpandable: true + file_ids: + description: &assistant_file_param_description | + A list of [file](/docs/api-reference/files) IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. Files are ordered by their creation date in ascending order. + default: [] type: array - minItems: 1 + maxItems: 20 items: - $ref: '#/components/schemas/ChatCompletionFunctions' - function_call: - description: 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. - oneOf: - - type: string - enum: [none, auto] - - type: object - properties: - name: - type: string - description: The name of the function to call. - required: - - name - temperature: - type: number - minimum: 0 - maximum: 2 - default: 1 - example: 1 - nullable: true - description: *completions_temperature_description - top_p: - type: number - minimum: 0 - maximum: 1 - default: 1 - example: 1 - nullable: true - description: *completions_top_p_description - n: - type: integer - minimum: 1 - maximum: 128 - default: 1 - example: 1 - nullable: true - description: How many chat completion choices to generate for each input message. - stream: - description: > - 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://github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb). - type: boolean + type: string + metadata: + description: &metadata_description | + Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long. + type: object + x-oaiTypeLabel: map nullable: true - default: false - stop: - description: | - Up to 4 sequences where the API will stop generating further tokens. - default: null - oneOf: - - type: string - nullable: true - - type: array - minItems: 1 - maxItems: 4 - items: - type: string - max_tokens: - description: | - The maximum number of [tokens](/tokenizer) to generate in the chat completion. + required: + - id + - object + - created_at + - name + - description + - model + - instructions + - tools + - file_ids + - metadata + x-oaiMeta: + name: The assistant object + beta: true + example: *create_assistants_example - The total length of input tokens and generated tokens is limited by the model's context length. [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) for counting tokens. - default: inf - type: integer - presence_penalty: - type: number - default: 0 - minimum: -2 - maximum: 2 - nullable: true - description: *completions_presence_penalty_description - frequency_penalty: - type: number - default: 0 - minimum: -2 - maximum: 2 + CreateAssistantRequest: + type: object + additionalProperties: false + properties: + model: + description: *model_description + anyOf: + - type: string + name: + description: *assistant_name_param_description + type: string nullable: true - description: *completions_frequency_penalty_description - logit_bias: + maxLength: 256 + description: + description: *assistant_description_param_description + type: string + nullable: true + maxLength: 512 + instructions: + description: *assistant_instructions_param_description + type: string + nullable: true + maxLength: 32768 + tools: + description: *assistant_tools_param_description + default: [] + type: array + maxItems: 128 + items: + oneOf: + - $ref: "#/components/schemas/AssistantToolsCode" + - $ref: "#/components/schemas/AssistantToolsRetrieval" + - $ref: "#/components/schemas/AssistantToolsFunction" + x-oaiExpandable: true + file_ids: + description: *assistant_file_param_description + default: [] + maxItems: 20 + type: array + items: + type: string + metadata: + description: *metadata_description type: object x-oaiTypeLabel: map - default: null nullable: true - description: | - 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. - user: *end_user_param_configuration required: - model - - messages - CreateChatCompletionResponse: + ModifyAssistantRequest: type: object + additionalProperties: false properties: - id: + model: + description: *model_description + anyOf: + - type: string + name: + description: *assistant_name_param_description type: string - object: + nullable: true + maxLength: 256 + description: + description: *assistant_description_param_description type: string - created: - type: integer - model: + nullable: true + maxLength: 512 + instructions: + description: *assistant_instructions_param_description type: string - choices: + nullable: true + maxLength: 32768 + tools: + description: *assistant_tools_param_description + default: [] type: array + maxItems: 128 items: - type: object - properties: - index: - type: integer - message: - $ref: '#/components/schemas/ChatCompletionResponseMessage' - finish_reason: - type: string - enum: ["stop", "length", "function_call"] - usage: + oneOf: + - $ref: "#/components/schemas/AssistantToolsCode" + - $ref: "#/components/schemas/AssistantToolsRetrieval" + - $ref: "#/components/schemas/AssistantToolsFunction" + x-oaiExpandable: true + file_ids: + description: | + A list of [File](/docs/api-reference/files) IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. Files are ordered by their creation date in ascending order. If a file was previously attached to the list but does not show up in the list, it will be deleted from the assistant. + default: [] + type: array + maxItems: 20 + items: + type: string + metadata: + description: *metadata_description type: object - properties: - prompt_tokens: - type: integer - completion_tokens: - type: integer - total_tokens: - type: integer - required: - - prompt_tokens - - completion_tokens - - total_tokens - required: - - id - - object - - created - - model - - choices + x-oaiTypeLabel: map + nullable: true - CreateChatCompletionStreamResponse: + DeleteAssistantResponse: type: object properties: id: type: string + deleted: + type: boolean object: type: string - created: - type: integer - model: + enum: [assistant.deleted] + required: + - id + - object + - deleted + + ListAssistantsResponse: + type: object + properties: + object: type: string - choices: + example: "list" + data: type: array items: - type: object - properties: - index: - type: integer - delta: - $ref: '#/components/schemas/ChatCompletionStreamResponseDelta' - finish_reason: - type: string - enum: ["stop", "length", "function_call"] - required: - - id + $ref: "#/components/schemas/AssistantObject" + first_id: + type: string + example: "asst_abc123" + last_id: + type: string + example: "asst_abc456" + has_more: + type: boolean + example: false + required: - object - - created - - model - - choices + - data + - first_id + - last_id + - has_more + x-oaiMeta: + name: List assistants response object + group: chat + example: *list_assistants_example - CreateEditRequest: + AssistantToolsCode: type: object + title: Code interpreter tool properties: - model: - description: ID of the model to use. You can use the `text-davinci-edit-001` or `code-davinci-edit-001` model with this endpoint. + type: type: string - example: "text-davinci-edit-001" - oneOf: - - type: string - - type: string - enum: ["text-davinci-edit-001","code-davinci-edit-001"] - input: - description: - The input text to use as a starting point for the edit. + description: "The type of tool being defined: `code_interpreter`" + enum: ["code_interpreter"] + required: + - type + + AssistantToolsRetrieval: + type: object + title: Retrieval tool + properties: + type: type: string - default: '' - nullable: true - example: "What day of the wek is it?" - instruction: - description: - The instruction that tells the model how to edit the prompt. + description: "The type of tool being defined: `retrieval`" + enum: ["retrieval"] + required: + - type + + AssistantToolsFunction: + type: object + title: Function tool + properties: + type: type: string - example: "Fix the spelling mistakes." - n: - type: integer - minimum: 1 - maximum: 20 - default: 1 - example: 1 - nullable: true - description: - How many edits to generate for the input and instruction. - temperature: - type: number - minimum: 0 - maximum: 2 - default: 1 - example: 1 - nullable: true - description: *completions_temperature_description - top_p: - type: number - minimum: 0 - maximum: 1 - default: 1 - example: 1 - nullable: true - description: *completions_top_p_description + description: "The type of tool being defined: `function`" + enum: ["function"] + function: + $ref: "#/components/schemas/FunctionObject" required: - - model - - instruction + - type + - function - CreateEditResponse: + RunObject: type: object + title: A run on a thread + description: Represents an execution run on a [thread](/docs/api-reference/threads). properties: + id: + description: The identifier, which can be referenced in API endpoints. + type: string object: + description: The object type, which is always `thread.run`. type: string - created: + enum: ["thread.run"] + created_at: + description: The Unix timestamp (in seconds) for when the run was created. type: integer - choices: + thread_id: + description: The ID of the [thread](/docs/api-reference/threads) that was executed on as a part of this run. + type: string + assistant_id: + description: The ID of the [assistant](/docs/api-reference/assistants) used for execution of this run. + type: string + status: + description: The status of the run, which can be either `queued`, `in_progress`, `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`, or `expired`. + type: string + enum: + [ + "queued", + "in_progress", + "requires_action", + "cancelling", + "cancelled", + "failed", + "completed", + "expired", + ] + required_action: + type: object + description: Details on the action required to continue the run. Will be `null` if no action is required. + nullable: true + properties: + type: + description: For now, this is always `submit_tool_outputs`. + type: string + enum: ["submit_tool_outputs"] + submit_tool_outputs: + type: object + description: Details on the tool outputs needed for this run to continue. + properties: + tool_calls: + type: array + description: A list of the relevant tool calls. + items: + $ref: "#/components/schemas/RunToolCallObject" + required: + - tool_calls + required: + - type + - submit_tool_outputs + last_error: + type: object + description: The last error associated with this run. Will be `null` if there are no errors. + nullable: true + properties: + code: + type: string + description: One of `server_error` or `rate_limit_exceeded`. + enum: ["server_error", "rate_limit_exceeded"] + message: + type: string + description: A human-readable description of the error. + required: + - code + - message + expires_at: + description: The Unix timestamp (in seconds) for when the run will expire. + type: integer + started_at: + description: The Unix timestamp (in seconds) for when the run was started. + type: integer + nullable: true + cancelled_at: + description: The Unix timestamp (in seconds) for when the run was cancelled. + type: integer + nullable: true + failed_at: + description: The Unix timestamp (in seconds) for when the run failed. + type: integer + nullable: true + completed_at: + description: The Unix timestamp (in seconds) for when the run was completed. + type: integer + nullable: true + model: + description: The model that the [assistant](/docs/api-reference/assistants) used for this run. + type: string + instructions: + description: The instructions that the [assistant](/docs/api-reference/assistants) used for this run. + type: string + tools: + description: The list of tools that the [assistant](/docs/api-reference/assistants) used for this run. + default: [] type: array + maxItems: 20 items: - type: object - properties: - text: - type: string - index: - type: integer - logprobs: - type: object - nullable: true - properties: - tokens: - type: array - items: - type: string - token_logprobs: - type: array - items: - type: number - top_logprobs: - type: array - items: - type: object - text_offset: - type: array - items: - type: integer - finish_reason: - type: string - enum: ["stop", "length"] - usage: + oneOf: + - $ref: "#/components/schemas/AssistantToolsCode" + - $ref: "#/components/schemas/AssistantToolsRetrieval" + - $ref: "#/components/schemas/AssistantToolsFunction" + x-oaiExpandable: true + file_ids: + description: The list of [File](/docs/api-reference/files) IDs the [assistant](/docs/api-reference/assistants) used for this run. + default: [] + type: array + items: + type: string + metadata: + description: *metadata_description type: object - properties: - prompt_tokens: - type: integer - completion_tokens: - type: integer - total_tokens: - type: integer - required: - - prompt_tokens - - completion_tokens - - total_tokens - required: + x-oaiTypeLabel: map + nullable: true + usage: + $ref: "#/components/schemas/RunCompletionUsage" + required: + - id - object - - created - - choices + - created_at + - thread_id + - assistant_id + - status + - required_action + - last_error + - expires_at + - started_at + - cancelled_at + - failed_at + - completed_at + - model + - instructions + - tools + - file_ids + - metadata - usage - - CreateImageRequest: + x-oaiMeta: + name: The run object + beta: true + example: | + { + "id": "run_abc123", + "object": "thread.run", + "created_at": 1698107661, + "assistant_id": "asst_abc123", + "thread_id": "thread_abc123", + "status": "completed", + "started_at": 1699073476, + "expires_at": null, + "cancelled_at": null, + "failed_at": null, + "completed_at": 1699073498, + "last_error": null, + "model": "gpt-4", + "instructions": null, + "tools": [{"type": "retrieval"}, {"type": "code_interpreter"}], + "file_ids": [], + "metadata": {}, + "usage": { + "prompt_tokens": 123, + "completion_tokens": 456, + "total_tokens": 579 + } + } + CreateRunRequest: type: object + additionalProperties: false properties: - prompt: - description: A text description of the desired image(s). The maximum length is 1000 characters. + assistant_id: + description: The ID of the [assistant](/docs/api-reference/assistants) to use to execute this run. + type: string + model: + description: The ID of the [Model](/docs/api-reference/models) to be used to execute this run. If a value is provided here, it will override the model associated with the assistant. If not, the model associated with the assistant will be used. type: string - example: "A cute baby sea otter" - n: &images_n - type: integer - minimum: 1 - maximum: 10 - default: 1 - example: 1 nullable: true - description: The number of images to generate. Must be between 1 and 10. - size: &images_size + instructions: + description: Overrides the [instructions](/docs/api-reference/assistants/createAssistant) of the assistant. This is useful for modifying the behavior on a per-run basis. type: string - enum: ["256x256", "512x512", "1024x1024"] - default: "1024x1024" - example: "1024x1024" nullable: true - description: The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. - response_format: &images_response_format + additional_instructions: + description: Appends additional instructions at the end of the instructions for the run. This is useful for modifying the behavior on a per-run basis without overriding other instructions. type: string - enum: ["url", "b64_json"] - default: "url" - example: "url" nullable: true - description: The format in which the generated images are returned. Must be one of `url` or `b64_json`. - user: *end_user_param_configuration + tools: + description: Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis. + nullable: true + type: array + maxItems: 20 + items: + oneOf: + - $ref: "#/components/schemas/AssistantToolsCode" + - $ref: "#/components/schemas/AssistantToolsRetrieval" + - $ref: "#/components/schemas/AssistantToolsFunction" + x-oaiExpandable: true + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true required: - - prompt - - ImagesResponse: + - thread_id + - assistant_id + ListRunsResponse: + type: object properties: - created: - type: integer + object: + type: string + example: "list" data: + type: array + items: + $ref: "#/components/schemas/RunObject" + first_id: + type: string + example: "run_abc123" + last_id: + type: string + example: "run_abc456" + has_more: + type: boolean + example: false + required: + - object + - data + - first_id + - last_id + - has_more + ModifyRunRequest: + type: object + additionalProperties: false + properties: + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true + SubmitToolOutputsRunRequest: + type: object + additionalProperties: false + properties: + tool_outputs: + description: A list of tools for which the outputs are being submitted. type: array items: type: object properties: - url: + tool_call_id: type: string - b64_json: + description: The ID of the tool call in the `required_action` object within the run object the output is being submitted for. + output: type: string + description: The output of the tool call to be submitted to continue the run. required: - - created - - data + - tool_outputs - CreateImageEditRequest: + RunToolCallObject: type: object + description: Tool call objects properties: - image: - description: The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask. + id: type: string - format: binary - mask: - description: An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where `image` should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as `image`. + description: The ID of the tool call. This ID must be referenced when you submit the tool outputs in using the [Submit tool outputs to run](/docs/api-reference/runs/submitToolOutputs) endpoint. + type: type: string - format: binary - prompt: - description: A text description of the desired image(s). The maximum length is 1000 characters. + description: The type of tool call the output is required for. For now, this is always `function`. + enum: ["function"] + function: + type: object + description: The function definition. + properties: + name: + type: string + description: The name of the function. + arguments: + type: string + description: The arguments that the model expects you to pass to the function. + required: + - name + - arguments + required: + - id + - type + - function + + CreateThreadAndRunRequest: + type: object + additionalProperties: false + properties: + assistant_id: + description: The ID of the [assistant](/docs/api-reference/assistants) to use to execute this run. type: string - example: "A cute baby sea otter wearing a beret" - n: *images_n - size: *images_size - response_format: *images_response_format - user: *end_user_param_configuration + thread: + $ref: "#/components/schemas/CreateThreadRequest" + description: If no thread is provided, an empty thread will be created. + model: + description: The ID of the [Model](/docs/api-reference/models) to be used to execute this run. If a value is provided here, it will override the model associated with the assistant. If not, the model associated with the assistant will be used. + type: string + nullable: true + instructions: + description: Override the default system message of the assistant. This is useful for modifying the behavior on a per-run basis. + type: string + nullable: true + tools: + description: Override the tools the assistant can use for this run. This is useful for modifying the behavior on a per-run basis. + nullable: true + type: array + maxItems: 20 + items: + oneOf: + - $ref: "#/components/schemas/AssistantToolsCode" + - $ref: "#/components/schemas/AssistantToolsRetrieval" + - $ref: "#/components/schemas/AssistantToolsFunction" + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true required: - - prompt - - image + - thread_id + - assistant_id - CreateImageVariationRequest: + ThreadObject: type: object + title: Thread + description: Represents a thread that contains [messages](/docs/api-reference/messages). properties: - image: - description: The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square. + id: + description: The identifier, which can be referenced in API endpoints. type: string - format: binary - n: *images_n - size: *images_size - response_format: *images_response_format - user: *end_user_param_configuration + object: + description: The object type, which is always `thread`. + type: string + enum: ["thread"] + created_at: + description: The Unix timestamp (in seconds) for when the thread was created. + type: integer + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true required: - - image + - id + - object + - created_at + - metadata + x-oaiMeta: + name: The thread object + beta: true + example: | + { + "id": "thread_abc123", + "object": "thread", + "created_at": 1698107661, + "metadata": {} + } - CreateModerationRequest: + CreateThreadRequest: + type: object + additionalProperties: false + properties: + messages: + description: A list of [messages](/docs/api-reference/messages) to start the thread with. + type: array + items: + $ref: "#/components/schemas/CreateMessageRequest" + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true + + ModifyThreadRequest: type: object + additionalProperties: false properties: - input: - description: The input text to classify - oneOf: - - type: string - default: '' - example: "I want to kill them." - - type: array - items: - type: string - default: '' - example: "I want to kill them." - model: - description: | - Two content moderations models are available: `text-moderation-stable` and `text-moderation-latest`. + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true - The default is `text-moderation-latest` which will be automatically upgraded over time. This ensures you are always using our most accurate model. If you use `text-moderation-stable`, we will provide advanced notice before updating the model. Accuracy of `text-moderation-stable` may be slightly lower than for `text-moderation-latest`. - nullable: false - default: "text-moderation-latest" - example: "text-moderation-stable" - oneOf: - - type: string - - type: string - enum: ["text-moderation-latest","text-moderation-stable"] + DeleteThreadResponse: + type: object + properties: + id: + type: string + deleted: + type: boolean + object: + type: string + enum: [thread.deleted] required: - - input + - id + - object + - deleted - CreateModerationResponse: + ListThreadsResponse: + properties: + object: + type: string + example: "list" + data: + type: array + items: + $ref: "#/components/schemas/ThreadObject" + first_id: + type: string + example: "asst_abc123" + last_id: + type: string + example: "asst_abc456" + has_more: + type: boolean + example: false + required: + - object + - data + - first_id + - last_id + - has_more + + MessageObject: type: object + title: The message object + description: Represents a message within a [thread](/docs/api-reference/threads). properties: id: + description: The identifier, which can be referenced in API endpoints. type: string - model: + object: + description: The object type, which is always `thread.message`. type: string - results: + enum: ["thread.message"] + created_at: + description: The Unix timestamp (in seconds) for when the message was created. + type: integer + thread_id: + description: The [thread](/docs/api-reference/threads) ID that this message belongs to. + type: string + role: + description: The entity that produced the message. One of `user` or `assistant`. + type: string + enum: ["user", "assistant"] + content: + description: The content of the message in array of text and/or images. type: array items: - type: object - properties: - flagged: - type: boolean - categories: - type: object - properties: - hate: - type: boolean - hate/threatening: - type: boolean - self-harm: - type: boolean - sexual: - type: boolean - sexual/minors: - type: boolean - violence: - type: boolean - violence/graphic: - type: boolean - required: - - hate - - hate/threatening - - self-harm - - sexual - - sexual/minors - - violence - - violence/graphic - category_scores: - type: object - properties: - hate: - type: number - hate/threatening: - type: number - self-harm: - type: number - sexual: - type: number - sexual/minors: - type: number - violence: - type: number - violence/graphic: - type: number - required: - - hate - - hate/threatening - - self-harm - - sexual - - sexual/minors - - violence - - violence/graphic - required: - - flagged - - categories - - category_scores - required: + oneOf: + - $ref: "#/components/schemas/MessageContentImageFileObject" + - $ref: "#/components/schemas/MessageContentTextObject" + x-oaiExpandable: true + assistant_id: + description: If applicable, the ID of the [assistant](/docs/api-reference/assistants) that authored this message. + type: string + nullable: true + run_id: + description: If applicable, the ID of the [run](/docs/api-reference/runs) associated with the authoring of this message. + type: string + nullable: true + file_ids: + description: A list of [file](/docs/api-reference/files) IDs that the assistant should use. Useful for tools like retrieval and code_interpreter that can access files. A maximum of 10 files can be attached to a message. + default: [] + maxItems: 10 + type: array + items: + type: string + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true + required: - id - - model - - results + - object + - created_at + - thread_id + - role + - content + - assistant_id + - run_id + - file_ids + - metadata + x-oaiMeta: + name: The message object + beta: true + example: | + { + "id": "msg_abc123", + "object": "thread.message", + "created_at": 1698983503, + "thread_id": "thread_abc123", + "role": "assistant", + "content": [ + { + "type": "text", + "text": { + "value": "Hi! How can I help you today?", + "annotations": [] + } + } + ], + "file_ids": [], + "assistant_id": "asst_abc123", + "run_id": "run_abc123", + "metadata": {} + } + + CreateMessageRequest: + type: object + additionalProperties: false + required: + - role + - content + properties: + role: + type: string + enum: ["user"] + description: The role of the entity that is creating the message. Currently only `user` is supported. + content: + type: string + minLength: 1 + maxLength: 32768 + description: The content of the message. + file_ids: + description: A list of [File](/docs/api-reference/files) IDs that the message should use. There can be a maximum of 10 files attached to a message. Useful for tools like `retrieval` and `code_interpreter` that can access and use files. + default: [] + type: array + minItems: 1 + maxItems: 10 + items: + type: string + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true - ListFilesResponse: + ModifyMessageRequest: + type: object + additionalProperties: false + properties: + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map + nullable: true + + DeleteMessageResponse: type: object + properties: + id: + type: string + deleted: + type: boolean + object: + type: string + enum: [thread.message.deleted] + required: + - id + - object + - deleted + + ListMessagesResponse: properties: object: type: string + example: "list" data: type: array items: - $ref: '#/components/schemas/OpenAIFile' - required: + $ref: "#/components/schemas/MessageObject" + first_id: + type: string + example: "msg_abc123" + last_id: + type: string + example: "msg_abc123" + has_more: + type: boolean + example: false + required: - object - data + - first_id + - last_id + - has_more - CreateFileRequest: + MessageContentImageFileObject: + title: Image file type: object - additionalProperties: false + description: References an image [File](/docs/api-reference/files) in the content of a message. properties: - file: - description: | - Name of the [JSON Lines](https://jsonlines.readthedocs.io/en/latest/) file to be uploaded. - - If the `purpose` is set to "fine-tune", each line is a JSON record with "prompt" and "completion" fields representing your [training examples](/docs/guides/fine-tuning/prepare-training-data). + type: + description: Always `image_file`. type: string - format: binary - purpose: - description: | - The intended purpose of the uploaded documents. - - Use "fine-tune" for [Fine-tuning](/docs/api-reference/fine-tunes). This allows us to validate the format of the uploaded file. + enum: ["image_file"] + image_file: + type: object + properties: + file_id: + description: The [File](/docs/api-reference/files) ID of the image in the message content. + type: string + required: + - file_id + required: + - type + - image_file + MessageContentTextObject: + title: Text + type: object + description: The text content that is part of a message. + properties: + type: + description: Always `text`. type: string + enum: ["text"] + text: + type: object + properties: + value: + description: The data that makes up the text. + type: string + annotations: + type: array + items: + oneOf: + - $ref: "#/components/schemas/MessageContentTextAnnotationsFileCitationObject" + - $ref: "#/components/schemas/MessageContentTextAnnotationsFilePathObject" + x-oaiExpandable: true + required: + - value + - annotations required: - - file - - purpose + - type + - text - DeleteFileResponse: + MessageContentTextAnnotationsFileCitationObject: + title: File citation type: object + description: A citation within the message that points to a specific quote from a specific File associated with the assistant or the message. Generated when the assistant uses the "retrieval" tool to search files. properties: - id: + type: + description: Always `file_citation`. type: string - object: + enum: ["file_citation"] + text: + description: The text in the message content that needs to be replaced. type: string - deleted: - type: boolean - required: - - id - - object - - deleted + file_citation: + type: object + properties: + file_id: + description: The ID of the specific File the citation is from. + type: string + quote: + description: The specific quote in the file. + type: string + required: + - file_id + - quote + start_index: + type: integer + minimum: 0 + end_index: + type: integer + minimum: 0 + required: + - type + - text + - file_citation + - start_index + - end_index - CreateFineTuneRequest: + MessageContentTextAnnotationsFilePathObject: + title: File path type: object + description: A URL for the file that's generated when the assistant used the `code_interpreter` tool to generate a file. properties: - training_file: - description: | - The ID of an uploaded file that contains training data. - - See [upload file](/docs/api-reference/files/upload) for how to upload a file. - - Your dataset must be formatted as a JSONL file, where each training - example is a JSON object with the keys "prompt" and "completion". - Additionally, you must upload your file with the purpose `fine-tune`. - - See the [fine-tuning guide](/docs/guides/fine-tuning/creating-training-data) for more details. + type: + description: Always `file_path`. type: string - example: "file-ajSREls59WBbvgSzJSVWxMCB" - validation_file: - description: | - The ID of an uploaded file that contains validation data. - - If you provide this file, the data is used to generate validation - metrics periodically during fine-tuning. These metrics can be viewed in - the [fine-tuning results file](/docs/guides/fine-tuning/analyzing-your-fine-tuned-model). - Your train and validation data should be mutually exclusive. - - Your dataset must be formatted as a JSONL file, where each validation - example is a JSON object with the keys "prompt" and "completion". - Additionally, you must upload your file with the purpose `fine-tune`. - - See the [fine-tuning guide](/docs/guides/fine-tuning/creating-training-data) for more details. + enum: ["file_path"] + text: + description: The text in the message content that needs to be replaced. type: string - nullable: true - example: "file-XjSREls59WBbvgSzJSVWxMCa" - model: - description: | - The name of the base model to fine-tune. You can select one of "ada", - "babbage", "curie", "davinci", or a fine-tuned model created after 2022-04-21. - To learn more about these models, see the - [Models](https://platform.openai.com/docs/models) documentation. - default: "curie" - example: "curie" - nullable: true - oneOf: - - type: string - - type: string - enum: ["ada","babbage","curie","davinci"] - n_epochs: - description: | - The number of epochs to train the model for. An epoch refers to one - full cycle through the training dataset. - default: 4 + file_path: + type: object + properties: + file_id: + description: The ID of the file that was generated. + type: string + required: + - file_id + start_index: type: integer - nullable: true - batch_size: - description: | - The batch size to use for training. The batch size is the number of - training examples used to train a single forward and backward pass. + minimum: 0 + end_index: + type: integer + minimum: 0 + required: + - type + - text + - file_path + - start_index + - end_index - By default, the batch size will be dynamically configured to be - ~0.2% of the number of examples in the training set, capped at 256 - - in general, we've found that larger batch sizes tend to work better - for larger datasets. - default: null + RunStepObject: + type: object + title: Run steps + description: | + Represents a step in execution of a run. + properties: + id: + description: The identifier of the run step, which can be referenced in API endpoints. + type: string + object: + description: The object type, which is always `thread.run.step`. + type: string + enum: ["thread.run.step"] + created_at: + description: The Unix timestamp (in seconds) for when the run step was created. type: integer + assistant_id: + description: The ID of the [assistant](/docs/api-reference/assistants) associated with the run step. + type: string + thread_id: + description: The ID of the [thread](/docs/api-reference/threads) that was run. + type: string + run_id: + description: The ID of the [run](/docs/api-reference/runs) that this run step is a part of. + type: string + type: + description: The type of run step, which can be either `message_creation` or `tool_calls`. + type: string + enum: ["message_creation", "tool_calls"] + status: + description: The status of the run step, which can be either `in_progress`, `cancelled`, `failed`, `completed`, or `expired`. + type: string + enum: ["in_progress", "cancelled", "failed", "completed", "expired"] + step_details: + type: object + description: The details of the run step. + oneOf: + - $ref: "#/components/schemas/RunStepDetailsMessageCreationObject" + - $ref: "#/components/schemas/RunStepDetailsToolCallsObject" + x-oaiExpandable: true + last_error: + type: object + description: The last error associated with this run step. Will be `null` if there are no errors. nullable: true - learning_rate_multiplier: - description: | - The learning rate multiplier to use for training. - The fine-tuning learning rate is the original learning rate used for - pretraining multiplied by this value. - - By default, the learning rate multiplier is the 0.05, 0.1, or 0.2 - depending on final `batch_size` (larger learning rates tend to - perform better with larger batch sizes). We recommend experimenting - with values in the range 0.02 to 0.2 to see what produces the best - results. - default: null - type: number - nullable: true - prompt_loss_weight: - description: | - The weight to use for loss on the prompt tokens. This controls how - much the model tries to learn to generate the prompt (as compared - to the completion which always has a weight of 1.0), and can add - a stabilizing effect to training when completions are short. - - If prompts are extremely long (relative to completions), it may make - sense to reduce this weight so as to avoid over-prioritizing - learning the prompt. - default: 0.01 - type: number - nullable: true - compute_classification_metrics: - description: | - If set, we calculate classification-specific metrics such as accuracy - and F-1 score using the validation set at the end of every epoch. - These metrics can be viewed in the [results file](/docs/guides/fine-tuning/analyzing-your-fine-tuned-model). - - In order to compute classification metrics, you must provide a - `validation_file`. Additionally, you must - specify `classification_n_classes` for multiclass classification or - `classification_positive_class` for binary classification. - type: boolean - default: false + properties: + code: + type: string + description: One of `server_error` or `rate_limit_exceeded`. + enum: ["server_error", "rate_limit_exceeded"] + message: + type: string + description: A human-readable description of the error. + required: + - code + - message + expired_at: + description: The Unix timestamp (in seconds) for when the run step expired. A step is considered expired if the parent run is expired. + type: integer nullable: true - classification_n_classes: - description: | - The number of classes in a classification task. - - This parameter is required for multiclass classification. + cancelled_at: + description: The Unix timestamp (in seconds) for when the run step was cancelled. type: integer - default: null nullable: true - classification_positive_class: - description: | - The positive class in binary classification. - - This parameter is needed to generate precision, recall, and F1 - metrics when doing binary classification. - type: string - default: null + failed_at: + description: The Unix timestamp (in seconds) for when the run step failed. + type: integer nullable: true - classification_betas: - description: | - If this is provided, we calculate F-beta scores at the specified - beta values. The F-beta score is a generalization of F-1 score. - This is only used for binary classification. - - With a beta of 1 (i.e. the F-1 score), precision and recall are - given the same weight. A larger beta score puts more weight on - recall and less on precision. A smaller beta score puts more weight - on precision and less on recall. - type: array - items: - type: number - example: [0.6, 1, 1.5, 2] - default: null + completed_at: + description: The Unix timestamp (in seconds) for when the run step completed. + type: integer nullable: true - suffix: - description: | - A string of up to 40 characters that will be added to your fine-tuned model name. - - For example, a `suffix` of "custom-model-name" would produce a model name like `ada:ft-your-org:custom-model-name-2022-02-15-04-21-04`. - type: string - minLength: 1 - maxLength: 40 - default: null + metadata: + description: *metadata_description + type: object + x-oaiTypeLabel: map nullable: true + usage: + $ref: "#/components/schemas/RunStepCompletionUsage" required: - - training_file - - ListFineTunesResponse: - type: object - properties: - object: - type: string - data: - type: array - items: - $ref: '#/components/schemas/FineTune' - required: + - id - object - - data + - created_at + - assistant_id + - thread_id + - run_id + - type + - status + - step_details + - last_error + - expired_at + - cancelled_at + - failed_at + - completed_at + - metadata + - usage + x-oaiMeta: + name: The run step object + beta: true + example: *run_step_object_example - ListFineTuneEventsResponse: - type: object + ListRunStepsResponse: properties: object: type: string + example: "list" data: type: array items: - $ref: '#/components/schemas/FineTuneEvent' - required: - - object - - data - - CreateEmbeddingRequest: - type: object - additionalProperties: false - properties: - model: - description: *model_description - example: "text-embedding-ada-002" - oneOf: - - type: string - - type: string - enum: ["text-embedding-ada-002"] - input: - description: | - Input text to embed, encoded as a string or array of tokens. To embed multiple inputs in a single request, pass an array of strings or array of token arrays. Each input must not exceed the max input tokens for the model (8191 tokens for `text-embedding-ada-002`). [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) for counting tokens. - example: "The quick brown fox jumped over the lazy dog" - oneOf: - - type: string - default: '' - example: "This is a test." - - type: array - items: - type: string - default: '' - example: "This is a test." - - type: array - minItems: 1 - items: - type: integer - example: "[1212, 318, 257, 1332, 13]" - - type: array - minItems: 1 - items: - type: array - minItems: 1 - items: - type: integer - example: "[[1212, 318, 257, 1332, 13]]" - user: *end_user_param_configuration - required: - - model - - input - - CreateEmbeddingResponse: - type: object - properties: - object: + $ref: "#/components/schemas/RunStepObject" + first_id: type: string - model: + example: "step_abc123" + last_id: type: string - data: - type: array - items: - type: object - properties: - index: - type: integer - object: - type: string - embedding: - type: array - items: - type: number - required: - - index - - object - - embedding - usage: - type: object - properties: - prompt_tokens: - type: integer - total_tokens: - type: integer - required: - - prompt_tokens - - total_tokens - required: + example: "step_abc456" + has_more: + type: boolean + example: false + required: - object - - model - data - - usage + - first_id + - last_id + - has_more - CreateTranscriptionRequest: + RunStepDetailsMessageCreationObject: + title: Message creation type: object - additionalProperties: false + description: Details of the message creation by the run step. properties: - file: - description: | - The audio file object (not file name) to transcribe, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm. + type: + description: Always `message_creation`. type: string - x-oaiTypeLabel: file - format: binary - model: - description: | - ID of the model to use. Only `whisper-1` is currently available. - example: whisper-1 - oneOf: - - type: string - - type: string - enum: ["whisper-1"] - prompt: - description: | - An optional text to guide the model's style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should match the audio language. + enum: ["message_creation"] + message_creation: + type: object + properties: + message_id: + type: string + description: The ID of the message that was created by this run step. + required: + - message_id + required: + - type + - message_creation + + RunStepDetailsToolCallsObject: + title: Tool calls + type: object + description: Details of the tool call. + properties: + type: + description: Always `tool_calls`. type: string - response_format: + enum: ["tool_calls"] + tool_calls: + type: array description: | - The format of the transcript output, in one of these options: json, text, srt, verbose_json, or vtt. + An array of tool calls the run step was involved in. These can be associated with one of three types of tools: `code_interpreter`, `retrieval`, or `function`. + items: + type: object + oneOf: + - $ref: "#/components/schemas/RunStepDetailsToolCallsCodeObject" + - $ref: "#/components/schemas/RunStepDetailsToolCallsRetrievalObject" + - $ref: "#/components/schemas/RunStepDetailsToolCallsFunctionObject" + x-oaiExpandable: true + required: + - type + - tool_calls + + RunStepDetailsToolCallsCodeObject: + title: Code interpreter tool call + type: object + description: Details of the Code Interpreter tool call the run step was involved in. + properties: + id: type: string - default: json - temperature: - description: | - The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. - type: number - default: 0 - language: - description: | - The language of the input audio. Supplying the input language in [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) format will improve accuracy and latency. + description: The ID of the tool call. + type: type: string + description: The type of tool call. This is always going to be `code_interpreter` for this type of tool call. + enum: ["code_interpreter"] + code_interpreter: + type: object + description: The Code Interpreter tool call definition. + required: + - input + - outputs + properties: + input: + type: string + description: The input to the Code Interpreter tool call. + outputs: + type: array + description: The outputs from the Code Interpreter tool call. Code Interpreter can output one or more items, including text (`logs`) or images (`image`). Each of these are represented by a different object type. + items: + type: object + oneOf: + - $ref: "#/components/schemas/RunStepDetailsToolCallsCodeOutputLogsObject" + - $ref: "#/components/schemas/RunStepDetailsToolCallsCodeOutputImageObject" + x-oaiExpandable: true required: - - file - - model + - id + - type + - code_interpreter - # Note: This does not currently support the non-default response format types. - CreateTranscriptionResponse: + RunStepDetailsToolCallsCodeOutputLogsObject: + title: Code interpreter log output type: object + description: Text output from the Code Interpreter tool call as part of a run step. properties: - text: + type: + description: Always `logs`. type: string - required: - - text + enum: ["logs"] + logs: + type: string + description: The text output from the Code Interpreter tool call. + required: + - type + - logs - CreateTranslationRequest: + RunStepDetailsToolCallsCodeOutputImageObject: + title: Code interpreter image output type: object - additionalProperties: false properties: - file: - description: | - The audio file object (not file name) translate, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm. + type: + description: Always `image`. type: string - x-oaiTypeLabel: file - format: binary - model: - description: | - ID of the model to use. Only `whisper-1` is currently available. - example: whisper-1 - oneOf: - - type: string - - type: string - enum: ["whisper-1"] - prompt: - description: | - An optional text to guide the model's style or continue a previous audio segment. The [prompt](/docs/guides/speech-to-text/prompting) should be in English. + enum: ["image"] + image: + type: object + properties: + file_id: + description: The [file](/docs/api-reference/files) ID of the image. + type: string + required: + - file_id + required: + - type + - image + + RunStepDetailsToolCallsRetrievalObject: + title: Retrieval tool call + type: object + properties: + id: type: string - response_format: - description: | - The format of the transcript output, in one of these options: json, text, srt, verbose_json, or vtt. + description: The ID of the tool call object. + type: type: string - default: json - temperature: - description: | - The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically increase the temperature until certain thresholds are hit. - type: number - default: 0 + description: The type of tool call. This is always going to be `retrieval` for this type of tool call. + enum: ["retrieval"] + retrieval: + type: object + description: For now, this is always going to be an empty object. + x-oaiTypeLabel: map required: - - file - - model + - id + - type + - retrieval - # Note: This does not currently support the non-default response format types. - CreateTranslationResponse: + RunStepDetailsToolCallsFunctionObject: type: object + title: Function tool call properties: - text: + id: type: string - required: - - text + description: The ID of the tool call object. + type: + type: string + description: The type of tool call. This is always going to be `function` for this type of tool call. + enum: ["function"] + function: + type: object + description: The definition of the function that was called. + properties: + name: + type: string + description: The name of the function. + arguments: + type: string + description: The arguments passed to the function. + output: + type: string + description: The output of the function. This will be `null` if the outputs have not been [submitted](/docs/api-reference/runs/submitToolOutputs) yet. + nullable: true + required: + - name + - arguments + - output + required: + - id + - type + - function - Model: - title: Model + AssistantFileObject: + type: object + title: Assistant files + description: A list of [Files](/docs/api-reference/files) attached to an `assistant`. properties: id: + description: The identifier, which can be referenced in API endpoints. type: string object: + description: The object type, which is always `assistant.file`. type: string - created: + enum: [assistant.file] + created_at: + description: The Unix timestamp (in seconds) for when the assistant file was created. type: integer - owned_by: + assistant_id: + description: The assistant ID that the file is attached to. type: string - required: + required: - id - object - - created - - owned_by + - created_at + - assistant_id + x-oaiMeta: + name: The assistant file object + beta: true + example: | + { + "id": "file-abc123", + "object": "assistant.file", + "created_at": 1699055364, + "assistant_id": "asst_abc123" + } - OpenAIFile: - title: OpenAIFile + CreateAssistantFileRequest: + type: object + additionalProperties: false + properties: + file_id: + description: A [File](/docs/api-reference/files) ID (with `purpose="assistants"`) that the assistant should use. Useful for tools like `retrieval` and `code_interpreter` that can access files. + type: string + required: + - file_id + + DeleteAssistantFileResponse: + type: object + description: Deletes the association between the assistant and the file, but does not delete the [File](/docs/api-reference/files) object itself. properties: id: type: string + deleted: + type: boolean object: type: string - bytes: - type: integer - created_at: - type: integer - filename: + enum: [assistant.file.deleted] + required: + - id + - object + - deleted + ListAssistantFilesResponse: + properties: + object: type: string - purpose: + example: "list" + data: + type: array + items: + $ref: "#/components/schemas/AssistantFileObject" + first_id: type: string - status: + example: "file-abc123" + last_id: type: string - status_details: - type: object - nullable: true - required: - - id + example: "file-abc456" + has_more: + type: boolean + example: false + required: - object - - bytes - - created_at - - filename - - purpose + - data + - items + - first_id + - last_id + - has_more - FineTune: - title: FineTune + MessageFileObject: + type: object + title: Message files + description: A list of files attached to a `message`. properties: id: + description: The identifier, which can be referenced in API endpoints. type: string object: + description: The object type, which is always `thread.message.file`. type: string + enum: ["thread.message.file"] created_at: + description: The Unix timestamp (in seconds) for when the message file was created. type: integer - updated_at: - type: integer - model: - type: string - fine_tuned_model: + message_id: + description: The ID of the [message](/docs/api-reference/messages) that the [File](/docs/api-reference/files) is attached to. type: string - nullable: true - organization_id: - type: string - status: - type: string - hyperparams: - type: object - training_files: - type: array - items: - $ref: '#/components/schemas/OpenAIFile' - validation_files: - type: array - items: - $ref: '#/components/schemas/OpenAIFile' - result_files: - type: array - items: - $ref: '#/components/schemas/OpenAIFile' - events: - type: array - items: - $ref: '#/components/schemas/FineTuneEvent' - required: + required: - id - object - created_at - - updated_at - - model - - fine_tuned_model - - organization_id - - status - - hyperparams - - training_files - - validation_files - - result_files + - message_id + x-oaiMeta: + name: The message file object + beta: true + example: | + { + "id": "file-abc123", + "object": "thread.message.file", + "created_at": 1698107661, + "message_id": "message_QLoItBbqwyAJEzlTy4y9kOMM", + "file_id": "file-abc123" + } - FineTuneEvent: - title: FineTuneEvent + ListMessageFilesResponse: properties: object: type: string - created_at: - type: integer - level: + example: "list" + data: + type: array + items: + $ref: "#/components/schemas/MessageFileObject" + first_id: type: string - message: + example: "file-abc123" + last_id: type: string - required: + example: "file-abc456" + has_more: + type: boolean + example: false + required: - object - - created_at - - level - - message + - data + - items + - first_id + - last_id + - has_more +security: + - ApiKeyAuth: [] x-oaiMeta: groups: - - id: models - title: Models + # > General Notes + # The `groups` section is used to generate the API reference pages and navigation, in the same + # order listed below. Additionally, each `group` can have a list of `sections`, each of which + # will become a navigation subroute and subsection under the group. Each section has: + # - `type`: Currently, either an `endpoint` or `object`, depending on how the section needs to + # be rendered + # - `key`: The reference key that can be used to lookup the section definition + # - `path`: The path (url) of the section, which is used to generate the navigation link. + # + # > The `object` sections maps to a schema component and the following fields are read for rendering + # - `x-oaiMeta.name`: The name of the object, which will become the section title + # - `x-oaiMeta.example`: The example object, which will be used to generate the example sample (always JSON) + # - `description`: The description of the object, which will be used to generate the section description + # + # > The `endpoint` section maps to an operation path and the following fields are read for rendering: + # - `x-oaiMeta.name`: The name of the endpoint, which will become the section title + # - `x-oaiMeta.examples`: The endpoint examples, which can be an object (meaning a single variation, most + # endpoints, or an array of objects, meaning multiple variations, e.g. the + # chat completion and completion endpoints, with streamed and non-streamed examples. + # - `x-oaiMeta.returns`: text describing what the endpoint returns. + # - `summary`: The summary of the endpoint, which will be used to generate the section description + - id: audio + title: Audio description: | - List and describe the various models available in the API. You can refer to the [Models](/docs/models) documentation to understand what models are available and the differences between them. + Learn how to turn audio into text or text into audio. + + Related guide: [Speech to text](/docs/guides/speech-to-text) + sections: + - type: endpoint + key: createSpeech + path: createSpeech + - type: endpoint + key: createTranscription + path: createTranscription + - type: endpoint + key: createTranslation + path: createTranslation - id: chat title: Chat description: | Given a list of messages comprising a conversation, the model will return a response. - - id: completions - title: Completions - description: | - Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position. - - id: edits - title: Edits - description: | - Given a prompt and an instruction, the model will return an edited version of the prompt. - - id: images - title: Images - description: | - Given a prompt and/or an input image, the model will generate a new image. - Related guide: [Image generation](/docs/guides/images) + Related guide: [Chat Completions](/docs/guides/text-generation) + sections: + - type: endpoint + key: createChatCompletion + path: create + - type: object + key: CreateChatCompletionResponse + path: object + - type: object + key: CreateChatCompletionStreamResponse + path: streaming - id: embeddings title: Embeddings description: | Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms. Related guide: [Embeddings](/docs/guides/embeddings) - - id: audio - title: Audio + sections: + - type: endpoint + key: createEmbedding + path: create + - type: object + key: Embedding + path: object + - id: fine-tuning + title: Fine-tuning description: | - Learn how to turn audio into text. + Manage fine-tuning jobs to tailor a model to your specific training data. - Related guide: [Speech to text](/docs/guides/speech-to-text) + Related guide: [Fine-tune models](/docs/guides/fine-tuning) + sections: + - type: endpoint + key: createFineTuningJob + path: create + - type: endpoint + key: listPaginatedFineTuningJobs + path: list + - type: endpoint + key: listFineTuningEvents + path: list-events + - type: endpoint + key: retrieveFineTuningJob + path: retrieve + - type: endpoint + key: cancelFineTuningJob + path: cancel + - type: object + key: FineTuningJob + path: object + - type: object + key: FineTuningJobEvent + path: event-object - id: files title: Files description: | - Files are used to upload documents that can be used with features like [Fine-tuning](/docs/api-reference/fine-tunes). - - id: fine-tunes - title: Fine-tunes + Files are used to upload documents that can be used with features like [Assistants](/docs/api-reference/assistants) and [Fine-tuning](/docs/api-reference/fine-tuning). + sections: + - type: endpoint + key: createFile + path: create + - type: endpoint + key: listFiles + path: list + - type: endpoint + key: retrieveFile + path: retrieve + - type: endpoint + key: deleteFile + path: delete + - type: endpoint + key: downloadFile + path: retrieve-contents + - type: object + key: OpenAIFile + path: object + - id: images + title: Images description: | - Manage fine-tuning jobs to tailor a model to your specific training data. + Given a prompt and/or an input image, the model will generate a new image. - Related guide: [Fine-tune models](/docs/guides/fine-tuning) + Related guide: [Image generation](/docs/guides/images) + sections: + - type: endpoint + key: createImage + path: create + - type: endpoint + key: createImageEdit + path: createEdit + - type: endpoint + key: createImageVariation + path: createVariation + - type: object + key: Image + path: object + - id: models + title: Models + description: | + List and describe the various models available in the API. You can refer to the [Models](/docs/models) documentation to understand what models are available and the differences between them. + sections: + - type: endpoint + key: listModels + path: list + - type: endpoint + key: retrieveModel + path: retrieve + - type: endpoint + key: deleteModel + path: delete + - type: object + key: Model + path: object - id: moderations title: Moderations description: | Given a input text, outputs if the model classifies it as violating OpenAI's content policy. - Related guide: [Moderations](/docs/guides/moderation) \ No newline at end of file + Related guide: [Moderations](/docs/guides/moderation) + sections: + - type: endpoint + key: createModeration + path: create + - type: object + key: CreateModerationResponse + path: object + - id: assistants + title: Assistants + beta: true + description: | + Build assistants that can call models and use tools to perform tasks. + + [Get started with the Assistants API](/docs/assistants) + sections: + - type: endpoint + key: createAssistant + path: createAssistant + - type: endpoint + key: createAssistantFile + path: createAssistantFile + - type: endpoint + key: listAssistants + path: listAssistants + - type: endpoint + key: listAssistantFiles + path: listAssistantFiles + - type: endpoint + key: getAssistant + path: getAssistant + - type: endpoint + key: getAssistantFile + path: getAssistantFile + - type: endpoint + key: modifyAssistant + path: modifyAssistant + - type: endpoint + key: deleteAssistant + path: deleteAssistant + - type: endpoint + key: deleteAssistantFile + path: deleteAssistantFile + - type: object + key: AssistantObject + path: object + - type: object + key: AssistantFileObject + path: file-object + - id: threads + title: Threads + beta: true + description: | + Create threads that assistants can interact with. + + Related guide: [Assistants](/docs/assistants/overview) + sections: + - type: endpoint + key: createThread + path: createThread + - type: endpoint + key: getThread + path: getThread + - type: endpoint + key: modifyThread + path: modifyThread + - type: endpoint + key: deleteThread + path: deleteThread + - type: object + key: ThreadObject + path: object + - id: messages + title: Messages + beta: true + description: | + Create messages within threads + + Related guide: [Assistants](/docs/assistants/overview) + sections: + - type: endpoint + key: createMessage + path: createMessage + - type: endpoint + key: listMessages + path: listMessages + - type: endpoint + key: listMessageFiles + path: listMessageFiles + - type: endpoint + key: getMessage + path: getMessage + - type: endpoint + key: getMessageFile + path: getMessageFile + - type: endpoint + key: modifyMessage + path: modifyMessage + - type: object + key: MessageObject + path: object + - type: object + key: MessageFileObject + path: file-object + - id: runs + title: Runs + beta: true + description: | + Represents an execution run on a thread. + + Related guide: [Assistants](/docs/assistants/overview) + sections: + - type: endpoint + key: createRun + path: createRun + - type: endpoint + key: createThreadAndRun + path: createThreadAndRun + - type: endpoint + key: listRuns + path: listRuns + - type: endpoint + key: listRunSteps + path: listRunSteps + - type: endpoint + key: getRun + path: getRun + - type: endpoint + key: getRunStep + path: getRunStep + - type: endpoint + key: modifyRun + path: modifyRun + - type: endpoint + key: submitToolOuputsToRun + path: submitToolOutputs + - type: endpoint + key: cancelRun + path: cancelRun + - type: object + key: RunObject + path: object + - type: object + key: RunStepObject + path: step-object + - id: completions + title: Completions + legacy: true + description: | + Given a prompt, the model will return one or more predicted completions along with the probabilities of alternative tokens at each position. Most developer should use our [Chat Completions API](/docs/guides/text-generation/text-generation-models) to leverage our best and newest models. Most models that support the legacy Completions endpoint [will be shut off on January 4th, 2024](/docs/deprecations/2023-07-06-gpt-and-embeddings). + sections: + - type: endpoint + key: createCompletion + path: create + - type: object + key: CreateCompletionResponse + path: object \ No newline at end of file diff --git a/openapi/openai.chat/types.bal b/openapi/openai.chat/types.bal index 9e9a7bcf5..01d2bc286 100644 --- a/openapi/openai.chat/types.bal +++ b/openapi/openai.chat/types.bal @@ -1,21 +1,7 @@ -// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/http; +// AUTO-GENERATED FILE. DO NOT MODIFY. +// This file is auto-generated by the Ballerina OpenAPI tool. import ballerina/constraint; +import ballerina/http; # Provides a set of configurations for controlling the behaviours when communicating with a remote HTTP endpoint. @display {label: "Connection Config"} @@ -75,135 +61,342 @@ public type ProxyConfig record {| string password = ""; |}; -public type ChatCompletionResponseMessage record { - # The role of the author of this message. - string role; - # The contents of the message. - string? content?; - # The name and arguments of a function that should be called, as generated by the model. - ChatCompletionRequestMessage_function_call function_call?; +# Specifies a tool the model should use. Use to force the model to call a specific function. +public type ChatCompletionNamedToolChoice record { + # The type of the tool. Currently, only `function` is supported. + "function" 'type; + # The function that should be called. + ChatCompletionNamedToolChoice_function 'function; +}; + +# Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. +# +# # Deprecated +@deprecated +public type ChatCompletionRequestAssistantMessage_function_call record { + # 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. + string arguments; + # The name of the function to call. + string name; +}; + +public type ChatCompletionTokenLogprob record { + # The token. + string token; + # The log probability of this token. + decimal logprob; + # 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. + int[]? bytes; + # 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. + ChatCompletionTokenLogprob_top_logprobs[] top_logprobs; }; -public type CreateChatCompletionStreamResponse_choices record { - int index?; - ChatCompletionStreamResponseDelta delta?; - string finish_reason?; +public type CreateChatCompletionResponse_choices record { + # 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. + "stop"|"length"|"tool_calls"|"content_filter"|"function_call" finish_reason; + # The index of the choice in the list of choices. + int index; + # A chat completion message generated by the model. + ChatCompletionResponseMessage message; + # Log probability information for the choice. + CreateChatCompletionResponse_logprobs? logprobs?; +}; + +public type ChatCompletionRequestMessage ChatCompletionRequestSystemMessage|ChatCompletionRequestUserMessage|ChatCompletionRequestAssistantMessage|ChatCompletionRequestToolMessage|ChatCompletionRequestFunctionMessage; + +public type FunctionObject record { + # A description of what the function does, used by the model to choose when and how to call the function. + string description?; + # 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. + string name; + # The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/text-generation/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. + FunctionParameters parameters?; +}; + +public type ChatCompletionRequestMessageContentPart ChatCompletionRequestMessageContentPartText|ChatCompletionRequestMessageContentPartImage; + +# The function that the model called. +public type ChatCompletionMessageToolCall_function record { + # The name of the function to call. + 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. + string arguments; }; public type CreateChatCompletionRequest record { - # 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. - string|string model; - # 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). + # A list of messages comprising the conversation so far. [Example Python code](https://cookbook.openai.com/examples/how_to_format_inputs_to_chatgpt_models). @constraint:Array {minLength: 1} ChatCompletionRequestMessage[] messages; - # A list of functions the model may generate JSON inputs for. - @constraint:Array {minLength: 1} - ChatCompletionFunctions[] 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. - string|record { - # The name of the function to call. - string name; - } function_call?; + # 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. + string|"gpt-4-0125-preview"|"gpt-4-turbo-preview"|"gpt-4-1106-preview"|"gpt-4-vision-preview"|"gpt-4"|"gpt-4-0314"|"gpt-4-0613"|"gpt-4-32k"|"gpt-4-32k-0314"|"gpt-4-32k-0613"|"gpt-3.5-turbo"|"gpt-3.5-turbo-16k"|"gpt-3.5-turbo-0301"|"gpt-3.5-turbo-0613"|"gpt-3.5-turbo-1106"|"gpt-3.5-turbo-16k-0613" model; + # 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. + # + # [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) + decimal? frequency_penalty = 0; + # 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. + record {|int...;|}? logit_bias?; + # 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`. This option is currently not available on the `gpt-4-vision-preview` model. + boolean? logprobs?; + # An integer between 0 and 5 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. + int? top_logprobs?; + # 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. + int? max_tokens?; + # 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. + int? n = 1; + # 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. + # + # [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) + decimal? presence_penalty = 0; + # An object specifying the format that the model must output. Compatible with [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and `gpt-3.5-turbo-1106`. + # + # 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. + CreateChatCompletionRequest_response_format response_format?; + # 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. + int? seed?; + # Up to 4 sequences where the API will stop generating further tokens. + string|string[]? stop = "null"; + # 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). + boolean? 'stream = false; # 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. decimal? temperature = 1; # 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. decimal? top_p = 1; - # How many chat completion choices to generate for each input message. - int? n = 1; - # 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://github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb). - boolean? 'stream = false; - # Up to 4 sequences where the API will stop generating further tokens. - string|string[]? stop?; - # The maximum number of [tokens](/tokenizer) to generate 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://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb) for counting tokens. - int max_tokens?; - # 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. - # - # [See more information about frequency and presence penalties.](/docs/api-reference/parameter-details) - decimal? presence_penalty = 0; - # 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. - # - # [See more information about frequency and presence penalties.](/docs/api-reference/parameter-details) - decimal? frequency_penalty = 0; - # 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. - record {}? logit_bias?; + # 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. + ChatCompletionTool[] tools?; + # 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 `{"type": "function", "function": {"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. + ChatCompletionToolChoiceOption tool_choice?; # A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids). string user?; + # 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. + "none"|"auto"|ChatCompletionFunctionCallOption function_call?; + # Deprecated in favor of `tools`. + # + # A list of functions the model may generate JSON inputs for. + @constraint:Array {maxLength: 128, minLength: 1} + ChatCompletionFunctions[] functions?; }; -public type ChatCompletionStreamResponseDelta record { - # The role of the author of this message. - string role?; - # The contents of the chunk message. +# Log probability information for the choice. +public type CreateChatCompletionResponse_logprobs record { + # A list of message content tokens with log probability information. + ChatCompletionTokenLogprob[]? content; +}; + +public type ChatCompletionRequestAssistantMessage record { + # The contents of the assistant message. Required unless `tool_calls` or `function_call` is specified. string? content?; - # The name and arguments of a function that should be called, as generated by the model. - ChatCompletionRequestMessage_function_call function_call?; + # The role of the messages author, in this case `assistant`. + "assistant" role; + # An optional name for the participant. Provides the model information to differentiate between participants of the same role. + string name?; + # The tool calls generated by the model, such as function calls. + ChatCompletionMessageToolCalls tool_calls?; + # Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. + ChatCompletionRequestAssistantMessage_function_call function_call?; }; +# 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 `{"type": "function", "function": {"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. +public type ChatCompletionToolChoiceOption "none"|"auto"|ChatCompletionNamedToolChoice; + +# Usage statistics for the completion request. +public type CompletionUsage record { + # Number of tokens in the generated completion. + int completion_tokens; + # Number of tokens in the prompt. + int prompt_tokens; + # Total number of tokens used in the request (prompt + completion). + int total_tokens; +}; + +# The function that should be called. +public type ChatCompletionNamedToolChoice_function record { + # The name of the function to call. + string name; +}; + +public type ChatCompletionRequestUserMessage record { + # The contents of the user message. + string|ChatCompletionRequestMessageContentPart[] content; + # The role of the messages author, in this case `user`. + "user" role; + # An optional name for the participant. Provides the model information to differentiate between participants of the same role. + string name?; +}; + +# The tool calls generated by the model, such as function calls. +public type ChatCompletionMessageToolCalls ChatCompletionMessageToolCall[]; + +# Represents a chat completion response returned by model, based on the provided input. public type CreateChatCompletionResponse record { + # A unique identifier for the chat completion. string id; - string 'object; + # A list of chat completion choices. Can be more than one if `n` is greater than 1. + CreateChatCompletionResponse_choices[] choices; + # The Unix timestamp (in seconds) of when the chat completion was created. int created; + # The model used for the chat completion. string model; - CreateChatCompletionResponse_choices[] choices; - CreateChatCompletionResponse_usage usage?; + # 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. + string system_fingerprint?; + # The object type, which is always `chat.completion`. + "chat.completion" 'object; + # Usage statistics for the completion request. + CompletionUsage usage?; }; -public type CreateChatCompletionStreamResponse record { - string id; - string 'object; - int created; - string model; - CreateChatCompletionStreamResponse_choices[] choices; +@deprecated +public type ChatCompletionRequestFunctionMessage record { + # The role of the messages author, in this case `function`. + "function" role; + # The contents of the function message. + string? content; + # The name of the function to call. + string name; }; -public type CreateChatCompletionResponse_usage record { - int prompt_tokens; - int completion_tokens; - int total_tokens; +# Specifying a particular function via `{"name": "my_function"}` forces the model to call that function. +public type ChatCompletionFunctionCallOption record { + # The name of the function to call. + string name; }; -public type CreateChatCompletionResponse_choices record { - int index?; - ChatCompletionResponseMessage message?; - string finish_reason?; +public type ChatCompletionRequestToolMessage record { + # The role of the messages author, in this case `tool`. + "tool" role; + # The contents of the tool message. + string content; + # Tool call that this message is responding to. + string tool_call_id; }; +@deprecated public type ChatCompletionFunctions record { + # A description of what the function does, used by the model to choose when and how to call the function. + string description?; # 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. string name; - # The description of what the function does. - 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. - ChatCompletionFunctionParameters parameters?; + # The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/text-generation/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. + FunctionParameters parameters?; }; -public type ChatCompletionRequestMessage record { - # The role of the messages author. One of `system`, `user`, `assistant`, or `function`. - string role; - # The contents of the message. `content` is required for all messages except assistant messages with function calls. - string? content; - # 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. - string name?; - # The name and arguments of a function that should be called, as generated by the model. - ChatCompletionRequestMessage_function_call function_call?; +public type ChatCompletionTool record { + # The type of the tool. Currently, only `function` is supported. + "function" 'type; + FunctionObject 'function; }; -# The name and arguments of a function that should be called, as generated by the model. -public type ChatCompletionRequestMessage_function_call record { - # The name of the function to call. +public type ChatCompletionRequestSystemMessage record { + # The contents of the system message. + string content; + # The role of the messages author, in this case `system`. + "system" role; + # An optional name for the participant. Provides the model information to differentiate between participants of the same role. 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. - string arguments?; }; -# 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. -public type ChatCompletionFunctionParameters record { +public type ChatCompletionMessageToolCall record { + # The ID of the tool call. + string id; + # The type of the tool. Currently, only `function` is supported. + "function" 'type; + # The function that the model called. + ChatCompletionMessageToolCall_function 'function; +}; + +public type ChatCompletionRequestMessageContentPartImage_image_url record { + # Either a URL of the image or the base64 encoded image data. + string url; + # Specifies the detail level of the image. Learn more in the [Vision guide](/docs/guides/vision/low-or-high-fidelity-image-understanding). + "auto"|"low"|"high" detail = "auto"; +}; + +# An object specifying the format that the model must output. Compatible with [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and `gpt-3.5-turbo-1106`. +# +# 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. +public type CreateChatCompletionRequest_response_format record { + # Must be one of `text` or `json_object`. + "text"|"json_object" 'type?; +}; + +# A chat completion message generated by the model. +public type ChatCompletionResponseMessage record { + # The contents of the message. + string? content; + # The tool calls generated by the model, such as function calls. + ChatCompletionMessageToolCalls tool_calls?; + # The role of the author of this message. + "assistant" role; + # Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. + ChatCompletionRequestAssistantMessage_function_call function_call?; +}; + +public type ChatCompletionTokenLogprob_top_logprobs record { + # The token. + string token; + # The log probability of this token. + decimal logprob; + # 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. + int[]? bytes; +}; + +# The role of the author of a message +public type ChatCompletionRole "system"|"user"|"assistant"|"tool"|"function"; + +public type ChatCompletionRequestMessageContentPartImage record { + # The type of the content part. + "image_url" 'type; + ChatCompletionRequestMessageContentPartImage_image_url image_url; +}; + +public type ChatCompletionRequestMessageContentPartText record { + # The type of the content part. + "text" 'type; + # The text content. + string text; +}; + +# The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/text-generation/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 type FunctionParameters record { }; diff --git a/openapi/openai.chat/utils.bal b/openapi/openai.chat/utils.bal index dee181bcb..49c38c165 100644 --- a/openapi/openai.chat/utils.bal +++ b/openapi/openai.chat/utils.bal @@ -1,19 +1,5 @@ -// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. -// -// WSO2 Inc. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - +// AUTO-GENERATED FILE. DO NOT MODIFY. +// This file is auto-generated by the Ballerina OpenAPI tool. import ballerina/url; # Get Encoded URI for a given value. From f77299abfe966fcd333c0f15d3346e2adec32306 Mon Sep 17 00:00:00 2001 From: "Nadheesh Jihan, nadheesh@wso2.com" Date: Tue, 30 Jan 2024 17:14:34 +0530 Subject: [PATCH 2/4] Update azure openai chat connector --- openapi/azure.openai.chat/Ballerina.toml | 4 +- openapi/azure.openai.chat/Module.md | 116 +- openapi/azure.openai.chat/Package.md | 2 +- openapi/azure.openai.chat/client.bal | 9 +- openapi/azure.openai.chat/openapi.yaml | 769 ++++++++++--- .../azure.openai.chat/original-openapi.yaml | 1019 +++++++++++++++-- openapi/azure.openai.chat/types.bal | 447 ++++++-- openapi/azure.openai.chat/utils.bal | 1 - 8 files changed, 2000 insertions(+), 367 deletions(-) diff --git a/openapi/azure.openai.chat/Ballerina.toml b/openapi/azure.openai.chat/Ballerina.toml index dd7048a74..05adbc97c 100644 --- a/openapi/azure.openai.chat/Ballerina.toml +++ b/openapi/azure.openai.chat/Ballerina.toml @@ -4,9 +4,9 @@ keywords = ["AI/Chat", "Azure OpenAI", "Cost/Paid", "GPT-3.5", "ChatGPT", "Vendo org = "ballerinax" name = "azure.openai.chat" icon = "icon.png" -distribution = "2201.4.1" +distribution = "2201.8.4" repository = "https://github.com/ballerina-platform/openapi-connectors/tree/main/openapi/azure.openai.chat" -version = "2.0.1" +version = "3.0.0" authors = ["Ballerina"] [build-options] observabilityIncluded = true diff --git a/openapi/azure.openai.chat/Module.md b/openapi/azure.openai.chat/Module.md index 53380115d..568a65700 100644 --- a/openapi/azure.openai.chat/Module.md +++ b/openapi/azure.openai.chat/Module.md @@ -1,7 +1,7 @@ ## Overview This is a generated connector from [Azure OpenAI Chat Completions API](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#chat-completions/) OpenAPI specification. -The Azure Azure OpenAI Service REST API Chat Completions Endpoint will create completions for chat messages with the ChatGPT (preview) and GPT-4 (preview) models. +The Azure Azure OpenAI Service REST API Chat Completions Endpoint will create completions for chat messages with the GPT3.5 (preview), GPT-4 (preview) models and GPT-4 Vision models. ## Prerequisites - Create an [Azure](https://azure.microsoft.com/en-us/features/azure-portal/) account @@ -52,7 +52,7 @@ Create and initialize a `chat:Client` with the obtained `apiKey` and a `serviceU messages: [{role: "user", content: "What is Ballerina?"}] }; - chat:CreateChatCompletionResponse chatResult = check chatClient->/deployments/["chat"]/chat/completions.post("2023-08-01-preview", chatBody); + chat:CreateChatCompletionResponse chatResult = check chatClient->/deployments/["chat"]/chat/completions.post("2023-12-01-preview", chatBody); io:println(chatResult); } @@ -68,44 +68,104 @@ Create and initialize a `chat:Client` with the obtained `apiKey` and a `serviceU serviceUrl = serviceUrl ); - chat:ChatCompletionRequestMessage[] messages = [{role: "user", content: "What is the weather in Seattle?"}]; - - chat:ChatCompletionFunctions[] functions = [ + chat:ChatCompletionRequestMessage[] messages = [{role: "user", "content": "What is the weather in Seattle?"}]; + chat:ChatCompletionTool[] tools = [ { - name: "get_current_weather", - description: "Get the current weather in a given location", - parameters: { - "type": "object", - "properties": { - "location": { - "type": "string", - "description": "The city or town to get the weather for" + 'type: "function", + 'function: { + name: "get_current_weather", + description: "Get the current weather in a given location", + parameters: { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city or town to get the weather for" + }, + "unit": { + "type": "string", + "enum": ["celsius", "fahrenheit"] + } }, - "unit": { - "type": "string", - "enum": ["celsius", "fahrenheit"] - } - }, - "required": ["location"] + "required": ["location"] + } } } ]; - chat:CreateChatCompletionRequest chatBody = {messages, functions}; + chat:CreateChatCompletionRequest chatBody = {messages, tools}; - chat:CreateChatCompletionResponse chatResult = check chatClient->/deployments/["chat"]/chat/completions.post("2023-08-01-preview", chatBody); + chat:CreateChatCompletionResponse chatResult = check chatClient->/deployments/[deployementId]/chat/completions.post("2023-12-01-preview", chatBody); io:println(chatResult); - chat:ChatCompletionRequestMessage_function_call? functionCall = chatResult.choices[0].message?.function_call; + record {|chat:ChatCompletionResponseMessage message?; chat:ContentFilterChoiceResults content_filter_results?; int index?; string finish_reason?; anydata...;|}[] choices = check chatResult.choices.ensureType(); + + // continue the chat + chat:ChatCompletionRequestMessage message = check choices[0].message.cloneWithType(); + messages.push(message); + + // check if there are any tool calls + chat:ChatCompletionMessageToolCall[]? toolCalls = choices[0].message?.tool_calls; + if toolCalls is chat:ChatCompletionMessageToolCall[] { + foreach chat:ChatCompletionMessageToolCall toolCall in toolCalls { + string functionName = toolCall.'function.name; + string functionArguments = toolCall.'function.arguments; + // invoke the function + anydata functionResponse = ""; + messages.push( + { + role: "tool", + "tool_call_id": toolCall.id, + "name": functionName, + "content": functionResponse + }); + } + } - if functionCall is chat:ChatCompletionRequestMessage_function_call { - messages.push({role: "assistant", content: (), function_call: functionCall}); - - // Invoke the function [functionCall.name] with the arguments [functionCall.arguments] and get the output [functionOutput] + // do the second chat request + chatResult = check chatClient->/deployments/["chatgpt"]/chat/completions.post("2023-12-01-preview", {messages}); + io:println(chatResult); + } + ``` - messages.push({role: "function", name: functionCall.name, content: functionOutput.toString()}); - } + Following a sample to use OpenAI vision capabilities with chat model + ```ballerina + public function main() returns error? { + final chat:Client chatClient = check new ( + config = {auth: {apiKey: apiKey}}, + serviceUrl = serviceUrl + ); + + chat:CreateChatCompletionResponse response = check chatClient->/deployments/[deployementId]/chat/completions.post("2023-12-01-preview", + { + messages: [ + { + "role": "system", + "content": "You are a helpful assistant." + }, + { + "role": "user", + "content": [ + { + "type": "text", + "text": "Describe the image." + }, + { + "type": "image_url", + "image_url": { + "url": "" + } + } + ] + + } + ] + } + ); + + record {|chat:ChatCompletionResponseMessage message?; chat:ContentFilterChoiceResults content_filter_results?; int index?; string finish_reason?; anydata...;|}[] choices = check response.choices.ensureType(); + io:println(choices[0].message?.content); } ``` diff --git a/openapi/azure.openai.chat/Package.md b/openapi/azure.openai.chat/Package.md index 686b1b7f0..41b137c22 100644 --- a/openapi/azure.openai.chat/Package.md +++ b/openapi/azure.openai.chat/Package.md @@ -5,7 +5,7 @@ Connects to [Azure OpenAI Chat Completions API](https://learn.microsoft.com/en-u The `azure.openai.chat` is a [Ballerina](https://ballerina.io/) connector for connecting to the Azure OpenAI Service REST API Chat Completions and Chat Completions extensions Endpoints. #### Compatibility -Azure OpenAI Service REST API: v2023-08-01-preview +Azure OpenAI Service REST API: v2023-12-01-preview ## Report issues To report bugs, request new features, start new discussions, view project boards, etc., go to the [Ballerina Extended Library repository](https://github.com/ballerina-platform/ballerina-extended-library). diff --git a/openapi/azure.openai.chat/client.bal b/openapi/azure.openai.chat/client.bal index 96178567d..943900a38 100644 --- a/openapi/azure.openai.chat/client.bal +++ b/openapi/azure.openai.chat/client.bal @@ -1,17 +1,12 @@ // AUTO-GENERATED FILE. DO NOT MODIFY. // This file is auto-generated by the Ballerina OpenAPI tool. - import ballerina/http; -# This is a generated connector from [Azure OpenAI Chat Completions API v2023-08-01-preview](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#chat-completions/) OpenAPI specification. -# The Azure Azure OpenAI Service REST API Chat Completions Endpoint will create completions for chat messages with the ChatGPT (preview) and GPT-4 (preview) models. -@display {label: "Azure OpenAI Chat", iconPath: "icon.png"} +# Azure OpenAI APIs for completions and search public isolated client class Client { final http:Client clientEp; final readonly & ApiKeysConfig? apiKeyConfig; # Gets invoked to initialize the `connector`. - # The connector initialization requires setting the API credentials. - # Create an [Azure](https://azure.microsoft.com/en-us/features/azure-portal/) account, an [Azure OpenAI resource with a model deployed](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource) and refer [this guide](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#authentication) to learn how to generate and use tokens # # + config - The configurations to be used when initializing the `connector` # + serviceUrl - URL of the target service @@ -52,7 +47,6 @@ public isolated client class Client { # Creates a completion for the chat message # # + return - OK - @display {label: "Create Chat Completion"} resource isolated function post deployments/[string deploymentId]/chat/completions(string apiVersion, CreateChatCompletionRequest payload) returns CreateChatCompletionResponse|error { string resourcePath = string `/deployments/${getEncodedUri(deploymentId)}/chat/completions`; map headerValues = {}; @@ -71,7 +65,6 @@ public isolated client class Client { # Using extensions to creates a completion for the chat messages. # # + return - OK - @display {label: "Create Extensions Chat Completion"} resource isolated function post deployments/[string deploymentId]/extensions/chat/completions(string apiVersion, ExtensionsChatCompletionsRequest payload) returns ExtensionsChatCompletionsResponse|error { string resourcePath = string `/deployments/${getEncodedUri(deploymentId)}/extensions/chat/completions`; map headerValues = {}; diff --git a/openapi/azure.openai.chat/openapi.yaml b/openapi/azure.openai.chat/openapi.yaml index b34be8100..701fae0e4 100644 --- a/openapi/azure.openai.chat/openapi.yaml +++ b/openapi/azure.openai.chat/openapi.yaml @@ -1,18 +1,8 @@ openapi: 3.0.0 info: - x-ballerina-display: - label: Azure OpenAI Chat - iconPath: "icon.png" title: Azure OpenAI Service API - description: > - This is a generated connector from [Azure OpenAI Chat Completions API v2023-08-01-preview](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#chat-completions/) OpenAPI specification. - - The Azure Azure OpenAI Service REST API Chat Completions Endpoint will create completions for chat messages with the ChatGPT (preview) and GPT-4 (preview) models. - x-ballerina-init-description: > - The connector initialization requires setting the API credentials. - - Create an [Azure](https://azure.microsoft.com/en-us/features/azure-portal/) account, an [Azure OpenAI resource with a model deployed](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource) and refer [this guide](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#authentication) to learn how to generate and use tokens - version: 2023-08-01-preview + description: Azure OpenAI APIs for completions and search + version: 2023-12-01-preview servers: - url: https://{endpoint}/openai variables: @@ -25,8 +15,6 @@ security: paths: /deployments/{deployment-id}/chat/completions: post: - x-ballerina-display: - label: Create Chat Completion summary: Creates a completion for the chat message operationId: ChatCompletions_Create parameters: @@ -41,21 +29,21 @@ paths: required: true schema: type: string - example: 2023-08-01-preview + example: 2023-12-01-preview description: api version requestBody: required: true content: application/json: schema: - $ref: '#/components/schemas/createChatCompletionRequest' + $ref: "#/components/schemas/createChatCompletionRequest" responses: - '200': + "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/createChatCompletionResponse' + $ref: "#/components/schemas/createChatCompletionResponse" headers: apim-request-id: description: Request ID for troubleshooting purposes @@ -66,7 +54,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/errorResponse' + $ref: "#/components/schemas/errorResponse" headers: apim-request-id: description: Request ID for troubleshooting purposes @@ -74,8 +62,6 @@ paths: type: string /deployments/{deployment-id}/extensions/chat/completions: post: - x-ballerina-display: - label: Create Extensions Chat Completion summary: Using extensions to creates a completion for the chat messages. operationId: ExtensionsChatCompletions_Create parameters: @@ -90,21 +76,21 @@ paths: required: true schema: type: string - example: 2023-08-01-preview + example: 2023-12-01-preview description: api version requestBody: required: true content: application/json: schema: - $ref: '#/components/schemas/extensionsChatCompletionsRequest' + $ref: "#/components/schemas/extensionsChatCompletionsRequest" responses: - '200': + "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/extensionsChatCompletionsResponse' + $ref: "#/components/schemas/extensionsChatCompletionsResponse" headers: apim-request-id: description: Request ID for troubleshooting purposes @@ -115,7 +101,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/errorResponse' + $ref: "#/components/schemas/errorResponse" headers: apim-request-id: description: Request ID for troubleshooting purposes @@ -127,21 +113,21 @@ components: type: object properties: error: - $ref: '#/components/schemas/error' + $ref: "#/components/schemas/error" errorBase: type: object - description: Error information returned by the service. + description: Error response object. properties: code: type: string - description: The error code. + description: Error code. message: type: string - description: The error message. + description: A human-readable representation of the error. error: type: object allOf: - - $ref: '#/components/schemas/errorBase' + - $ref: "#/components/schemas/errorBase" properties: code: type: string @@ -152,15 +138,15 @@ components: type: type: string inner_error: - $ref: '#/components/schemas/innerError' + $ref: "#/components/schemas/innerError" innerError: description: Inner error with additional details. type: object properties: code: - $ref: '#/components/schemas/innerErrorCode' + $ref: "#/components/schemas/innerErrorCode" content_filter_results: - $ref: '#/components/schemas/contentFilterResults' + $ref: "#/components/schemas/contentFilterPromptResults" innerErrorCode: description: Error codes for the inner error object. enum: @@ -172,64 +158,138 @@ components: values: - value: ResponsibleAIPolicyViolation description: The prompt violated one of more content filter rules. - contentFilterResult: + contentFilterResultBase: type: object - description: Information about the content filtering category including 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. properties: - severity: - type: string - description: The severity level of the content filter result. - enum: - - safe - - low - - medium - - high - x-ms-enum: - name: ContentFilterSeverity - modelAsString: true - values: - - value: safe - description: General content or related content in generic or non-harmful contexts. - - value: low - description: Harmful content at a low intensity and risk level. - - value: medium - description: Harmful content at a medium intensity and risk level. - - value: high - description: Harmful content at a high intensity and risk level. filtered: type: boolean - description: Whether the content filter result has been filtered or not. required: - - severity - filtered - contentFilterResults: + contentFilterSeverityResult: type: object description: 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. + allOf: + - $ref: "#/components/schemas/contentFilterResultBase" + - properties: + severity: + type: string + description: The severity level of the content filtering category. + enum: + - safe + - low + - medium + - high + x-ms-enum: + name: ContentFilterSeverity + modelAsString: true + values: + - value: safe + description: General content or related content in generic or non-harmful contexts. + - value: low + description: Harmful content at a low intensity and risk level. + - value: medium + description: Harmful content at a medium intensity and risk level. + - value: high + description: Harmful content at a high intensity and risk level. + required: + - severity + - filtered + contentFilterDetectedResult: + type: object + description: Detected content filtering results + allOf: + - $ref: "#/components/schemas/contentFilterResultBase" + - properties: + detected: + type: boolean + description: Whether the content filtering category has been detected or not. + required: + - detected + - filtered + contentFilterDetectedWithCitationResult: + type: object + description: Detected content filtering results with citation + allOf: + - $ref: "#/components/schemas/contentFilterDetectedResult" + - properties: + citation: + type: object + description: The citation of the detected content. + properties: + URL: + type: string + description: The URL of the citation of detected content. + license: + type: string + description: The license of the citation of detected content. + required: + - detected + - filtered + contentFilterIdResult: + type: object + allOf: + - $ref: "#/components/schemas/contentFilterResultBase" + - properties: + id: + type: string + required: + - id + - filtered + contentFilterResultsBase: + type: object + description: Information about the content filtering results. properties: sexual: - $ref: '#/components/schemas/contentFilterResult' + $ref: "#/components/schemas/contentFilterSeverityResult" + description: violence: - $ref: '#/components/schemas/contentFilterResult' + $ref: "#/components/schemas/contentFilterSeverityResult" hate: - $ref: '#/components/schemas/contentFilterResult' + $ref: "#/components/schemas/contentFilterSeverityResult" self_harm: - $ref: '#/components/schemas/contentFilterResult' + $ref: "#/components/schemas/contentFilterSeverityResult" + profanity: + $ref: "#/components/schemas/contentFilterDetectedResult" + custom_blocklists: + description: Information about custom block list, if it has been filtered and its id. + items: + $ref: "#/components/schemas/contentFilterIdResult" + type: array error: - $ref: '#/components/schemas/errorBase' + $ref: "#/components/schemas/errorBase" + contentFilterPromptResults: + type: object + description: 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. + allOf: + - $ref: "#/components/schemas/contentFilterResultsBase" + - properties: + jailbreak: + $ref: "#/components/schemas/contentFilterDetectedResult" + contentFilterChoiceResults: + type: object + description: 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. + allOf: + - $ref: "#/components/schemas/contentFilterResultsBase" + - properties: + protected_material_text: + $ref: "#/components/schemas/contentFilterDetectedResult" + - properties: + protected_material_code: + $ref: "#/components/schemas/contentFilterDetectedWithCitationResult" promptFilterResult: type: object description: Content filtering results for a single prompt in the request. properties: prompt_index: - description: The index of the prompt in the set of prompt results. + description: The index of the prompt in the request. type: integer content_filter_results: - $ref: '#/components/schemas/contentFilterResults' + $ref: "#/components/schemas/contentFilterPromptResults" promptFilterResults: type: array description: 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. items: - $ref: '#/components/schemas/promptFilterResult' + $ref: "#/components/schemas/promptFilterResult" chatCompletionsRequestCommon: type: object properties: @@ -254,7 +314,7 @@ components: example: 1 nullable: true stream: - description: '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.' + description: "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." type: boolean nullable: true default: false @@ -299,45 +359,87 @@ components: createChatCompletionRequest: type: object allOf: - - $ref: '#/components/schemas/chatCompletionsRequestCommon' + - $ref: "#/components/schemas/chatCompletionsRequestCommon" - properties: messages: description: 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). type: array minItems: 1 items: - $ref: '#/components/schemas/chatCompletionRequestMessage' + $ref: "#/components/schemas/chatCompletionRequestMessage" + "n": + type: integer + minimum: 1 + maximum: 128 + default: 1 + example: 1 + nullable: true + description: How many chat completion choices to generate for each input message. + seed: + type: integer + minimum: -9223372036854776000 + maximum: 9223372036854776000 + default: 0 + example: 1 + nullable: true + description: 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. + response_format: + type: object + description: An object specifying the format that the model must output. Used to enable JSON mode. + properties: + type: + $ref: "#/components/schemas/chatCompletionResponseFormat" + tools: + description: 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. + type: array + minItems: 1 + items: + $ref: "#/components/schemas/chatCompletionTool" + tool_choice: + $ref: "#/components/schemas/chatCompletionToolChoiceOption" functions: - description: A list of functions the model may generate JSON inputs for. + description: Deprecated in favor of `tools`. A list of functions the model may generate JSON inputs for. type: array minItems: 1 + maxItems: 128 items: - $ref: '#/components/schemas/chatCompletionFunctions' + $ref: "#/components/schemas/chatCompletionFunction" function_call: - description: 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. + description: Deprecated in favor of `tool_choice`. 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. oneOf: - type: string enum: - none - auto + description: "`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." - type: object + description: 'Specifying a particular function via `{"name": "my_function"}` forces the model to call that function.' properties: name: type: string description: The name of the function to call. required: - name - 'n': - type: integer - minimum: 1 - maximum: 128 - default: 1 - example: 1 - nullable: true - description: How many chat completion choices to generate for each input message. - required: - - messages - chatCompletionFunctions: + required: + - messages + chatCompletionResponseFormat: + type: string + enum: + - text + - json_object + default: text + example: json_object + nullable: true + description: Setting to `json_object` enables JSON mode. This guarantees that the message the model generates is valid JSON. + x-ms-enum: + name: ChatCompletionResponseFormat + modelAsString: true + values: + - value: text + description: Response format is a plain text string. + - value: json_object + description: Response format is a JSON object. + chatCompletionFunction: type: object properties: name: @@ -347,7 +449,7 @@ components: type: string description: The description of what the function does. parameters: - $ref: '#/components/schemas/chatCompletionFunctionParameters' + $ref: "#/components/schemas/chatCompletionFunctionParameters" required: - name chatCompletionFunctionParameters: @@ -358,23 +460,162 @@ components: type: object properties: role: + $ref: "#/components/schemas/chatCompletionRequestMessageRole" + discriminator: + propertyName: role + mapping: + system: "#/components/schemas/chatCompletionRequestMessageSystem" + user: "#/components/schemas/chatCompletionRequestMessageUser" + assistant: "#/components/schemas/chatCompletionRequestMessageAssistant" + tool: "#/components/schemas/chatCompletionRequestMessageTool" + function: "#/components/schemas/chatCompletionRequestMessageFunction" + required: + - role + chatCompletionRequestMessageRole: + type: string + enum: + - system + - user + - assistant + - tool + - function + description: The role of the messages author. + x-ms-enum: + name: ChatCompletionRequestMessageRole + modelAsString: true + values: + - value: system + description: The message author role is system. + - value: user + description: The message author role is user. + - value: assistant + description: The message author role is assistant. + - value: tool + description: The message author role is tool. + - value: function + description: Deprecated. The message author role is function. + chatCompletionRequestMessageSystem: + allOf: + - $ref: "#/components/schemas/chatCompletionRequestMessage" + - type: object + properties: + content: + type: string + description: The contents of the message. + nullable: true + required: + - content + chatCompletionRequestMessageUser: + allOf: + - $ref: "#/components/schemas/chatCompletionRequestMessage" + - type: object + properties: + content: + oneOf: + - type: string + description: The contents of the message. + - type: array + description: An array of content parts with a defined type, each can be of type `text` or `image_url` when passing in images. You can pass multiple images by adding multiple `image_url` content parts. Image input is only supported when using the `gpt-4-visual-preview` model. + minimum: 1 + items: + $ref: "#/components/schemas/chatCompletionRequestMessageContentPart" + nullable: true + required: + - content + chatCompletionRequestMessageContentPart: + type: object + properties: + type: + $ref: "#/components/schemas/chatCompletionRequestMessageContentPartType" + discriminator: + propertyName: type + mapping: + text: "#/components/schemas/chatCompletionRequestMessageContentPartText" + image_url: "#/components/schemas/chatCompletionRequestMessageContentPartImage" + required: + - type + chatCompletionRequestMessageContentPartType: + type: string + enum: + - text + - image_url + description: The type of the content part. + x-ms-enum: + name: ChatCompletionRequestMessageContentPartType + modelAsString: true + values: + - value: text + description: The content part type is text. + - value: image_url + description: The content part type is image_url. + chatCompletionRequestMessageContentPartText: + allOf: + - $ref: "#/components/schemas/chatCompletionRequestMessageContentPart" + - type: object + properties: + text: + type: string + description: The text content. + required: + - text + chatCompletionRequestMessageContentPartImage: + allOf: + - $ref: "#/components/schemas/chatCompletionRequestMessageContentPart" + - type: object + properties: + url: + type: string + description: Either a URL of the image or the base64 encoded image data. + format: uri + detail: + $ref: "#/components/schemas/imageDetailLevel" + required: + - url + imageDetailLevel: + type: string + description: Specifies the detail level of the image. + enum: + - auto + - low + - high + default: auto + x-ms-enum: + name: ImageDetailLevel + modelAsString: true + values: + - value: auto + description: The image detail level is auto. + - value: low + description: The image detail level is low. + - value: high + description: The image detail level is high. + chatCompletionRequestMessageAssistant: + allOf: + - $ref: "#/components/schemas/chatCompletionRequestMessage" + - type: object + properties: + content: + type: string + description: The contents of the message. + nullable: true + tool_calls: + type: array + description: The tool calls generated by the model, such as function calls. + items: + $ref: "#/components/schemas/chatCompletionMessageToolCall" + required: + - content + chatCompletionMessageToolCall: + type: object + properties: + id: type: string - enum: - - system - - user - - assistant - - function - description: The role of the messages author. One of `system`, `user`, `assistant`, or `function`. - content: - type: string - description: The contents of the message. `content` is required for all messages except assistant messages with function calls. - nullable: true - name: - type: string - description: 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. - function_call: + description: The ID of the tool call. + type: + $ref: "#/components/schemas/toolCallType" + function: type: object - description: The name and arguments of a function that should be called, as generated by the model. + description: The function that the model called. properties: name: type: string @@ -382,77 +623,192 @@ components: arguments: type: string description: 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. + required: + - name + - arguments required: - - role + - id + - type + - function + toolCallType: + type: string + enum: + - function + description: The type of the tool call, in this case `function`. + x-ms-enum: + name: ToolCallType + modelAsString: true + values: + - value: function + description: The tool call type is function. + chatCompletionRequestMessageTool: + allOf: + - $ref: "#/components/schemas/chatCompletionRequestMessage" + - type: object + nullable: true + properties: + tool_call_id: + type: string + description: Tool call that this message is responding to. + content: + type: string + description: The contents of the message. + nullable: true + required: + - tool_call_id + - content + chatCompletionRequestMessageFunction: + allOf: + - $ref: "#/components/schemas/chatCompletionRequestMessage" + - type: object + description: Deprecated. Message that represents a function. + nullable: true + properties: + role: + type: string + enum: + - function + description: The role of the messages author, in this case `function`. + name: + type: string + description: The contents of the message. + content: + type: string + description: The contents of the message. + nullable: true + required: + - function_call_id - content createChatCompletionResponse: type: object allOf: - - $ref: '#/components/schemas/chatCompletionsResponseCommon' + - $ref: "#/components/schemas/chatCompletionsResponseCommon" - properties: + prompt_filter_results: + $ref: "#/components/schemas/promptFilterResults" choices: type: array items: type: object allOf: - - $ref: '#/components/schemas/chatCompletionChoiceCommon' + - $ref: "#/components/schemas/chatCompletionChoiceCommon" - properties: message: - $ref: '#/components/schemas/chatCompletionResponseMessage' + $ref: "#/components/schemas/chatCompletionResponseMessage" content_filter_results: - $ref: '#/components/schemas/contentFilterResults' - required: - - choices + $ref: "#/components/schemas/contentFilterChoiceResults" + required: + - id + - object + - created + - model + - choices chatCompletionResponseMessage: type: object + description: A chat completion message generated by the model. properties: role: - type: string - enum: - - system - - user - - assistant - - function - description: The role of the author of this message. + $ref: "#/components/schemas/chatCompletionResponseMessageRole" content: type: string description: The contents of the message. + nullable: true + tool_calls: + type: array + description: The tool calls generated by the model, such as function calls. + items: + $ref: "#/components/schemas/chatCompletionMessageToolCall" function_call: + $ref: "#/components/schemas/chatCompletionFunctionCall" + chatCompletionResponseMessageRole: + type: string + enum: + - assistant + description: The role of the author of the response message. + chatCompletionToolChoiceOption: + description: '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 `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that function.' + oneOf: + - type: string + description: "`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." + enum: + - none + - auto + - $ref: "#/components/schemas/chatCompletionNamedToolChoice" + chatCompletionNamedToolChoice: + type: object + description: Specifies a tool the model should use. Use to force the model to call a specific function. + properties: + type: + type: string + enum: + - function + description: The type of the tool. Currently, only `function` is supported. + function: type: object - description: The name and arguments of a function that should be called, as generated by the model. + description: The function that should be called. properties: name: type: string description: The name of the function to call. - arguments: - type: string - description: 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. + required: + - name + chatCompletionFunctionCall: + type: object + description: Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. + properties: + name: + type: string + description: The name of the function to call. + arguments: + type: string + description: 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. required: - - role + - name + - arguments extensionsChatCompletionsRequest: type: object description: Request for the chat completions using extensions + required: + - messages allOf: - - $ref: '#/components/schemas/chatCompletionsRequestCommon' + - $ref: "#/components/schemas/chatCompletionsRequestCommon" - properties: messages: + description: A list of messages comprising the conversation so far. type: array - description: 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). items: - $ref: '#/components/schemas/message' + $ref: "#/components/schemas/message" dataSources: type: array description: The data sources to be used for the Azure OpenAI on your data feature. items: - $ref: '#/components/schemas/dataSource' - required: - - messages + $ref: "#/components/schemas/dataSource" + enhancements: + type: object + description: The type of enhancements needed. + properties: + grounding: + type: object + description: Request object to specify if grounding enhancement is needed. + properties: + enabled: + description: If grounding enhancement is enabled. + type: boolean + default: false + ocr: + type: object + description: Request object to specify if ocr enhancement is needed. + properties: + enabled: + description: If ocr enhancement is enabled. + type: boolean + default: false example: dataSources: - type: AzureCognitiveSearch parameters: endpoint: https://mysearchexample.search.windows.net - key: '***(admin key)' + key: "***(admin key)" indexName: my-chunk-index fieldsMapping: titleField: productName @@ -519,7 +875,7 @@ components: description: Messages exchanged between model and extensions prior to final message from model minItems: 1 items: - $ref: '#/components/schemas/message' + $ref: "#/components/schemas/message" nullable: true required: - role @@ -529,31 +885,87 @@ components: properties: id: type: string + description: A unique identifier for the chat completion. object: - type: string + $ref: "#/components/schemas/chatCompletionResponseObject" created: type: integer format: unixtime + description: The Unix timestamp (in seconds) of when the chat completion was created. model: type: string + description: The model used for the chat completion. usage: - type: object - properties: - prompt_tokens: - type: integer - completion_tokens: - type: integer - total_tokens: - type: integer - required: - - prompt_tokens - - completion_tokens - - total_tokens + $ref: "#/components/schemas/completionUsage" + system_fingerprint: + type: string + description: Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism. required: - id - object - created - model + chatCompletionResponseObject: + type: string + description: The object type. + enum: + - chat.completion + x-ms-enum: + name: ChatCompletionResponseObject + modelAsString: true + values: + - value: chat.completion + description: The object type is chat completion. + completionUsage: + type: object + description: Usage statistics for the completion request. + properties: + prompt_tokens: + type: integer + description: Number of tokens in the prompt. + completion_tokens: + type: integer + description: Number of tokens in the generated completion. + total_tokens: + type: integer + description: Total number of tokens used in the request (prompt + completion). + required: + - prompt_tokens + - completion_tokens + - total_tokens + chatCompletionTool: + type: object + properties: + type: + $ref: "#/components/schemas/chatCompletionToolType" + function: + type: object + properties: + description: + type: string + description: A description of what the function does, used by the model to choose when and how to call the function. + name: + type: string + description: 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. + parameters: + $ref: "#/components/schemas/chatCompletionFunctionParameters" + required: + - name + - parameters + required: + - type + - function + chatCompletionToolType: + type: string + enum: + - function + description: The type of the tool. Currently, only `function` is supported. + x-ms-enum: + name: ChatCompletionToolType + modelAsString: true + values: + - value: function + description: The tool type is function. chatCompletionChoiceCommon: type: object properties: @@ -564,24 +976,25 @@ components: extensionsChatCompletionChoice: type: object allOf: - - $ref: '#/components/schemas/chatCompletionChoiceCommon' + - $ref: "#/components/schemas/chatCompletionChoiceCommon" - properties: message: - description: The message returned by the service. - $ref: '#/components/schemas/message' + $ref: "#/components/schemas/message" + enhancements: + $ref: "#/components/schemas/enhancement" extensionsChatCompletionsResponse: type: object description: The response of the extensions chat completions. allOf: - - $ref: '#/components/schemas/chatCompletionsResponseCommon' + - $ref: "#/components/schemas/chatCompletionsResponseCommon" - properties: choices: type: array - description: A list of chat completion choices. + description: The chat completion choices. items: - $ref: '#/components/schemas/extensionsChatCompletionChoice' + $ref: "#/components/schemas/extensionsChatCompletionChoice" example: - id: '1' + id: "1" object: extensions.chat.completion created: 1679201802 model: gpt-3.5-turbo-0301 @@ -597,6 +1010,65 @@ components: - role: tool content: '{"citations":[{"filepath":"ContosoTraveler.pdf","content":"This is the content of the citation 1"},{"filepath":"WestCoastTraveler.html","content":"This is the content of the citation 2"},{"content":"This is the content of the citation 3 without filepath"}],"intent":"hiking place in seattle"}' end_turn: false + enhancement: + type: object + properties: + grounding: + type: object + description: The grounding enhancement that returns the bounding box of the objects detected in the image. + properties: + lines: + type: array + description: An array of lines that represent the detected objects and its bounding box information. + items: + $ref: "#/components/schemas/line" + required: + - lines + line: + type: object + description: A content line object consisting of an adjacent sequence of content elements, such as words and selection marks. + properties: + text: + type: string + description: The text content of the line. + spans: + type: array + description: An array of spans that represent detected objects and its bounding box information. + items: + $ref: "#/components/schemas/span" + required: + - text + - spans + span: + type: object + description: A span object that represents a detected object and its bounding box information. + properties: + text: + type: string + description: The text content of the span that represents the detected object. + offset: + type: integer + description: The character offset within the text where the span begins. This offset is defined as the position of the first character of the span, counting from the start of the text as Unicode codepoints. + length: + type: integer + description: The length of the span in characters, measured in Unicode codepoints. + polygon: + type: array + description: An array of objects representing points in the polygon that encloses the detected object. + items: + type: object + properties: + x: + type: number + description: The x-coordinate of the point. + "y": + type: number + description: The y-coordinate of the point. + required: + - text + - offset + - length + - polygon securitySchemes: bearer: type: oauth2 @@ -608,6 +1080,7 @@ components: x-scopeValidateFunc: api.middleware.auth.validate_scopes apiKey: type: apiKey - description: The key used to access the OpenAI APIs + description: | + The API key to use. This is the same as your subscription key. name: api-key in: header diff --git a/openapi/azure.openai.chat/original-openapi.yaml b/openapi/azure.openai.chat/original-openapi.yaml index 15277878b..065fc0946 100644 --- a/openapi/azure.openai.chat/original-openapi.yaml +++ b/openapi/azure.openai.chat/original-openapi.yaml @@ -2,7 +2,7 @@ openapi: 3.0.0 info: title: Azure OpenAI Service API description: Azure OpenAI APIs for completions and search - version: 2023-08-01-preview + version: 2023-12-01-preview servers: - url: https://{endpoint}/openai variables: @@ -30,7 +30,7 @@ paths: required: true schema: type: string - example: 2023-08-01-preview + example: 2023-12-01-preview description: api version requestBody: required: true @@ -204,7 +204,7 @@ paths: finish_reason: type: string content_filter_results: - $ref: '#/components/schemas/contentFilterResults' + $ref: '#/components/schemas/contentFilterChoiceResults' usage: type: object properties: @@ -270,7 +270,7 @@ paths: required: true schema: type: string - example: 2023-08-01-preview + example: 2023-12-01-preview description: api version requestBody: required: true @@ -367,7 +367,7 @@ paths: required: true schema: type: string - example: 2023-08-01-preview + example: 2023-12-01-preview description: api version requestBody: required: true @@ -414,7 +414,7 @@ paths: required: true schema: type: string - example: 2023-08-01-preview + example: 2023-12-01-preview description: api version requestBody: required: true @@ -445,6 +445,120 @@ paths: description: Request ID for troubleshooting purposes schema: type: string + /deployments/{deployment-id}/audio/transcriptions: + post: + summary: Transcribes audio into the input language. + operationId: Transcriptions_Create + parameters: + - in: path + name: deployment-id + required: true + schema: + type: string + example: whisper + description: Deployment id of the whisper model. + - in: query + name: api-version + required: true + schema: + type: string + example: 2023-12-01-preview + description: api version + requestBody: + required: true + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/createTranscriptionRequest' + responses: + '200': + description: OK + content: + application/json: + schema: + oneOf: + - $ref: '#/components/schemas/audioResponse' + - $ref: '#/components/schemas/audioVerboseResponse' + text/plain: + schema: + type: string + description: Transcribed text in the output format (when response_format was one of text, vtt or srt). + /deployments/{deployment-id}/audio/translations: + post: + summary: Transcribes and translates input audio into English text. + operationId: Translations_Create + parameters: + - in: path + name: deployment-id + required: true + schema: + type: string + example: whisper + description: Deployment id of the whisper model which was deployed. + - in: query + name: api-version + required: true + schema: + type: string + example: 2023-12-01-preview + description: api version + requestBody: + required: true + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/createTranslationRequest' + responses: + '200': + description: OK + content: + application/json: + schema: + oneOf: + - $ref: '#/components/schemas/audioResponse' + - $ref: '#/components/schemas/audioVerboseResponse' + text/plain: + schema: + type: string + description: Transcribed text in the output format (when response_format was one of text, vtt or srt). + /deployments/{deployment-id}/images/generations: + post: + summary: Generates a batch of images from a text caption on a given DALLE model deployment + operationId: ImageGenerations_Create + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/imageGenerationsRequest' + parameters: + - in: path + name: deployment-id + required: true + schema: + type: string + example: dalle-deployment + description: Deployment id of the dalle model which was deployed. + - in: query + name: api-version + required: true + schema: + type: string + example: 2023-12-01-preview + description: api version + responses: + '200': + description: Ok + content: + application/json: + schema: + $ref: '#/components/schemas/generateImagesResponse' + default: + description: An error occurred. + content: + application/json: + schema: + $ref: '#/components/schemas/errorResponse' components: schemas: errorResponse: @@ -481,7 +595,7 @@ components: code: $ref: '#/components/schemas/innerErrorCode' content_filter_results: - $ref: '#/components/schemas/contentFilterResults' + $ref: '#/components/schemas/contentFilterPromptResults' innerErrorCode: description: Error codes for the inner error object. enum: @@ -493,47 +607,114 @@ components: values: - value: ResponsibleAIPolicyViolation description: The prompt violated one of more content filter rules. - contentFilterResult: + contentFilterResultBase: type: object properties: - severity: - type: string - enum: - - safe - - low - - medium - - high - x-ms-enum: - name: ContentFilterSeverity - modelAsString: true - values: - - value: safe - description: General content or related content in generic or non-harmful contexts. - - value: low - description: Harmful content at a low intensity and risk level. - - value: medium - description: Harmful content at a medium intensity and risk level. - - value: high - description: Harmful content at a high intensity and risk level. filtered: type: boolean + required: + - filtered + contentFilterSeverityResult: + type: object + allOf: + - $ref: '#/components/schemas/contentFilterResultBase' + - properties: + severity: + type: string + enum: + - safe + - low + - medium + - high + x-ms-enum: + name: ContentFilterSeverity + modelAsString: true + values: + - value: safe + description: General content or related content in generic or non-harmful contexts. + - value: low + description: Harmful content at a low intensity and risk level. + - value: medium + description: Harmful content at a medium intensity and risk level. + - value: high + description: Harmful content at a high intensity and risk level. required: - severity - filtered - contentFilterResults: + contentFilterDetectedResult: type: object - description: 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. + allOf: + - $ref: '#/components/schemas/contentFilterResultBase' + - properties: + detected: + type: boolean + required: + - detected + - filtered + contentFilterDetectedWithCitationResult: + type: object + allOf: + - $ref: '#/components/schemas/contentFilterDetectedResult' + - properties: + citation: + type: object + properties: + URL: + type: string + license: + type: string + required: + - detected + - filtered + contentFilterIdResult: + type: object + allOf: + - $ref: '#/components/schemas/contentFilterResultBase' + - properties: + id: + type: string + required: + - id + - filtered + contentFilterResultsBase: + type: object + description: Information about the content filtering results. properties: sexual: - $ref: '#/components/schemas/contentFilterResult' + $ref: '#/components/schemas/contentFilterSeverityResult' violence: - $ref: '#/components/schemas/contentFilterResult' + $ref: '#/components/schemas/contentFilterSeverityResult' hate: - $ref: '#/components/schemas/contentFilterResult' + $ref: '#/components/schemas/contentFilterSeverityResult' self_harm: - $ref: '#/components/schemas/contentFilterResult' + $ref: '#/components/schemas/contentFilterSeverityResult' + profanity: + $ref: '#/components/schemas/contentFilterDetectedResult' + custom_blocklists: + items: + $ref: '#/components/schemas/contentFilterIdResult' + type: array error: $ref: '#/components/schemas/errorBase' + contentFilterPromptResults: + type: object + description: 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. + allOf: + - $ref: '#/components/schemas/contentFilterResultsBase' + - properties: + jailbreak: + $ref: '#/components/schemas/contentFilterDetectedResult' + contentFilterChoiceResults: + type: object + description: 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. + allOf: + - $ref: '#/components/schemas/contentFilterResultsBase' + - properties: + protected_material_text: + $ref: '#/components/schemas/contentFilterDetectedResult' + - properties: + protected_material_code: + $ref: '#/components/schemas/contentFilterDetectedWithCitationResult' promptFilterResult: type: object description: Content filtering results for a single prompt in the request. @@ -541,7 +722,7 @@ components: prompt_index: type: integer content_filter_results: - $ref: '#/components/schemas/contentFilterResults' + $ref: '#/components/schemas/contentFilterPromptResults' promptFilterResults: type: array description: 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. @@ -624,37 +805,79 @@ components: minItems: 1 items: $ref: '#/components/schemas/chatCompletionRequestMessage' + 'n': + type: integer + minimum: 1 + maximum: 128 + default: 1 + example: 1 + nullable: true + description: How many chat completion choices to generate for each input message. + seed: + type: integer + minimum: -9223372036854776000 + maximum: 9223372036854776000 + default: 0 + example: 1 + nullable: true + description: 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. + response_format: + type: object + description: An object specifying the format that the model must output. Used to enable JSON mode. + properties: + type: + $ref: '#/components/schemas/chatCompletionResponseFormat' + tools: + description: 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. + type: array + minItems: 1 + items: + $ref: '#/components/schemas/chatCompletionTool' + tool_choice: + $ref: '#/components/schemas/chatCompletionToolChoiceOption' functions: - description: A list of functions the model may generate JSON inputs for. + description: Deprecated in favor of `tools`. A list of functions the model may generate JSON inputs for. type: array minItems: 1 + maxItems: 128 items: - $ref: '#/components/schemas/chatCompletionFunctions' + $ref: '#/components/schemas/chatCompletionFunction' function_call: - description: 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. + description: Deprecated in favor of `tool_choice`. 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. oneOf: - type: string enum: - none - auto + description: '`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.' - type: object + description: 'Specifying a particular function via `{"name": "my_function"}` forces the model to call that function.' properties: name: type: string description: The name of the function to call. required: - name - 'n': - type: integer - minimum: 1 - maximum: 128 - default: 1 - example: 1 - nullable: true - description: How many chat completion choices to generate for each input message. required: - messages - chatCompletionFunctions: + chatCompletionResponseFormat: + type: string + enum: + - text + - json_object + default: text + example: json_object + nullable: true + description: Setting to `json_object` enables JSON mode. This guarantees that the message the model generates is valid JSON. + x-ms-enum: + name: ChatCompletionResponseFormat + modelAsString: true + values: + - value: text + description: Response format is a plain text string. + - value: json_object + description: Response format is a JSON object. + chatCompletionFunction: type: object properties: name: @@ -675,22 +898,162 @@ components: type: object properties: role: + $ref: '#/components/schemas/chatCompletionRequestMessageRole' + discriminator: + propertyName: role + mapping: + system: '#/components/schemas/chatCompletionRequestMessageSystem' + user: '#/components/schemas/chatCompletionRequestMessageUser' + assistant: '#/components/schemas/chatCompletionRequestMessageAssistant' + tool: '#/components/schemas/chatCompletionRequestMessageTool' + function: '#/components/schemas/chatCompletionRequestMessageFunction' + required: + - role + chatCompletionRequestMessageRole: + type: string + enum: + - system + - user + - assistant + - tool + - function + description: The role of the messages author. + x-ms-enum: + name: ChatCompletionRequestMessageRole + modelAsString: true + values: + - value: system + description: The message author role is system. + - value: user + description: The message author role is user. + - value: assistant + description: The message author role is assistant. + - value: tool + description: The message author role is tool. + - value: function + description: Deprecated. The message author role is function. + chatCompletionRequestMessageSystem: + allOf: + - $ref: '#/components/schemas/chatCompletionRequestMessage' + - type: object + properties: + content: + type: string + description: The contents of the message. + nullable: true + required: + - content + chatCompletionRequestMessageUser: + allOf: + - $ref: '#/components/schemas/chatCompletionRequestMessage' + - type: object + properties: + content: + oneOf: + - type: string + description: The contents of the message. + - type: array + description: An array of content parts with a defined type, each can be of type `text` or `image_url` when passing in images. You can pass multiple images by adding multiple `image_url` content parts. Image input is only supported when using the `gpt-4-visual-preview` model. + minimum: 1 + items: + $ref: '#/components/schemas/chatCompletionRequestMessageContentPart' + nullable: true + required: + - content + chatCompletionRequestMessageContentPart: + type: object + properties: + type: + $ref: '#/components/schemas/chatCompletionRequestMessageContentPartType' + discriminator: + propertyName: type + mapping: + text: '#/components/schemas/chatCompletionRequestMessageContentPartText' + image_url: '#/components/schemas/chatCompletionRequestMessageContentPartImage' + required: + - type + chatCompletionRequestMessageContentPartType: + type: string + enum: + - text + - image_url + description: The type of the content part. + x-ms-enum: + name: ChatCompletionRequestMessageContentPartType + modelAsString: true + values: + - value: text + description: The content part type is text. + - value: image_url + description: The content part type is image_url. + chatCompletionRequestMessageContentPartText: + allOf: + - $ref: '#/components/schemas/chatCompletionRequestMessageContentPart' + - type: object + properties: + text: + type: string + description: The text content. + required: + - text + chatCompletionRequestMessageContentPartImage: + allOf: + - $ref: '#/components/schemas/chatCompletionRequestMessageContentPart' + - type: object + properties: + url: + type: string + description: Either a URL of the image or the base64 encoded image data. + format: uri + detail: + $ref: '#/components/schemas/imageDetailLevel' + required: + - url + imageDetailLevel: + type: string + description: Specifies the detail level of the image. + enum: + - auto + - low + - high + default: auto + x-ms-enum: + name: ImageDetailLevel + modelAsString: true + values: + - value: auto + description: The image detail level is auto. + - value: low + description: The image detail level is low. + - value: high + description: The image detail level is high. + chatCompletionRequestMessageAssistant: + allOf: + - $ref: '#/components/schemas/chatCompletionRequestMessage' + - type: object + properties: + content: + type: string + description: The contents of the message. + nullable: true + tool_calls: + type: array + description: The tool calls generated by the model, such as function calls. + items: + $ref: '#/components/schemas/chatCompletionMessageToolCall' + required: + - content + chatCompletionMessageToolCall: + type: object + properties: + id: type: string - enum: - - system - - user - - assistant - - function - description: The role of the messages author. One of `system`, `user`, `assistant`, or `function`. - content: - type: string - description: The contents of the message. `content` is required for all messages except assistant messages with function calls. - name: - type: string - description: 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. - function_call: + description: The ID of the tool call. + type: + $ref: '#/components/schemas/toolCallType' + function: type: object - description: The name and arguments of a function that should be called, as generated by the model. + description: The function that the model called. properties: name: type: string @@ -698,8 +1061,62 @@ components: arguments: type: string description: 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. + required: + - name + - arguments required: - - role + - id + - type + - function + toolCallType: + type: string + enum: + - function + description: The type of the tool call, in this case `function`. + x-ms-enum: + name: ToolCallType + modelAsString: true + values: + - value: function + description: The tool call type is function. + chatCompletionRequestMessageTool: + allOf: + - $ref: '#/components/schemas/chatCompletionRequestMessage' + - type: object + nullable: true + properties: + tool_call_id: + type: string + description: Tool call that this message is responding to. + content: + type: string + description: The contents of the message. + nullable: true + required: + - tool_call_id + - content + chatCompletionRequestMessageFunction: + allOf: + - $ref: '#/components/schemas/chatCompletionRequestMessage' + - type: object + description: Deprecated. Message that represents a function. + nullable: true + properties: + role: + type: string + enum: + - function + description: The role of the messages author, in this case `function`. + name: + type: string + description: The contents of the message. + content: + type: string + description: The contents of the message. + nullable: true + required: + - function_call_id + - content createChatCompletionResponse: type: object allOf: @@ -717,7 +1134,7 @@ components: message: $ref: '#/components/schemas/chatCompletionResponseMessage' content_filter_results: - $ref: '#/components/schemas/contentFilterResults' + $ref: '#/components/schemas/contentFilterChoiceResults' required: - id - object @@ -726,30 +1143,65 @@ components: - choices chatCompletionResponseMessage: type: object + description: A chat completion message generated by the model. properties: role: - type: string - enum: - - system - - user - - assistant - - function - description: The role of the author of this message. + $ref: '#/components/schemas/chatCompletionResponseMessageRole' content: type: string description: The contents of the message. + nullable: true + tool_calls: + type: array + description: The tool calls generated by the model, such as function calls. + items: + $ref: '#/components/schemas/chatCompletionMessageToolCall' function_call: + $ref: '#/components/schemas/chatCompletionFunctionCall' + chatCompletionResponseMessageRole: + type: string + enum: + - assistant + description: The role of the author of the response message. + chatCompletionToolChoiceOption: + description: '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 `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that function.' + oneOf: + - type: string + description: '`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.' + enum: + - none + - auto + - $ref: '#/components/schemas/chatCompletionNamedToolChoice' + chatCompletionNamedToolChoice: + type: object + description: Specifies a tool the model should use. Use to force the model to call a specific function. + properties: + type: + type: string + enum: + - function + description: The type of the tool. Currently, only `function` is supported. + function: type: object - description: The name and arguments of a function that should be called, as generated by the model. properties: name: type: string description: The name of the function to call. - arguments: - type: string - description: 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. + required: + - name + chatCompletionFunctionCall: + type: object + description: Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. + properties: + name: + type: string + description: The name of the function to call. + arguments: + type: string + description: 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. required: - - role + - name + - arguments extensionsChatCompletionsRequest: type: object description: Request for the chat completions using extensions @@ -767,6 +1219,24 @@ components: description: The data sources to be used for the Azure OpenAI on your data feature. items: $ref: '#/components/schemas/dataSource' + enhancements: + type: object + description: The type of enhancements needed. + properties: + grounding: + type: object + description: Request object to specify if grounding enhancement is needed. + properties: + enabled: + type: boolean + default: false + ocr: + type: object + description: Request object to specify if ocr enhancement is needed. + properties: + enabled: + type: boolean + default: false example: dataSources: - type: AzureCognitiveSearch @@ -849,31 +1319,87 @@ components: properties: id: type: string + description: A unique identifier for the chat completion. object: - type: string + $ref: '#/components/schemas/chatCompletionResponseObject' created: type: integer format: unixtime + description: The Unix timestamp (in seconds) of when the chat completion was created. model: type: string + description: The model used for the chat completion. usage: - type: object - properties: - prompt_tokens: - type: integer - completion_tokens: - type: integer - total_tokens: - type: integer - required: - - prompt_tokens - - completion_tokens - - total_tokens + $ref: '#/components/schemas/completionUsage' + system_fingerprint: + type: string + description: Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism. required: - id - object - created - model + chatCompletionResponseObject: + type: string + description: The object type. + enum: + - chat.completion + x-ms-enum: + name: ChatCompletionResponseObject + modelAsString: true + values: + - value: chat.completion + description: The object type is chat completion. + completionUsage: + type: object + description: Usage statistics for the completion request. + properties: + prompt_tokens: + type: integer + description: Number of tokens in the prompt. + completion_tokens: + type: integer + description: Number of tokens in the generated completion. + total_tokens: + type: integer + description: Total number of tokens used in the request (prompt + completion). + required: + - prompt_tokens + - completion_tokens + - total_tokens + chatCompletionTool: + type: object + properties: + type: + $ref: '#/components/schemas/chatCompletionToolType' + function: + type: object + properties: + description: + type: string + description: A description of what the function does, used by the model to choose when and how to call the function. + name: + type: string + description: 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. + parameters: + $ref: '#/components/schemas/chatCompletionFunctionParameters' + required: + - name + - parameters + required: + - type + - function + chatCompletionToolType: + type: string + enum: + - function + description: The type of the tool. Currently, only `function` is supported. + x-ms-enum: + name: ChatCompletionToolType + modelAsString: true + values: + - value: function + description: The tool type is function. chatCompletionChoiceCommon: type: object properties: @@ -887,8 +1413,10 @@ components: - $ref: '#/components/schemas/chatCompletionChoiceCommon' - properties: message: - description: The message returned by the service. $ref: '#/components/schemas/message' + enhancements: + description: The enhancement results returned by the service. + $ref: '#/components/schemas/enhancement' extensionsChatCompletionsResponse: type: object description: The response of the extensions chat completions. @@ -916,6 +1444,321 @@ components: - role: tool content: '{"citations":[{"filepath":"ContosoTraveler.pdf","content":"This is the content of the citation 1"},{"filepath":"WestCoastTraveler.html","content":"This is the content of the citation 2"},{"content":"This is the content of the citation 3 without filepath"}],"intent":"hiking place in seattle"}' end_turn: false + createTranslationRequest: + type: object + description: Translation request. + properties: + file: + type: string + description: The audio file to translate. + format: binary + prompt: + type: string + description: An optional text to guide the model's style or continue a previous audio segment. The prompt should be in English. + response_format: + $ref: '#/components/schemas/audioResponseFormat' + temperature: + type: number + default: 0 + description: The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit. + required: + - file + audioResponse: + description: Translation or transcription response when response_format was json + type: object + properties: + text: + type: string + description: Translated or transcribed text. + required: + - text + audioVerboseResponse: + description: Translation or transcription response when response_format was verbose_json + type: object + allOf: + - $ref: '#/components/schemas/audioResponse' + - properties: + task: + type: string + description: Type of audio task. + enum: + - transcribe + - translate + x-ms-enum: + modelAsString: true + language: + type: string + description: Language. + duration: + type: number + description: Duration. + segments: + type: array + items: + $ref: '#/components/schemas/audioSegment' + required: + - text + audioResponseFormat: + title: AudioResponseFormat + description: Defines the format of the output. + enum: + - json + - text + - srt + - verbose_json + - vtt + type: string + x-ms-enum: + modelAsString: true + createTranscriptionRequest: + type: object + description: Transcription request. + properties: + file: + type: string + description: The audio file object to transcribe. + format: binary + prompt: + type: string + description: An optional text to guide the model's style or continue a previous audio segment. The prompt should match the audio language. + response_format: + $ref: '#/components/schemas/audioResponseFormat' + temperature: + type: number + default: 0 + description: The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature until certain thresholds are hit. + language: + type: string + description: The language of the input audio. Supplying the input language in ISO-639-1 format will improve accuracy and latency. + required: + - file + audioSegment: + type: object + description: Transcription or translation segment. + properties: + id: + type: integer + description: Segment identifier. + seek: + type: number + description: Offset of the segment. + start: + type: number + description: Segment start offset. + end: + type: number + description: Segment end offset. + text: + type: string + description: Segment text. + tokens: + type: array + items: + type: number + nullable: false + description: Tokens of the text. + temperature: + type: number + description: Temperature. + avg_logprob: + type: number + description: Average log probability. + compression_ratio: + type: number + description: Compression ratio. + no_speech_prob: + type: number + description: Probability of 'no speech'. + imageQuality: + description: The quality of the image that will be generated. + type: string + enum: + - standard + - hd + default: standard + x-ms-enum: + name: Quality + modelAsString: true + values: + - value: standard + description: Standard quality creates images with standard quality. + name: Standard + - value: hd + description: HD quality creates images with finer details and greater consistency across the image. + name: HD + imagesResponseFormat: + description: The format in which the generated images are returned. + type: string + enum: + - url + - b64_json + default: url + x-ms-enum: + name: ImagesResponseFormat + modelAsString: true + values: + - value: url + description: The URL that provides temporary access to download the generated images. + name: Url + - value: b64_json + description: The generated images are returned as base64 encoded string. + name: Base64Json + imageSize: + description: The size of the generated images. + type: string + enum: + - 1792x1024 + - 1024x1792 + - 1024x1024 + default: 1024x1024 + x-ms-enum: + name: Size + modelAsString: true + values: + - value: 1792x1024 + description: The desired size of the generated image is 1792x1024 pixels. + name: Size1792x1024 + - value: 1024x1792 + description: The desired size of the generated image is 1024x1792 pixels. + name: Size1024x1792 + - value: 1024x1024 + description: The desired size of the generated image is 1024x1024 pixels. + name: Size1024x1024 + imageStyle: + description: The style of the generated images. + type: string + enum: + - vivid + - natural + default: vivid + x-ms-enum: + name: Style + modelAsString: true + values: + - value: vivid + description: Vivid creates images that are hyper-realistic and dramatic. + name: Vivid + - value: natural + description: Natural creates images that are more natural and less hyper-realistic. + name: Natural + imageGenerationsRequest: + type: object + properties: + prompt: + description: A text description of the desired image(s). The maximum length is 4000 characters. + type: string + format: string + example: a corgi in a field + minLength: 1 + 'n': + description: The number of images to generate. + type: integer + minimum: 1 + maximum: 1 + default: 1 + size: + $ref: '#/components/schemas/imageSize' + response_format: + $ref: '#/components/schemas/imagesResponseFormat' + user: + description: A unique identifier representing your end-user, which can help to monitor and detect abuse. + type: string + format: string + example: user123456 + style: + $ref: '#/components/schemas/imageStyle' + quality: + $ref: '#/components/schemas/imageQuality' + required: + - prompt + generateImagesResponse: + type: object + properties: + created: + type: integer + format: unixtime + description: The unix timestamp when the operation was created. + example: '1676540381' + data: + type: array + description: The result data of the operation, if successful + items: + $ref: '#/components/schemas/imageResult' + error: + $ref: '#/components/schemas/error' + required: + - created + imageResult: + type: object + description: The image url or encoded image if successful, and an error otherwise. + properties: + url: + type: string + description: The image url. + example: https://www.contoso.com + b64_json: + type: string + description: The base64 encoded image + revised_prompt: + type: string + description: The prompt that was used to generate the image, if there was any revision to the prompt. + enhancement: + type: object + properties: + grounding: + type: object + description: The grounding enhancement that returns the bounding box of the objects detected in the image. + properties: + lines: + type: array + items: + $ref: '#/components/schemas/line' + required: + - lines + line: + type: object + description: A content line object consisting of an adjacent sequence of content elements, such as words and selection marks. + properties: + text: + type: string + spans: + type: array + description: An array of spans that represent detected objects and its bounding box information. + items: + $ref: '#/components/schemas/span' + required: + - text + - spans + span: + type: object + description: A span object that represents a detected object and its bounding box information. + properties: + text: + type: string + description: The text content of the span that represents the detected object. + offset: + type: integer + description: The character offset within the text where the span begins. This offset is defined as the position of the first character of the span, counting from the start of the text as Unicode codepoints. + length: + type: integer + description: The length of the span in characters, measured in Unicode codepoints. + polygon: + type: array + description: An array of objects representing points in the polygon that encloses the detected object. + items: + type: object + properties: + x: + type: number + description: The x-coordinate of the point. + 'y': + type: number + description: The y-coordinate of the point. + required: + - text + - offset + - length + - polygon securitySchemes: bearer: type: oauth2 diff --git a/openapi/azure.openai.chat/types.bal b/openapi/azure.openai.chat/types.bal index ac26dce06..f7e883ed9 100644 --- a/openapi/azure.openai.chat/types.bal +++ b/openapi/azure.openai.chat/types.bal @@ -1,8 +1,7 @@ // AUTO-GENERATED FILE. DO NOT MODIFY. // This file is auto-generated by the Ballerina OpenAPI tool. - -import ballerina/http; import ballerina/constraint; +import ballerina/http; # Provides a set of configurations for controlling the behaviours when communicating with a remote HTTP endpoint. @display {label: "Connection Config"} @@ -64,11 +63,213 @@ public type ProxyConfig record {| # Provides API key configurations needed when communicating with a remote HTTP endpoint. public type ApiKeysConfig record {| - # The key used to access the OpenAI APIs + # The API key to use. This is the same as your subscription key. @display {label: "", kind: "password"} string apiKey; |}; +public type ContentFilterIdResult record { + *ContentFilterResultBase; + string id?; +}; + +# Inner error with additional details. +public type InnerError record { + # Error codes for the inner error object. + InnerErrorCode code?; + # 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. + ContentFilterPromptResults content_filter_results?; +}; + +public type ChatCompletionRequestMessage record { + # The role of the messages author. + ChatCompletionRequestMessageRole role; +}; + +# Detected content filtering results +public type ContentFilterDetectedResult record { + *ContentFilterResultBase; + # Whether the content filtering category has been detected or not. + boolean detected?; +}; + +# Information about the content filtering results. +public type ContentFilterResultsBase record { + # 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. + ContentFilterSeverityResult sexual?; + # 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. + ContentFilterSeverityResult violence?; + # 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. + ContentFilterSeverityResult hate?; + # 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. + ContentFilterSeverityResult self_harm?; + # Detected content filtering results + ContentFilterDetectedResult profanity?; + # Information about custom block list, if it has been filtered and its id. + ContentFilterIdResult[] custom_blocklists?; + # Error response object. + ErrorBase 'error?; +}; + +# The function that the model called. +public type ChatCompletionMessageToolCall_function record { + # The name of the function to call. + 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. + string arguments; +}; + +public type ChatCompletionRequestMessageSystem record { + *ChatCompletionRequestMessage; + # The contents of the message. + string? content?; +}; + +public type ChatCompletionRequestMessageUser record { + *ChatCompletionRequestMessage; + string|ChatCompletionRequestMessageContentPart[]? content?; +}; + +# 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 `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that function. +public type ChatCompletionToolChoiceOption "none"|"auto"|ChatCompletionNamedToolChoice; + +public type Enhancement record { + # The grounding enhancement that returns the bounding box of the objects detected in the image. + Enhancement_grounding grounding?; +}; + +# 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. +public type ContentFilterChoiceResults record { + *ContentFilterResultsBase; + # Detected content filtering results + ContentFilterDetectedResult protected_material_text?; + # Detected content filtering results with citation + ContentFilterDetectedWithCitationResult protected_material_code?; +}; + +# Error codes for the inner error object. +public type InnerErrorCode "ResponsibleAIPolicyViolation"; + +# The type of enhancements needed. +public type ExtensionsChatCompletionsRequest_enhancements record { + # Request object to specify if grounding enhancement is needed. + ExtensionsChatCompletionsRequest_enhancements_grounding grounding?; + # Request object to specify if ocr enhancement is needed. + ExtensionsChatCompletionsRequest_enhancements_ocr ocr?; +}; + +# The type of the tool. Currently, only `function` is supported. +public type ChatCompletionToolType "function"; + +# 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. +public type ContentFilterPromptResults record { + *ContentFilterResultsBase; + # Detected content filtering results + ContentFilterDetectedResult jailbreak?; +}; + +public type Span_polygon record { + # The x-coordinate of the point. + decimal x?; + # The y-coordinate of the point. + decimal y?; +}; + +# Setting to `json_object` enables JSON mode. This guarantees that the message the model generates is valid JSON. +public type ChatCompletionResponseFormat "text"|"json_object"; + +public type ChatCompletionRequestMessageAssistant record { + *ChatCompletionRequestMessage; + # The contents of the message. + string? content?; + # The tool calls generated by the model, such as function calls. + ChatCompletionMessageToolCall[] tool_calls?; +}; + +# Request object to specify if grounding enhancement is needed. +public type ExtensionsChatCompletionsRequest_enhancements_grounding record { + # If grounding enhancement is enabled. + boolean enabled?; +}; + +public type ChatCompletionRequestMessageTool record { + *ChatCompletionRequestMessage; + # Tool call that this message is responding to. + string tool_call_id?; + # The contents of the message. + string? content?; +}; + +# The type of the content part. +public type ChatCompletionRequestMessageContentPartType "text"|"image_url"; + +# The type of the tool call, in this case `function`. +public type ToolCallType "function"; + +public type ChatCompletionTool record { + # The type of the tool. Currently, only `function` is supported. + ChatCompletionToolType 'type; + ChatCompletionTool_function 'function; +}; + +# An object specifying the format that the model must output. Used to enable JSON mode. +public type CreateChatCompletionRequest_response_format record { + # Setting to `json_object` enables JSON mode. This guarantees that the message the model generates is valid JSON. + ChatCompletionResponseFormat? 'type?; +}; + +# The data source to be used for the Azure OpenAI on your data feature. +public type DataSource record { + # The data source type. + string 'type; + # The parameters to be used for the data source in runtime. + record {} parameters?; +}; + +# A content line object consisting of an adjacent sequence of content elements, such as words and selection marks. +public type Line record { + # The text content of the line. + string text; + # An array of spans that represent detected objects and its bounding box information. + Span[] spans; +}; + +public type ExtensionsChatCompletionChoice record { + *ChatCompletionChoiceCommon; + # A chat message. + Message message?; + Enhancement enhancements?; +}; + +# 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. +public type ContentFilterSeverityResult record { + *ContentFilterResultBase; + # The severity level of the content filtering category. + "safe"|"low"|"medium"|"high" severity?; +}; + +public type ChatCompletionRequestMessageContentPartImage record { + *ChatCompletionRequestMessageContentPart; + # Either a URL of the image or the base64 encoded image data. + string url?; + # Specifies the detail level of the image. + ImageDetailLevel detail?; +}; + +public type ChatCompletionRequestMessageContentPartText record { + *ChatCompletionRequestMessageContentPart; + # The text content. + string text?; +}; + +# Specifies a tool the model should use. Use to force the model to call a specific function. +public type ChatCompletionNamedToolChoice record { + # The type of the tool. Currently, only `function` is supported. + "function" 'type?; + # The function that should be called. + ChatCompletionNamedToolChoice_function 'function?; +}; + # A chat message. public type Message record { # The index of the message in the conversation. @@ -85,29 +286,41 @@ public type Message record { Message_context? context?; }; -public type ChatCompletionsResponseCommon_usage record { - int prompt_tokens; - int completion_tokens; - int total_tokens; +public type ContentFilterResultBase record { + boolean filtered; }; -# Inner error with additional details. -public type InnerError record { - # Error codes for the inner error object. - InnerErrorCode code?; - # 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. - ContentFilterResults content_filter_results?; +# Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. +public type ChatCompletionFunctionCall record { + # The name of the function to call. + 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. + string arguments; }; -public type ChatCompletionRequestMessage record { - # The role of the messages author. One of `system`, `user`, `assistant`, or `function`. - "system"|"user"|"assistant"|"function" role; - # The contents of the message. `content` is required for all messages except assistant messages with function calls. - string? content; - # 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. +# A span object that represents a detected object and its bounding box information. +public type Span record { + # The text content of the span that represents the detected object. + string text; + # The character offset within the text where the span begins. This offset is defined as the position of the first character of the span, counting from the start of the text as Unicode codepoints. + int offset; + # The length of the span in characters, measured in Unicode codepoints. + int length; + # An array of objects representing points in the polygon that encloses the detected object. + Span_polygon[] polygon; +}; + +# The role of the messages author. +public type ChatCompletionRequestMessageRole "system"|"user"|"assistant"|"tool"|"function"; + +public type ChatCompletionRequestMessageFunction record { + *ChatCompletionRequestMessage; + # The role of the messages author, in this case `function`. + "function" role?; + # The contents of the message. string name?; - # The name and arguments of a function that should be called, as generated by the model. - ChatCompletionRequestMessage_function_call function_call?; + # The contents of the message. + string? content?; }; public type ChatCompletionChoiceCommon record { @@ -115,50 +328,57 @@ public type ChatCompletionChoiceCommon record { string finish_reason?; }; +public type ChatCompletionRequestMessageContentPart record { + # The type of the content part. + ChatCompletionRequestMessageContentPartType 'type; +}; + public type CreateChatCompletionRequest record { *ChatCompletionsRequestCommon; # 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). @constraint:Array {minLength: 1} - ChatCompletionRequestMessage[] messages; - # A list of functions the model may generate JSON inputs for. + ChatCompletionRequestMessage[] messages?; + # How many chat completion choices to generate for each input message. + int? n?; + # 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. + int? seed?; + # An object specifying the format that the model must output. Used to enable JSON mode. + CreateChatCompletionRequest_response_format response_format?; + # 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. @constraint:Array {minLength: 1} - ChatCompletionFunctions[] 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. + ChatCompletionTool[] tools?; + # 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 `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that function. + ChatCompletionToolChoiceOption tool_choice?; + # Deprecated in favor of `tools`. A list of functions the model may generate JSON inputs for. + @constraint:Array {maxLength: 128, minLength: 1} + ChatCompletionFunction[] functions?; + # Deprecated in favor of `tool_choice`. 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. "none"|"auto"|record { # The name of the function to call. string name; } function_call?; - # How many chat completion choices to generate for each input message. - int? n = 1; }; public type ChatCompletionsResponseCommon record { + # A unique identifier for the chat completion. string id; - string 'object; + # The object type. + ChatCompletionResponseObject 'object; + # The Unix timestamp (in seconds) of when the chat completion was created. int created; + # The model used for the chat completion. string model; - ChatCompletionsResponseCommon_usage usage?; -}; - -# 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. -public type ContentFilterResults record { - # Information about the content filtering category including 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. - ContentFilterResult sexual?; - # Information about the content filtering category including 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. - ContentFilterResult violence?; - # Information about the content filtering category including 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. - ContentFilterResult hate?; - # Information about the content filtering category including 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. - ContentFilterResult self_harm?; - # Error information returned by the service. - ErrorBase 'error?; + # Usage statistics for the completion request. + CompletionUsage usage?; + # Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism. + string system_fingerprint?; }; -# Error information returned by the service. +# Error response object. public type ErrorBase record { - # The error code. + # Error code. string code?; - # The error message. + # A human-readable representation of the error. string message?; }; @@ -187,30 +407,41 @@ public type ChatCompletionsRequestCommon record { string user?; }; -# The name and arguments of a function that should be called, as generated by the model. -public type ChatCompletionRequestMessage_function_call record { - # The name of the function to call. - 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. - string arguments?; +# The role of the author of the response message. +public type ChatCompletionResponseMessageRole "assistant"; + +# Usage statistics for the completion request. +public type CompletionUsage record { + # Number of tokens in the prompt. + int prompt_tokens; + # Number of tokens in the generated completion. + int completion_tokens; + # Total number of tokens used in the request (prompt + completion). + int total_tokens; }; +# The object type. +public type ChatCompletionResponseObject "chat.completion"; + # The response of the extensions chat completions. public type ExtensionsChatCompletionsResponse record { *ChatCompletionsResponseCommon; - # A list of chat completion choices. + # The chat completion choices. ExtensionsChatCompletionChoice[] choices?; }; -# Error codes for the inner error object. -public type InnerErrorCode "ResponsibleAIPolicyViolation"; +# The function that should be called. +public type ChatCompletionNamedToolChoice_function record { + # The name of the function to call. + string name; +}; # Content filtering results for a single prompt in the request. public type PromptFilterResult record { - # The index of the prompt in the set of prompt results. + # The index of the prompt in the request. int prompt_index?; - # 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. - ContentFilterResults content_filter_results?; + # 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. + ContentFilterPromptResults content_filter_results?; }; # 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. @@ -218,44 +449,57 @@ public type PromptFilterResults PromptFilterResult[]; public type CreateChatCompletionResponse record { *ChatCompletionsResponseCommon; + # 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. + PromptFilterResults prompt_filter_results?; record { *ChatCompletionChoiceCommon; + # A chat completion message generated by the model. ChatCompletionResponseMessage message?; - # 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. - ContentFilterResults content_filter_results?; - }[] choices; + # 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. + ContentFilterChoiceResults content_filter_results?; + }[] choices?; }; public type Error ErrorBase; -public type ChatCompletionFunctions record { - # 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. - string name; - # The description of what the function does. - 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. - ChatCompletionFunctionParameters parameters?; +public type ChatCompletionMessageToolCall record { + # The ID of the tool call. + string id; + # The type of the tool call, in this case `function`. + ToolCallType 'type; + # The function that the model called. + ChatCompletionMessageToolCall_function 'function; }; public type ErrorResponse record { Error 'error?; }; -# The data source to be used for the Azure OpenAI on your data feature. -public type DataSource record { - # The data source type. - string 'type; - # The parameters to be used for the data source in runtime. - record {} parameters?; +# Detected content filtering results with citation +public type ContentFilterDetectedWithCitationResult record { + *ContentFilterDetectedResult; + # The citation of the detected content. + ContentFilterDetectedWithCitationResult_citation citation?; }; +# A chat completion message generated by the model. public type ChatCompletionResponseMessage record { - # The role of the author of this message. - "system"|"user"|"assistant"|"function" role; + # The role of the author of the response message. + ChatCompletionResponseMessageRole role?; # The contents of the message. - string content?; - # The name and arguments of a function that should be called, as generated by the model. - ChatCompletionRequestMessage_function_call function_call?; + string? content?; + # The tool calls generated by the model, such as function calls. + ChatCompletionMessageToolCall[] tool_calls?; + # Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. + ChatCompletionFunctionCall function_call?; +}; + +# The citation of the detected content. +public type ContentFilterDetectedWithCitationResult_citation record { + # The URL of the citation of detected content. + string URL?; + # The license of the citation of detected content. + string license?; }; # The conversation context @@ -264,29 +508,50 @@ public type Message_context record { Message[]? messages?; }; -# Information about the content filtering category including 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. -public type ContentFilterResult record { - # The severity level of the content filter result. - "safe"|"low"|"medium"|"high" severity; - # Whether the content filter result has been filtered or not. - boolean filtered; +# Request object to specify if ocr enhancement is needed. +public type ExtensionsChatCompletionsRequest_enhancements_ocr record { + # If ocr enhancement is enabled. + boolean enabled?; }; # Request for the chat completions using extensions public type ExtensionsChatCompletionsRequest record { *ChatCompletionsRequestCommon; - # 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). - Message[] messages; + # A list of messages comprising the conversation so far. + Message[] messages?; # The data sources to be used for the Azure OpenAI on your data feature. DataSource[] dataSources?; + # The type of enhancements needed. + ExtensionsChatCompletionsRequest_enhancements enhancements?; }; -public type ExtensionsChatCompletionChoice record { - *ChatCompletionChoiceCommon; - # A chat message. - Message message?; +# Specifies the detail level of the image. +public type ImageDetailLevel "auto"|"low"|"high"; + +public type ChatCompletionTool_function record { + # A description of what the function does, used by the model to choose when and how to call the function. + string description?; + # 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. + string name; + # 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. + ChatCompletionFunctionParameters parameters; +}; + +public type ChatCompletionFunction record { + # 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. + string name; + # The description of what the function does. + 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. + ChatCompletionFunctionParameters parameters?; }; # 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. public type ChatCompletionFunctionParameters record { }; + +# The grounding enhancement that returns the bounding box of the objects detected in the image. +public type Enhancement_grounding record { + # An array of lines that represent the detected objects and its bounding box information. + Line[] lines; +}; diff --git a/openapi/azure.openai.chat/utils.bal b/openapi/azure.openai.chat/utils.bal index 29d80caaa..10412d703 100644 --- a/openapi/azure.openai.chat/utils.bal +++ b/openapi/azure.openai.chat/utils.bal @@ -1,6 +1,5 @@ // AUTO-GENERATED FILE. DO NOT MODIFY. // This file is auto-generated by the Ballerina OpenAPI tool. - import ballerina/url; type SimpleBasicType string|boolean|int|float|decimal; From d3dc6421cebcdd2e7810715a53371f33b533b9be Mon Sep 17 00:00:00 2001 From: "Nadheesh Jihan, nadheesh@wso2.com" Date: Tue, 30 Jan 2024 17:27:32 +0530 Subject: [PATCH 3/4] Add ballerina x-tags --- openapi/azure.openai.chat/client.bal | 7 ++++- openapi/azure.openai.chat/openapi.yaml | 12 +++++++- openapi/azure.openai.chat/types.bal | 1 + openapi/azure.openai.chat/utils.bal | 1 + openapi/openai.chat/client.bal | 5 +++- openapi/openai.chat/openapi.yaml | 10 +++++-- openapi/openai.chat/types.bal | 41 +++++++++++++------------- openapi/openai.chat/utils.bal | 1 + 8 files changed, 53 insertions(+), 25 deletions(-) diff --git a/openapi/azure.openai.chat/client.bal b/openapi/azure.openai.chat/client.bal index 943900a38..850e57a1b 100644 --- a/openapi/azure.openai.chat/client.bal +++ b/openapi/azure.openai.chat/client.bal @@ -1,12 +1,17 @@ // AUTO-GENERATED FILE. DO NOT MODIFY. // This file is auto-generated by the Ballerina OpenAPI tool. + import ballerina/http; -# Azure OpenAI APIs for completions and search +# This is a generated connector from [Azure OpenAI Chat Completions API v2023-12-01-preview](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#chat-completions/) OpenAPI specification. +# The Azure Azure OpenAI Service REST API Chat Completions Endpoint will create completions for chat messages with the ChatGPT (preview) and GPT-4 (preview) models. +@display {label: "Azure OpenAI Chat", iconPath: "icon.png"} public isolated client class Client { final http:Client clientEp; final readonly & ApiKeysConfig? apiKeyConfig; # Gets invoked to initialize the `connector`. + # The connector initialization requires setting the API credentials. + # Create an [Azure](https://azure.microsoft.com/en-us/features/azure-portal/) account, an [Azure OpenAI resource with a model deployed](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource) and refer [this guide](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#authentication) to learn how to generate and use tokens # # + config - The configurations to be used when initializing the `connector` # + serviceUrl - URL of the target service diff --git a/openapi/azure.openai.chat/openapi.yaml b/openapi/azure.openai.chat/openapi.yaml index 701fae0e4..6aace7f58 100644 --- a/openapi/azure.openai.chat/openapi.yaml +++ b/openapi/azure.openai.chat/openapi.yaml @@ -1,7 +1,17 @@ openapi: 3.0.0 info: + x-ballerina-display: + label: Azure OpenAI Chat + iconPath: "icon.png" title: Azure OpenAI Service API - description: Azure OpenAI APIs for completions and search + description: > + This is a generated connector from [Azure OpenAI Chat Completions API v2023-12-01-preview](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#chat-completions/) OpenAPI specification. + + The Azure Azure OpenAI Service REST API Chat Completions Endpoint will create completions for chat messages with the ChatGPT (preview) and GPT-4 (preview) models. + x-ballerina-init-description: > + The connector initialization requires setting the API credentials. + + Create an [Azure](https://azure.microsoft.com/en-us/features/azure-portal/) account, an [Azure OpenAI resource with a model deployed](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource) and refer [this guide](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#authentication) to learn how to generate and use tokens version: 2023-12-01-preview servers: - url: https://{endpoint}/openai diff --git a/openapi/azure.openai.chat/types.bal b/openapi/azure.openai.chat/types.bal index f7e883ed9..dcb616f38 100644 --- a/openapi/azure.openai.chat/types.bal +++ b/openapi/azure.openai.chat/types.bal @@ -1,5 +1,6 @@ // AUTO-GENERATED FILE. DO NOT MODIFY. // This file is auto-generated by the Ballerina OpenAPI tool. + import ballerina/constraint; import ballerina/http; diff --git a/openapi/azure.openai.chat/utils.bal b/openapi/azure.openai.chat/utils.bal index 10412d703..29d80caaa 100644 --- a/openapi/azure.openai.chat/utils.bal +++ b/openapi/azure.openai.chat/utils.bal @@ -1,5 +1,6 @@ // AUTO-GENERATED FILE. DO NOT MODIFY. // This file is auto-generated by the Ballerina OpenAPI tool. + import ballerina/url; type SimpleBasicType string|boolean|int|float|decimal; diff --git a/openapi/openai.chat/client.bal b/openapi/openai.chat/client.bal index c73de05ee..fb39a252f 100644 --- a/openapi/openai.chat/client.bal +++ b/openapi/openai.chat/client.bal @@ -1,11 +1,14 @@ // AUTO-GENERATED FILE. DO NOT MODIFY. // This file is auto-generated by the Ballerina OpenAPI tool. + import ballerina/http; -# The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details. +# This is a generated connector for the [OpenAI API] (https://platform.openai.com/docs/api-reference/introduction) specification. Use the OpenAI API to access the state-of-the-art language models that can complete sentences, transcribe audio, and generate images. The API also supports natural language processing tasks such as text classification, entity recognition, and sentiment analysis. By using the OpenAI API, you can incorporate advanced AI capabilities into your own applications and services. +@display {label: "OpenAI Chat", iconPath: "icon.png"} public isolated client class Client { final http:Client clientEp; # Gets invoked to initialize the `connector`. + # To use the OpenAI API, you will need an API key. You can sign up for an API key by creating an [account](https://beta.openai.com/signup/) on the OpenAI website and following the [provided instructions](https://platform.openai.com/docs/api-reference/authentication). # # + config - The configurations to be used when initializing the `connector` # + serviceUrl - URL of the target service diff --git a/openapi/openai.chat/openapi.yaml b/openapi/openai.chat/openapi.yaml index 4ed78c4e9..1c2c0e85b 100644 --- a/openapi/openai.chat/openapi.yaml +++ b/openapi/openai.chat/openapi.yaml @@ -1,8 +1,14 @@ openapi: 3.0.0 info: title: OpenAI API - description: The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details. - version: 2.0.0 + version: '2.0.0' + x-ballerina-display: + label: OpenAI Chat + iconPath: "icon.png" + description: >- + This is a generated connector for the [OpenAI API] (https://platform.openai.com/docs/api-reference/introduction) specification. Use the OpenAI API to access the state-of-the-art language models that can complete sentences, transcribe audio, and generate images. The API also supports natural language processing tasks such as text classification, entity recognition, and sentiment analysis. By using the OpenAI API, you can incorporate advanced AI capabilities into your own applications and services. + x-ballerina-init-description: >- + To use the OpenAI API, you will need an API key. You can sign up for an API key by creating an [account](https://beta.openai.com/signup/) on the OpenAI website and following the [provided instructions](https://platform.openai.com/docs/api-reference/authentication). termsOfService: https://openai.com/policies/terms-of-use contact: name: OpenAI Support diff --git a/openapi/openai.chat/types.bal b/openapi/openai.chat/types.bal index 01d2bc286..97e1cbf80 100644 --- a/openapi/openai.chat/types.bal +++ b/openapi/openai.chat/types.bal @@ -1,5 +1,6 @@ // AUTO-GENERATED FILE. DO NOT MODIFY. // This file is auto-generated by the Ballerina OpenAPI tool. + import ballerina/constraint; import ballerina/http; @@ -70,7 +71,7 @@ public type ChatCompletionNamedToolChoice record { }; # Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. -# +# # # Deprecated @deprecated public type ChatCompletionRequestAssistantMessage_function_call record { @@ -113,7 +114,7 @@ public type FunctionObject record { # 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. string name; # The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/text-generation/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. FunctionParameters parameters?; }; @@ -135,11 +136,11 @@ public type CreateChatCompletionRequest record { # 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. string|"gpt-4-0125-preview"|"gpt-4-turbo-preview"|"gpt-4-1106-preview"|"gpt-4-vision-preview"|"gpt-4"|"gpt-4-0314"|"gpt-4-0613"|"gpt-4-32k"|"gpt-4-32k-0314"|"gpt-4-32k-0613"|"gpt-3.5-turbo"|"gpt-3.5-turbo-16k"|"gpt-3.5-turbo-0301"|"gpt-3.5-turbo-0613"|"gpt-3.5-turbo-1106"|"gpt-3.5-turbo-16k-0613" model; # 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. - # + # # [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) decimal? frequency_penalty = 0; # 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. record {|int...;|}? logit_bias?; # 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`. This option is currently not available on the `gpt-4-vision-preview` model. @@ -147,19 +148,19 @@ public type CreateChatCompletionRequest record { # An integer between 0 and 5 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. int? top_logprobs?; # 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. int? max_tokens?; # 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. int? n = 1; # 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. - # + # # [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) decimal? presence_penalty = 0; # An object specifying the format that the model must output. Compatible with [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and `gpt-3.5-turbo-1106`. - # + # # 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. CreateChatCompletionRequest_response_format response_format?; # This feature is in Beta. @@ -171,11 +172,11 @@ public type CreateChatCompletionRequest record { # 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). boolean? 'stream = false; # 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. decimal? temperature = 1; # 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. decimal? top_p = 1; # 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. @@ -184,22 +185,22 @@ public type CreateChatCompletionRequest record { # `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 `{"type": "function", "function": {"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. ChatCompletionToolChoiceOption tool_choice?; # A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids). string user?; # 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. "none"|"auto"|ChatCompletionFunctionCallOption function_call?; # Deprecated in favor of `tools`. - # + # # A list of functions the model may generate JSON inputs for. @constraint:Array {maxLength: 128, minLength: 1} ChatCompletionFunctions[] functions?; @@ -228,7 +229,7 @@ public type ChatCompletionRequestAssistantMessage record { # `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 `{"type": "function", "function": {"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. public type ChatCompletionToolChoiceOption "none"|"auto"|ChatCompletionNamedToolChoice; @@ -271,7 +272,7 @@ public type CreateChatCompletionResponse record { # The model used for the chat completion. string model; # 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. string system_fingerprint?; # The object type, which is always `chat.completion`. @@ -312,7 +313,7 @@ public type ChatCompletionFunctions record { # 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. string name; # The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/text-generation/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. FunctionParameters parameters?; }; @@ -349,9 +350,9 @@ public type ChatCompletionRequestMessageContentPartImage_image_url record { }; # An object specifying the format that the model must output. Compatible with [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and `gpt-3.5-turbo-1106`. -# +# # 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. public type CreateChatCompletionRequest_response_format record { # Must be one of `text` or `json_object`. @@ -396,7 +397,7 @@ public type ChatCompletionRequestMessageContentPartText record { }; # The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/text-generation/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 type FunctionParameters record { }; diff --git a/openapi/openai.chat/utils.bal b/openapi/openai.chat/utils.bal index 49c38c165..7c3856fba 100644 --- a/openapi/openai.chat/utils.bal +++ b/openapi/openai.chat/utils.bal @@ -1,5 +1,6 @@ // AUTO-GENERATED FILE. DO NOT MODIFY. // This file is auto-generated by the Ballerina OpenAPI tool. + import ballerina/url; # Get Encoded URI for a given value. From acb85dfbdeb67b52846e1c402bdbc2596665bb18 Mon Sep 17 00:00:00 2001 From: "Nadheesh Jihan, nadheesh@wso2.com" Date: Tue, 30 Jan 2024 17:29:33 +0530 Subject: [PATCH 4/4] Add license headers --- openapi/azure.openai.chat/client.bal | 18 +++++++-- openapi/azure.openai.chat/types.bal | 18 +++++++-- openapi/azure.openai.chat/utils.bal | 18 +++++++-- openapi/openai.chat/client.bal | 18 +++++++-- openapi/openai.chat/types.bal | 58 +++++++++++++++++----------- openapi/openai.chat/utils.bal | 18 +++++++-- 6 files changed, 110 insertions(+), 38 deletions(-) diff --git a/openapi/azure.openai.chat/client.bal b/openapi/azure.openai.chat/client.bal index 850e57a1b..1ad7c9f2e 100644 --- a/openapi/azure.openai.chat/client.bal +++ b/openapi/azure.openai.chat/client.bal @@ -1,6 +1,18 @@ -// AUTO-GENERATED FILE. DO NOT MODIFY. -// This file is auto-generated by the Ballerina OpenAPI tool. - +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. import ballerina/http; # This is a generated connector from [Azure OpenAI Chat Completions API v2023-12-01-preview](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#chat-completions/) OpenAPI specification. diff --git a/openapi/azure.openai.chat/types.bal b/openapi/azure.openai.chat/types.bal index dcb616f38..b3c53895b 100644 --- a/openapi/azure.openai.chat/types.bal +++ b/openapi/azure.openai.chat/types.bal @@ -1,6 +1,18 @@ -// AUTO-GENERATED FILE. DO NOT MODIFY. -// This file is auto-generated by the Ballerina OpenAPI tool. - +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. import ballerina/constraint; import ballerina/http; diff --git a/openapi/azure.openai.chat/utils.bal b/openapi/azure.openai.chat/utils.bal index 29d80caaa..d8ae77d81 100644 --- a/openapi/azure.openai.chat/utils.bal +++ b/openapi/azure.openai.chat/utils.bal @@ -1,6 +1,18 @@ -// AUTO-GENERATED FILE. DO NOT MODIFY. -// This file is auto-generated by the Ballerina OpenAPI tool. - +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. import ballerina/url; type SimpleBasicType string|boolean|int|float|decimal; diff --git a/openapi/openai.chat/client.bal b/openapi/openai.chat/client.bal index fb39a252f..b5270fa39 100644 --- a/openapi/openai.chat/client.bal +++ b/openapi/openai.chat/client.bal @@ -1,6 +1,18 @@ -// AUTO-GENERATED FILE. DO NOT MODIFY. -// This file is auto-generated by the Ballerina OpenAPI tool. - +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. import ballerina/http; # This is a generated connector for the [OpenAI API] (https://platform.openai.com/docs/api-reference/introduction) specification. Use the OpenAI API to access the state-of-the-art language models that can complete sentences, transcribe audio, and generate images. The API also supports natural language processing tasks such as text classification, entity recognition, and sentiment analysis. By using the OpenAI API, you can incorporate advanced AI capabilities into your own applications and services. diff --git a/openapi/openai.chat/types.bal b/openapi/openai.chat/types.bal index 97e1cbf80..704a984bb 100644 --- a/openapi/openai.chat/types.bal +++ b/openapi/openai.chat/types.bal @@ -1,6 +1,18 @@ -// AUTO-GENERATED FILE. DO NOT MODIFY. -// This file is auto-generated by the Ballerina OpenAPI tool. - +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. import ballerina/constraint; import ballerina/http; @@ -71,7 +83,7 @@ public type ChatCompletionNamedToolChoice record { }; # Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model. -# +# # # Deprecated @deprecated public type ChatCompletionRequestAssistantMessage_function_call record { @@ -114,7 +126,7 @@ public type FunctionObject record { # 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. string name; # The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/text-generation/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. FunctionParameters parameters?; }; @@ -136,11 +148,11 @@ public type CreateChatCompletionRequest record { # 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. string|"gpt-4-0125-preview"|"gpt-4-turbo-preview"|"gpt-4-1106-preview"|"gpt-4-vision-preview"|"gpt-4"|"gpt-4-0314"|"gpt-4-0613"|"gpt-4-32k"|"gpt-4-32k-0314"|"gpt-4-32k-0613"|"gpt-3.5-turbo"|"gpt-3.5-turbo-16k"|"gpt-3.5-turbo-0301"|"gpt-3.5-turbo-0613"|"gpt-3.5-turbo-1106"|"gpt-3.5-turbo-16k-0613" model; # 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. - # + # # [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) decimal? frequency_penalty = 0; # 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. record {|int...;|}? logit_bias?; # 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`. This option is currently not available on the `gpt-4-vision-preview` model. @@ -148,19 +160,19 @@ public type CreateChatCompletionRequest record { # An integer between 0 and 5 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. int? top_logprobs?; # 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. int? max_tokens?; # 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. int? n = 1; # 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. - # + # # [See more information about frequency and presence penalties.](/docs/guides/text-generation/parameter-details) decimal? presence_penalty = 0; # An object specifying the format that the model must output. Compatible with [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and `gpt-3.5-turbo-1106`. - # + # # 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. CreateChatCompletionRequest_response_format response_format?; # This feature is in Beta. @@ -172,11 +184,11 @@ public type CreateChatCompletionRequest record { # 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). boolean? 'stream = false; # 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. decimal? temperature = 1; # 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. decimal? top_p = 1; # 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. @@ -185,22 +197,22 @@ public type CreateChatCompletionRequest record { # `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 `{"type": "function", "function": {"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. ChatCompletionToolChoiceOption tool_choice?; # A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids). string user?; # 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. "none"|"auto"|ChatCompletionFunctionCallOption function_call?; # Deprecated in favor of `tools`. - # + # # A list of functions the model may generate JSON inputs for. @constraint:Array {maxLength: 128, minLength: 1} ChatCompletionFunctions[] functions?; @@ -229,7 +241,7 @@ public type ChatCompletionRequestAssistantMessage record { # `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 `{"type": "function", "function": {"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. public type ChatCompletionToolChoiceOption "none"|"auto"|ChatCompletionNamedToolChoice; @@ -272,7 +284,7 @@ public type CreateChatCompletionResponse record { # The model used for the chat completion. string model; # 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. string system_fingerprint?; # The object type, which is always `chat.completion`. @@ -313,7 +325,7 @@ public type ChatCompletionFunctions record { # 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. string name; # The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/text-generation/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. FunctionParameters parameters?; }; @@ -350,9 +362,9 @@ public type ChatCompletionRequestMessageContentPartImage_image_url record { }; # An object specifying the format that the model must output. Compatible with [GPT-4 Turbo](/docs/models/gpt-4-and-gpt-4-turbo) and `gpt-3.5-turbo-1106`. -# +# # 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. public type CreateChatCompletionRequest_response_format record { # Must be one of `text` or `json_object`. @@ -397,7 +409,7 @@ public type ChatCompletionRequestMessageContentPartText record { }; # The parameters the functions accepts, described as a JSON Schema object. See the [guide](/docs/guides/text-generation/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 type FunctionParameters record { }; diff --git a/openapi/openai.chat/utils.bal b/openapi/openai.chat/utils.bal index 7c3856fba..a93f7c176 100644 --- a/openapi/openai.chat/utils.bal +++ b/openapi/openai.chat/utils.bal @@ -1,6 +1,18 @@ -// AUTO-GENERATED FILE. DO NOT MODIFY. -// This file is auto-generated by the Ballerina OpenAPI tool. - +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. import ballerina/url; # Get Encoded URI for a given value.