From 6fb8083838aae08b878b351deb78dd3b62dc8a00 Mon Sep 17 00:00:00 2001 From: hahuyhoang411 Date: Tue, 21 Nov 2023 14:11:24 +0700 Subject: [PATCH 01/13] fix navi --- docs/docusaurus.config.js | 9 +- docs/openapi/jan.json | 673 +++ docs/openapi/jan.yaml | 9738 ------------------------------------- docs/openapi/janapi.yaml | 0 docs/src/styles/base.scss | 3 - 5 files changed, 680 insertions(+), 9743 deletions(-) create mode 100644 docs/openapi/jan.json delete mode 100644 docs/openapi/jan.yaml create mode 100644 docs/openapi/janapi.yaml diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index 09757c67a..a0f96ed6d 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -25,7 +25,7 @@ const config = { onBrokenLinks: "warn", onBrokenMarkdownLinks: "warn", - + trailingSlash: true, // Even if you don't use internalization, you can use this field to set useful // metadata like html lang. For example, if your site is Chinese, you may want // to replace "en" with "zh-Hans". @@ -103,13 +103,18 @@ const config = { { specs: [ { - spec: "openapi/jan.yaml", // can be local file, url, or parsed json object + spec: "openapi/jan.json", // can be local file, url, or parsed json object route: "/api-reference", // path where to render docs }, ], theme: { primaryColor: "#1a73e8", primaryColorDark: "#1a73e8", + options: { + disableSearch: true, + requiredPropsFirst: true, + noAutoAuth: true + }, // redocOptions: { hideDownloadButton: false }, }, }, diff --git a/docs/openapi/jan.json b/docs/openapi/jan.json new file mode 100644 index 000000000..0cc3d8603 --- /dev/null +++ b/docs/openapi/jan.json @@ -0,0 +1,673 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.", + "version": "1.0.6", + "title": "Swagger Petstore", + "termsOfService": "http://swagger.io/terms/", + "contact": { "email": "apiteam@swagger.io" }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "petstore.swagger.io", + "basePath": "/v2", + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { "name": "store", "description": "Access to Petstore orders" }, + { + "name": "user", + "description": "Operations about user", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "schemes": ["https", "http"], + "paths": { + "/pet/{petId}/uploadImage": { + "post": { + "tags": ["pet"], + "summary": "uploads an image", + "description": "", + "operationId": "uploadFile", + "consumes": ["multipart/form-data"], + "produces": ["application/json"], + "parameters": [ + { + "name": "petId", + "in": "path", + "description": "ID of pet to update", + "required": true, + "type": "integer", + "format": "int64" + }, + { + "name": "additionalMetadata", + "in": "formData", + "description": "Additional data to pass to server", + "required": false, + "type": "string" + }, + { + "name": "file", + "in": "formData", + "description": "file to upload", + "required": false, + "type": "file" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { "$ref": "#/definitions/ApiResponse" } + } + }, + "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] + } + }, + "/pet": { + "post": { + "tags": ["pet"], + "summary": "Add a new pet to the store", + "description": "", + "operationId": "addPet", + "consumes": ["application/json", "application/xml"], + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { "$ref": "#/definitions/Pet" } + } + ], + "responses": { "405": { "description": "Invalid input" } }, + "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] + }, + "put": { + "tags": ["pet"], + "summary": "Update an existing pet", + "description": "", + "operationId": "updatePet", + "consumes": ["application/json", "application/xml"], + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Pet object that needs to be added to the store", + "required": true, + "schema": { "$ref": "#/definitions/Pet" } + } + ], + "responses": { + "400": { "description": "Invalid ID supplied" }, + "404": { "description": "Pet not found" }, + "405": { "description": "Validation exception" } + }, + "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] + } + }, + "/pet/findByStatus": { + "get": { + "tags": ["pet"], + "summary": "Finds Pets by status", + "description": "Multiple status values can be provided with comma separated strings", + "operationId": "findPetsByStatus", + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "name": "status", + "in": "query", + "description": "Status values that need to be considered for filter", + "required": true, + "type": "array", + "items": { + "type": "string", + "enum": ["available", "pending", "sold"], + "default": "available" + }, + "collectionFormat": "multi" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "array", + "items": { "$ref": "#/definitions/Pet" } + } + }, + "400": { "description": "Invalid status value" } + }, + "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] + } + }, + "/pet/findByTags": { + "get": { + "tags": ["pet"], + "summary": "Finds Pets by tags", + "description": "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + "operationId": "findPetsByTags", + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "name": "tags", + "in": "query", + "description": "Tags to filter by", + "required": true, + "type": "array", + "items": { "type": "string" }, + "collectionFormat": "multi" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "array", + "items": { "$ref": "#/definitions/Pet" } + } + }, + "400": { "description": "Invalid tag value" } + }, + "security": [{ "petstore_auth": ["write:pets", "read:pets"] }], + "deprecated": true + } + }, + "/pet/{petId}": { + "get": { + "tags": ["pet"], + "summary": "Find pet by ID", + "description": "Returns a single pet", + "operationId": "getPetById", + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "name": "petId", + "in": "path", + "description": "ID of pet to return", + "required": true, + "type": "integer", + "format": "int64" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { "$ref": "#/definitions/Pet" } + }, + "400": { "description": "Invalid ID supplied" }, + "404": { "description": "Pet not found" } + }, + "security": [{ "api_key": [] }] + }, + "post": { + "tags": ["pet"], + "summary": "Updates a pet in the store with form data", + "description": "", + "operationId": "updatePetWithForm", + "consumes": ["application/x-www-form-urlencoded"], + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "name": "petId", + "in": "path", + "description": "ID of pet that needs to be updated", + "required": true, + "type": "integer", + "format": "int64" + }, + { + "name": "name", + "in": "formData", + "description": "Updated name of the pet", + "required": false, + "type": "string" + }, + { + "name": "status", + "in": "formData", + "description": "Updated status of the pet", + "required": false, + "type": "string" + } + ], + "responses": { "405": { "description": "Invalid input" } }, + "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] + }, + "delete": { + "tags": ["pet"], + "summary": "Deletes a pet", + "description": "", + "operationId": "deletePet", + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "name": "api_key", + "in": "header", + "required": false, + "type": "string" + }, + { + "name": "petId", + "in": "path", + "description": "Pet id to delete", + "required": true, + "type": "integer", + "format": "int64" + } + ], + "responses": { + "400": { "description": "Invalid ID supplied" }, + "404": { "description": "Pet not found" } + }, + "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] + } + }, + "/store/order": { + "post": { + "tags": ["store"], + "summary": "Place an order for a pet", + "description": "", + "operationId": "placeOrder", + "consumes": ["application/json"], + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "order placed for purchasing the pet", + "required": true, + "schema": { "$ref": "#/definitions/Order" } + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { "$ref": "#/definitions/Order" } + }, + "400": { "description": "Invalid Order" } + } + } + }, + "/store/order/{orderId}": { + "get": { + "tags": ["store"], + "summary": "Find purchase order by ID", + "description": "For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions", + "operationId": "getOrderById", + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "name": "orderId", + "in": "path", + "description": "ID of pet that needs to be fetched", + "required": true, + "type": "integer", + "maximum": 10, + "minimum": 1, + "format": "int64" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { "$ref": "#/definitions/Order" } + }, + "400": { "description": "Invalid ID supplied" }, + "404": { "description": "Order not found" } + } + }, + "delete": { + "tags": ["store"], + "summary": "Delete purchase order by ID", + "description": "For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors", + "operationId": "deleteOrder", + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "name": "orderId", + "in": "path", + "description": "ID of the order that needs to be deleted", + "required": true, + "type": "integer", + "minimum": 1, + "format": "int64" + } + ], + "responses": { + "400": { "description": "Invalid ID supplied" }, + "404": { "description": "Order not found" } + } + } + }, + "/store/inventory": { + "get": { + "tags": ["store"], + "summary": "Returns pet inventories by status", + "description": "Returns a map of status codes to quantities", + "operationId": "getInventory", + "produces": ["application/json"], + "parameters": [], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { "type": "integer", "format": "int32" } + } + } + }, + "security": [{ "api_key": [] }] + } + }, + "/user/createWithArray": { + "post": { + "tags": ["user"], + "summary": "Creates list of users with given input array", + "description": "", + "operationId": "createUsersWithArrayInput", + "consumes": ["application/json"], + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "List of user object", + "required": true, + "schema": { + "type": "array", + "items": { "$ref": "#/definitions/User" } + } + } + ], + "responses": { "default": { "description": "successful operation" } } + } + }, + "/user/createWithList": { + "post": { + "tags": ["user"], + "summary": "Creates list of users with given input array", + "description": "", + "operationId": "createUsersWithListInput", + "consumes": ["application/json"], + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "List of user object", + "required": true, + "schema": { + "type": "array", + "items": { "$ref": "#/definitions/User" } + } + } + ], + "responses": { "default": { "description": "successful operation" } } + } + }, + "/user/{username}": { + "get": { + "tags": ["user"], + "summary": "Get user by user name", + "description": "", + "operationId": "getUserByName", + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "name": "username", + "in": "path", + "description": "The name that needs to be fetched. Use user1 for testing. ", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { "$ref": "#/definitions/User" } + }, + "400": { "description": "Invalid username supplied" }, + "404": { "description": "User not found" } + } + }, + "put": { + "tags": ["user"], + "summary": "Updated user", + "description": "This can only be done by the logged in user.", + "operationId": "updateUser", + "consumes": ["application/json"], + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "name": "username", + "in": "path", + "description": "name that need to be updated", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "body", + "description": "Updated user object", + "required": true, + "schema": { "$ref": "#/definitions/User" } + } + ], + "responses": { + "400": { "description": "Invalid user supplied" }, + "404": { "description": "User not found" } + } + }, + "delete": { + "tags": ["user"], + "summary": "Delete user", + "description": "This can only be done by the logged in user.", + "operationId": "deleteUser", + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "name": "username", + "in": "path", + "description": "The name that needs to be deleted", + "required": true, + "type": "string" + } + ], + "responses": { + "400": { "description": "Invalid username supplied" }, + "404": { "description": "User not found" } + } + } + }, + "/user/login": { + "get": { + "tags": ["user"], + "summary": "Logs user into the system", + "description": "", + "operationId": "loginUser", + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "name": "username", + "in": "query", + "description": "The user name for login", + "required": true, + "type": "string" + }, + { + "name": "password", + "in": "query", + "description": "The password for login in clear text", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "headers": { + "X-Expires-After": { + "type": "string", + "format": "date-time", + "description": "date in UTC when token expires" + }, + "X-Rate-Limit": { + "type": "integer", + "format": "int32", + "description": "calls per hour allowed by the user" + } + }, + "schema": { "type": "string" } + }, + "400": { "description": "Invalid username/password supplied" } + } + } + }, + "/user/logout": { + "get": { + "tags": ["user"], + "summary": "Logs out current logged in user session", + "description": "", + "operationId": "logoutUser", + "produces": ["application/json", "application/xml"], + "parameters": [], + "responses": { "default": { "description": "successful operation" } } + } + }, + "/user": { + "post": { + "tags": ["user"], + "summary": "Create user", + "description": "This can only be done by the logged in user.", + "operationId": "createUser", + "consumes": ["application/json"], + "produces": ["application/json", "application/xml"], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "Created user object", + "required": true, + "schema": { "$ref": "#/definitions/User" } + } + ], + "responses": { "default": { "description": "successful operation" } } + } + } + }, + "securityDefinitions": { + "api_key": { "type": "apiKey", "name": "api_key", "in": "header" }, + "petstore_auth": { + "type": "oauth2", + "authorizationUrl": "https://petstore.swagger.io/oauth/authorize", + "flow": "implicit", + "scopes": { + "read:pets": "read your pets", + "write:pets": "modify pets in your account" + } + } + }, + "definitions": { + "ApiResponse": { + "type": "object", + "properties": { + "code": { "type": "integer", "format": "int32" }, + "type": { "type": "string" }, + "message": { "type": "string" } + } + }, + "Category": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64" }, + "name": { "type": "string" } + }, + "xml": { "name": "Category" } + }, + "Pet": { + "type": "object", + "required": ["name", "photoUrls"], + "properties": { + "id": { "type": "integer", "format": "int64" }, + "category": { "$ref": "#/definitions/Category" }, + "name": { "type": "string", "example": "doggie" }, + "photoUrls": { + "type": "array", + "xml": { "wrapped": true }, + "items": { "type": "string", "xml": { "name": "photoUrl" } } + }, + "tags": { + "type": "array", + "xml": { "wrapped": true }, + "items": { "xml": { "name": "tag" }, "$ref": "#/definitions/Tag" } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": ["available", "pending", "sold"] + } + }, + "xml": { "name": "Pet" } + }, + "Tag": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64" }, + "name": { "type": "string" } + }, + "xml": { "name": "Tag" } + }, + "Order": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64" }, + "petId": { "type": "integer", "format": "int64" }, + "quantity": { "type": "integer", "format": "int32" }, + "shipDate": { "type": "string", "format": "date-time" }, + "status": { + "type": "string", + "description": "Order Status", + "enum": ["placed", "approved", "delivered"] + }, + "complete": { "type": "boolean" } + }, + "xml": { "name": "Order" } + }, + "User": { + "type": "object", + "properties": { + "id": { "type": "integer", "format": "int64" }, + "username": { "type": "string" }, + "firstName": { "type": "string" }, + "lastName": { "type": "string" }, + "email": { "type": "string" }, + "password": { "type": "string" }, + "phone": { "type": "string" }, + "userStatus": { + "type": "integer", + "format": "int32", + "description": "User Status" + } + }, + "xml": { "name": "User" } + } + }, + "externalDocs": { + "description": "Find out more about Swagger", + "url": "http://swagger.io" + } +} \ No newline at end of file diff --git a/docs/openapi/jan.yaml b/docs/openapi/jan.yaml deleted file mode 100644 index 763e25785..000000000 --- a/docs/openapi/jan.yaml +++ /dev/null @@ -1,9738 +0,0 @@ -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" - 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: 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. - - name: Fine-tunes - description: Manage legacy fine-tuning jobs to tailor a model to your specific training data. - - name: Edits - description: Given a prompt and an instruction, the model will return an edited version of the prompt. -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: - - Chat - summary: Creates a model response for the given chat conversation. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateChatCompletionRequest" - responses: - "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 - examples: - - 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?", - }, - "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?", - }, - "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":""},"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"},"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":"!"},"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"},"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":"?"},"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":{},"finish_reason":"stop"}]} - - title: Function calling - 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?" - } - ], - "functions": [ - { - "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"] - } - } - ], - "function_call": "auto" - }' - python: | - from openai import OpenAI - client = OpenAI() - - functions = [ - { - "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, - functions=functions, - function_call="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 functions = [ - { - "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, - functions: functions, - function_call: "auto", // auto is default, but we'll be explicit - }); - - console.log(response); - } - - main(); - response: &chat_completion_function_example | - { - "choices": [ - { - "finish_reason": "function_call", - "index": 0, - "message": { - "content": null, - "function_call": { - "arguments": "{\n \"location\": \"Boston, MA\"\n}", - "name": "get_current_weather" - }, - "role": "assistant" - } - } - ], - "created": 1694028367, - "model": "gpt-3.5-turbo-0613", - "system_fingerprint": "fp_44709d6fcb", - "object": "chat.completion", - "usage": { - "completion_tokens": 18, - "prompt_tokens": 82, - "total_tokens": 100 - } - } - /completions: - post: - operationId: createCompletion - tags: - - Completions - summary: Creates a completion for the provided prompt and parameters. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateCompletionRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/CreateCompletionResponse" - x-oaiMeta: - name: Create completion - returns: | - Returns a [completion](/docs/api-reference/completions/object) object, or a sequence of completion objects if the request is streamed. - legacy: true - examples: - - 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: | - { - "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7", - "object": "text_completion", - "created": 1589478378, - "model": "VAR_model_id", - "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: | - { - "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", - } - /edits: - post: - operationId: createEdit - deprecated: true - tags: - - Edits - 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 - returns: | - Returns an [edit](/docs/api-reference/edits/object) object. - group: edits - examples: - request: - curl: | - curl https://api.openai.com/v1/edits \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "model": "VAR_model_id", - "input": "What day of the wek is it?", - "instruction": "Fix the spelling mistakes" - }' - python: | - from openai import OpenAI - client = OpenAI() - - client.edits.create( - model="VAR_model_id", - input="What day of the wek is it?", - instruction="Fix the spelling mistakes" - ) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const edit = await openai.edits.create({ - model: "VAR_model_id", - input: "What day of the wek is it?", - instruction: "Fix the spelling mistakes.", - }); - - console.log(edit); - } - - main(); - response: &edit_example | - { - "object": "edit", - "created": 1589478378, - "choices": [ - { - "text": "What day of the week is it?", - "index": 0, - } - ], - "usage": { - "prompt_tokens": 25, - "completion_tokens": 32, - "total_tokens": 57 - } - } - - /images/generations: - post: - operationId: createImage - tags: - - Images - summary: Creates an image given a prompt. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateImageRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ImagesResponse" - x-oaiMeta: - name: Create image - returns: Returns a list of [image](/docs/api-reference/images/object) objects. - examples: - 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: - - 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" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ImagesResponse" - x-oaiMeta: - name: Create image edit - returns: Returns a list of [image](/docs/api-reference/images/object) objects. - examples: - 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: - - Images - summary: Creates a variation of a given image. - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: "#/components/schemas/CreateImageVariationRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ImagesResponse" - x-oaiMeta: - name: Create image variation - returns: Returns a list of [image](/docs/api-reference/images/object) objects. - examples: - 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: - - Embeddings - summary: Creates an embedding vector representing the input text. - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateEmbeddingRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/CreateEmbeddingResponse" - x-oaiMeta: - name: Create embeddings - returns: A list of [embedding](/docs/api-reference/embeddings/object) objects. - examples: - 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 - } - } - - /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 - 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: - - Audio - summary: Transcribes audio into the input language. - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: "#/components/schemas/CreateTranscriptionRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/CreateTranscriptionResponse" - x-oaiMeta: - name: Create transcription - returns: The transcribed text. - examples: - 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: - - Audio - summary: Translates audio into English. - requestBody: - required: true - content: - multipart/form-data: - schema: - $ref: "#/components/schemas/CreateTranslationRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/CreateTranslationResponse" - x-oaiMeta: - name: Create translation - returns: The translated text. - examples: - 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: | - 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" - ); - response: | - { - "text": "Hello, my name is Wolfgang and I come from Germany. Where are you heading today?" - } - - /files: - get: - operationId: listFiles - tags: - - 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" - x-oaiMeta: - name: List files - returns: A list of [File](/docs/api-reference/files/object) objects. - examples: - 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); - } - } - - 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: - - Files - summary: | - Upload a file that can be used across various endpoints/features. The size of all the files uploaded by one organization can be up to 100 GB. - - The size of individual files for can be a maximum of 512MB. 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" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/OpenAIFile" - x-oaiMeta: - name: Upload file - returns: The uploaded [File](/docs/api-reference/files/object) object. - examples: - 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-BK7bzQj3FfZFXr7DbL6xJwfo", - "object": "file", - "bytes": 120000, - "created_at": 1677610602, - "filename": "mydata.jsonl", - "purpose": "fine-tune", - } - /files/{file_id}: - delete: - operationId: deleteFile - tags: - - Files - summary: Delete a file. - parameters: - - in: path - name: file_id - required: true - schema: - type: string - description: The ID of the file to use for this request. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/DeleteFileResponse" - x-oaiMeta: - name: Delete file - returns: Deletion status. - examples: - 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-oaG6vwLtV3v3mWpvxexWDKxq") - 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: - - Files - summary: Returns information about a specific file. - parameters: - - in: path - name: file_id - required: true - schema: - type: string - description: The ID of the file to use for this request. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/OpenAIFile" - x-oaiMeta: - name: Retrieve file - returns: The [File](/docs/api-reference/files/object) object matching the specified ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/files/file-BK7bzQj3FfZFXr7DbL6xJwfo \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - from openai import OpenAI - client = OpenAI() - - client.files.retrieve("file-BK7bzQj3FfZFXr7DbL6xJwfo") - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const file = await openai.files.retrieve("file-BK7bzQj3FfZFXr7DbL6xJwfo"); - - console.log(file); - } - - main(); - response: | - { - "id": "file-BK7bzQj3FfZFXr7DbL6xJwfo", - "object": "file", - "bytes": 120000, - "created_at": 1677610602, - "filename": "mydata.jsonl", - "purpose": "fine-tune", - } - /files/{file_id}/content: - get: - operationId: downloadFile - tags: - - 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. - responses: - "200": - description: OK - content: - application/json: - schema: - type: string - x-oaiMeta: - name: Retrieve file content - returns: The file content. - examples: - request: - curl: | - curl https://api.openai.com/v1/files/file-BK7bzQj3FfZFXr7DbL6xJwfo/content \ - -H "Authorization: Bearer $OPENAI_API_KEY" > file.jsonl - python: | - from openai import OpenAI - client = OpenAI() - - content = client.files.retrieve_content("file-BK7bzQj3FfZFXr7DbL6xJwfo") - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const file = await openai.files.retrieveContent("file-BK7bzQj3FfZFXr7DbL6xJwfo"); - - console.log(file); - } - - main(); - - /fine_tuning/jobs: - post: - operationId: createFineTuningJob - tags: - - Fine-tuning - summary: | - Creates a job that fine-tunes a specified 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) - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateFineTuningJobRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/FineTuningJob" - x-oaiMeta: - name: Create fine-tuning job - returns: A [fine-tuning.job](/docs/api-reference/fine-tuning/object) object. - examples: - - title: No hyperparameters - 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_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", - } - - title: Hyperparameters - 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: | - { - "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", - } - get: - operationId: listPaginatedFineTuningJobs - tags: - - 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/ListPaginatedFineTuningJobsResponse" - x-oaiMeta: - name: List fine-tuning jobs - returns: A list of paginated [fine-tuning job](/docs/api-reference/fine-tuning/object) objects. - examples: - 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(); - - 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: retrieveFineTuningJob - tags: - - Fine-tuning - summary: | - Get info about a fine-tuning job. - - [Learn more about fine-tuning](/docs/guides/fine-tuning) - parameters: - - in: path - name: fine_tuning_job_id - required: true - schema: - type: string - example: ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - The ID of the fine-tuning job. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/FineTuningJob" - x-oaiMeta: - name: Retrieve fine-tuning job - returns: The [fine-tuning](/docs/api-reference/fine-tunes/object) object with the given ID. - examples: - 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); - } - - 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: - - Fine-tuning - summary: | - Get status updates for a fine-tuning job. - parameters: - - in: path - name: fine_tuning_job_id - required: true - schema: - type: string - example: ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - 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/ListFineTuningJobEventsResponse" - x-oaiMeta: - name: List fine-tuning events - returns: A list of fine-tuning event objects. - examples: - 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); - } - } - - 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: - - Fine-tuning - summary: | - Immediately cancel a fine-tune job. - parameters: - - in: path - name: fine_tuning_job_id - required: true - schema: - type: string - example: ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - The ID of the fine-tuning job to cancel. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/FineTuningJob" - x-oaiMeta: - name: Cancel fine-tuning - returns: The cancelled [fine-tuning](/docs/api-reference/fine-tuning/object) object. - examples: - 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" - } - - /fine-tunes: - post: - operationId: createFineTune - deprecated: true - tags: - - Fine-tunes - summary: | - Creates a job that fine-tunes a specified 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/legacy-fine-tuning) - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateFineTuneRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/FineTune" - x-oaiMeta: - name: Create fine-tune - returns: A [fine-tune](/docs/api-reference/fine-tunes/object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/fine-tunes \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $OPENAI_API_KEY" \ - -d '{ - "training_file": "file-abc123" - }' - python: | - # deprecated - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const fineTune = await openai.fineTunes.create({ - training_file: "file-abc123" - }); - - console.log(fineTune); - } - - main(); - 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." - } - ], - "fine_tuned_model": null, - "hyperparams": { - "batch_size": 4, - "learning_rate_multiplier": 0.1, - "n_epochs": 4, - "prompt_loss_weight": 0.1, - }, - "organization_id": "org-123", - "result_files": [], - "status": "pending", - "validation_files": [], - "training_files": [ - { - "id": "file-abc123", - "object": "file", - "bytes": 1547276, - "created_at": 1610062281, - "filename": "my-data-train.jsonl", - "purpose": "fine-tune-results" - } - ], - "updated_at": 1614807352, - } - get: - operationId: listFineTunes - deprecated: true - tags: - - Fine-tunes - summary: | - List your organization's fine-tuning jobs - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ListFineTunesResponse" - x-oaiMeta: - name: List fine-tunes - returns: A list of [fine-tune](/docs/api-reference/fine-tunes/object) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/fine-tunes \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - # deprecated - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const list = await openai.fineTunes.list(); - - for await (const fineTune of list) { - console.log(fineTune); - } - } - - main(); - response: | - { - "object": "list", - "data": [ - { - "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F", - "object": "fine-tune", - "model": "curie", - "created_at": 1614807352, - "fine_tuned_model": null, - "hyperparams": { ... }, - "organization_id": "org-123", - "result_files": [], - "status": "pending", - "validation_files": [], - "training_files": [ { ... } ], - "updated_at": 1614807352, - }, - { ... }, - { ... } - ] - } - /fine-tunes/{fine_tune_id}: - get: - operationId: retrieveFineTune - deprecated: true - tags: - - Fine-tunes - summary: | - Gets info about the fine-tune job. - - [Learn more about fine-tuning](/docs/guides/legacy-fine-tuning) - parameters: - - in: path - name: fine_tune_id - required: true - schema: - type: string - example: ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - The ID of the fine-tune job - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/FineTune" - x-oaiMeta: - name: Retrieve fine-tune - returns: The [fine-tune](/docs/api-reference/fine-tunes/object) object with the given ID. - examples: - request: - curl: | - curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - # deprecated - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const fineTune = await openai.fineTunes.retrieve("ft-AF1WoRqd3aJAHsqc9NY7iL8F"); - - console.log(fineTune); - } - - main(); - response: &fine_tune_example | - { - "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-abc123." - }, - { - "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-123", - "result_files": [ - { - "id": "file-abc123", - "object": "file", - "bytes": 81509, - "created_at": 1614807863, - "filename": "compiled_results.csv", - "purpose": "fine-tune-results" - } - ], - "status": "succeeded", - "validation_files": [], - "training_files": [ - { - "id": "file-abc123", - "object": "file", - "bytes": 1547276, - "created_at": 1610062281, - "filename": "my-data-train.jsonl", - "purpose": "fine-tune" - } - ], - "updated_at": 1614807865, - } - /fine-tunes/{fine_tune_id}/cancel: - post: - operationId: cancelFineTune - deprecated: true - tags: - - Fine-tunes - summary: | - Immediately cancel a fine-tune job. - parameters: - - in: path - name: fine_tune_id - required: true - schema: - type: string - example: ft-AF1WoRqd3aJAHsqc9NY7iL8F - description: | - The ID of the fine-tune job to cancel - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/FineTune" - x-oaiMeta: - name: Cancel fine-tune - returns: The cancelled [fine-tune](/docs/api-reference/fine-tunes/object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F/cancel \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - # deprecated - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const fineTune = await openai.fineTunes.cancel("ft-AF1WoRqd3aJAHsqc9NY7iL8F"); - - console.log(fineTune); - } - main(); - response: | - { - "id": "ft-xhrpBbvVUzYGo8oUO1FY4nI7", - "object": "fine-tune", - "model": "curie", - "created_at": 1614807770, - "events": [ { ... } ], - "fine_tuned_model": null, - "hyperparams": { ... }, - "organization_id": "org-123", - "result_files": [], - "status": "cancelled", - "validation_files": [], - "training_files": [ - { - "id": "file-abc123", - "object": "file", - "bytes": 1547276, - "created_at": 1610062281, - "filename": "my-data-train.jsonl", - "purpose": "fine-tune" - } - ], - "updated_at": 1614807789, - } - /fine-tunes/{fine_tune_id}/events: - get: - operationId: listFineTuneEvents - deprecated: true - tags: - - Fine-tunes - summary: | - Get fine-grained status updates for a fine-tune job. - parameters: - - in: path - name: fine_tune_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 - 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. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ListFineTuneEventsResponse" - x-oaiMeta: - name: List fine-tune events - returns: A list of fine-tune event objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F/events \ - -H "Authorization: Bearer $OPENAI_API_KEY" - python: | - # deprecated - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const fineTune = await openai.fineTunes.listEvents("ft-AF1WoRqd3aJAHsqc9NY7iL8F"); - - console.log(fineTune); - } - main(); - 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-abc123" - }, - { - "object": "fine-tune-event", - "created_at": 1614807864, - "level": "info", - "message": "Job succeeded." - } - ] - } - - # Models - /models: - get: - operationId: listModels - tags: - - Models - summary: List Models - description: Lists the currently available models, and provides basic information about each one such as the owner and availability. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/ListModelsResponse" - x-oaiMeta: - name: List models - returns: A list of [model](/docs/api-reference/models/object) objects. - examples: - 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" - } - post: - operationId: importModel - tags: - - Models - summary: Import Model - description: Imports a model instance. The model can be from a local folder, remote source, or an API endpoint. The model importer will examine the source_url for formatting. - parameters: - - in: path - name: source_url - required: true - schema: - type: string - # ideally this will be an actual ID, so this will always work from browser - example: https://huggingface.com/thebloke/example.gguf - description: The ID of the model to use for this request - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/Model" - x-oaiMeta: - name: Import model - returns: The [model](/docs/api-reference/models/object) object matching the specified ID. - examples: - 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", - "state": "ready" - } - /models/{model}: - get: - operationId: retrieveModel - tags: - - Models - summary: Retrieve Model - description: Retrieves a model instance, providing basic information about the model such as the owner and permissioning. - parameters: - - in: path - name: model - required: true - schema: - type: string - # ideally this will be an actual ID, so this will always work from browser - 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" - x-oaiMeta: - name: Retrieve model - returns: The [model](/docs/api-reference/models/object) object matching the specified ID. - examples: - 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: - - Models - summary: Delete Model - description: 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: ft:gpt-3.5-turbo:acemeco:suffix:abc123 - description: The model to delete - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/DeleteModelResponse" - x-oaiMeta: - name: Delete fine-tune model - returns: Deletion status. - examples: - 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 - } - post: - operationId: startModel - tags: - - Models - summary: Start Model - description: Starts an imported model. Loads the model into V/RAM. - parameters: - - in: path - name: model - required: true - schema: - type: string - # ideally this will be an actual ID, so this will always work from browser - 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" - x-oaiMeta: - name: Import model - returns: The [model](/docs/api-reference/models/object) object matching the specified ID. - examples: - response: &retrieve_model_response | - { - "id": "VAR_model_id", - "object": "model", - "created": 1686935002, - "owned_by": "openai" - } - /models/{model}/stop: - post: - operationId: stopModel - tags: - - Models - summary: Stop Model - description: Stops a running model. Unloads the model from V/RAM. - parameters: - - in: path - name: model - required: true - schema: - type: string - description: The ID of the model that is running. - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/RunObject" - x-oaiMeta: - name: Stop a running model - beta: true - returns: The modified [run](/docs/api-reference/runs/object) object matching the specified ID. - examples: - request: - response: | - { - "todo": "run_BeRGmpGt2wb1VI22ZRniOkrR" - } - - /moderations: - post: - operationId: createModeration - tags: - - Moderations - summary: Classifies if text violates OpenAI's Content Policy - requestBody: - required: true - content: - application/json: - schema: - $ref: "#/components/schemas/CreateModerationRequest" - responses: - "200": - description: OK - content: - application/json: - schema: - $ref: "#/components/schemas/CreateModerationResponse" - x-oaiMeta: - name: Create moderation - returns: A [moderation](/docs/api-reference/moderations/object) object. - examples: - 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() - - client.moderations.create(input="I want to kill them.") - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - 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 - /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 - 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 - 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 - 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: - - Assistant - 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 - 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 - 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_QLoItBbqwyAJEzlTy4y9kOMM") - print(response) - node.js: |- - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const response = await openai.beta.assistants.del("asst_QLoItBbqwyAJEzlTy4y9kOMM"); - - console.log(response); - } - main(); - response: | - { - "id": "asst_abc123", - "object": "assistant.deleted", - "deleted": true - } - - # Threads - /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 - 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 - 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 - 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 - 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 - 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_1OWaSqVIxJdy3KYnJLbXEWhy") - 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_1OWaSqVIxJdy3KYnJLbXEWhy" - ); - - 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 - 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 - 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 - 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 - 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_IgmpQTah3ZfPHCVZjTqAY8Kv", - "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_IgmpQTah3ZfPHCVZjTqAY8Kv", - 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_IgmpQTah3ZfPHCVZjTqAY8Kv", - thread: { - messages: [ - { role: "user", content: "Explain deep learning to a 5 year old." }, - ], - }, - }); - - console.log(run); - } - - main(); - response: | - { - "id": "run_3Qudf05GGhCleEg9ggwfJQih", - "object": "thread.run", - "created_at": 1699076792, - "assistant_id": "asst_IgmpQTah3ZfPHCVZjTqAY8Kv", - "thread_id": "thread_Ec3eKZcWI00WDZRC7FZci8hP", - "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": {} - } - - /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 - beta: true - returns: A list of [run](/docs/api-reference/runs/object) objects. - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_BDDwIqM4KgHibXX3mqmN3Lgs/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_BDDwIqM4KgHibXX3mqmN3Lgs" - ) - print(runs) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const runs = await openai.beta.threads.runs.list( - "thread_BDDwIqM4KgHibXX3mqmN3Lgs" - ); - - console.log(runs); - } - - main(); - response: | - { - "object": "list", - "data": [ - { - "id": "run_5pyUEwhaPk11vCKiDneUWXXY", - "object": "thread.run", - "created_at": 1699075072, - "assistant_id": "asst_nGl00s4xa9zmVY6Fvuvz9wwQ", - "thread_id": "thread_BDDwIqM4KgHibXX3mqmN3Lgs", - "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-9F1ex49ipEnKzyLUNnCA0Yzx", - "file-dEWwUbt2UGHp3v0e0DpCzemP" - ], - "metadata": {} - }, - { - "id": "run_UWvV94U0FQYiT2rlbBrdEVmC", - "object": "thread.run", - "created_at": 1699063290, - "assistant_id": "asst_nGl00s4xa9zmVY6Fvuvz9wwQ", - "thread_id": "thread_BDDwIqM4KgHibXX3mqmN3Lgs", - "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-9F1ex49ipEnKzyLUNnCA0Yzx", - "file-dEWwUbt2UGHp3v0e0DpCzemP" - ], - "metadata": {} - } - ], - "first_id": "run_5pyUEwhaPk11vCKiDneUWXXY", - "last_id": "run_UWvV94U0FQYiT2rlbBrdEVmC", - "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 - beta: true - returns: A [run](/docs/api-reference/runs/object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_BDDwIqM4KgHibXX3mqmN3Lgs/runs \ - -H 'Authorization: Bearer $OPENAI_API_KEY' \ - -H 'Content-Type: application/json' \ - -H 'OpenAI-Beta: assistants=v1' \ - -d '{ - "assistant_id": "asst_nGl00s4xa9zmVY6Fvuvz9wwQ" - }' - python: | - from openai import OpenAI - client = OpenAI() - - run = client.beta.threads.runs.create( - thread_id="thread_BDDwIqM4KgHibXX3mqmN3Lgs", - assistant_id="asst_nGl00s4xa9zmVY6Fvuvz9wwQ" - ) - print(run) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const run = await openai.beta.threads.runs.create( - "thread_BDDwIqM4KgHibXX3mqmN3Lgs", - { assistant_id: "asst_nGl00s4xa9zmVY6Fvuvz9wwQ" } - ); - - console.log(run); - } - - main(); - response: &run_object_example | - { - "id": "run_UWvV94U0FQYiT2rlbBrdEVmC", - "object": "thread.run", - "created_at": 1699063290, - "assistant_id": "asst_nGl00s4xa9zmVY6Fvuvz9wwQ", - "thread_id": "thread_BDDwIqM4KgHibXX3mqmN3Lgs", - "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-9F1ex49ipEnKzyLUNnCA0Yzx", - "file-dEWwUbt2UGHp3v0e0DpCzemP" - ], - "metadata": {} - } - - /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 - 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_BDDwIqM4KgHibXX3mqmN3Lgs/runs/run_5pyUEwhaPk11vCKiDneUWXXY \ - -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_BDDwIqM4KgHibXX3mqmN3Lgs", - run_id="run_5pyUEwhaPk11vCKiDneUWXXY" - ) - print(run) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const run = await openai.beta.threads.runs.retrieve( - "thread_BDDwIqM4KgHibXX3mqmN3Lgs", - "run_5pyUEwhaPk11vCKiDneUWXXY" - ); - - console.log(run); - } - - main(); - response: | - { - "id": "run_5pyUEwhaPk11vCKiDneUWXXY", - "object": "thread.run", - "created_at": 1699075072, - "assistant_id": "asst_nGl00s4xa9zmVY6Fvuvz9wwQ", - "thread_id": "thread_BDDwIqM4KgHibXX3mqmN3Lgs", - "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-9F1ex49ipEnKzyLUNnCA0Yzx", - "file-dEWwUbt2UGHp3v0e0DpCzemP" - ], - "metadata": {} - } - 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 - 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_BDDwIqM4KgHibXX3mqmN3Lgs/runs/run_5pyUEwhaPk11vCKiDneUWXXY \ - -H 'Authorization: Bearer $OPENAI_API_KEY' \ - -H 'Content-Type: application/json' \ - -H 'OpenAI-Beta: assistants=v1' \ - -d '{ - "metadata": { - "user_id": "user_zmVY6FvuBDDwIqM4KgH" - } - }' - python: | - from openai import OpenAI - client = OpenAI() - - run = client.beta.threads.runs.update( - thread_id="thread_BDDwIqM4KgHibXX3mqmN3Lgs", - run_id="run_5pyUEwhaPk11vCKiDneUWXXY", - metadata={"user_id": "user_zmVY6FvuBDDwIqM4KgH"}, - ) - print(run) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const run = await openai.beta.threads.runs.update( - "thread_BDDwIqM4KgHibXX3mqmN3Lgs", - "run_5pyUEwhaPk11vCKiDneUWXXY", - { - metadata: { - user_id: "user_zmVY6FvuBDDwIqM4KgH", - }, - } - ); - - console.log(run); - } - - main(); - response: | - { - "id": "run_5pyUEwhaPk11vCKiDneUWXXY", - "object": "thread.run", - "created_at": 1699075072, - "assistant_id": "asst_nGl00s4xa9zmVY6Fvuvz9wwQ", - "thread_id": "thread_BDDwIqM4KgHibXX3mqmN3Lgs", - "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-9F1ex49ipEnKzyLUNnCA0Yzx", - "file-dEWwUbt2UGHp3v0e0DpCzemP" - ], - "metadata": { - "user_id": "user_zmVY6FvuBDDwIqM4KgH" - } - } - - /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 - 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_EdR8UvCDJ035LFEJZMt3AxCd/runs/run_PHLyHQYIQn4F7JrSXslEYWwh/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_MbELIQcB72cq35Yzo2MRw5qs", - "output": "28C" - } - ] - }' - python: | - from openai import OpenAI - client = OpenAI() - - run = client.beta.threads.runs.submit_tool_outputs( - thread_id="thread_EdR8UvCDJ035LFEJZMt3AxCd", - run_id="run_PHLyHQYIQn4F7JrSXslEYWwh", - tool_outputs=[ - { - "tool_call_id": "call_MbELIQcB72cq35Yzo2MRw5qs", - "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_EdR8UvCDJ035LFEJZMt3AxCd", - "run_PHLyHQYIQn4F7JrSXslEYWwh", - { - tool_outputs: [ - { - tool_call_id: "call_MbELIQcB72cq35Yzo2MRw5qs", - output: "28C", - }, - ], - } - ); - - console.log(run); - } - - main(); - response: | - { - "id": "run_PHLyHQYIQn4F7JrSXslEYWwh", - "object": "thread.run", - "created_at": 1699075592, - "assistant_id": "asst_IgmpQTah3ZfPHCVZjTqAY8Kv", - "thread_id": "thread_EdR8UvCDJ035LFEJZMt3AxCd", - "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": {} - } - - /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 - 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_1cjnJPXj8MFiqTx58jU9TivC/runs/run_BeRGmpGt2wb1VI22ZRniOkrR/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_1cjnJPXj8MFiqTx58jU9TivC", - run_id="run_BeRGmpGt2wb1VI22ZRniOkrR" - ) - print(run) - node.js: | - import OpenAI from "openai"; - - const openai = new OpenAI(); - - async function main() { - const run = await openai.beta.threads.runs.cancel( - "thread_1cjnJPXj8MFiqTx58jU9TivC", - "run_BeRGmpGt2wb1VI22ZRniOkrR" - ); - - console.log(run); - } - - main(); - response: | - { - "id": "run_BeRGmpGt2wb1VI22ZRniOkrR", - "object": "thread.run", - "created_at": 1699076126, - "assistant_id": "asst_IgmpQTah3ZfPHCVZjTqAY8Kv", - "thread_id": "thread_1cjnJPXj8MFiqTx58jU9TivC", - "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": {} - } - - /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 - 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_BDDwIqM4KgHibXX3mqmN3Lgs/runs/run_UWvV94U0FQYiT2rlbBrdEVmC/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_BDDwIqM4KgHibXX3mqmN3Lgs", - run_id="run_UWvV94U0FQYiT2rlbBrdEVmC" - ) - 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_BDDwIqM4KgHibXX3mqmN3Lgs", - "run_UWvV94U0FQYiT2rlbBrdEVmC" - ); - console.log(runStep); - } - - main(); - response: | - { - "object": "list", - "data": [ - { - "id": "step_QyjyrsVsysd7F4K894BZHG97", - "object": "thread.run.step", - "created_at": 1699063291, - "run_id": "run_UWvV94U0FQYiT2rlbBrdEVmC", - "assistant_id": "asst_nGl00s4xa9zmVY6Fvuvz9wwQ", - "thread_id": "thread_BDDwIqM4KgHibXX3mqmN3Lgs", - "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_6YmiCRmMbbE6FALYNePPHqwm" - } - } - } - ], - "first_id": "step_QyjyrsVsysd7F4K894BZHG97", - "last_id": "step_QyjyrsVsysd7F4K894BZHG97", - "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 - 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_BDDwIqM4KgHibXX3mqmN3Lgs/runs/run_UWvV94U0FQYiT2rlbBrdEVmC/steps/step_QyjyrsVsysd7F4K894BZHG97 \ - -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_BDDwIqM4KgHibXX3mqmN3Lgs", - run_id="run_UWvV94U0FQYiT2rlbBrdEVmC", - step_id="step_QyjyrsVsysd7F4K894BZHG97" - ) - 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_BDDwIqM4KgHibXX3mqmN3Lgs", - "run_UWvV94U0FQYiT2rlbBrdEVmC", - "step_QyjyrsVsysd7F4K894BZHG97" - ); - console.log(runStep); - } - - main(); - response: &run_step_object_example | - { - "id": "step_QyjyrsVsysd7F4K894BZHG97", - "object": "thread.run.step", - "created_at": 1699063291, - "run_id": "run_UWvV94U0FQYiT2rlbBrdEVmC", - "assistant_id": "asst_nGl00s4xa9zmVY6Fvuvz9wwQ", - "thread_id": "thread_BDDwIqM4KgHibXX3mqmN3Lgs", - "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_6YmiCRmMbbE6FALYNePPHqwm" - } - } - } - - /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 - 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_DUGk5I7sK0FpKeijvrO30z9J/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_DUGk5I7sK0FpKeijvrO30z9J" - ) - 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_FBOFvAOHhwEWMghbMGseaPGQ" - ); - console.log(assistantFiles); - } - - main(); - response: | - { - "object": "list", - "data": [ - { - "id": "file-dEWwUbt2UGHp3v0e0DpCzemP", - "object": "assistant.file", - "created_at": 1699060412, - "assistant_id": "asst_DUGk5I7sK0FpKeijvrO30z9J" - }, - { - "id": "file-9F1ex49ipEnKzyLUNnCA0Yzx", - "object": "assistant.file", - "created_at": 1699060412, - "assistant_id": "asst_DUGk5I7sK0FpKeijvrO30z9J" - } - ], - "first_id": "file-dEWwUbt2UGHp3v0e0DpCzemP", - "last_id": "file-9F1ex49ipEnKzyLUNnCA0Yzx", - "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-AF1WoRqd3aJAHsqc9NY7iL8F - 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 - beta: true - returns: An [assistant file](/docs/api-reference/assistants/file-object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/assistants/asst_FBOFvAOHhwEWMghbMGseaPGQ/files \ - -H 'Authorization: Bearer $OPENAI_API_KEY"' \ - -H 'Content-Type: application/json' \ - -H 'OpenAI-Beta: assistants=v1' \ - -d '{ - "file_id": "file-wB6RM6wHdA49HfS2DJ9fEyrH" - }' - python: | - from openai import OpenAI - client = OpenAI() - - assistant_file = client.beta.assistants.files.create( - assistant_id="asst_FBOFvAOHhwEWMghbMGseaPGQ", - file_id="file-wB6RM6wHdA49HfS2DJ9fEyrH" - ) - 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_FBOFvAOHhwEWMghbMGseaPGQ", - { - file_id: "file-wB6RM6wHdA49HfS2DJ9fEyrH" - } - ); - console.log(myAssistantFile); - } - - main(); - response: &assistant_file_object | - { - "id": "file-wB6RM6wHdA49HfS2DJ9fEyrH", - "object": "assistant.file", - "created_at": 1699055364, - "assistant_id": "asst_FBOFvAOHhwEWMghbMGseaPGQ" - } - - /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 - 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_FBOFvAOHhwEWMghbMGseaPGQ/files/file-wB6RM6wHdA49HfS2DJ9fEyrH \ - -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_FBOFvAOHhwEWMghbMGseaPGQ", - file_id="file-wB6RM6wHdA49HfS2DJ9fEyrH" - ) - 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_FBOFvAOHhwEWMghbMGseaPGQ", - "file-wB6RM6wHdA49HfS2DJ9fEyrH" - ); - 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 - beta: true - returns: Deletion status - examples: - request: - curl: | - curl https://api.openai.com/v1/assistants/asst_DUGk5I7sK0FpKeijvrO30z9J/files/file-9F1ex49ipEnKzyLUNnCA0Yzx \ - -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_DUGk5I7sK0FpKeijvrO30z9J", - file_id="file-dEWwUbt2UGHp3v0e0DpCzemP" - ) - 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_FBOFvAOHhwEWMghbMGseaPGQ", - "file-wB6RM6wHdA49HfS2DJ9fEyrH" - ); - console.log(deletedAssistantFile); - } - - main(); - response: | - { - id: "file-BK7bzQj3FfZFXr7DbL6xJwfo", - 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 - 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_RGUhOuO9b2nrktrmsQ2uSR6I/messages/msg_q3XhbGmMzsqEFa81gMLBDAVU/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_RGUhOuO9b2nrktrmsQ2uSR6I", - message_id="msg_q3XhbGmMzsqEFa81gMLBDAVU" - ) - 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_RGUhOuO9b2nrktrmsQ2uSR6I", - "msg_q3XhbGmMzsqEFa81gMLBDAVU" - ); - console.log(messageFiles); - } - - main(); - response: | - { - "object": "list", - "data": [ - { - "id": "file-dEWwUbt2UGHp3v0e0DpCzemP", - "object": "thread.message.file", - "created_at": 1699061776, - "message_id": "msg_q3XhbGmMzsqEFa81gMLBDAVU" - }, - { - "id": "file-dEWwUbt2UGHp3v0e0DpCzemP", - "object": "thread.message.file", - "created_at": 1699061776, - "message_id": "msg_q3XhbGmMzsqEFa81gMLBDAVU" - } - ], - "first_id": "file-dEWwUbt2UGHp3v0e0DpCzemP", - "last_id": "file-dEWwUbt2UGHp3v0e0DpCzemP", - "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_AF1WoRqd3aJAHsqc9NY7iL8F - 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_AF1WoRqd3aJAHsqc9NY7iL8F - description: The ID of the message the file belongs to. - - in: path - name: file_id - required: true - schema: - type: string - example: file-AF1WoRqd3aJAHsqc9NY7iL8F - 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 - beta: true - returns: The [message file](/docs/api-reference/messages/file-object) object. - examples: - request: - curl: | - curl https://api.openai.com/v1/threads/thread_RGUhOuO9b2nrktrmsQ2uSR6I/messages/msg_q3XhbGmMzsqEFa81gMLBDAVU/files/file-dEWwUbt2UGHp3v0e0DpCzemP \ - -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_RGUhOuO9b2nrktrmsQ2uSR6I", - message_id="msg_q3XhbGmMzsqEFa81gMLBDAVU", - file_id="file-dEWwUbt2UGHp3v0e0DpCzemP" - ) - 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_RGUhOuO9b2nrktrmsQ2uSR6I", - "msg_q3XhbGmMzsqEFa81gMLBDAVU", - "file-dEWwUbt2UGHp3v0e0DpCzemP" - ); - console.log(messageFile); - } - - main(); - response: | - { - "id": "file-dEWwUbt2UGHp3v0e0DpCzemP", - "object": "thread.message.file", - "created_at": 1699061776, - "message_id": "msg_q3XhbGmMzsqEFa81gMLBDAVU" - } - -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: - [ - "babbage-002", - "davinci-002", - "gpt-3.5-turbo-instruct", - "text-davinci-003", - "text-davinci-002", - "text-davinci-001", - "code-davinci-002", - "text-curie-001", - "text-babbage-001", - "text-ada-001", - ] - 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|>" - 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/gpt/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) (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. - - 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 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) to generate 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/gpt/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. - 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: - nullable: true - 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`. - required: - - content - - role - - ChatCompletionRequestUserMessage: - type: object - title: User message - properties: - content: - nullable: true - 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 - role: - type: string - enum: ["user"] - description: The role of the messages author, in this case `user`. - required: - - content - - role - - ChatCompletionRequestAssistantMessage: - type: object - title: Assistant message - properties: - content: - nullable: true - type: string - description: | - The contents of the assistant message. - role: - type: string - enum: ["assistant"] - description: The role of the messages author, in this case `assistant`. - 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: - - content - - 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: - nullable: true - 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: - type: string - nullable: true - description: The return value from the function call, to return to the model. - name: - type: string - description: The name of the function to call. - required: - - role - - name - - content - - FunctionParameters: - 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.\n\nTo describe a function that accepts no parameters, provide the value `{\"type\": \"object\", \"properties\": {}}`." - 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 - - parameters - - 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 - - parameters - - 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 - - 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-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-1106", - "gpt-3.5-turbo", - "gpt-3.5-turbo-16k", - "gpt-3.5-turbo-0301", - "gpt-3.5-turbo-0613", - "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. - max_tokens: - 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://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken) for counting tokens. - default: inf - 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. - 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. - - 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 increased latency and appearance of a "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 - 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" - 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 - 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 - - 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" - 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 - - CreateEditRequest: - type: object - properties: - instruction: - description: The instruction that tells the model how to edit the prompt. - type: string - example: "Fix the spelling mistakes." - 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. - example: "text-davinci-edit-001" - anyOf: - - type: string - - type: string - enum: ["text-davinci-edit-001", "code-davinci-edit-001"] - x-oaiTypeLabel: string - input: - description: The input text to use as a starting point for the edit. - type: string - default: "" - nullable: true - example: "What day of the wek is it?" - 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 - required: - - model - - instruction - - CreateEditResponse: - type: object - title: Edit - deprecated: true - properties: - choices: - type: array - description: A list of edit choices. Can be more than one if `n` is greater than 1. - items: - type: object - required: - - text - - index - - finish_reason - properties: - finish_reason: - type: string - description: *completion_finish_reason_description - enum: ["stop", "length"] - index: - type: integer - description: The index of the choice in the list of choices. - text: - type: string - description: The edited result. - object: - type: string - description: The object type, which is always `edit`. - enum: [edit] - created: - type: integer - description: The Unix timestamp (in seconds) of when the edit was created. - usage: - $ref: "#/components/schemas/CompletionUsage" - required: - - object - - created - - choices - - usage - x-oaiMeta: - name: The edit object - example: *edit_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 harrassment. - 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 - - CreateFineTuneRequest: - type: object - 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/legacy-fine-tuning/creating-training-data) for more details. - type: string - example: "file-abc123" - 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. - - 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 - 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 - nullable: true - classification_n_classes: - description: | - The number of classes in a classification task. - - This parameter is required for multiclass classification. - 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 - 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/legacy-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 - nullable: true - hyperparameters: - type: object - description: The hyperparameters used for the fine-tuning job. - properties: - 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 - 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 - 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 and before 2023-08-22. - To learn more about these models, see the - [Models](/docs/models) documentation. - default: "curie" - example: "curie" - nullable: true - anyOf: - - type: string - - type: string - enum: ["ada", "babbage", "curie", "davinci"] - x-oaiTypeLabel: string - 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 - 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 - 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](/docs/guides/legacy-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/legacy-fine-tuning/creating-training-data) for more details. - type: string - nullable: true - example: "file-abc123" - required: - - training_file - - ListFineTunesResponse: - type: object - properties: - data: - type: array - items: - $ref: "#/components/schemas/FineTune" - object: - type: string - enum: [list] - required: - - object - - data - - ListFineTuneEventsResponse: - type: object - properties: - data: - type: array - items: - $ref: "#/components/schemas/FineTuneEvent" - 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`) and cannot be an empty string. [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: "" - example: "This is a test." - - type: array - minItems: 1 - 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]]" - model: - description: *model_description - example: "text-embedding-ada-002" - anyOf: - - type: string - - type: string - enum: ["text-embedding-ada-002"] - 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 - enum: ["float", "base64"] - 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 - - 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 - default: 0 - required: - - file - - model - - # 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`. - 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 - default: 1.0 - minimum: 0.25 - maximum: 4.0 - required: - - model - - input - - voice - Model: - title: Model - description: Describes an Jan model - properties: - object: - type: string - default: model - version: - type: integer - description: The version of the Model Object file - default: 1 - source_url: - type: string - format: uri - example: https://huggingface.co/TheBloke/zephyr-7B-beta-GGUF/blob/main/zephyr-7b-beta.Q4_K_M.gguf - description: The model download source. It can be an external url or a local filepath. - id: # OpenAI-equivalent - type: string - description: The model identifier, which can be referenced in the API endpoints. - example: zephyr-7b - name: - type: string - description: Human-readable name that is used for UI - owned_by: # OpenAI-equivalent - type: string - description: The organization that owns the model (you!) - default: you # TODO - created: - type: integer - description: The Unix timestamp (in seconds) for when the model was created - description: - type: string - default: A cool model from Huggingface - state: - type: string - enum: [to_download, downloading, ready, running] - default: to_download - parameters: - type: object - description: - properties: - init: - type: object - properties: - ctx_len: - type: string - description: TODO - default: 2048 - ngl: - type: string - description: TODO - default: 100 - embedding: - type: bool - description: TODO - default: true - n_parallel: - type: string - description: TODO - default: 4 - pre_prompt: - type: string - description: TODO - default: A chat between a curious user and an artificial intelligence - user_prompt: - type: string - description: TODO - default: "USER:" - ai_prompt: - type: string - description: TODO - default: "ASSISTANT:" - default: - { - ctx_len: 2048, - ngl: 100, - embedding: true, - n_parallel: 4, - pre_prompt: "A chat between a curious user and an artificial intelligence", - user_prompt: "USER:", - ai_prompt: "ASSISTANT:", - } - runtime: - type: object - properties: - temperature: - type: string - description: TODO - default: 0.7 - token_limit: - type: string - description: TODO - default: 2048 - top_k: - type: string - description: TODO - default: 0 - top_p: - type: string - description: TODO - default: 1 - stream: - type: string - description: TODO - default: true - default: - { - temperature: 0.7, - token_limit: 2048, - top_k: 0, - top_p: 1, - stream: true, - } - metadata: - type: object - properties: - engine: - type: string - enum: [llamacpp, api, tensorrt] - default: llamacpp - quantization: - type: string - description: TODO - default: Q4_K_M - size: - type: string - default: 7b - binaries: - type: array - description: TODO - default: TODO - default: - { engine: llamacpp, quantization: Q4_K_M, size: 7b, binaries: TODO } - required: - - id # From OpenAI - - version - - source_url - - created # From OpenAI, autogenerated in Jan - - object # From OpenAI, autogenerated in Jan - - owned_by # From OpenAI, autogenerated in Jan - x-oaiMeta: - name: The model object - example: *retrieve_model_response - - 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 - 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-BK7bzQj3FfZFXr7DbL6xJwfo", - "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 - } - - 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 - 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 - required: - - code - - message - - param - fine_tuned_model: - type: string - nullable: true - 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 - nullable: true - 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 - 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. - - "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 - 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 - - 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 - created_at: - type: integer - level: - type: string - enum: ["info", "warn", "error"] - message: - type: string - object: - type: string - enum: [fine_tuning.job.event] - required: - - id - - object - - 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" - } - - FineTune: - type: object - deprecated: true - description: | - The `FineTune` object represents a legacy fine-tune 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. - events: - type: array - description: The list of events that have been observed in the lifecycle of the FineTune job. - items: - $ref: "#/components/schemas/FineTuneEvent" - fine_tuned_model: - type: string - nullable: true - description: The name of the fine-tuned model that is being created. - hyperparams: - type: object - description: The hyperparameters used for the fine-tuning job. See the [fine-tuning guide](/docs/guides/legacy-fine-tuning/hyperparameters) for more details. - properties: - batch_size: - type: integer - 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. - classification_n_classes: - type: integer - description: | - The number of classes to use for computing classification metrics. - classification_positive_class: - type: string - description: | - The positive class to use for computing classification metrics. - compute_classification_metrics: - type: boolean - description: | - The classification metrics to compute using the validation dataset at the end of every epoch. - learning_rate_multiplier: - type: number - description: | - The learning rate multiplier to use for training. - n_epochs: - type: integer - description: | - The number of epochs to train the model for. An epoch refers to one - full cycle through the training dataset. - prompt_loss_weight: - type: number - description: | - The weight to use for loss on the prompt tokens. - required: - - batch_size - - learning_rate_multiplier - - n_epochs - - prompt_loss_weight - model: - type: string - description: The base model that is being fine-tuned. - object: - type: string - description: The object type, which is always "fine-tune". - enum: [fine-tune] - organization_id: - type: string - description: The organization that owns the fine-tuning job. - result_files: - type: array - description: The compiled results files for the fine-tuning job. - items: - $ref: "#/components/schemas/OpenAIFile" - status: - type: string - description: The current status of the fine-tuning job, which can be either `created`, `running`, `succeeded`, `failed`, or `cancelled`. - training_files: - type: array - description: The list of files used for training. - items: - $ref: "#/components/schemas/OpenAIFile" - updated_at: - type: integer - description: The Unix timestamp (in seconds) for when the fine-tuning job was last updated. - validation_files: - type: array - description: The list of files used for validation. - items: - $ref: "#/components/schemas/OpenAIFile" - required: - - created_at - - fine_tuned_model - - hyperparams - - id - - model - - object - - organization_id - - result_files - - status - - training_files - - updated_at - - validation_files - x-oaiMeta: - name: The fine-tune object - example: *fine_tune_example - - FineTuneEvent: - type: object - deprecated: true - description: Fine-tune event object - properties: - created_at: - type: integer - level: - type: string - message: - type: string - object: - type: string - enum: [fine-tune-event] - required: - - object - - created_at - - level - - message - x-oaiMeta: - name: The fine-tune event object - example: | - { - "object": "fine-tune-event", - "created_at": 1677610602, - "level": "info", - "message": "Created fine-tune job" - } - - 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 - - AssistantObject: - type: object - title: Assistant - description: Represents an `assistant` that can call the model and use tools. - properties: - id: - description: The identifier, which can be referenced in API endpoints. - type: string - object: - description: The object type, which is always `assistant`. - type: string - 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 - maxLength: 256 - nullable: true - description: - description: &assistant_description_param_description | - The description of the assistant. The maximum length is 512 characters. - type: string - maxLength: 512 - nullable: true - model: - 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 - 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 | - 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 - maxItems: 20 - items: - 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 - 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 - - CreateAssistantRequest: - type: object - additionalProperties: false - properties: - model: - description: *model_description - anyOf: - - type: string - name: - description: *assistant_name_param_description - type: string - nullable: true - 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 - nullable: true - required: - - model - - ModifyAssistantRequest: - type: object - additionalProperties: false - properties: - model: - description: *model_description - anyOf: - - type: string - name: - description: *assistant_name_param_description - type: string - nullable: true - 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: | - 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 previosuly 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 - x-oaiTypeLabel: map - nullable: true - - DeleteAssistantResponse: - type: object - properties: - id: - type: string - deleted: - type: boolean - object: - type: string - enum: [assistant.deleted] - required: - - id - - object - - deleted - - ListAssistantsResponse: - type: object - properties: - object: - type: string - example: "list" - data: - type: array - items: - $ref: "#/components/schemas/AssistantObject" - first_id: - type: string - example: "asst_hLBK7PXBv5Lr2NQT7KLY0ag1" - last_id: - type: string - example: "asst_QLoItBbqwyAJEzlTy4y9kOMM" - has_more: - type: boolean - example: false - required: - - object - - data - - first_id - - last_id - - has_more - x-oaiMeta: - name: List assistants response object - group: chat - example: *list_assistants_example - - AssistantToolsCode: - type: object - title: Code interpreter tool - properties: - type: - type: string - description: "The type of tool being defined: `code_interpreter`" - enum: ["code_interpreter"] - required: - - type - - AssistantToolsRetrieval: - type: object - title: Retrieval tool - properties: - type: - type: string - description: "The type of tool being defined: `retrieval`" - enum: ["retrieval"] - required: - - type - - AssistantToolsFunction: - type: object - title: Function tool - properties: - type: - type: string - description: "The type of tool being defined: `function`" - enum: ["function"] - function: - $ref: "#/components/schemas/FunctionObject" - required: - - type - - function - - 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 - enum: ["thread.run"] - created_at: - description: The Unix timestamp (in seconds) for when the run was created. - type: integer - 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: - 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 - x-oaiTypeLabel: map - nullable: true - required: - - id - - object - - 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 - x-oaiMeta: - name: The run object - beta: true - example: | - { - "id": "run_example123", - "object": "thread.run", - "created_at": 1698107661, - "assistant_id": "asst_gZ1aOomboBuYWPcXJx4vAYB0", - "thread_id": "thread_adOpf7Jbb5Abymz0QbwxAh3c", - "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": {} - } - CreateRunRequest: - 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 - 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" - x-oaiExpandable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - required: - - thread_id - - assistant_id - ListRunsResponse: - type: object - properties: - object: - type: string - example: "list" - data: - type: array - items: - $ref: "#/components/schemas/RunObject" - first_id: - type: string - example: "run_hLBK7PXBv5Lr2NQT7KLY0ag1" - last_id: - type: string - example: "run_QLoItBbqwyAJEzlTy4y9kOMM" - 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: - tool_call_id: - type: string - 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: - - tool_outputs - RunToolCallObject: - type: object - description: Tool call objects - properties: - id: - type: string - 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 - 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 - 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: - - thread_id - - assistant_id - - ThreadObject: - type: object - title: Thread - description: Represents a thread that contains [messages](/docs/api-reference/messages). - properties: - id: - description: The identifier, which can be referenced in API endpoints. - type: string - 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: - - id - - object - - created_at - - metadata - x-oaiMeta: - name: The thread object - beta: true - example: | - { - "id": "thread_abc123", - "object": "thread", - "created_at": 1698107661, - "metadata": {} - } - - 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: - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - - DeleteThreadResponse: - type: object - properties: - id: - type: string - deleted: - type: boolean - object: - type: string - enum: [thread.deleted] - required: - - id - - object - - deleted - - ListThreadsResponse: - properties: - object: - type: string - example: "list" - data: - type: array - items: - $ref: "#/components/schemas/ThreadObject" - first_id: - type: string - example: "asst_hLBK7PXBv5Lr2NQT7KLY0ag1" - last_id: - type: string - example: "asst_QLoItBbqwyAJEzlTy4y9kOMM" - 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 - object: - description: The object type, which is always `thread.message`. - type: string - 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: - 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 - - 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_dKYDWyQvtjDBi3tudL1yWKDa", - "object": "thread.message", - "created_at": 1698983503, - "thread_id": "thread_RGUhOuO9b2nrktrmsQ2uSR6I", - "role": "assistant", - "content": [ - { - "type": "text", - "text": { - "value": "Hi! How can I help you today?", - "annotations": [] - } - } - ], - "file_ids": [], - "assistant_id": "asst_ToSF7Gb04YMj8AMMm50ZLLtY", - "run_id": "run_BjylUJgDqYK9bOhy4yjAiMrn", - "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 - - 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/MessageObject" - first_id: - type: string - example: "msg_hLBK7PXBv5Lr2NQT7KLY0ag1" - last_id: - type: string - example: "msg_QLoItBbqwyAJEzlTy4y9kOMM" - has_more: - type: boolean - example: false - required: - - object - - data - - first_id - - last_id - - has_more - - MessageContentImageFileObject: - title: Image file - type: object - description: References an image [File](/docs/api-reference/files) in the content of a message. - properties: - type: - description: Always `image_file`. - type: string - 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: - - type - - text - - 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: - type: - description: Always `file_citation`. - type: string - enum: ["file_citation"] - text: - description: The text in the message content that needs to be replaced. - type: string - 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 - - 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: - type: - description: Always `file_path`. - type: string - enum: ["file_path"] - text: - description: The text in the message content that needs to be replaced. - type: string - 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 - minimum: 0 - end_index: - type: integer - minimum: 0 - required: - - type - - text - - file_path - - start_index - - end_index - - 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 - 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 - cancelled_at: - description: The Unix timestamp (in seconds) for when the run step was cancelled. - type: integer - nullable: true - failed_at: - description: The Unix timestamp (in seconds) for when the run step failed. - type: integer - nullable: true - completed_at: - description: The Unix timestamp (in seconds) for when the run step completed. - type: integer - nullable: true - metadata: - description: *metadata_description - type: object - x-oaiTypeLabel: map - nullable: true - required: - - id - - object - - created_at - - assistant_id - - thread_id - - run_id - - type - - status - - step_details - - last_error - - expired_at - - cancelled_at - - failed_at - - completed_at - - metadata - x-oaiMeta: - name: The run step object - beta: true - example: *run_step_object_example - - ListRunStepsResponse: - properties: - object: - type: string - example: "list" - data: - type: array - items: - $ref: "#/components/schemas/RunStepObject" - first_id: - type: string - example: "step_hLBK7PXBv5Lr2NQT7KLY0ag1" - last_id: - type: string - example: "step_QLoItBbqwyAJEzlTy4y9kOMM" - has_more: - type: boolean - example: false - required: - - object - - data - - first_id - - last_id - - has_more - - RunStepDetailsMessageCreationObject: - title: Message creation - type: object - description: Details of the message creation by the run step. - properties: - type: - description: Always `message_creation``. - type: string - 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 - enum: ["tool_calls"] - tool_calls: - type: array - description: | - 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 - 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: - - id - - type - - code_interpreter - - RunStepDetailsToolCallsCodeOutputLogsObject: - title: Code interpreter log output - type: object - description: Text output from the Code Interpreter tool call as part of a run step. - properties: - type: - description: Always `logs`. - type: string - enum: ["logs"] - logs: - type: string - description: The text output from the Code Interpreter tool call. - required: - - type - - logs - - RunStepDetailsToolCallsCodeOutputImageObject: - title: Code interpreter image output - type: object - properties: - type: - description: Always `image`. - type: string - 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 - description: The ID of the tool call object. - type: - type: string - 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: - - id - - type - - retrieval - - RunStepDetailsToolCallsFunctionObject: - type: object - title: Function tool call - properties: - id: - type: string - 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 - - 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 - enum: [assistant.file] - created_at: - description: The Unix timestamp (in seconds) for when the assistant file was created. - type: integer - assistant_id: - description: The assistant ID that the file is attached to. - type: string - required: - - id - - object - - created_at - - assistant_id - x-oaiMeta: - name: The assistant file object - beta: true - example: | - { - "id": "file-wB6RM6wHdA49HfS2DJ9fEyrH", - "object": "assistant.file", - "created_at": 1699055364, - "assistant_id": "asst_FBOFvAOHhwEWMghbMGseaPGQ" - } - - 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 - enum: [assistant.file.deleted] - required: - - id - - object - - deleted - ListAssistantFilesResponse: - properties: - object: - type: string - example: "list" - data: - type: array - items: - $ref: "#/components/schemas/AssistantFileObject" - first_id: - type: string - example: "file-hLBK7PXBv5Lr2NQT7KLY0ag1" - last_id: - type: string - example: "file-QLoItBbqwyAJEzlTy4y9kOMM" - has_more: - type: boolean - example: false - required: - - object - - data - - items - - first_id - - last_id - - has_more - - 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 - message_id: - description: The ID of the [message](/docs/api-reference/messages) that the [File](/docs/api-reference/files) is attached to. - type: string - required: - - id - - object - - created_at - - message_id - x-oaiMeta: - name: The message file object - beta: true - example: | - { - "id": "file-BK7bzQj3FfZFXr7DbL6xJwfo", - "object": "thread.message.file", - "created_at": 1698107661, - "message_id": "message_QLoItBbqwyAJEzlTy4y9kOMM", - "file_id": "file-BK7bzQj3FfZFXr7DbL6xJwfo" - } - - ListMessageFilesResponse: - properties: - object: - type: string - example: "list" - data: - type: array - items: - $ref: "#/components/schemas/MessageFileObject" - first_id: - type: string - example: "file-hLBK7PXBv5Lr2NQT7KLY0ag1" - last_id: - type: string - example: "file-QLoItBbqwyAJEzlTy4y9kOMM" - has_more: - type: boolean - example: false - required: - - object - - data - - items - - first_id - - last_id - - has_more - -security: - - ApiKeyAuth: [] -x-oaiMeta: - groups: - # > 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: | - 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. - - Related guide: [Chat Completions](/docs/guides/gpt) - sections: - - type: object - key: CreateChatCompletionResponse - path: object - - type: object - key: CreateChatCompletionStreamResponse - path: streaming - - type: endpoint - key: createChatCompletion - path: create - - id: completions - title: Completions - legacy: true - 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. We recommend most users use our Chat Completions API. [Learn more](/docs/deprecations/2023-07-06-gpt-and-embeddings) - - Related guide: [Legacy Completions](/docs/guides/gpt/completions-api) - sections: - - type: object - key: CreateCompletionResponse - path: object - - type: endpoint - key: createCompletion - path: create - - 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) - sections: - - type: object - key: Embedding - path: object - - type: endpoint - key: createEmbedding - path: create - - id: fine-tuning - title: Fine-tuning - description: | - Manage fine-tuning jobs to tailor a model to your specific training data. - - Related guide: [Fine-tune models](/docs/guides/fine-tuning) - sections: - - type: object - key: FineTuningJob - path: object - - type: endpoint - key: createFineTuningJob - path: create - - type: endpoint - key: listPaginatedFineTuningJobs - path: list - - type: endpoint - key: retrieveFineTuningJob - path: retrieve - - type: endpoint - key: cancelFineTuningJob - path: cancel - - type: object - key: FineTuningJobEvent - path: event-object - - type: endpoint - key: listFineTuningEvents - path: list-events - - id: files - title: Files - description: | - 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: object - key: OpenAIFile - path: object - - type: endpoint - key: listFiles - path: list - - type: endpoint - key: createFile - path: create - - type: endpoint - key: deleteFile - path: delete - - type: endpoint - key: retrieveFile - path: retrieve - - type: endpoint - key: downloadFile - path: retrieve-contents - - 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) - sections: - - type: object - key: Image - path: object - - type: endpoint - key: createImage - path: create - - type: endpoint - key: createImageEdit - path: createEdit - - type: endpoint - key: createImageVariation - path: createVariation - - 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: object - key: Model - path: object - - type: endpoint - key: listModels - path: list - - type: endpoint - key: retrieveModel - path: retrieve - - type: endpoint - key: deleteModel - path: delete - - 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) - sections: - - type: object - key: CreateModerationResponse - path: object - - type: endpoint - key: createModeration - path: create - - 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: object - key: AssistantObject - path: object - - type: endpoint - key: createAssistant - path: createAssistant - - type: endpoint - key: getAssistant - path: getAssistant - - type: endpoint - key: modifyAssistant - path: modifyAssistant - - type: endpoint - key: deleteAssistant - path: deleteAssistant - - type: endpoint - key: listAssistants - path: listAssistants - - type: object - key: AssistantFileObject - path: file-object - - type: endpoint - key: createAssistantFile - path: createAssistantFile - - type: endpoint - key: getAssistantFile - path: getAssistantFile - - type: endpoint - key: deleteAssistantFile - path: deleteAssistantFile - - type: endpoint - key: listAssistantFiles - path: listAssistantFiles - - id: threads - title: Threads - beta: true - description: | - Create threads that assistants can interact with. - - Related guide: [Assistants](/docs/assistants/overview) - sections: - - type: object - key: ThreadObject - path: object - - type: endpoint - key: createThread - path: createThread - - type: endpoint - key: getThread - path: getThread - - type: endpoint - key: modifyThread - path: modifyThread - - type: endpoint - key: deleteThread - path: deleteThread - - id: messages - title: Messages - beta: true - description: | - Create messages within threads - - Related guide: [Assistants](/docs/assistants/overview) - sections: - - type: object - key: MessageObject - path: object - - type: endpoint - key: createMessage - path: createMessage - - type: endpoint - key: getMessage - path: getMessage - - type: endpoint - key: modifyMessage - path: modifyMessage - - type: endpoint - key: listMessages - path: listMessages - - type: object - key: MessageFileObject - path: file-object - - type: endpoint - key: getMessageFile - path: getMessageFile - - type: endpoint - key: listMessageFiles - path: listMessageFiles - - id: runs - title: Runs - beta: true - description: | - Represents an execution run on a thread. - - Related guide: [Assistants](/docs/assistants/overview) - sections: - - type: object - key: RunObject - path: object - - type: endpoint - key: createRun - path: createRun - - type: endpoint - key: getRun - path: getRun - - type: endpoint - key: modifyRun - path: modifyRun - - type: endpoint - key: listRuns - path: listRuns - - type: endpoint - key: submitToolOuputsToRun - path: submitToolOutputs - - type: endpoint - key: cancelRun - path: cancelRun - - type: endpoint - key: createThreadAndRun - path: createThreadAndRun - - type: object - key: RunStepObject - path: step-object - - type: endpoint - key: getRunStep - path: getRunStep - - type: endpoint - key: listRunSteps - path: listRunSteps - - id: fine-tunes - title: Fine-tunes - deprecated: true - description: | - Manage legacy fine-tuning jobs to tailor a model to your specific training data. - - We recommend transitioning to the updating [fine-tuning API](/docs/guides/fine-tuning) - sections: - - type: object - key: FineTune - path: object - - type: endpoint - key: createFineTune - path: create - - type: endpoint - key: listFineTunes - path: list - - type: endpoint - key: retrieveFineTune - path: retrieve - - type: endpoint - key: cancelFineTune - path: cancel - - type: object - key: FineTuneEvent - path: event-object - - type: endpoint - key: listFineTuneEvents - path: list-events - - id: edits - title: Edits - deprecated: true - description: | - Given a prompt and an instruction, the model will return an edited version of the prompt. - sections: - - type: object - key: CreateEditResponse - path: object - - type: endpoint - key: createEdit - path: create diff --git a/docs/openapi/janapi.yaml b/docs/openapi/janapi.yaml new file mode 100644 index 000000000..e69de29bb diff --git a/docs/src/styles/base.scss b/docs/src/styles/base.scss index 27f85cb28..a59df6f73 100644 --- a/docs/src/styles/base.scss +++ b/docs/src/styles/base.scss @@ -1,7 +1,4 @@ @layer base { - html { - @apply scroll-smooth; - } html[data-theme="light"] { --ifm-background-color: white; --ifm-color-primary: #2563eb; /* New Primary Blue */ From fd3f699a29d52de2d92c997a86f9daad0a5ec515 Mon Sep 17 00:00:00 2001 From: hahuyhoang411 Date: Tue, 21 Nov 2023 18:45:36 +0700 Subject: [PATCH 02/13] Model API --- docs/docusaurus.config.js | 2 +- docs/openapi/jan.json | 673 ------------------ docs/openapi/jan.yaml | 190 +++++ docs/openapi/specs/models/models.yaml | 329 +++++++++ .../threads/threads.yaml} | 0 5 files changed, 520 insertions(+), 674 deletions(-) delete mode 100644 docs/openapi/jan.json create mode 100644 docs/openapi/jan.yaml create mode 100644 docs/openapi/specs/models/models.yaml rename docs/openapi/{janapi.yaml => specs/threads/threads.yaml} (100%) diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index a0f96ed6d..ef4d7d017 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -103,7 +103,7 @@ const config = { { specs: [ { - spec: "openapi/jan.json", // can be local file, url, or parsed json object + spec: "openapi/jan.yaml", // can be local file, url, or parsed json object route: "/api-reference", // path where to render docs }, ], diff --git a/docs/openapi/jan.json b/docs/openapi/jan.json deleted file mode 100644 index 0cc3d8603..000000000 --- a/docs/openapi/jan.json +++ /dev/null @@ -1,673 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "description": "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.", - "version": "1.0.6", - "title": "Swagger Petstore", - "termsOfService": "http://swagger.io/terms/", - "contact": { "email": "apiteam@swagger.io" }, - "license": { - "name": "Apache 2.0", - "url": "http://www.apache.org/licenses/LICENSE-2.0.html" - } - }, - "host": "petstore.swagger.io", - "basePath": "/v2", - "tags": [ - { - "name": "pet", - "description": "Everything about your Pets", - "externalDocs": { - "description": "Find out more", - "url": "http://swagger.io" - } - }, - { "name": "store", "description": "Access to Petstore orders" }, - { - "name": "user", - "description": "Operations about user", - "externalDocs": { - "description": "Find out more about our store", - "url": "http://swagger.io" - } - } - ], - "schemes": ["https", "http"], - "paths": { - "/pet/{petId}/uploadImage": { - "post": { - "tags": ["pet"], - "summary": "uploads an image", - "description": "", - "operationId": "uploadFile", - "consumes": ["multipart/form-data"], - "produces": ["application/json"], - "parameters": [ - { - "name": "petId", - "in": "path", - "description": "ID of pet to update", - "required": true, - "type": "integer", - "format": "int64" - }, - { - "name": "additionalMetadata", - "in": "formData", - "description": "Additional data to pass to server", - "required": false, - "type": "string" - }, - { - "name": "file", - "in": "formData", - "description": "file to upload", - "required": false, - "type": "file" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { "$ref": "#/definitions/ApiResponse" } - } - }, - "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] - } - }, - "/pet": { - "post": { - "tags": ["pet"], - "summary": "Add a new pet to the store", - "description": "", - "operationId": "addPet", - "consumes": ["application/json", "application/xml"], - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "in": "body", - "name": "body", - "description": "Pet object that needs to be added to the store", - "required": true, - "schema": { "$ref": "#/definitions/Pet" } - } - ], - "responses": { "405": { "description": "Invalid input" } }, - "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] - }, - "put": { - "tags": ["pet"], - "summary": "Update an existing pet", - "description": "", - "operationId": "updatePet", - "consumes": ["application/json", "application/xml"], - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "in": "body", - "name": "body", - "description": "Pet object that needs to be added to the store", - "required": true, - "schema": { "$ref": "#/definitions/Pet" } - } - ], - "responses": { - "400": { "description": "Invalid ID supplied" }, - "404": { "description": "Pet not found" }, - "405": { "description": "Validation exception" } - }, - "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] - } - }, - "/pet/findByStatus": { - "get": { - "tags": ["pet"], - "summary": "Finds Pets by status", - "description": "Multiple status values can be provided with comma separated strings", - "operationId": "findPetsByStatus", - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "name": "status", - "in": "query", - "description": "Status values that need to be considered for filter", - "required": true, - "type": "array", - "items": { - "type": "string", - "enum": ["available", "pending", "sold"], - "default": "available" - }, - "collectionFormat": "multi" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "type": "array", - "items": { "$ref": "#/definitions/Pet" } - } - }, - "400": { "description": "Invalid status value" } - }, - "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] - } - }, - "/pet/findByTags": { - "get": { - "tags": ["pet"], - "summary": "Finds Pets by tags", - "description": "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", - "operationId": "findPetsByTags", - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "name": "tags", - "in": "query", - "description": "Tags to filter by", - "required": true, - "type": "array", - "items": { "type": "string" }, - "collectionFormat": "multi" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "type": "array", - "items": { "$ref": "#/definitions/Pet" } - } - }, - "400": { "description": "Invalid tag value" } - }, - "security": [{ "petstore_auth": ["write:pets", "read:pets"] }], - "deprecated": true - } - }, - "/pet/{petId}": { - "get": { - "tags": ["pet"], - "summary": "Find pet by ID", - "description": "Returns a single pet", - "operationId": "getPetById", - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "name": "petId", - "in": "path", - "description": "ID of pet to return", - "required": true, - "type": "integer", - "format": "int64" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { "$ref": "#/definitions/Pet" } - }, - "400": { "description": "Invalid ID supplied" }, - "404": { "description": "Pet not found" } - }, - "security": [{ "api_key": [] }] - }, - "post": { - "tags": ["pet"], - "summary": "Updates a pet in the store with form data", - "description": "", - "operationId": "updatePetWithForm", - "consumes": ["application/x-www-form-urlencoded"], - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "name": "petId", - "in": "path", - "description": "ID of pet that needs to be updated", - "required": true, - "type": "integer", - "format": "int64" - }, - { - "name": "name", - "in": "formData", - "description": "Updated name of the pet", - "required": false, - "type": "string" - }, - { - "name": "status", - "in": "formData", - "description": "Updated status of the pet", - "required": false, - "type": "string" - } - ], - "responses": { "405": { "description": "Invalid input" } }, - "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] - }, - "delete": { - "tags": ["pet"], - "summary": "Deletes a pet", - "description": "", - "operationId": "deletePet", - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "name": "api_key", - "in": "header", - "required": false, - "type": "string" - }, - { - "name": "petId", - "in": "path", - "description": "Pet id to delete", - "required": true, - "type": "integer", - "format": "int64" - } - ], - "responses": { - "400": { "description": "Invalid ID supplied" }, - "404": { "description": "Pet not found" } - }, - "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] - } - }, - "/store/order": { - "post": { - "tags": ["store"], - "summary": "Place an order for a pet", - "description": "", - "operationId": "placeOrder", - "consumes": ["application/json"], - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "in": "body", - "name": "body", - "description": "order placed for purchasing the pet", - "required": true, - "schema": { "$ref": "#/definitions/Order" } - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { "$ref": "#/definitions/Order" } - }, - "400": { "description": "Invalid Order" } - } - } - }, - "/store/order/{orderId}": { - "get": { - "tags": ["store"], - "summary": "Find purchase order by ID", - "description": "For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions", - "operationId": "getOrderById", - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "name": "orderId", - "in": "path", - "description": "ID of pet that needs to be fetched", - "required": true, - "type": "integer", - "maximum": 10, - "minimum": 1, - "format": "int64" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { "$ref": "#/definitions/Order" } - }, - "400": { "description": "Invalid ID supplied" }, - "404": { "description": "Order not found" } - } - }, - "delete": { - "tags": ["store"], - "summary": "Delete purchase order by ID", - "description": "For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors", - "operationId": "deleteOrder", - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "name": "orderId", - "in": "path", - "description": "ID of the order that needs to be deleted", - "required": true, - "type": "integer", - "minimum": 1, - "format": "int64" - } - ], - "responses": { - "400": { "description": "Invalid ID supplied" }, - "404": { "description": "Order not found" } - } - } - }, - "/store/inventory": { - "get": { - "tags": ["store"], - "summary": "Returns pet inventories by status", - "description": "Returns a map of status codes to quantities", - "operationId": "getInventory", - "produces": ["application/json"], - "parameters": [], - "responses": { - "200": { - "description": "successful operation", - "schema": { - "type": "object", - "additionalProperties": { "type": "integer", "format": "int32" } - } - } - }, - "security": [{ "api_key": [] }] - } - }, - "/user/createWithArray": { - "post": { - "tags": ["user"], - "summary": "Creates list of users with given input array", - "description": "", - "operationId": "createUsersWithArrayInput", - "consumes": ["application/json"], - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "in": "body", - "name": "body", - "description": "List of user object", - "required": true, - "schema": { - "type": "array", - "items": { "$ref": "#/definitions/User" } - } - } - ], - "responses": { "default": { "description": "successful operation" } } - } - }, - "/user/createWithList": { - "post": { - "tags": ["user"], - "summary": "Creates list of users with given input array", - "description": "", - "operationId": "createUsersWithListInput", - "consumes": ["application/json"], - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "in": "body", - "name": "body", - "description": "List of user object", - "required": true, - "schema": { - "type": "array", - "items": { "$ref": "#/definitions/User" } - } - } - ], - "responses": { "default": { "description": "successful operation" } } - } - }, - "/user/{username}": { - "get": { - "tags": ["user"], - "summary": "Get user by user name", - "description": "", - "operationId": "getUserByName", - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "name": "username", - "in": "path", - "description": "The name that needs to be fetched. Use user1 for testing. ", - "required": true, - "type": "string" - } - ], - "responses": { - "200": { - "description": "successful operation", - "schema": { "$ref": "#/definitions/User" } - }, - "400": { "description": "Invalid username supplied" }, - "404": { "description": "User not found" } - } - }, - "put": { - "tags": ["user"], - "summary": "Updated user", - "description": "This can only be done by the logged in user.", - "operationId": "updateUser", - "consumes": ["application/json"], - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "name": "username", - "in": "path", - "description": "name that need to be updated", - "required": true, - "type": "string" - }, - { - "in": "body", - "name": "body", - "description": "Updated user object", - "required": true, - "schema": { "$ref": "#/definitions/User" } - } - ], - "responses": { - "400": { "description": "Invalid user supplied" }, - "404": { "description": "User not found" } - } - }, - "delete": { - "tags": ["user"], - "summary": "Delete user", - "description": "This can only be done by the logged in user.", - "operationId": "deleteUser", - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "name": "username", - "in": "path", - "description": "The name that needs to be deleted", - "required": true, - "type": "string" - } - ], - "responses": { - "400": { "description": "Invalid username supplied" }, - "404": { "description": "User not found" } - } - } - }, - "/user/login": { - "get": { - "tags": ["user"], - "summary": "Logs user into the system", - "description": "", - "operationId": "loginUser", - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "name": "username", - "in": "query", - "description": "The user name for login", - "required": true, - "type": "string" - }, - { - "name": "password", - "in": "query", - "description": "The password for login in clear text", - "required": true, - "type": "string" - } - ], - "responses": { - "200": { - "description": "successful operation", - "headers": { - "X-Expires-After": { - "type": "string", - "format": "date-time", - "description": "date in UTC when token expires" - }, - "X-Rate-Limit": { - "type": "integer", - "format": "int32", - "description": "calls per hour allowed by the user" - } - }, - "schema": { "type": "string" } - }, - "400": { "description": "Invalid username/password supplied" } - } - } - }, - "/user/logout": { - "get": { - "tags": ["user"], - "summary": "Logs out current logged in user session", - "description": "", - "operationId": "logoutUser", - "produces": ["application/json", "application/xml"], - "parameters": [], - "responses": { "default": { "description": "successful operation" } } - } - }, - "/user": { - "post": { - "tags": ["user"], - "summary": "Create user", - "description": "This can only be done by the logged in user.", - "operationId": "createUser", - "consumes": ["application/json"], - "produces": ["application/json", "application/xml"], - "parameters": [ - { - "in": "body", - "name": "body", - "description": "Created user object", - "required": true, - "schema": { "$ref": "#/definitions/User" } - } - ], - "responses": { "default": { "description": "successful operation" } } - } - } - }, - "securityDefinitions": { - "api_key": { "type": "apiKey", "name": "api_key", "in": "header" }, - "petstore_auth": { - "type": "oauth2", - "authorizationUrl": "https://petstore.swagger.io/oauth/authorize", - "flow": "implicit", - "scopes": { - "read:pets": "read your pets", - "write:pets": "modify pets in your account" - } - } - }, - "definitions": { - "ApiResponse": { - "type": "object", - "properties": { - "code": { "type": "integer", "format": "int32" }, - "type": { "type": "string" }, - "message": { "type": "string" } - } - }, - "Category": { - "type": "object", - "properties": { - "id": { "type": "integer", "format": "int64" }, - "name": { "type": "string" } - }, - "xml": { "name": "Category" } - }, - "Pet": { - "type": "object", - "required": ["name", "photoUrls"], - "properties": { - "id": { "type": "integer", "format": "int64" }, - "category": { "$ref": "#/definitions/Category" }, - "name": { "type": "string", "example": "doggie" }, - "photoUrls": { - "type": "array", - "xml": { "wrapped": true }, - "items": { "type": "string", "xml": { "name": "photoUrl" } } - }, - "tags": { - "type": "array", - "xml": { "wrapped": true }, - "items": { "xml": { "name": "tag" }, "$ref": "#/definitions/Tag" } - }, - "status": { - "type": "string", - "description": "pet status in the store", - "enum": ["available", "pending", "sold"] - } - }, - "xml": { "name": "Pet" } - }, - "Tag": { - "type": "object", - "properties": { - "id": { "type": "integer", "format": "int64" }, - "name": { "type": "string" } - }, - "xml": { "name": "Tag" } - }, - "Order": { - "type": "object", - "properties": { - "id": { "type": "integer", "format": "int64" }, - "petId": { "type": "integer", "format": "int64" }, - "quantity": { "type": "integer", "format": "int32" }, - "shipDate": { "type": "string", "format": "date-time" }, - "status": { - "type": "string", - "description": "Order Status", - "enum": ["placed", "approved", "delivered"] - }, - "complete": { "type": "boolean" } - }, - "xml": { "name": "Order" } - }, - "User": { - "type": "object", - "properties": { - "id": { "type": "integer", "format": "int64" }, - "username": { "type": "string" }, - "firstName": { "type": "string" }, - "lastName": { "type": "string" }, - "email": { "type": "string" }, - "password": { "type": "string" }, - "phone": { "type": "string" }, - "userStatus": { - "type": "integer", - "format": "int32", - "description": "User Status" - } - }, - "xml": { "name": "User" } - } - }, - "externalDocs": { - "description": "Find out more about Swagger", - "url": "http://swagger.io" - } -} \ No newline at end of file diff --git a/docs/openapi/jan.yaml b/docs/openapi/jan.yaml new file mode 100644 index 000000000..734537258 --- /dev/null +++ b/docs/openapi/jan.yaml @@ -0,0 +1,190 @@ +openapi: 3.0.0 +info: + title: Jan API Reference + description: Please see https://jan.ai for documentation. +version: "0.1.8" +contact: + name: Jan Discord + url: https://discord.gg/7EcEz7MrvA +license: + name: AGPLv3 + url: https://github.com/janhq/nitro/blob/main/LICENSE +servers: + - url: https://localhost:1337/v1/ +tags: + - name: Models + description: List and describe the various models available in the API. + - name: Chat Completion + description: Given a list of messages comprising a conversation, the model will return a response. + - name: Messages + description: Operations for individual messages, including creation, retrieval, and modification + - name: Threads + description: Manages series of related messages or conversation threads + - name: Assistants + description: Configures and utilizes different AI assistants for varied tasks +x-tagGroups: + - name: Endpoints + tags: + - Models + - Chat Completion + - name: Chat + tags: + - Assistants + - Messages + - Threads +paths: + /models: + get: + operationId: listModels + tags: + - Models + summary: List Models + description: Lists the currently available models, and provides basic information about each one such as the owner and availability. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "specs/models/models.yaml#/components/schemas/ListModelsResponse" + x-codeSamples: + - lang: "curl" + source: | + curl https://localhost:1337/v1/models + post: + operationId: downloadModel + tags: + - Models + summary: Download Model + description: Download a model. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "specs/models/models.yaml#/components/schemas/DownloadModelResponse" + x-codeSamples: + - lang: "curl" + source: | + curl -X POST https://localhost:1337/v1/models + /models/{model_id}: + get: + operationId: getModel + tags: + - Models + summary: Get Model + description: Get a model instance, providing basic information about the model such as the owner and permissioning. + parameters: + - in: path + name: source_url + required: true + schema: + type: string + # ideally this will be an actual ID, so this will always work from browser + example: https://huggingface.com/thebloke/example.gguf + description: The ID of the model to use for this request + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "specs/models/models.yaml#/components/schemas/GetModelResponse" + x-codeSamples: + - lang: "curl" + source: | + curl https://localhost:1337/v1/models/zephyr-7b + delete: + operationId: deleteModel + tags: + - Models + summary: Delete Model + description: Delete a model. + parameters: + - in: path + name: model + required: true + schema: + type: string + example: zephyr-7b + description: The model to delete + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "specs/models/models.yaml#/components/schemas/DeleteModelResponse" + x-codeSamples: + - lang: "curl" + source: | + curl -X DELETE https://localhost:1337/v1/models/zephyr-7b + /models/{model_id}/start: + put: + operationId: startModel + tags: + - Models + summary: Start Model + description: Starts an imported model. Loads the model into V/RAM. + parameters: + - in: path + name: model + required: true + schema: + type: string + # ideally this will be an actual ID, so this will always work from browser + example: zephyr-7b + description: The ID of the model to use for this request + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "specs/models/models.yaml#/components/schemas/StartModelResponse" + x-codeSamples: + - lang: "curl" + source: | + curl -X PUT https://localhost:1337/v1/models/zephyr-7b/start + /models/{model_id}/stop: + put: + operationId: stopModel + tags: + - Models + summary: Stop Model + description: Stop an imported model. + parameters: + - in: path + name: model + required: true + schema: + type: string + # ideally this will be an actual ID, so this will always work from browser + example: zephyr-7b + description: The ID of the model to use for this request + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "specs/models/models.yaml#/components/schemas/StopModelResponse" + x-codeSamples: + - lang: "curl" + source: | + curl -X PUT https://localhost:1337/v1/models/zephyr-7b/stop + +x-webhooks: + ModelObject: + post: + summary: The model object + description: Information about a model in the systems + operationId: ModelObject + tags: + - Models + requestBody: + content: + application/json: + schema: + $ref: 'specs/models/models.yaml#/components/schemas/ModelObject' diff --git a/docs/openapi/specs/models/models.yaml b/docs/openapi/specs/models/models.yaml new file mode 100644 index 000000000..da07eed4d --- /dev/null +++ b/docs/openapi/specs/models/models.yaml @@ -0,0 +1,329 @@ +components: + schemas: + ListModelsResponse: + type: object + properties: + object: + type: string + enum: [list] + data: + type: array + items: + $ref: "#/components/schemas/Model" + required: + - object + - data + + Model: + type: object + properties: + type: + type: string + default: "model" + description: "The type of the object." + version: + type: string + default: "1" + description: "The version number of the model." + id: + type: string + description: "Unique identifier used in chat-completions model_name, matches folder name." + example: "zephyr-7b" + name: + type: string + description: "Name of the model." + example: "Zephyr 7B" + owned_by: + type: string + description: "Compatibility field for OpenAI." + default: "" + created: + type: integer + format: int64 + description: "Unix timestamp representing the creation time." + description: + type: string + description: "Description of the model." + state: + type: string + enum: [null, "downloading", "available"] + description: "Current state of the model." + format: + type: string + description: "State format of the model, distinct from the engine." + example: "ggufv3" + source_url: + type: string + format: uri + description: "URL to the source of the model." + example: "https://huggingface.co/TheBloke/zephyr-7B-beta-GGUF/blob/main/zephyr-7b-beta.Q4_K_M.gguf" + settings: + type: object + properties: + ctx_len: + type: string + description: "Context length." + example: "2048" + ngl: + type: string + description: "Number of layers." + example: "100" + embedding: + type: string + description: "Indicates if embedding is enabled." + example: "true" + n_parallel: + type: string + description: "Number of parallel processes." + example: "4" + additionalProperties: false + parameters: + type: object + properties: + temperature: + type: string + description: "Temperature setting for the model." + example: "0.7" + token_limit: + type: string + description: "Token limit for the model." + example: "2048" + top_k: + type: string + description: "Top-k setting for the model." + example: "0" + top_p: + type: string + description: "Top-p setting for the model." + example: "1" + stream: + type: string + description: "Indicates if streaming is enabled." + example: "true" + additionalProperties: false + metadata: + type: object + description: "Additional metadata." + assets: + type: array + items: + type: string + description: "List of assets related to the model." + required: + - type + - version + - id + - name + - created + - state + - format + - source_url + - settings + - parameters + + ModelObject: + type: object + properties: + id: + type: string + description: "The identifier of the model." + example: "zephyr-7b" + object: + type: string + description: "The type of the object, indicating it's a model." + default: "model" + created: + type: integer + format: int64 + description: "Unix timestamp representing the creation time of the model." + example: "1253935178" + owned_by: + type: string + description: "The entity that owns the model." + example: "_" + required: + - id + - object + - created + - owned_by + + GetModelResponse: + type: object + properties: + id: + type: string + description: "The identifier of the model." + example: "zephyr-7b" + object: + type: string + description: "Type of the object, indicating it's a model." + default: "model" + created: + type: integer + format: int64 + description: "Unix timestamp representing the creation time of the model." + owned_by: + type: string + description: "The entity that owns the model." + example: "_" + state: + type: string + enum: [not_downloaded, downloaded, running, stopped] + description: "The current state of the model." + source_url: + type: string + format: uri + description: "URL to the source of the model." + example: "https://huggingface.co/TheBloke/zephyr-7B-beta-GGUF/blob/main/zephyr-7b-beta.Q4_K_M.gguf" + parameters: + type: object + properties: + ctx_len: + type: integer + description: "Context length." + example: 2048 + ngl: + type: integer + description: "Number of layers." + example: 100 + embedding: + type: boolean + description: "Indicates if embedding is enabled." + example: true + n_parallel: + type: integer + description: "Number of parallel processes." + example: 4 + # pre_prompt: + # type: string + # description: "Predefined prompt for initiating the chat." + # example: "A chat between a curious user and an artificial intelligence" + # user_prompt: + # type: string + # description: "Format of user's prompt." + # example: "USER: " + # ai_prompt: + # type: string + # description: "Format of AI's response." + # example: "ASSISTANT: " + temperature: + type: string + description: "Temperature setting for the model." + example: "0.7" + token_limit: + type: string + description: "Token limit for the model." + example: "2048" + top_k: + type: string + description: "Top-k setting for the model." + example: "0" + top_p: + type: string + description: "Top-p setting for the model." + example: "1" + metadata: + type: object + properties: + engine: + type: string + description: "The engine used by the model." + example: "llamacpp" + quantization: + type: string + description: "Quantization parameter of the model." + example: "Q3_K_L" + size: + type: string + description: "Size of the model." + example: "7B" + required: + - id + - object + - created + - owned_by + - state + - source_url + - parameters + - metadata + + DeleteModelResponse: + type: object + properties: + id: + type: string + description: "The identifier of the model that was deleted." + example: "model-zephyr-7B" + object: + type: string + description: "Type of the object, indicating it's a model." + default: "model" + deleted: + type: boolean + description: "Indicates whether the model was successfully deleted." + example: true + required: + - id + - object + - deleted + + StartModelResponse: + type: object + properties: + id: + type: string + description: "The identifier of the model that was started." + example: "model-zephyr-7B" + object: + type: string + description: "Type of the object, indicating it's a model." + default: "model" + state: + type: string + description: "The current state of the model after the start operation." + example: "running" + required: + - id + - object + - state + + StopModelResponse: + type: object + properties: + id: + type: string + description: "The identifier of the model that was started." + example: "model-zephyr-7B" + object: + type: string + description: "Type of the object, indicating it's a model." + default: "model" + state: + type: string + description: "The current state of the model after the start operation." + example: "stopped" + required: + - id + - object + - state + + DownloadModelResponse: + type: object + properties: + id: + type: string + description: "The identifier of the model that was started." + example: "model-zephyr-7B" + object: + type: string + description: "Type of the object, indicating it's a model." + default: "model" + state: + type: string + description: "The current state of the model after the start operation." + example: "downloaded" + required: + - id + - object + - state + diff --git a/docs/openapi/janapi.yaml b/docs/openapi/specs/threads/threads.yaml similarity index 100% rename from docs/openapi/janapi.yaml rename to docs/openapi/specs/threads/threads.yaml From 611bd0e9d997e50e664629c6822a128ef3e6d21b Mon Sep 17 00:00:00 2001 From: hahuyhoang411 Date: Wed, 22 Nov 2023 11:01:26 +0700 Subject: [PATCH 03/13] merged with Nicole --- docs/docs/specs/messages.md | 208 +++++++++++--------- docs/docs/specs/models.md | 365 +++++++----------------------------- docs/docs/specs/threads.md | 214 ++++++++++++--------- docs/sidebars.js | 4 +- 4 files changed, 309 insertions(+), 482 deletions(-) diff --git a/docs/docs/specs/messages.md b/docs/docs/specs/messages.md index 66e4eeaa2..cefb99275 100644 --- a/docs/docs/specs/messages.md +++ b/docs/docs/specs/messages.md @@ -2,57 +2,72 @@ title: Messages --- -:::warning +:::caution -Draft Specification: functionality has not been implemented yet. - -Feedback: [HackMD: Threads Spec](https://hackmd.io/BM_8o_OCQ-iLCYhunn2Aug) +This is currently under development. ::: -Messages are within `threads` and capture additional metadata. -> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages +## Overview + +`Messages` are in `threads` and capture additional metadata. + +- Users and assistants can send multimedia messages. +- An [OpenAI Message API](https://platform.openai.com/docs/api-reference/messages) compatible endpoint at `localhost:3000/v1/messages`. + +## Folder Structure + +- `Message` objects are stored in `thread.json` files under the `messages` property. See [threads](./threads.md). + +## `message` object + +### Example + +Here's a standard example `message` json. -## Message Object -> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/object ```json -{ - // Jan specific properties - "updatedAt": "...", // that's it I think - - // OpenAI compatible properties: https://platform.openai.com/docs/api-reference/messages) - "id": "msg_dKYDWyQvtjDBi3tudL1yWKDa", - "object": "thread.message", - "created_at": 1698983503, - "thread_id": "thread_RGUhOuO9b2nrktrmsQ2uSR6I", - "role": "assistant", - "content": [ - { - "type": "text", - "text": { - "value": "Hi! How can I help you today?", - "annotations": [] - } +"id": "0", // Sequential or UUID? +"object": "thread.message", // Defaults to "thread.message" +"created_at": 1698983503, +"thread_id": "thread_asdf", // Defaults to parent thread +"assistant_id": "jan", // Defaults to parent thread +"role": "assistant", // From either "user" or "assistant" +"content": [ + { + "type": "text", + "text": { + "value": "Hi! How can I help you today?", + "annotations": [] } - ], - "file_ids": [], - "assistant_id": "asst_ToSF7Gb04YMj8AMMm50ZLLtY", - "run_id": "run_BjylUJgDqYK9bOhy4yjAiMrn", - "metadata": {} -} + } +], +"metadata": {}, // Defaults to {} +"chat_completion_id": "", // For now, we use `chat` completion id +// "run_id": "...", // Rather than `run` id +// "file_ids": [], ``` -## Messages API -> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages +## API Reference + +Jan's Threads API is compatible with [OpenAI's Messages API](https://platform.openai.com/docs/api-reference/messages), with additional methods for managing messages locally. + +See [Jan Messages API](https://jan.ai/api-reference#tag/Messages) + + ### Get list message + > OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/getMessage + - Example request + ```shell curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id} \ -H "Content-Type: application/json" ``` + - Example response + ```json { "id": "msg_abc123", @@ -75,9 +90,13 @@ Messages are within `threads` and capture additional metadata. "metadata": {} } ``` + ### Create message + > OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/createMessage + - Example request + ```shell curl -X POST {JAN_URL}/v1/threads/{thread_id}/messages \ -H "Content-Type: application/json" \ @@ -86,93 +105,112 @@ Messages are within `threads` and capture additional metadata. "content": "How does AI work? Explain it in simple terms." }' ``` + - Example response + ```json - { - "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": [] - } +{ + "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": {} - } + } + ], + "file_ids": [], + "assistant_id": null, + "run_id": null, + "metadata": {} +} ``` + ### Get message + > OpenAI Equivalent: https://platform.openai.com/docs/api-reference/assistants/listAssistants + - Example request + ```shell curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id} \ -H "Content-Type: application/json" ``` + - Example response + ```json - { - "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": [] - } +{ + "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": {} - } + } + ], + "file_ids": [], + "assistant_id": null, + "run_id": null, + "metadata": {} +} ``` ### Modify message + > Jan: TODO: Do we need to modify message? Or let user create new message? # Get message file + > OpenAI Equivalent: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} + - Example request + ```shell curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} \ -H "Content-Type: application/json" ``` + - Example response + ```json - { - "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" +} ``` + # List message files + > OpenAI Equivalent: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files -``` + +```` - Example request ```shell curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} \ -H "Content-Type: application/json" -``` +```` + - Example response + ```json - { - "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" +} ``` \ No newline at end of file diff --git a/docs/docs/specs/models.md b/docs/docs/specs/models.md index c214f7557..ef2ca7f95 100644 --- a/docs/docs/specs/models.md +++ b/docs/docs/specs/models.md @@ -2,344 +2,105 @@ title: Models --- -import ApiSchema from '@theme/ApiSchema'; +:::caution -:::warning - -Draft Specification: functionality has not been implemented yet. - -Feedback: [HackMD: Models Spec](https://hackmd.io/ulO3uB1AQCqLa5SAAMFOQw) +This is currently under development. ::: ## Overview -Jan's Model API aims to be as similar as possible to [OpenAI's Models API](https://platform.openai.com/docs/api-reference/models), with additional methods for managing and running models locally. +In Jan, models are primary entities with the following capabilities: -### Objectives +- Users can import, configure, and run models locally. +- An [OpenAI Model API](https://platform.openai.com/docs/api-reference/models) compatible endpoint at `localhost:3000/v1/models`. +- Supported model formats: `ggufv3`, and more. -- Users can download, import and delete models -- Users can use remote models (e.g. OpenAI, OpenRouter) -- Users can start/stop models and use them in a thread (or via Chat Completions API) -- User can configure default model parameters at the model level (to be overridden later at message or thread level) +## Folder Structure -## Models Folder +- Models are stored in the `/models` folder. +- Models are organized by individual folders, each containing the binaries and configurations needed to run the model. This makes for easy packaging and sharing. +- Model folder names are unique and used as `model_id` default values. -Models in Jan are stored in the `/models` folder. - -Models are stored and organized by folders, which are atomic representations of a model for easy packaging and version control. - -A model's folder name is its `model.id` and contains: - -- `.json`, i.e. the [Model Object](#model-object) -- Binaries (may be downloaded later) - -```shell -/jan # Jan root folder - /models - # GGUF model - /llama2-70b - llama2-70b.json - llama2-70b-q4_k_m.gguf - - # Recommended Model (yet to be downloaded) - /mistral-7b - mistral-7b.json # Contains download instructions - # Note: mistral-7b-*.gguf binaries not downloaded yet - - # Remote model - /azure-openai-gpt3-5 - azure-openai-gpt3-5.json - # Note: No binaries - - # Multiple Binaries - # COMING SOON - - # Multiple Quantizations - # COMING SOON - - # Imported model (autogenerated .json) - random-model-q4_k_m.bin - # Note: will be moved into a autogenerated folder - # /random-model-q4_k_m - # random-model-q4_k_m.bin - # random-model-q4_k_m.json (autogenerated) +```bash +jan/ # Jan root folder + models/ + llama2-70b-q4_k_m/ # Example: standard GGUF model + model.json + model-binary-1.gguf + mistral-7b-gguf-q3_k_l/ # Example: quantizations are separate folders + model.json + mistral-7b-q3-K-L.gguf + mistral-7b-gguf-q8_k_m/ # Example: quantizations are separate folders + model.json + mistral-7b-q8_k_k.gguf + llava-ggml-Q5/ # Example: model with many partitions + model.json + mmprj.bin + model_q5.ggml ``` -### Importing Models +## `model.json` -:::warning +- Each `model` folder contains a `model.json` file, which is a representation of a model. +- `model.json` contains metadata and default parameters used to run a model. +- The only required field is `source_url`. -- This has not been confirmed -- Dan's view: Jan should auto-detect and create folders automatically -- Jan's UI will allow users to rename folders and add metadata +### Example -::: +Here's a standard example `model.json` for a GGUF model. -You can import a model by just dragging it into the `/models` folder, similar to Oobabooga. - -- Jan will detect and generate a corresponding `model-filename.json` file based on filename -- Jan will move it into its own `/model-id` folder once you define a `model-id` via the UI -- Jan will populate the model's `model-id.json` as you add metadata through the UI - -## Model Object - -:::warning - -- This is currently not finalized -- Dan's view: I think the current JSON is extremely clunky - - We should move `init` to top-level (e.g. "settings"?) - - We should move `runtime` to top-level (e.g. "parameters"?) - - `metadata` is extremely overloaded and should be refactored -- Dan's view: we should make a model object very extensible - - A `GGUF` model would "extend" a common model object with extra fields (at top level) -- Dan's view: State is extremely badly named - - Recommended: `downloaded`, `started`, `stopped`, null (for yet-to-download) - - We should also note that this is only for local models (not remote) - -::: - -Jan represents models as `json`-based Model Object files, known colloquially as `model.jsons`. Jan aims for rough equivalence with [OpenAI's Model Object](https://platform.openai.com/docs/api-reference/models/object) with additional properties to support local models. - -Jan's models follow a `model_id.json` naming convention, and are built to be extremely lightweight, with the only mandatory field being a `source_url` to download the model binaries. - - - -### Types of Models - -:::warning - -- This is currently not in the Model Object, and requires further discussion. -- Dan's view: we should have a field to differentiate between `local` and `remote` models - -::: - -There are 3 types of models. - -- Local model -- Local model, yet-to-be downloaded (we have the URL) -- Remote model (i.e. OpenAI API) - -#### Local Models - -:::warning - -- This is currently not finalized -- Dan's view: we should have `download_url` and `local_url` for local models (and possibly more) - -::: - -A `model.json` for a local model should always reference the following fields: - -- `download_url`: the original download source of the model -- `local_url`: the current location of the model binaries (may be array of multiple binaries) +- `source_url`: https://huggingface.co/TheBloke/zephyr-7B-beta-GGUF/. ```json -// ./models/llama2/llama2-7bn-gguf.json -"local_url": "~/Downloads/llama-2-7bn-q5-k-l.gguf", -``` - -#### Remote Models - -:::warning - -- This is currently not finalized -- Dan's view: each cloud model should be provided via a syste module, or define its own params field on the `model` or `model.init` object - -::: - -A `model.json` for a remote model should always reference the following fields: - -- `api_url`: the API endpoint of the model -- Any authentication parameters - -```json -// Dan's view: This needs to be refactored pretty significantly -"source_url": "https://docs-test-001.openai.azure.com/openai.azure.com/docs-test-001/gpt4-turbo", -"parameters": { - "init" { - "API-KEY": "", - "DEPLOYMENT-NAME": "", - "api-version": "2023-05-15" - }, - "runtime": { - "temperature": "0.7", - "max_tokens": "2048", - "presence_penalty": "0", - "top_p": "1", - "stream": "true" - } -} -"metadata": { - "engine": "api", // Dan's view: this should be a `type` field -} -``` - -### Importers - -:::caution - -- This is only an idea, has not been confirmed as part of spec - -::: - -Jan builds "importers" for users to seamlessly import models from a single URL. - -We currently only provide this for [TheBloke models on Huggingface](https://huggingface.co/TheBloke) (i.e. one of the patron saints of llama.cpp), but we plan to add more in the future. - -Currently, pasting a TheBloke Huggingface link in the Explore Models page will fire an importer, resulting in an: - -- Nicely-formatted model card -- Fully-annotated `model.json` file - -### Multiple Binaries - -:::warning - -- This is currently not finalized -- Dan's view: having these fields under `model.metadata` is not maintainable -- We should explore some sort of `local_url` structure - -::: - -- Model has multiple binaries `model-llava-1.5-ggml.json` -- See [source](https://huggingface.co/mys/ggml_llava-v1.5-13b) - -```json -"source_url": "https://huggingface.co/mys/ggml_llava-v1.5-13b", -"parameters": {"init": {}, "runtime": {}} -"metadata": { - "mmproj_binary": "https://huggingface.co/mys/ggml_llava-v1.5-13b/blob/main/mmproj-model-f16.gguf", - "ggml_binary": "https://huggingface.co/mys/ggml_llava-v1.5-13b/blob/main/ggml-model-q5_k.gguf", - "engine": "llamacpp", - "quantization": "Q5_K" -} -``` - -## Models API - -:::warning - -- We should use the OpenAPI spec to discuss APIs -- Dan's view: This needs @louis and App Pod to review as they are more familiar with this -- Dan's view: Start/Stop model should have some UI indicator (show state, block input) - -::: - -See http://localhost:3001/api-reference#tag/Models. - -| Method | API Call | OpenAI-equivalent | -| -------------- | ------------------------------- | ----------------- | -| List Models | GET /v1/models | true | -| Get Model | GET /v1/models/{model_id} | true | -| Delete Model | DELETE /v1/models/{model_id} | true | -| Start Model | PUT /v1/models/{model_id}/start | | -| Stop Model | PUT /v1/models/{model_id}/start | | -| Download Model | POST /v1/models/ | | - -## Examples - -### Local Model - -- Model has 1 binary `model-zephyr-7B.json` -- See [source](https://huggingface.co/TheBloke/zephyr-7B-beta-GGUF/) - -```json -// ./models/zephr/zephyr-7b-beta-Q4_K_M.json -// Note: Default fields omitted for brevity +"id": "zephyr-7b" // Defaults to foldername +"object": "model", // Defaults to "model" "source_url": "https://huggingface.co/TheBloke/zephyr-7B-beta-GGUF/blob/main/zephyr-7b-beta.Q4_K_M.gguf", -"parameters": { - "init": { +"name": "Zephyr 7B" // Defaults to foldername +"owned_by": "you" // Defaults to you +"version": "1", // Defaults to 1 +"created": 1231231 // Defaults to file creation time +"description": "" +"state": enum[null, "downloading", "ready", "starting", "stopping", ...] +"format": "ggufv3", // Defaults to "ggufv3" +"settings": { // Models are initialized with these settings "ctx_len": "2048", "ngl": "100", "embedding": "true", "n_parallel": "4", - "pre_prompt": "A chat between a curious user and an artificial intelligence", - "user_prompt": "USER: ", - "ai_prompt": "ASSISTANT: " - }, - "runtime": { + // KIV: "pre_prompt": "A chat between a curious user and an artificial intelligence", + // KIV:"user_prompt": "USER: ", + // KIV: "ai_prompt": "ASSISTANT: " +} +"parameters": { // Models are called with these parameters "temperature": "0.7", "token_limit": "2048", "top_k": "0", "top_p": "1", "stream": "true" - } }, -"metadata": { - "engine": "llamacpp", - "quantization": "Q3_K_L", - "size": "7B", -} +"metadata": {} // Defaults to {} +"assets": [ // Filepaths to model binaries; Defaults to current dir + "file://.../zephyr-7b-q4_k_m.bin", +] ``` -### Remote Model +## API Reference -- Using a remote API to access model `model-azure-openai-gpt4-turbo.json` -- See [source](https://learn.microsoft.com/en-us/azure/ai-services/openai/quickstart?tabs=command-line%2Cpython&pivots=rest-api) +Jan's Model API is compatible with [OpenAI's Models API](https://platform.openai.com/docs/api-reference/models), with additional methods for managing and running models locally. -```json -"source_url": "https://docs-test-001.openai.azure.com/openai.azure.com/docs-test-001/gpt4-turbo", -"parameters": { - "init" { - "API-KEY": "", - "DEPLOYMENT-NAME": "", - "api-version": "2023-05-15" - }, - "runtime": { - "temperature": "0.7", - "max_tokens": "2048", - "presence_penalty": "0", - "top_p": "1", - "stream": "true" - } -} -"metadata": { - "engine": "api", -} -``` +See [Jan Models API](https://jan.ai/api-reference#tag/Models) -### Deferred Download +## Importing Models -- Jan ships with a default model folders containing recommended models -- Only the Model Object `json` files are included -- Users must later explicitly download the model binaries -- -```sh -models/ - mistral-7b/ - mistral-7b.json - hermes-7b/ - hermes-7b.json -``` +:::caution -### Multiple quantizations +This is currently under development. -- Each quantization has its own `Jan Model Object` file -- TODO: `model.json`? +::: -```sh -llama2-7b-gguf/ - llama2-7b-gguf-Q2.json - llama2-7b-gguf-Q3_K_L.json - .bin -``` +You can import a model by dragging the model binary or gguf file into the `/models` folder. -### Multiple model partitions - -- A Model that is partitioned into several binaries use just 1 file - -```sh -llava-ggml/ - llava-ggml-Q5.json - .proj - ggml -``` - -### Locally fine-tuned model - -```sh -llama-70b-finetune/ - llama-70b-finetune-q5.json - .bin -``` \ No newline at end of file +- Jan automatically generates a corresponding `model.json` file based on the binary filename. +- Jan automatically organizes it into its own `/models/model-id` folder. +- Jan automatically populates the `model.json` properties, which you can subsequently modify. \ No newline at end of file diff --git a/docs/docs/specs/threads.md b/docs/docs/specs/threads.md index d5bc15c8f..bc9a1fed9 100644 --- a/docs/docs/specs/threads.md +++ b/docs/docs/specs/threads.md @@ -2,89 +2,95 @@ title: Threads --- -:::warning +:::caution -Draft Specification: functionality has not been implemented yet. - -Feedback: [HackMD: Threads Spec](https://hackmd.io/BM_8o_OCQ-iLCYhunn2Aug) +This is currently under development. ::: -## User Stories +## Overview -_Users can chat with an assistant in a thread_ +`Threads` are conversations between an `assistant` and the user: -- See [Messages Spec](./messages.md) +- Users can tweak `model` params and `assistant` behavior within each thread. +- Users can import and export threads. +- An [OpenAI Thread API](https://platform.openai.com/docs/api-reference/threads) compatible endpoint at `localhost:3000/v1/threads`. -_Users can change assistant and model parameters in a thread_ +## Folder Structure -- Wireframes of - -_Users can delete all thread history_ - -- Wireframes of settings page. - -## Jan Thread Object - -- A `Jan Thread Object` is a "representation of a conversation thread" between an `assistant` and the user -- Objects are defined by `thread-uuid.json` files in `json` format -- Objects are designed to be compatible with `OpenAI Thread Objects` with additional properties needed to run on our infrastructure. -- Objects contain a `models` field, to track when the user overrides the assistant's default model parameters. - -| Property | Type | Description | Validation | -| ---------- | ----------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | -| `object` | enum: `model`, `assistant`, `thread`, `message` | The Jan Object type | Defaults to `thread` | -| `assistants` | array | An array of Jan Assistant Objects. Threads can "override" an assistant's parameters. Thread-level model parameters are directly saved in the `thread.models` property! (see Models spec) | Defaults to `assistant.name` | -| `messages` | array | An array of Jan Message Objects. (see Messages spec) | Defaults to `[]` | -| `metadata` | map | Useful for storing additional information about the object in a structured format. | Defaults to `{}` | - -### Generic Example - -```json -// janroot/threads/jan_1700123404.json -"assistants": ["assistant-123"], -"messages": [ - {...message0}, {...message1} -], -"metadata": { - "summary": "funny physics joke", -}, -``` - -## Filesystem - -- `Jan Thread Objects`'s `json` files always has the naming schema: `assistant_uuid` + `unix_time_thread_created_at. See below. -- Threads are all saved in the `janroot/threads` folder in a flat folder structure. -- The folder is standalone and can be easily zipped, exported, and cleared. +- Threads are saved in the `/threads` folder. +- Threads are organized by folders, one for each thread, and can be easily zipped, exported, and cleared. +- Thread folders follow the naming: `assistant_id` + `thread_created_at`. ```sh -janroot/ +jan/ threads/ - jan_1700123404.json - homework_helper_700120003.json + assistant_name_unix_timestamp/ + thread.json + jan_2341243134/ + thread.json ``` -## Jan API +## `thread.json` + +- Each `thread` folder contains a `thread.json` file, which is a representation of a thread. +- `thread.json` contains metadata, model parameter overrides, and [message](https://jan.ai/specs/messages) history. +- There are no required fields. + +### Example + +Here's a standard example `thread.json` for a conversation between the user and the default Jan assistant. + +```json +"id": "thread_....", // Defaults to foldername +"object": "thread", // Defaults to "thread" +"summary": "funny physics joke", // Defaults to "" +"assistants": ["jan"], // Defaults to "jan" +"created": 1231231 // Defaults to file creation time +"metadata": {}, // Defaults to {} +"messages": [], +"model_id": "...", // Defaults to assistant.model ??? +"settings": {}, // Defaults to and overrides assistant.settings +"parameters": {}, // Defaults to and overrides assistant.settings +``` + +## API Reference + +Jan's Threads API is compatible with [OpenAI's Threads API](https://platform.openai.com/docs/api-reference/threads), with additional methods for managing threads locally. + +See [Jan Threads API](https://jan.ai/api-reference#tag/Threads) + + + ### Get thread + > OpenAI Equivalent: https://platform.openai.com/docs/api-reference/threads/getThread + - Example request + ```shell curl {JAN_URL}/v1/threads/{thread_id} ``` + - Example response + ```json - { - "id": "thread_abc123", - "object": "thread", - "created_at": 1699014083, - "assistants": ["assistant-001"], - "metadata": {}, - "messages": [] - } +{ + "id": "thread_abc123", + "object": "thread", + "created_at": 1699014083, + "assistants": ["assistant-001"], + "metadata": {}, + "messages": [] +} ``` + ### Create Thread + > OpenAI Equivalent: https://platform.openai.com/docs/api-reference/threads/createThread + - Example request + ```shell curl -X POST {JAN_URL}/v1/threads \ -H "Content-Type: application/json" \ @@ -99,18 +105,24 @@ janroot/ }] }' ``` + - Example response + ```json - { - "id": 'thread_abc123', - "object": 'thread', - "created_at": 1699014083, - "metadata": {} - } +{ + "id": "thread_abc123", + "object": "thread", + "created_at": 1699014083, + "metadata": {} +} ``` + ### Modify Thread + > OpenAI Equivalent: https://platform.openai.com/docs/api-reference/threads/modifyThread + - Example request + ```shell curl -X POST {JAN_URL}/v1/threads/{thread_id} \ -H "Content-Type: application/json" \ @@ -125,69 +137,85 @@ janroot/ }] }' ``` + - Example response + ```json - { - "id": 'thread_abc123', - "object": 'thread', - "created_at": 1699014083, - "metadata": {} - } +{ + "id": "thread_abc123", + "object": "thread", + "created_at": 1699014083, + "metadata": {} +} ``` - https://platform.openai.com/docs/api-reference/threads/modifyThread ### Delete Thread + > OpenAI Equivalent: https://platform.openai.com/docs/api-reference/threads/deleteThread + - Example request + ```shell curl -X DELETE {JAN_URL}/v1/threads/{thread_id} ``` + - Example response + ```json - { - "id": "thread_abc123", - "object": "thread.deleted", - "deleted": true - } +{ + "id": "thread_abc123", + "object": "thread.deleted", + "deleted": true +} ``` ### List Threads + > This is a Jan-only endpoint, not supported by OAI yet. + - Example request + ```shell curl {JAN_URL}/v1/threads \ -H "Content-Type: application/json" \ ``` + - Example response + ```json - [ - { - "id": "thread_abc123", - "object": "thread", - "created_at": 1699014083, - "assistants": ["assistant-001"], - "metadata": {}, - "messages": [] - }, - { - "id": "thread_abc456", - "object": "thread", - "created_at": 1699014083, - "assistants": ["assistant-002", "assistant-002"], - "metadata": {}, - } - ] +[ + { + "id": "thread_abc123", + "object": "thread", + "created_at": 1699014083, + "assistants": ["assistant-001"], + "metadata": {}, + "messages": [] + }, + { + "id": "thread_abc456", + "object": "thread", + "created_at": 1699014083, + "assistants": ["assistant-002", "assistant-002"], + "metadata": {} + } +] ``` ### Get & Modify `Thread.Assistants` + -> Can achieve this goal by calling `Modify Thread` API #### `GET v1/threads/{thread_id}/assistants` + -> Can achieve this goal by calling `Get Thread` API #### `POST v1/threads/{thread_id}/assistants/{assistant_id}` + -> Can achieve this goal by calling `Modify Assistant` API with `thread.assistant[]` ### List `Thread.Messages` --> Can achieve this goal by calling `Get Thread` API + +-> Can achieve this goal by calling `Get Thread` API \ No newline at end of file diff --git a/docs/sidebars.js b/docs/sidebars.js index aa05c4117..711c00a7a 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -61,8 +61,8 @@ const sidebars = { items: [ "specs/chats", "specs/models", - // "specs/threads", - // "specs/messages", + "specs/threads", + "specs/messages", // "specs/assistants", // "specs/files", // "specs/jan", From 00b583659ac797e1c483a71f1f3a6e2400cda585 Mon Sep 17 00:00:00 2001 From: hahuyhoang411 Date: Wed, 22 Nov 2023 12:46:09 +0700 Subject: [PATCH 04/13] update messages and threads --- docs/docs/specs/messages.md | 64 +++- docs/openapi/jan.yaml | 392 +++++++++++++++++++- docs/openapi/specs/messages.yaml | 326 ++++++++++++++++ docs/openapi/specs/{models => }/models.yaml | 2 +- docs/openapi/specs/threads.yaml | 169 +++++++++ docs/openapi/specs/threads/threads.yaml | 0 6 files changed, 926 insertions(+), 27 deletions(-) create mode 100644 docs/openapi/specs/messages.yaml rename docs/openapi/specs/{models => }/models.yaml (99%) create mode 100644 docs/openapi/specs/threads.yaml delete mode 100644 docs/openapi/specs/threads/threads.yaml diff --git a/docs/docs/specs/messages.md b/docs/docs/specs/messages.md index cefb99275..883a1f333 100644 --- a/docs/docs/specs/messages.md +++ b/docs/docs/specs/messages.md @@ -57,12 +57,12 @@ See [Jan Messages API](https://jan.ai/api-reference#tag/Messages) ### Get list message -> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/getMessage +> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/listMessages - Example request ```shell - curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id} \ + curl {JAN_URL}/v1/threads/{thread_id}/messages \ -H "Content-Type: application/json" ``` @@ -70,24 +70,54 @@ See [Jan Messages API](https://jan.ai/api-reference#tag/Messages) ```json { - "id": "msg_abc123", - "object": "thread.message", - "created_at": 1699017614, - "thread_id": "thread_abc123", - "role": "user", - "content": [ + "object": "list", + "data": [ { - "type": "text", - "text": { - "value": "How does AI work? Explain it in simple terms.", - "annotations": [] - } + "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": {} } ], - "file_ids": [], - "assistant_id": null, - "run_id": null, - "metadata": {} + "first_id": "msg_abc123", + "last_id": "msg_abc456", + "has_more": false } ``` diff --git a/docs/openapi/jan.yaml b/docs/openapi/jan.yaml index 734537258..39e613e78 100644 --- a/docs/openapi/jan.yaml +++ b/docs/openapi/jan.yaml @@ -33,6 +33,7 @@ x-tagGroups: - Messages - Threads paths: + ### MODELS /models: get: operationId: listModels @@ -46,7 +47,7 @@ paths: content: application/json: schema: - $ref: "specs/models/models.yaml#/components/schemas/ListModelsResponse" + $ref: "specs/models.yaml#/components/schemas/ListModelsResponse" x-codeSamples: - lang: "curl" source: | @@ -63,7 +64,7 @@ paths: content: application/json: schema: - $ref: "specs/models/models.yaml#/components/schemas/DownloadModelResponse" + $ref: "specs/models.yaml#/components/schemas/DownloadModelResponse" x-codeSamples: - lang: "curl" source: | @@ -90,7 +91,7 @@ paths: content: application/json: schema: - $ref: "specs/models/models.yaml#/components/schemas/GetModelResponse" + $ref: "specs/models.yaml#/components/schemas/GetModelResponse" x-codeSamples: - lang: "curl" source: | @@ -115,7 +116,7 @@ paths: content: application/json: schema: - $ref: "specs/models/models.yaml#/components/schemas/DeleteModelResponse" + $ref: "specs/models.yaml#/components/schemas/DeleteModelResponse" x-codeSamples: - lang: "curl" source: | @@ -142,7 +143,7 @@ paths: content: application/json: schema: - $ref: "specs/models/models.yaml#/components/schemas/StartModelResponse" + $ref: "specs/models.yaml#/components/schemas/StartModelResponse" x-codeSamples: - lang: "curl" source: | @@ -169,12 +170,359 @@ paths: content: application/json: schema: - $ref: "specs/models/models.yaml#/components/schemas/StopModelResponse" + $ref: "specs/models.yaml#/components/schemas/StopModelResponse" x-codeSamples: - lang: "curl" source: | - curl -X PUT https://localhost:1337/v1/models/zephyr-7b/stop - + curl -X PUT https://localhost:1337/v1/models/zephyr-7b/stop + + ### THREADS + /threads: + post: + operationId: createThread + tags: + - Threads + summary: Create a new thread + description: Creates a new thread with an initial set of messages. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + messages: + type: array + description: "Initial set of messages for the thread." + items: + $ref: 'specs/threads.yaml#/components/schemas/ThreadMessageObject' + required: + - messages + responses: + "200": + description: Thread created successfully + content: + application/json: + schema: + $ref: 'specs/threads.yaml#/components/schemas/CreateThreadResponse' + x-codeSamples: + - lang: "curl" + source: | + curl -X POST {JAN_URL}/v1/threads \ + -H "Content-Type: application/json" \ + -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."}]}' + get: + operationId: listThreads + tags: + - Threads + summary: List all threads + description: Retrieves a list of all threads available in the system. + responses: + "200": + description: List of threads retrieved successfully + content: + application/json: + schema: + type: array + items: + $ref: 'specs/threads.yaml#/components/schemas/ThreadObject' + example: + - id: "thread_abc123" + object: "thread" + created_at: 1699014083 + assistants: ["assistant-001"] + metadata: {} + messages: [] + - id: "thread_abc456" + object: "thread" + created_at: 1699014083 + assistants: ["assistant-002", "assistant-003"] + metadata: {} + x-codeSamples: + - lang: "curl" + source: | + curl {JAN_URL}/v1/threads \ + -H "Content-Type: application/json" + + /threads/{thread_id}: + get: + operationId: getThread + tags: + - Threads + summary: Get details of a specific thread + description: Retrieves detailed information about a specific thread using its thread_id. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + example: thread_abc123 + description: The ID of the thread to retrieve. + responses: + "200": + description: Thread details retrieved successfully + content: + application/json: + schema: + $ref: "specs/threads.yaml#/components/schemas/GetThreadResponse" + x-codeSamples: + - lang: "curl" + source: | + curl {JAN_URL}/v1/threads/{thread_id} + post: + operationId: modifyThread + tags: + - Threads + summary: Modify an existing thread + description: Updates a thread with new or modified messages. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + example: thread_abc123 + description: The ID of the thread to be modified. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + messages: + type: array + description: "Set of messages to update in the thread." + items: + $ref: 'specs/threads.yaml#/components/schemas/ThreadMessageObject' + required: + - messages + responses: + "200": + description: Thread modified successfully + content: + application/json: + schema: + $ref: 'specs/threads.yaml#/components/schemas/ModifyThreadResponse' + x-codeSamples: + - lang: "curl" + source: | + curl -X POST {JAN_URL}/v1/threads/{thread_id} \ + -H "Content-Type: application/json" \ + -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."}]}' + delete: + operationId: deleteThread + tags: + - Threads + summary: Delete a specific thread + description: Deletes a thread identified by its thread_id. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + example: thread_abc123 + description: The ID of the thread to be deleted. + responses: + "200": + description: Thread deleted successfully + content: + application/json: + schema: + $ref: 'specs/threads.yaml#/components/schemas/DeleteThreadResponse' + x-codeSamples: + - lang: "curl" + source: | + curl -X DELETE {JAN_URL}/v1/threads/{thread_id} + ### MESSAGES + /threads/{thread_id}/messages: + get: + operationId: listMessages + tags: + - Messages + summary: Get a list of messages from a thread + description: Retrieves all messages from the specified thread. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + example: thread_abc123 + description: The ID of the thread from which to retrieve messages. + responses: + "200": + description: List of messages retrieved successfully + content: + application/json: + schema: + $ref: "specs/messages.yaml#/components/schemas/ListMessagesResponse" + x-codeSamples: + - lang: "curl" + source: | + curl {JAN_URL}/v1/threads/{thread_id}/messages \ + -H "Content-Type: application/json" + post: + operationId: createMessage + tags: + - Messages + summary: Create a new message in a thread + description: Sends a new message to the specified thread. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + example: thread_abc123 + description: The ID of the thread to which the message will be posted. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + role: + type: string + description: "Role of the sender, either 'user' or 'assistant'." + example: "user" + enum: ["user", "assistant"] + content: + type: string + description: "Text content of the message." + example: "How does AI work? Explain it in simple terms." + required: + - role + - content + responses: + "200": + description: Message created successfully + content: + application/json: + schema: + $ref: "specs/messages.yaml#/components/schemas/CreateMessageResponse" + x-codeSamples: + - lang: "curl" + source: | + curl -X POST {JAN_URL}/v1/threads/{thread_id}/messages \ + -H "Content-Type: application/json" \ + -d '{"role": "user", "content": "How does AI work? Explain it in simple terms."}' + + /threads/{thread_id}/messages/{message_id}: + get: + operationId: getMessage + tags: + - Messages + summary: Retrieve Message + description: Retrieve a specific message from a thread using its thread_id and message_id. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + example: thread_abc123 + description: The ID of the thread containing the message. + - in: path + name: message_id + required: true + schema: + type: string + example: msg_abc123 + description: The ID of the message to retrieve. + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: "specs/messages.yaml#/components/schemas/GetMessageResponse" + x-codeSamples: + - lang: "curl" + source: | + curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id} \ + -H "Content-Type: application/json" + + /threads/{thread_id}/messages/{message_id}/files: + get: + operationId: listMessageFiles + tags: + - Messages + summary: message files + description: Retrieves a list of files associated with a specific message in a thread. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + example: thread_abc123 + description: The ID of the thread containing the message. + - in: path + name: message_id + required: true + schema: + type: string + example: msg_abc123 + description: The ID of the message whose files are to be listed. + responses: + "200": + description: List of files retrieved successfully + content: + application/json: + schema: + $ref: "specs/messages.yaml#/components/schemas/ListMessageFilesResponse" + x-codeSamples: + - lang: "curl" + source: | + curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id}/files \ + -H "Content-Type: application/json" + + /threads/{thread_id}/messages/{message_id}/files/{file_id}: + get: + operationId: getMessageFile + tags: + - Messages + summary: Get message file + description: Retrieves a file associated with a specific message in a thread. + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + example: thread_abc123 + description: The ID of the thread containing the message. + - in: path + name: message_id + required: true + schema: + type: string + example: msg_abc123 + description: The ID of the message associated with the file. + - in: path + name: file_id + required: true + schema: + type: string + example: file-abc123 + description: The ID of the file to retrieve. + responses: + "200": + description: File retrieved successfully + content: + application/json: + schema: + $ref: "specs/messages.yaml#/components/schemas/MessageFileObject" + x-codeSamples: + - lang: "curl" + source: | + curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} \ + -H "Content-Type: application/json" + x-webhooks: ModelObject: post: @@ -187,4 +535,30 @@ x-webhooks: content: application/json: schema: - $ref: 'specs/models/models.yaml#/components/schemas/ModelObject' + $ref: 'specs/models.yaml#/components/schemas/ModelObject' + + MessageObject: + post: + summary: The message object + description: Information about a message in the thread + operationId: MessageObject + tags: + - Messages + requestBody: + content: + application/json: + schema: + $ref: 'specs/messages.yaml#/components/schemas/MessageObject' + + ThreadObject: + post: + summary: The thread object + description: Information about a thread + operationId: ThreadObject + tags: + - Threads + requestBody: + content: + application/json: + schema: + $ref: 'specs/threads.yaml#/components/schemas/ThreadObject' diff --git a/docs/openapi/specs/messages.yaml b/docs/openapi/specs/messages.yaml new file mode 100644 index 000000000..a3dc74a0d --- /dev/null +++ b/docs/openapi/specs/messages.yaml @@ -0,0 +1,326 @@ +components: + schemas: + MessageObject: + type: object + properties: + id: + type: string + description: "Sequential or UUID identifier of the message." + example: "0" + object: + type: string + description: "Type of the object, typically 'thread.message'." + default: "thread.message" + created_at: + type: integer + format: int64 + description: "Unix timestamp representing the creation time of the message." + thread_id: + type: string + description: "Identifier of the thread to which this message belongs. Defaults to parent thread." + example: "thread_asdf" + assistant_id: + type: string + description: "Identifier of the assistant involved in the message. Defaults to parent thread." + example: "jan" + role: + type: string + enum: ["user", "assistant"] + description: "Role of the sender, either 'user' or 'assistant'." + content: + type: array + items: + type: object + properties: + type: + type: string + description: "Type of content, e.g., 'text'." + text: + type: object + properties: + value: + type: string + description: "Text content of the message." + annotations: + type: array + items: + type: string + description: "Annotations for the text content, if any." + metadata: + type: object + description: "Metadata associated with the message, defaults to an empty object." + chat_completion_id: + type: string + description: "Identifier of the chat completion, if applicable." + required: + - id + - object + - created_at + - thread_id + - assistant_id + - role + - content + + GetMessageResponse: + type: object + properties: + id: + type: string + description: "The identifier of the message." + example: "msg_abc123" + object: + type: string + description: "Type of the object, indicating it's a thread message." + default: "thread.message" + created_at: + type: integer + format: int64 + description: "Unix timestamp representing the creation time of the message." + thread_id: + type: string + description: "Identifier of the thread to which this message belongs." + example: "thread_abc123" + role: + type: string + description: "Role of the sender, either 'user' or 'assistant'." + example: "user" + content: + type: array + items: + type: object + properties: + type: + type: string + description: "Type of content, e.g., 'text'." + text: + type: object + properties: + value: + type: string + description: "Text content of the message." + example: "How does AI work? Explain it in simple terms." + annotations: + type: array + items: + type: string + description: "Annotations for the text content, if any." + file_ids: + type: array + items: + type: string + description: "Array of file IDs associated with the message, if any." + assistant_id: + type: string + description: "Identifier of the assistant involved in the message, if applicable." + run_id: + type: string + description: "Run ID associated with the message, if applicable." + metadata: + type: object + description: "Metadata associated with the message." + required: + - id + - object + - created_at + - thread_id + - role + - content + + CreateMessageResponse: + type: object + properties: + id: + type: string + description: "The identifier of the created message." + example: "msg_abc123" + object: + type: string + description: "Type of the object, indicating it's a thread message." + default: "thread.message" + created_at: + type: integer + format: int64 + description: "Unix timestamp representing the creation time of the message." + thread_id: + type: string + description: "Identifier of the thread to which this message belongs." + example: "thread_abc123" + role: + type: string + description: "Role of the sender, either 'user' or 'assistant'." + example: "user" + content: + type: array + items: + type: object + properties: + type: + type: string + description: "Type of content, e.g., 'text'." + text: + type: object + properties: + value: + type: string + description: "Text content of the message." + example: "How does AI work? Explain it in simple terms." + annotations: + type: array + items: + type: string + description: "Annotations for the text content, if any." + file_ids: + type: array + items: + type: string + description: "Array of file IDs associated with the message, if any." + assistant_id: + type: string + description: "Identifier of the assistant involved in the message, if applicable." + run_id: + type: string + description: "Run ID associated with the message, if applicable." + metadata: + type: object + description: "Metadata associated with the message." + required: + - id + - object + - created_at + - thread_id + - role + - content + + ListMessagesResponse: + type: object + properties: + object: + type: string + description: "Type of the object, indicating it's a list." + default: "list" + data: + type: array + items: + $ref: '#/components/schemas/ListMessageObject' + first_id: + type: string + description: "Identifier of the first message in the list." + example: "msg_abc123" + last_id: + type: string + description: "Identifier of the last message in the list." + example: "msg_abc456" + has_more: + type: boolean + description: "Indicates whether there are more messages to retrieve." + example: false + required: + - object + - data + - first_id + - last_id + - has_more + + ListMessageObject: + type: object + properties: + id: + type: string + description: "The identifier of the message." + example: "msg_abc123" + object: + type: string + description: "Type of the object, indicating it's a thread message." + default: "thread.message" + created_at: + type: integer + format: int64 + description: "Unix timestamp representing the creation time of the message." + thread_id: + type: string + description: "Identifier of the thread to which this message belongs." + example: "thread_abc123" + role: + type: string + description: "Role of the sender, either 'user' or 'assistant'." + example: "user" + content: + type: array + items: + type: object + properties: + type: + type: string + description: "Type of content, e.g., 'text'." + text: + type: object + properties: + value: + type: string + description: "Text content of the message." + example: "How does AI work? Explain it in simple terms." + annotations: + type: array + items: + type: string + description: "Annotations for the text content, if any." + file_ids: + type: array + items: + type: string + description: "Array of file IDs associated with the message, if any." + assistant_id: + type: string + description: "Identifier of the assistant involved in the message, if applicable." + run_id: + type: string + description: "Run ID associated with the message, if applicable." + metadata: + type: object + description: "Metadata associated with the message." + required: + - id + - object + - created_at + - thread_id + - role + - content + + MessageFileObject: + type: object + properties: + id: + type: string + description: "The identifier of the file." + example: "file-abc123" + object: + type: string + description: "Type of the object, indicating it's a thread message file." + default: "thread.message.file" + created_at: + type: integer + format: int64 + description: "Unix timestamp representing the creation time of the file." + message_id: + type: string + description: "Identifier of the message to which this file is associated." + example: "msg_abc123" + required: + - id + - object + - created_at + - message_id + ListMessageFilesResponse: + type: object + properties: + object: + type: string + description: "Type of the object, indicating it's a list." + default: "list" + data: + type: array + items: + $ref: '#/components/schemas/MessageFileObject' + required: + - object + - data \ No newline at end of file diff --git a/docs/openapi/specs/models/models.yaml b/docs/openapi/specs/models.yaml similarity index 99% rename from docs/openapi/specs/models/models.yaml rename to docs/openapi/specs/models.yaml index da07eed4d..6eb2b13f7 100644 --- a/docs/openapi/specs/models/models.yaml +++ b/docs/openapi/specs/models.yaml @@ -46,7 +46,7 @@ components: description: "Description of the model." state: type: string - enum: [null, "downloading", "available"] + enum: [null, "downloading", "ready", "starting", "stopping"] description: "Current state of the model." format: type: string diff --git a/docs/openapi/specs/threads.yaml b/docs/openapi/specs/threads.yaml new file mode 100644 index 000000000..b3db26fc2 --- /dev/null +++ b/docs/openapi/specs/threads.yaml @@ -0,0 +1,169 @@ +components: + schemas: + ThreadObject: + type: object + properties: + id: + type: string + description: "Identifier of the thread, defaults to folder name." + example: "thread_...." + object: + type: string + description: "Type of the object, typically 'thread'." + default: "thread" + summary: + type: string + description: "A brief summary or description of the thread, defaults to an empty string." + example: "funny physics joke" + assistants: + type: array + items: + type: string + description: "List of assistants involved in the thread, defaults to ['jan']." + example: ["jan"] + created: + type: integer + format: int64 + description: "Unix timestamp representing the creation time of the thread, defaults to file creation time." + metadata: + type: object + description: "Metadata associated with the thread, defaults to an empty object." + messages: + type: array + description: "List of messages within the thread." + items: + type: string + model_id: + type: string + description: "Model identifier associated with the thread, defaults to assistant's model." + example: "..." + settings: + type: object + description: "Settings for the thread, defaults to and overrides assistant's settings." + parameters: + type: object + description: "Parameters for the thread, defaults to and overrides assistant's settings." + required: + - id + - object + GetThreadResponse: + type: object + properties: + id: + type: string + description: "The identifier of the thread." + example: "thread_abc123" + object: + type: string + description: "Type of the object, indicating it's a thread." + default: "thread" + created_at: + type: integer + format: int64 + description: "Unix timestamp representing the creation time of the thread." + assistants: + type: array + items: + type: string + description: "List of assistants involved in the thread." + metadata: + type: object + description: "Metadata associated with the thread." + messages: + type: array + items: + type: string + description: "List of messages within the thread." + required: + - id + - object + - created_at + - assistants + - metadata + - messages + CreateThreadResponse: + type: object + properties: + id: + type: string + description: "The identifier of the newly created thread." + example: "thread_abc123" + object: + type: string + description: "Type of the object, indicating it's a thread." + default: "thread" + created_at: + type: integer + format: int64 + description: "Unix timestamp representing the creation time of the thread." + metadata: + type: object + description: "Metadata associated with the newly created thread." + required: + - id + - object + - created_at + - metadata + + ThreadMessageObject: + type: object + properties: + role: + type: string + description: "Role of the sender, either 'user' or 'assistant'." + enum: ["user", "assistant"] + content: + type: string + description: "Text content of the message." + file_ids: + type: array + items: + type: string + description: "Array of file IDs associated with the message, if any." + required: + - role + - content + + ModifyThreadResponse: + type: object + properties: + id: + type: string + description: "The identifier of the modified thread." + example: "thread_abc123" + object: + type: string + description: "Type of the object, indicating it's a thread." + default: "thread" + created_at: + type: integer + format: int64 + description: "Unix timestamp representing the creation time of the thread." + metadata: + type: object + description: "Metadata associated with the modified thread." + required: + - id + - object + - created_at + - metadata + + DeleteThreadResponse: + type: object + properties: + id: + type: string + description: "The identifier of the deleted thread." + example: "thread_abc123" + object: + type: string + description: "Type of the object, indicating the thread has been deleted." + default: "thread.deleted" + deleted: + type: boolean + description: "Indicates whether the thread was successfully deleted." + example: true + required: + - id + - object + - deleted \ No newline at end of file diff --git a/docs/openapi/specs/threads/threads.yaml b/docs/openapi/specs/threads/threads.yaml deleted file mode 100644 index e69de29bb..000000000 From 7a9cd83e805372e977fd3dc4cf8c3a2058177e2b Mon Sep 17 00:00:00 2001 From: hieu-jan <150573299+hieu-jan@users.noreply.github.com> Date: Thu, 23 Nov 2023 10:12:38 +0900 Subject: [PATCH 05/13] docs: update threads --- docs/openapi/jan.yaml | 54 ++++++++++++++++-------- docs/openapi/specs/threads.yaml | 73 ++++++++++++++------------------- 2 files changed, 67 insertions(+), 60 deletions(-) diff --git a/docs/openapi/jan.yaml b/docs/openapi/jan.yaml index 39e613e78..f426f95d3 100644 --- a/docs/openapi/jan.yaml +++ b/docs/openapi/jan.yaml @@ -182,8 +182,8 @@ paths: operationId: createThread tags: - Threads - summary: Create a new thread - description: Creates a new thread with an initial set of messages. + summary: Create thread + description: Create a thread requestBody: required: true content: @@ -196,8 +196,6 @@ paths: description: "Initial set of messages for the thread." items: $ref: 'specs/threads.yaml#/components/schemas/ThreadMessageObject' - required: - - messages responses: "200": description: Thread created successfully @@ -206,16 +204,25 @@ paths: schema: $ref: 'specs/threads.yaml#/components/schemas/CreateThreadResponse' x-codeSamples: - - lang: "curl" + - lang: "cURL" source: | curl -X POST {JAN_URL}/v1/threads \ -H "Content-Type: application/json" \ - -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."}]}' + -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." + }] + }' get: operationId: listThreads tags: - Threads - summary: List all threads + summary: List threads description: Retrieves a list of all threads available in the system. responses: "200": @@ -241,15 +248,15 @@ paths: x-codeSamples: - lang: "curl" source: | - curl {JAN_URL}/v1/threads \ - -H "Content-Type: application/json" + curl {JAN_URL}/v1/threads \ + -H "Content-Type: application/json" \ /threads/{thread_id}: get: operationId: getThread tags: - Threads - summary: Get details of a specific thread + summary: Get thread description: Retrieves detailed information about a specific thread using its thread_id. parameters: - in: path @@ -274,8 +281,8 @@ paths: operationId: modifyThread tags: - Threads - summary: Modify an existing thread - description: Updates a thread with new or modified messages. + summary: Modify thread + description: Modifies a thread parameters: - in: path name: thread_id @@ -308,15 +315,24 @@ paths: x-codeSamples: - lang: "curl" source: | - curl -X POST {JAN_URL}/v1/threads/{thread_id} \ - -H "Content-Type: application/json" \ - -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."}]}' + curl -X POST {JAN_URL}/v1/threads/{thread_id} \ + -H "Content-Type: application/json" \ + -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." + }] + }' delete: operationId: deleteThread tags: - Threads - summary: Delete a specific thread - description: Deletes a thread identified by its thread_id. + summary: Delete thread + description: Delete a thread parameters: - in: path name: thread_id @@ -336,6 +352,7 @@ paths: - lang: "curl" source: | curl -X DELETE {JAN_URL}/v1/threads/{thread_id} + ### MESSAGES /threads/{thread_id}/messages: get: @@ -553,7 +570,8 @@ x-webhooks: ThreadObject: post: summary: The thread object - description: Information about a thread + description: + - Each thread folder contains a `thread.json` file, which is a representation of a thread. operationId: ThreadObject tags: - Threads diff --git a/docs/openapi/specs/threads.yaml b/docs/openapi/specs/threads.yaml index b3db26fc2..bd1397e2d 100644 --- a/docs/openapi/specs/threads.yaml +++ b/docs/openapi/specs/threads.yaml @@ -5,12 +5,12 @@ components: properties: id: type: string - description: "Identifier of the thread, defaults to folder name." - example: "thread_...." + description: "The identifier of the thread, defaults to foldername." + example: thread_.... object: type: string - description: "Type of the object, typically 'thread'." - default: "thread" + description: "Type of the object, defaults to thread." + example: thread summary: type: string description: "A brief summary or description of the thread, defaults to an empty string." @@ -19,91 +19,87 @@ components: type: array items: type: string - description: "List of assistants involved in the thread, defaults to ['jan']." + description: "List of assistants involved in the thread, defaults to [\"jan\"]." example: ["jan"] created: type: integer format: int64 description: "Unix timestamp representing the creation time of the thread, defaults to file creation time." + example: 1231231 metadata: type: object description: "Metadata associated with the thread, defaults to an empty object." + example: {} messages: type: array description: "List of messages within the thread." items: type: string + example: [] model_id: type: string - description: "Model identifier associated with the thread, defaults to assistant's model." + description: "Model identifier associated with the thread, defaults to assistant.model." example: "..." settings: type: object - description: "Settings for the thread, defaults to and overrides assistant's settings." + description: "Settings for the thread, defaults to and overrides assistant.settings." parameters: type: object - description: "Parameters for the thread, defaults to and overrides assistant's settings." - required: - - id - - object + description: "Parameters for the thread, defaults to and overrides assistant.settings." + GetThreadResponse: type: object properties: id: type: string description: "The identifier of the thread." - example: "thread_abc123" + example: thread_abc123 object: type: string - description: "Type of the object, indicating it's a thread." - default: "thread" + description: "Type of the object" + example: thread created_at: type: integer format: int64 description: "Unix timestamp representing the creation time of the thread." + example: 1699014083 assistants: type: array items: type: string description: "List of assistants involved in the thread." + example: ["assistant-001"] metadata: type: object description: "Metadata associated with the thread." + example: {} messages: type: array items: type: string description: "List of messages within the thread." - required: - - id - - object - - created_at - - assistants - - metadata - - messages + example: [] + CreateThreadResponse: type: object properties: id: type: string description: "The identifier of the newly created thread." - example: "thread_abc123" + example: thread_abc123 object: type: string description: "Type of the object, indicating it's a thread." - default: "thread" + example: thread created_at: type: integer format: int64 description: "Unix timestamp representing the creation time of the thread." + example: 1699014083 metadata: type: object description: "Metadata associated with the newly created thread." - required: - - id - - object - - created_at - - metadata + example: {} ThreadMessageObject: type: object @@ -130,23 +126,20 @@ components: id: type: string description: "The identifier of the modified thread." - example: "thread_abc123" + example: thread_abc123 object: type: string description: "Type of the object, indicating it's a thread." - default: "thread" + example: thread created_at: type: integer format: int64 description: "Unix timestamp representing the creation time of the thread." + example: 1699014083 metadata: type: object description: "Metadata associated with the modified thread." - required: - - id - - object - - created_at - - metadata + example: {} DeleteThreadResponse: type: object @@ -154,16 +147,12 @@ components: id: type: string description: "The identifier of the deleted thread." - example: "thread_abc123" + example: thread_abc123 object: type: string description: "Type of the object, indicating the thread has been deleted." - default: "thread.deleted" + example: thread.deleted deleted: type: boolean description: "Indicates whether the thread was successfully deleted." - example: true - required: - - id - - object - - deleted \ No newline at end of file + example: true \ No newline at end of file From 3162e66e466c7ee7ad8a7c6b22a6411caed70416 Mon Sep 17 00:00:00 2001 From: hieu-jan <150573299+hieu-jan@users.noreply.github.com> Date: Thu, 23 Nov 2023 10:56:12 +0900 Subject: [PATCH 06/13] docs: complete thread --- docs/openapi/jan.yaml | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/openapi/jan.yaml b/docs/openapi/jan.yaml index f426f95d3..64166a63c 100644 --- a/docs/openapi/jan.yaml +++ b/docs/openapi/jan.yaml @@ -327,6 +327,7 @@ paths: "content": "How does AI work? Explain it in simple terms." }] }' + delete: operationId: deleteThread tags: @@ -352,7 +353,35 @@ paths: - lang: "curl" source: | curl -X DELETE {JAN_URL}/v1/threads/{thread_id} - + + + /threads/{thread_id}/assistants: + get: + operationId: getThreadAssistants + tags: + - Threads + summary: Get Thread.Assistants + description: + - Can achieve this goal by calling Get thread API + + /threads/{thread_id}/assistants/{assistants_id}: + post: + operationId: postThreadAssistants + tags: + - Threads + summary: Modify Thread.Assistants + description: + - Can achieve this goal by calling Modify Assistant API with thread.assistant[] + + /threads/{thread_id}/: + get: + operationId: listThreadMessage + tags: + - Threads + summary: List Thread.Messages + description: + - Can achieve this goal by calling Get Thread API + ### MESSAGES /threads/{thread_id}/messages: get: From f5bb2e51a8a61a4de557903c7858a5654153d26e Mon Sep 17 00:00:00 2001 From: hieu-jan <150573299+hieu-jan@users.noreply.github.com> Date: Thu, 23 Nov 2023 11:03:02 +0900 Subject: [PATCH 07/13] docs: add thread.assistants --- docs/openapi/jan.yaml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/docs/openapi/jan.yaml b/docs/openapi/jan.yaml index 64166a63c..1c7ef714c 100644 --- a/docs/openapi/jan.yaml +++ b/docs/openapi/jan.yaml @@ -363,6 +363,25 @@ paths: summary: Get Thread.Assistants description: - Can achieve this goal by calling Get thread API + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + example: thread_abc123 + description: The ID of the thread to retrieve. + responses: + "200": + description: Thread details retrieved successfully + content: + application/json: + schema: + $ref: "specs/threads.yaml#/components/schemas/GetThreadResponse" + x-codeSamples: + - lang: "curl" + source: | + curl {JAN_URL}/v1/threads/{thread_id}/assistants /threads/{thread_id}/assistants/{assistants_id}: post: @@ -381,6 +400,25 @@ paths: summary: List Thread.Messages description: - Can achieve this goal by calling Get Thread API + parameters: + - in: path + name: thread_id + required: true + schema: + type: string + example: thread_abc123 + description: The ID of the thread to retrieve. + responses: + "200": + description: Thread details retrieved successfully + content: + application/json: + schema: + $ref: "specs/threads.yaml#/components/schemas/GetThreadResponse" + x-codeSamples: + - lang: "curl" + source: | + curl {JAN_URL}/v1/threads/{thread_id} ### MESSAGES /threads/{thread_id}/messages: From 62e8a8253daf98b16e3f3149ac0aa6914ef48e62 Mon Sep 17 00:00:00 2001 From: hieu-jan <150573299+hieu-jan@users.noreply.github.com> Date: Thu, 23 Nov 2023 11:17:26 +0900 Subject: [PATCH 08/13] docs: add thread description --- docs/openapi/jan.yaml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/openapi/jan.yaml b/docs/openapi/jan.yaml index 1c7ef714c..cc452ffe3 100644 --- a/docs/openapi/jan.yaml +++ b/docs/openapi/jan.yaml @@ -19,7 +19,11 @@ tags: - name: Messages description: Operations for individual messages, including creation, retrieval, and modification - name: Threads - description: Manages series of related messages or conversation threads + description: | + `Threads` are conversations between an `assistant` and the user: + - Users can tweak `model` params and `assistant` behavior within each thread. + - Users can import and export threads. + - An [OpenAI Thread API](https://platform.openai.com/docs/api-reference/threads) compatible endpoint at `localhost:3000/v1/threads`. - name: Assistants description: Configures and utilizes different AI assistants for varied tasks x-tagGroups: @@ -637,8 +641,11 @@ x-webhooks: ThreadObject: post: summary: The thread object - description: - - Each thread folder contains a `thread.json` file, which is a representation of a thread. + description: | + - Each `thread` folder contains a `thread.json` file, which is a representation of a thread. + - `thread.json` contains metadata and model parameter overrides. + - There are no required fields. + operationId: ThreadObject tags: - Threads From 536df7de71f6e27ac2af8b5f135481f9d7fd9a85 Mon Sep 17 00:00:00 2001 From: hieu-jan <150573299+hieu-jan@users.noreply.github.com> Date: Thu, 23 Nov 2023 11:26:31 +0900 Subject: [PATCH 09/13] docs: update require section --- docs/openapi/jan.yaml | 6 ++---- docs/openapi/specs/threads.yaml | 3 --- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/docs/openapi/jan.yaml b/docs/openapi/jan.yaml index cc452ffe3..fca3d97ba 100644 --- a/docs/openapi/jan.yaml +++ b/docs/openapi/jan.yaml @@ -189,7 +189,7 @@ paths: summary: Create thread description: Create a thread requestBody: - required: true + required: false content: application/json: schema: @@ -296,7 +296,7 @@ paths: example: thread_abc123 description: The ID of the thread to be modified. requestBody: - required: true + required: false content: application/json: schema: @@ -307,8 +307,6 @@ paths: description: "Set of messages to update in the thread." items: $ref: 'specs/threads.yaml#/components/schemas/ThreadMessageObject' - required: - - messages responses: "200": description: Thread modified successfully diff --git a/docs/openapi/specs/threads.yaml b/docs/openapi/specs/threads.yaml index bd1397e2d..317447f90 100644 --- a/docs/openapi/specs/threads.yaml +++ b/docs/openapi/specs/threads.yaml @@ -116,9 +116,6 @@ components: items: type: string description: "Array of file IDs associated with the message, if any." - required: - - role - - content ModifyThreadResponse: type: object From 53245faa542ec4782c379466b24878a7249764c2 Mon Sep 17 00:00:00 2001 From: hieu-jan <150573299+hieu-jan@users.noreply.github.com> Date: Thu, 23 Nov 2023 13:53:23 +0900 Subject: [PATCH 10/13] docs: change endpoint port --- docs/docs/specs/messages.md | 12 ++++-------- docs/docs/specs/threads.md | 2 +- docs/openapi/jan.yaml | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/docs/docs/specs/messages.md b/docs/docs/specs/messages.md index 8758ba542..bb1efb49f 100644 --- a/docs/docs/specs/messages.md +++ b/docs/docs/specs/messages.md @@ -13,7 +13,7 @@ This is currently under development. `Messages` capture a conversation's content. This can include the content from LLM responses and other metadata from [chat completions](/specs/chats). - Users and assistants can send multimedia messages. -- An [OpenAI Message API](https://platform.openai.com/docs/api-reference/messages) compatible endpoint at `localhost:3000/v1/messages`. +- An [OpenAI Message API](https://platform.openai.com/docs/api-reference/messages) compatible endpoint at `localhost:1337/v1/messages`. ## Folder Structure @@ -104,12 +104,8 @@ See [Jan Messages API](https://jan.ai/api-reference#tag/Messages) - Example request ```shell - curl -X POST {JAN_URL}/v1/threads/{thread_id}/messages \ - -H "Content-Type: application/json" \ - -d '{ - "role": "user", - "content": "How does AI work? Explain it in simple terms." - }' + curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id} \ + -H "Content-Type: application/json" ``` - Example response @@ -259,4 +255,4 @@ See [Jan Messages API](https://jan.ai/api-reference#tag/Messages) "created_at": 1699061776, "message_id": "msg_abc123" } -``` --> +``` --> \ No newline at end of file diff --git a/docs/docs/specs/threads.md b/docs/docs/specs/threads.md index c9d9c9d4c..0097caa66 100644 --- a/docs/docs/specs/threads.md +++ b/docs/docs/specs/threads.md @@ -224,4 +224,4 @@ See [Jan Threads API](https://jan.ai/api-reference#tag/Threads) ### List `Thread.Messages` --> Can achieve this goal by calling `Get Thread` API --> +-> Can achieve this goal by calling `Get Thread` API --> \ No newline at end of file diff --git a/docs/openapi/jan.yaml b/docs/openapi/jan.yaml index fca3d97ba..cf2f8ed25 100644 --- a/docs/openapi/jan.yaml +++ b/docs/openapi/jan.yaml @@ -23,7 +23,7 @@ tags: `Threads` are conversations between an `assistant` and the user: - Users can tweak `model` params and `assistant` behavior within each thread. - Users can import and export threads. - - An [OpenAI Thread API](https://platform.openai.com/docs/api-reference/threads) compatible endpoint at `localhost:3000/v1/threads`. + - An [OpenAI Thread API](https://platform.openai.com/docs/api-reference/threads) compatible endpoint at `localhost:1337/v1/threads`. - name: Assistants description: Configures and utilizes different AI assistants for varied tasks x-tagGroups: From c45b74457a38ae5ceeb9c3f4ed537f5f61da22f3 Mon Sep 17 00:00:00 2001 From: hieu-jan <150573299+hieu-jan@users.noreply.github.com> Date: Thu, 23 Nov 2023 14:00:38 +0900 Subject: [PATCH 11/13] docs: update models --- docs/docs/specs/threads.md | 2 +- docs/openapi/specs/models.yaml | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/docs/docs/specs/threads.md b/docs/docs/specs/threads.md index 0097caa66..3c9b17286 100644 --- a/docs/docs/specs/threads.md +++ b/docs/docs/specs/threads.md @@ -14,7 +14,7 @@ This is currently under development. - Users can tweak `model` params and `assistant` behavior within each thread. - Users can import and export threads. -- An [OpenAI Thread API](https://platform.openai.com/docs/api-reference/threads) compatible endpoint at `localhost:3000/v1/threads`. +- An [OpenAI Thread API](https://platform.openai.com/docs/api-reference/threads) compatible endpoint at `localhost:1337/v1/threads`. ## Folder Structure diff --git a/docs/openapi/specs/models.yaml b/docs/openapi/specs/models.yaml index 6eb2b13f7..6f136d30e 100644 --- a/docs/openapi/specs/models.yaml +++ b/docs/openapi/specs/models.yaml @@ -110,16 +110,7 @@ components: type: string description: "List of assets related to the model." required: - - type - - version - - id - - name - - created - - state - - format - source_url - - settings - - parameters ModelObject: type: object From 015856104cad53c91be1b56b1fd2b03b78625851 Mon Sep 17 00:00:00 2001 From: hieu-jan <150573299+hieu-jan@users.noreply.github.com> Date: Thu, 23 Nov 2023 15:08:02 +0900 Subject: [PATCH 12/13] docs: update api reference messages --- docs/docs/specs/messages.md | 160 ++++++++++++++++++++++++++++++- docs/openapi/jan.yaml | 43 +++++---- docs/openapi/specs/messages.yaml | 110 +++++++++------------ 3 files changed, 230 insertions(+), 83 deletions(-) diff --git a/docs/docs/specs/messages.md b/docs/docs/specs/messages.md index bb1efb49f..db54f7782 100644 --- a/docs/docs/specs/messages.md +++ b/docs/docs/specs/messages.md @@ -255,4 +255,162 @@ See [Jan Messages API](https://jan.ai/api-reference#tag/Messages) "created_at": 1699061776, "message_id": "msg_abc123" } -``` --> \ No newline at end of file +``` --> +### Get list message + +> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/getMessage + +- Example request + +```shell + curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id} \ + -H "Content-Type: application/json" +``` + +- Example response + +```json +{ + "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": {} +} +``` + +### Create message + +> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/createMessage + +- Example request + +```shell + curl -X POST {JAN_URL}/v1/threads/{thread_id}/messages \ + -H "Content-Type: application/json" \ + -d '{ + "role": "user", + "content": "How does AI work? Explain it in simple terms." + }' +``` + +- Example response + +```json +{ + "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": {} +} +``` + +### Get message + +> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/assistants/listAssistants + +- Example request + +```shell + curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id} \ + -H "Content-Type: application/json" +``` + +- Example response + +```json +{ + "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": {} +} +``` + +### Modify message + +> Jan: TODO: Do we need to modify message? Or let user create new message? + +# Get message file + +> OpenAI Equivalent: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} + +- Example request + +```shell + curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} \ + -H "Content-Type: application/json" +``` + +- Example response + +```json +{ + "id": "file-abc123", + "object": "thread.message.file", + "created_at": 1699061776, + "message_id": "msg_abc123" +} +``` + +# List message files + +> OpenAI Equivalent: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files + +```` +- Example request +```shell + curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} \ + -H "Content-Type: application/json" +```` + +- Example response + +```json +{ + "id": "file-abc123", + "object": "thread.message.file", + "created_at": 1699061776, + "message_id": "msg_abc123" +} \ No newline at end of file diff --git a/docs/openapi/jan.yaml b/docs/openapi/jan.yaml index cf2f8ed25..c1bd48143 100644 --- a/docs/openapi/jan.yaml +++ b/docs/openapi/jan.yaml @@ -17,10 +17,18 @@ tags: - name: Chat Completion description: Given a list of messages comprising a conversation, the model will return a response. - name: Messages - description: Operations for individual messages, including creation, retrieval, and modification + description: | + Messages capture a conversation's content. This can include the content from LLM responses and other metadata from [chat completions](/specs/chats). + + - Users and assistants can send multimedia messages. + + - An [OpenAI Message API](https://platform.openai.com/docs/api-reference/messages) compatible endpoint at `localhost:1337/v1/messages`. + + - Jan's `messages` API is compatible with [OpenAI's Messages API](https://platform.openai.com/docs/api-reference/messages), with additional methods for managing messages locally. + - name: Threads description: | - `Threads` are conversations between an `assistant` and the user: + Threads are conversations between an `assistant` and the user: - Users can tweak `model` params and `assistant` behavior within each thread. - Users can import and export threads. - An [OpenAI Thread API](https://platform.openai.com/docs/api-reference/threads) compatible endpoint at `localhost:1337/v1/threads`. @@ -428,8 +436,8 @@ paths: operationId: listMessages tags: - Messages - summary: Get a list of messages from a thread - description: Retrieves all messages from the specified thread. + summary: List messaages + description: Retrieves all messages from the given thread. parameters: - in: path name: thread_id @@ -454,8 +462,8 @@ paths: operationId: createMessage tags: - Messages - summary: Create a new message in a thread - description: Sends a new message to the specified thread. + summary: Create message + description: Create a message parameters: - in: path name: thread_id @@ -493,13 +501,16 @@ paths: x-codeSamples: - lang: "curl" source: | - curl -X POST {JAN_URL}/v1/threads/{thread_id}/messages \ - -H "Content-Type: application/json" \ - -d '{"role": "user", "content": "How does AI work? Explain it in simple terms."}' + curl -X POST {JAN_URL}/v1/threads/{thread_id}/messages \ + -H "Content-Type: application/json" \ + -d '{ + "role": "user", + "content": "How does AI work? Explain it in simple terms." + }' /threads/{thread_id}/messages/{message_id}: get: - operationId: getMessage + operationId: retrieveMessage tags: - Messages summary: Retrieve Message @@ -529,16 +540,16 @@ paths: x-codeSamples: - lang: "curl" source: | - curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id} \ - -H "Content-Type: application/json" + curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id} \ + -H "Content-Type: application/json" /threads/{thread_id}/messages/{message_id}/files: get: operationId: listMessageFiles tags: - Messages - summary: message files - description: Retrieves a list of files associated with a specific message in a thread. + summary: List message files + description: Returns a list of message files. parameters: - in: path name: thread_id @@ -569,10 +580,10 @@ paths: /threads/{thread_id}/messages/{message_id}/files/{file_id}: get: - operationId: getMessageFile + operationId: retrieveMessageFile tags: - Messages - summary: Get message file + summary: Retrieve message file description: Retrieves a file associated with a specific message in a thread. parameters: - in: path diff --git a/docs/openapi/specs/messages.yaml b/docs/openapi/specs/messages.yaml index a3dc74a0d..daa998767 100644 --- a/docs/openapi/specs/messages.yaml +++ b/docs/openapi/specs/messages.yaml @@ -6,11 +6,11 @@ components: id: type: string description: "Sequential or UUID identifier of the message." - example: "0" + example: 0 object: type: string - description: "Type of the object, typically 'thread.message'." - default: "thread.message" + description: "Type of the object, defaults to 'thread.message'." + example: thread.message created_at: type: integer format: int64 @@ -22,7 +22,7 @@ components: assistant_id: type: string description: "Identifier of the assistant involved in the message. Defaults to parent thread." - example: "jan" + example: jan role: type: string enum: ["user", "assistant"] @@ -41,25 +41,17 @@ components: value: type: string description: "Text content of the message." + example: "Hi!?" annotations: type: array items: type: string description: "Annotations for the text content, if any." + example: [] metadata: type: object description: "Metadata associated with the message, defaults to an empty object." - chat_completion_id: - type: string - description: "Identifier of the chat completion, if applicable." - required: - - id - - object - - created_at - - thread_id - - assistant_id - - role - - content + example: {} GetMessageResponse: type: object @@ -67,23 +59,24 @@ components: id: type: string description: "The identifier of the message." - example: "msg_abc123" + example: msg_abc123 object: type: string description: "Type of the object, indicating it's a thread message." - default: "thread.message" + default: thread.message created_at: type: integer format: int64 description: "Unix timestamp representing the creation time of the message." + example: 1699017614 thread_id: type: string description: "Identifier of the thread to which this message belongs." - example: "thread_abc123" + example: thread_abc123 role: type: string description: "Role of the sender, either 'user' or 'assistant'." - example: "user" + example: user content: type: array items: @@ -92,6 +85,7 @@ components: type: type: string description: "Type of content, e.g., 'text'." + example: text text: type: object properties: @@ -104,27 +98,25 @@ components: items: type: string description: "Annotations for the text content, if any." + example: [] file_ids: type: array items: type: string description: "Array of file IDs associated with the message, if any." + example: [] assistant_id: type: string description: "Identifier of the assistant involved in the message, if applicable." + example: null run_id: type: string description: "Run ID associated with the message, if applicable." + example: null metadata: type: object description: "Metadata associated with the message." - required: - - id - - object - - created_at - - thread_id - - role - - content + example: {} CreateMessageResponse: type: object @@ -132,23 +124,24 @@ components: id: type: string description: "The identifier of the created message." - example: "msg_abc123" + example: msg_abc123 object: type: string description: "Type of the object, indicating it's a thread message." - default: "thread.message" + example: thread.message created_at: type: integer format: int64 description: "Unix timestamp representing the creation time of the message." + example: 1699017614 thread_id: type: string description: "Identifier of the thread to which this message belongs." - example: "thread_abc123" + example: thread_abc123 role: type: string description: "Role of the sender, either 'user' or 'assistant'." - example: "user" + example: user content: type: array items: @@ -157,6 +150,7 @@ components: type: type: string description: "Type of content, e.g., 'text'." + example: text text: type: object properties: @@ -169,27 +163,25 @@ components: items: type: string description: "Annotations for the text content, if any." + example: [] file_ids: type: array items: type: string description: "Array of file IDs associated with the message, if any." + example: [] assistant_id: type: string description: "Identifier of the assistant involved in the message, if applicable." + example: null run_id: type: string description: "Run ID associated with the message, if applicable." + example: null metadata: type: object description: "Metadata associated with the message." - required: - - id - - object - - created_at - - thread_id - - role - - content + example: {} ListMessagesResponse: type: object @@ -214,12 +206,6 @@ components: type: boolean description: "Indicates whether there are more messages to retrieve." example: false - required: - - object - - data - - first_id - - last_id - - has_more ListMessageObject: type: object @@ -227,23 +213,24 @@ components: id: type: string description: "The identifier of the message." - example: "msg_abc123" + example: msg_abc123 object: type: string description: "Type of the object, indicating it's a thread message." - default: "thread.message" + example: thread.message created_at: type: integer format: int64 description: "Unix timestamp representing the creation time of the message." + example: 1699017614 thread_id: type: string description: "Identifier of the thread to which this message belongs." - example: "thread_abc123" + example: thread_abc123 role: type: string description: "Role of the sender, either 'user' or 'assistant'." - example: "user" + example: user content: type: array items: @@ -269,22 +256,19 @@ components: items: type: string description: "Array of file IDs associated with the message, if any." + example: [] assistant_id: type: string description: "Identifier of the assistant involved in the message, if applicable." + example: null run_id: type: string description: "Run ID associated with the message, if applicable." + example: null metadata: type: object description: "Metadata associated with the message." - required: - - id - - object - - created_at - - thread_id - - role - - content + example: {} MessageFileObject: type: object @@ -292,24 +276,21 @@ components: id: type: string description: "The identifier of the file." - example: "file-abc123" + example: file-abc123 object: type: string description: "Type of the object, indicating it's a thread message file." - default: "thread.message.file" + example: thread.message.file created_at: type: integer format: int64 description: "Unix timestamp representing the creation time of the file." + example: 1699061776 message_id: type: string description: "Identifier of the message to which this file is associated." - example: "msg_abc123" - required: - - id - - object - - created_at - - message_id + example: msg_abc123 + ListMessageFilesResponse: type: object properties: @@ -320,7 +301,4 @@ components: data: type: array items: - $ref: '#/components/schemas/MessageFileObject' - required: - - object - - data \ No newline at end of file + $ref: '#/components/schemas/MessageFileObject' \ No newline at end of file From 3770a7a13d735d507ebe17f098c8eb05e67a5894 Mon Sep 17 00:00:00 2001 From: hieu-jan <150573299+hieu-jan@users.noreply.github.com> Date: Thu, 23 Nov 2023 15:08:39 +0900 Subject: [PATCH 13/13] comment spec/messages --- docs/docs/specs/messages.md | 158 ------------------------------------ 1 file changed, 158 deletions(-) diff --git a/docs/docs/specs/messages.md b/docs/docs/specs/messages.md index db54f7782..049e190c6 100644 --- a/docs/docs/specs/messages.md +++ b/docs/docs/specs/messages.md @@ -256,161 +256,3 @@ See [Jan Messages API](https://jan.ai/api-reference#tag/Messages) "message_id": "msg_abc123" } ``` --> -### Get list message - -> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/getMessage - -- Example request - -```shell - curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id} \ - -H "Content-Type: application/json" -``` - -- Example response - -```json -{ - "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": {} -} -``` - -### Create message - -> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/createMessage - -- Example request - -```shell - curl -X POST {JAN_URL}/v1/threads/{thread_id}/messages \ - -H "Content-Type: application/json" \ - -d '{ - "role": "user", - "content": "How does AI work? Explain it in simple terms." - }' -``` - -- Example response - -```json -{ - "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": {} -} -``` - -### Get message - -> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/assistants/listAssistants - -- Example request - -```shell - curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id} \ - -H "Content-Type: application/json" -``` - -- Example response - -```json -{ - "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": {} -} -``` - -### Modify message - -> Jan: TODO: Do we need to modify message? Or let user create new message? - -# Get message file - -> OpenAI Equivalent: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} - -- Example request - -```shell - curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} \ - -H "Content-Type: application/json" -``` - -- Example response - -```json -{ - "id": "file-abc123", - "object": "thread.message.file", - "created_at": 1699061776, - "message_id": "msg_abc123" -} -``` - -# List message files - -> OpenAI Equivalent: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files - -```` -- Example request -```shell - curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} \ - -H "Content-Type: application/json" -```` - -- Example response - -```json -{ - "id": "file-abc123", - "object": "thread.message.file", - "created_at": 1699061776, - "message_id": "msg_abc123" -} \ No newline at end of file