UNPKG

llmatic

Version:

Use self-hosted LLMs with an OpenAI compatible API

1,537 lines (1,503 loc) 123 kB
openapi: 3.0.0 info: title: OpenAI API description: APIs for sampling from and fine-tuning language models version: "1.2.0" servers: - url: https://api.openai.com/v1 tags: - name: OpenAI description: The OpenAI REST API paths: /engines: get: operationId: listEngines deprecated: true tags: - OpenAI summary: Lists the currently available (non-finetuned) 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/ListEnginesResponse" x-oaiMeta: name: List engines group: engines path: list examples: curl: | curl https://api.openai.com/v1/engines \ -H 'Authorization: Bearer YOUR_API_KEY' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.Engine.list() node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.listEngines(); response: | { "data": [ { "id": "engine-id-0", "object": "engine", "owner": "organization-owner", "ready": true }, { "id": "engine-id-2", "object": "engine", "owner": "organization-owner", "ready": true }, { "id": "engine-id-3", "object": "engine", "owner": "openai", "ready": false }, ], "object": "list" } /engines/{engine_id}: get: operationId: retrieveEngine deprecated: true tags: - OpenAI summary: Retrieves a model instance, providing basic information about it such as the owner and availability. parameters: - in: path name: engine_id required: true schema: type: string # ideally this will be an actual ID, so this will always work from browser example: davinci description: &engine_id_description > The ID of the engine to use for this request responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/Engine" x-oaiMeta: name: Retrieve engine group: engines path: retrieve examples: curl: | curl https://api.openai.com/v1/engines/VAR_model_id \ -H 'Authorization: Bearer YOUR_API_KEY' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.Engine.retrieve("VAR_model_id") node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.retrieveEngine("VAR_model_id"); response: | { "id": "VAR_model_id", "object": "engine", "owner": "openai", "ready": true } /completions: post: operationId: createCompletion tags: - OpenAI 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 group: completions path: create examples: curl: | curl https://api.openai.com/v1/completions \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -d '{ "model": "VAR_model_id", "prompt": "Say this is a test", "max_tokens": 7, "temperature": 0 }' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.Completion.create( model="VAR_model_id", prompt="Say this is a test", max_tokens=7, temperature=0 ) node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.createCompletion({ model: "VAR_model_id", prompt: "Say this is a test", max_tokens: 7, temperature: 0, }); parameters: | { "model": "VAR_model_id", "prompt": "Say this is a test", "max_tokens": 7, "temperature": 0, "top_p": 1, "n": 1, "stream": false, "logprobs": null, "stop": "\n" } response: | { "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7", "object": "text_completion", "created": 1589478378, "model": "VAR_model_id", "choices": [ { "text": "\n\nThis is indeed a test", "index": 0, "logprobs": null, "finish_reason": "length" } ], "usage": { "prompt_tokens": 5, "completion_tokens": 7, "total_tokens": 12 } } /chat/completions: post: operationId: createChatCompletion tags: - OpenAI summary: Creates a completion for the chat message 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 path: create beta: true examples: curl: | curl https://api.openai.com/v1/chat/completions \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -d '{ "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello!"}] }' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") completion = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[ {"role": "user", "content": "Hello!"} ] ) print(completion.choices[0].message) node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const completion = await openai.createChatCompletion({ model: "gpt-3.5-turbo", messages: [{role: "user", content: "Hello world"}], }); console.log(completion.data.choices[0].message); parameters: | { "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello!"}] } response: | { "id": "chatcmpl-123", "object": "chat.completion", "created": 1677652288, "choices": [{ "index": 0, "message": { "role": "assistant", "content": "\n\nHello there, how may I assist you today?", }, "finish_reason": "stop" }], "usage": { "prompt_tokens": 9, "completion_tokens": 12, "total_tokens": 21 } } /edits: post: operationId: createEdit tags: - OpenAI summary: Creates a new edit for the provided input, instruction, and parameters. requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreateEditRequest" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/CreateEditResponse" x-oaiMeta: name: Create edit group: edits path: create examples: curl: | curl https://api.openai.com/v1/edits \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -d '{ "model": "VAR_model_id", "input": "What day of the wek is it?", "instruction": "Fix the spelling mistakes" }' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.Edit.create( model="VAR_model_id", input="What day of the wek is it?", instruction="Fix the spelling mistakes" ) node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.createEdit({ model: "VAR_model_id", input: "What day of the wek is it?", instruction: "Fix the spelling mistakes", }); parameters: | { "model": "VAR_model_id", "input": "What day of the wek is it?", "instruction": "Fix the spelling mistakes", } response: | { "object": "edit", "created": 1589478378, "choices": [ { "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: - OpenAI 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 group: images path: create beta: true examples: curl: | curl https://api.openai.com/v1/images/generations \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -d '{ "prompt": "A cute baby sea otter", "n": 2, "size": "1024x1024" }' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.Image.create( prompt="A cute baby sea otter", n=2, size="1024x1024" ) node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.createImage({ prompt: "A cute baby sea otter", n: 2, size: "1024x1024", }); parameters: | { "prompt": "A cute baby sea otter", "n": 2, "size": "1024x1024" } response: | { "created": 1589478378, "data": [ { "url": "https://..." }, { "url": "https://..." } ] } /images/edits: post: operationId: createImageEdit tags: - OpenAI 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 group: images path: create-edit beta: true examples: curl: | curl https://api.openai.com/v1/images/edits \ -H 'Authorization: Bearer YOUR_API_KEY' \ -F image='@otter.png' \ -F mask='@mask.png' \ -F prompt="A cute baby sea otter wearing a beret" \ -F n=2 \ -F size="1024x1024" python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.Image.create_edit( image=open("otter.png", "rb"), mask=open("mask.png", "rb"), prompt="A cute baby sea otter wearing a beret", n=2, size="1024x1024" ) node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.createImageEdit( fs.createReadStream("otter.png"), fs.createReadStream("mask.png"), "A cute baby sea otter wearing a beret", 2, "1024x1024" ); response: | { "created": 1589478378, "data": [ { "url": "https://..." }, { "url": "https://..." } ] } /images/variations: post: operationId: createImageVariation tags: - OpenAI 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 group: images path: create-variation beta: true examples: curl: | curl https://api.openai.com/v1/images/variations \ -H 'Authorization: Bearer YOUR_API_KEY' \ -F image='@otter.png' \ -F n=2 \ -F size="1024x1024" python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.Image.create_variation( image=open("otter.png", "rb"), n=2, size="1024x1024" ) node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.createImageVariation( fs.createReadStream("otter.png"), 2, "1024x1024" ); response: | { "created": 1589478378, "data": [ { "url": "https://..." }, { "url": "https://..." } ] } /embeddings: post: operationId: createEmbedding tags: - OpenAI 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 group: embeddings path: create examples: curl: | curl https://api.openai.com/v1/embeddings \ -X POST \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"input": "The food was delicious and the waiter...", "model": "text-embedding-ada-002"}' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.Embedding.create( model="text-embedding-ada-002", input="The food was delicious and the waiter..." ) node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.createEmbedding({ model: "text-embedding-ada-002", input: "The food was delicious and the waiter...", }); parameters: | { "model": "text-embedding-ada-002", "input": "The food was delicious and the waiter..." } response: | { "object": "list", "data": [ { "object": "embedding", "embedding": [ 0.0023064255, -0.009327292, .... (1536 floats total for ada-002) -0.0028842222, ], "index": 0 } ], "model": "text-embedding-ada-002", "usage": { "prompt_tokens": 8, "total_tokens": 8 } } /audio/transcriptions: post: operationId: createTranscription tags: - OpenAI 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 group: audio path: create beta: true examples: curl: | curl https://api.openai.com/v1/audio/transcriptions \ -X POST \ -H 'Authorization: Bearer TOKEN' \ -H 'Content-Type: multipart/form-data' \ -F file=@/path/to/file/audio.mp3 \ -F model=whisper-1 python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") audio_file = open("audio.mp3", "rb") transcript = openai.Audio.transcribe("whisper-1", audio_file) node: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const resp = await openai.createTranscription( fs.createReadStream("audio.mp3"), "whisper-1" ); parameters: | { "file": "audio.mp3", "model": "whisper-1" } response: | { "text": "Imagine the wildest idea that you've ever had, and you're curious about how it might scale to something that's a 100, a 1,000 times bigger. This is a place where you can get to do that." } /audio/translations: post: operationId: createTranslation tags: - OpenAI summary: Translates audio into 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 group: audio path: create beta: true examples: curl: | curl https://api.openai.com/v1/audio/translations \ -X POST \ -H 'Authorization: Bearer TOKEN' \ -H 'Content-Type: multipart/form-data' \ -F file=@/path/to/file/german.m4a \ -F model=whisper-1 python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") audio_file = open("german.m4a", "rb") transcript = openai.Audio.translate("whisper-1", audio_file) node: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const resp = await openai.createTranslation( fs.createReadStream("audio.mp3"), "whisper-1" ); parameters: | { "file": "german.m4a", "model": "whisper-1" } response: | { "text": "Hello, my name is Wolfgang and I come from Germany. Where are you heading today?" } /engines/{engine_id}/search: post: operationId: createSearch deprecated: true tags: - OpenAI summary: | The search endpoint computes similarity scores between provided query and documents. Documents can be passed directly to the API if there are no more than 200 of them. To go beyond the 200 document limit, documents can be processed offline and then used for efficient retrieval at query time. When `file` is set, the search endpoint searches over all the documents in the given file and returns up to the `max_rerank` number of documents. These documents will be returned along with their search scores. The similarity score is a positive score that usually ranges from 0 to 300 (but can sometimes go higher), where a score above 200 usually means the document is semantically similar to the query. parameters: - in: path name: engine_id required: true schema: type: string example: davinci description: The ID of the engine to use for this request. You can select one of `ada`, `babbage`, `curie`, or `davinci`. requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreateSearchRequest" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/CreateSearchResponse" x-oaiMeta: name: Create search group: searches path: create examples: curl: | curl https://api.openai.com/v1/engines/davinci/search \ -H "Content-Type: application/json" \ -H 'Authorization: Bearer YOUR_API_KEY' \ -d '{ "documents": ["White House", "hospital", "school"], "query": "the president" }' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.Engine("davinci").search( documents=["White House", "hospital", "school"], query="the president" ) node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.createSearch("davinci", { documents: ["White House", "hospital", "school"], query: "the president", }); parameters: | { "documents": [ "White House", "hospital", "school" ], "query": "the president" } response: | { "data": [ { "document": 0, "object": "search_result", "score": 215.412 }, { "document": 1, "object": "search_result", "score": 40.316 }, { "document": 2, "object": "search_result", "score": 55.226 } ], "object": "list" } /files: get: operationId: listFiles tags: - OpenAI summary: Returns a list of files that belong to the user's organization. responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/ListFilesResponse" x-oaiMeta: name: List files group: files path: list examples: curl: | curl https://api.openai.com/v1/files \ -H 'Authorization: Bearer YOUR_API_KEY' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.File.list() node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.listFiles(); response: | { "data": [ { "id": "file-ccdDZrC3iZVNiQVeEA6Z66wf", "object": "file", "bytes": 175, "created_at": 1613677385, "filename": "train.jsonl", "purpose": "search" }, { "id": "file-XjGxS3KTG0uNmNOK362iJua3", "object": "file", "bytes": 140, "created_at": 1613779121, "filename": "puppy.jsonl", "purpose": "search" } ], "object": "list" } post: operationId: createFile tags: - OpenAI summary: | Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact us if you need to increase the storage limit. 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 group: files path: upload examples: curl: | curl https://api.openai.com/v1/files \ -H "Authorization: Bearer YOUR_API_KEY" \ -F purpose="fine-tune" \ -F file='@mydata.jsonl' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.File.create( file=open("mydata.jsonl", "rb"), purpose='fine-tune' ) node.js: | const fs = require("fs"); const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.createFile( fs.createReadStream("mydata.jsonl"), "fine-tune" ); response: | { "id": "file-XjGxS3KTG0uNmNOK362iJua3", "object": "file", "bytes": 140, "created_at": 1613779121, "filename": "mydata.jsonl", "purpose": "fine-tune" } /files/{file_id}: delete: operationId: deleteFile tags: - OpenAI 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 group: files path: delete examples: curl: | curl https://api.openai.com/v1/files/file-XjGxS3KTG0uNmNOK362iJua3 \ -X DELETE \ -H 'Authorization: Bearer YOUR_API_KEY' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.File.delete("file-XjGxS3KTG0uNmNOK362iJua3") node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.deleteFile("file-XjGxS3KTG0uNmNOK362iJua3"); response: | { "id": "file-XjGxS3KTG0uNmNOK362iJua3", "object": "file", "deleted": true } get: operationId: retrieveFile tags: - OpenAI 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 group: files path: retrieve examples: curl: | curl https://api.openai.com/v1/files/file-XjGxS3KTG0uNmNOK362iJua3 \ -H 'Authorization: Bearer YOUR_API_KEY' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.File.retrieve("file-XjGxS3KTG0uNmNOK362iJua3") node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.retrieveFile("file-XjGxS3KTG0uNmNOK362iJua3"); response: | { "id": "file-XjGxS3KTG0uNmNOK362iJua3", "object": "file", "bytes": 140, "created_at": 1613779657, "filename": "mydata.jsonl", "purpose": "fine-tune" } /files/{file_id}/content: get: operationId: downloadFile tags: - OpenAI 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 group: files path: retrieve-content examples: curl: | curl https://api.openai.com/v1/files/file-XjGxS3KTG0uNmNOK362iJua3/content \ -H 'Authorization: Bearer YOUR_API_KEY' > file.jsonl python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") content = openai.File.download("file-XjGxS3KTG0uNmNOK362iJua3") node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.downloadFile("file-XjGxS3KTG0uNmNOK362iJua3"); /answers: post: operationId: createAnswer deprecated: true tags: - OpenAI summary: | Answers the specified question using the provided documents and examples. The endpoint first [searches](/docs/api-reference/searches) over provided documents or files to find relevant context. The relevant context is combined with the provided examples and question to create the prompt for [completion](/docs/api-reference/completions). requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreateAnswerRequest" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/CreateAnswerResponse" x-oaiMeta: name: Create answer group: answers path: create examples: curl: | curl https://api.openai.com/v1/answers \ -X POST \ -H "Authorization: Bearer YOUR_API_KEY" \ -H 'Content-Type: application/json' \ -d '{ "documents": ["Puppy A is happy.", "Puppy B is sad."], "question": "which puppy is happy?", "search_model": "ada", "model": "curie", "examples_context": "In 2017, U.S. life expectancy was 78.6 years.", "examples": [["What is human life expectancy in the United States?","78 years."]], "max_tokens": 5, "stop": ["\n", "<|endoftext|>"] }' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.Answer.create( search_model="ada", model="curie", question="which puppy is happy?", documents=["Puppy A is happy.", "Puppy B is sad."], examples_context="In 2017, U.S. life expectancy was 78.6 years.", examples=[["What is human life expectancy in the United States?","78 years."]], max_tokens=5, stop=["\n", "<|endoftext|>"], ) node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.createAnswer({ search_model: "ada", model: "curie", question: "which puppy is happy?", documents: ["Puppy A is happy.", "Puppy B is sad."], examples_context: "In 2017, U.S. life expectancy was 78.6 years.", examples: [["What is human life expectancy in the United States?","78 years."]], max_tokens: 5, stop: ["\n", "<|endoftext|>"], }); parameters: | { "documents": ["Puppy A is happy.", "Puppy B is sad."], "question": "which puppy is happy?", "search_model": "ada", "model": "curie", "examples_context": "In 2017, U.S. life expectancy was 78.6 years.", "examples": [["What is human life expectancy in the United States?","78 years."]], "max_tokens": 5, "stop": ["\n", "<|endoftext|>"] } response: | { "answers": [ "puppy A." ], "completion": "cmpl-2euVa1kmKUuLpSX600M41125Mo9NI", "model": "curie:2020-05-03", "object": "answer", "search_model": "ada", "selected_documents": [ { "document": 0, "text": "Puppy A is happy. " }, { "document": 1, "text": "Puppy B is sad. " } ] } /classifications: post: operationId: createClassification deprecated: true tags: - OpenAI summary: | Classifies the specified `query` using provided examples. The endpoint first [searches](/docs/api-reference/searches) over the labeled examples to select the ones most relevant for the particular query. Then, the relevant examples are combined with the query to construct a prompt to produce the final label via the [completions](/docs/api-reference/completions) endpoint. Labeled examples can be provided via an uploaded `file`, or explicitly listed in the request using the `examples` parameter for quick tests and small scale use cases. requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreateClassificationRequest" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/CreateClassificationResponse" x-oaiMeta: name: Create classification group: classifications path: create examples: curl: | curl https://api.openai.com/v1/classifications \ -X POST \ -H "Authorization: Bearer YOUR_API_KEY" \ -H 'Content-Type: application/json' \ -d '{ "examples": [ ["A happy moment", "Positive"], ["I am sad.", "Negative"], ["I am feeling awesome", "Positive"]], "query": "It is a raining day :(", "search_model": "ada", "model": "curie", "labels":["Positive", "Negative", "Neutral"] }' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.Classification.create( search_model="ada", model="curie", examples=[ ["A happy moment", "Positive"], ["I am sad.", "Negative"], ["I am feeling awesome", "Positive"] ], query="It is a raining day :(", labels=["Positive", "Negative", "Neutral"], ) node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.createClassification({ search_model: "ada", model: "curie", examples: [ ["A happy moment", "Positive"], ["I am sad.", "Negative"], ["I am feeling awesome", "Positive"] ], query:"It is a raining day :(", labels: ["Positive", "Negative", "Neutral"], }); parameters: | { "examples": [ ["A happy moment", "Positive"], ["I am sad.", "Negative"], ["I am feeling awesome", "Positive"] ], "labels": ["Positive", "Negative", "Neutral"], "query": "It is a raining day :(", "search_model": "ada", "model": "curie" } response: | { "completion": "cmpl-2euN7lUVZ0d4RKbQqRV79IiiE6M1f", "label": "Negative", "model": "curie:2020-05-03", "object": "classification", "search_model": "ada", "selected_examples": [ { "document": 1, "label": "Negative", "text": "I am sad." }, { "document": 0, "label": "Positive", "text": "A happy moment" }, { "document": 2, "label": "Positive", "text": "I am feeling awesome" } ] } /fine-tunes: post: operationId: createFineTune tags: - OpenAI 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/CreateFineTuneRequest" responses: "200": description: OK content: application/json: schema: $ref: "#/components/schemas/FineTune" x-oaiMeta: name: Create fine-tune group: fine-tunes path: create examples: curl: | curl https://api.openai.com/v1/fine-tunes \ -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{ "training_file": "file-XGinujblHPwGLSztz8cPS8XY" }' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.FineTune.create(training_file="file-XGinujblHPwGLSztz8cPS8XY") node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.createFineTune({ training_file: "file-XGinujblHPwGLSztz8cPS8XY", }); response: | { "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F", "object": "fine-tune", "model": "curie", "created_at": 1614807352, "events": [ { "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-...", "result_files": [], "status": "pending", "validation_files": [], "training_files": [ { "id": "file-XGinujblHPwGLSztz8cPS8XY", "object": "file", "bytes": 1547276, "created_at": 1610062281, "filename": "my-data-train.jsonl", "purpose": "fine-tune-train" } ], "updated_at": 1614807352, } get: operationId: listFineTunes tags: - OpenAI 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 group: fine-tunes path: list examples: curl: | curl https://api.openai.com/v1/fine-tunes \ -H 'Authorization: Bearer YOUR_API_KEY' python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.FineTune.list() node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.listFineTunes(); response: | { "object": "list", "data": [ { "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F", "object": "fine-tune", "model": "curie", "created_at": 1614807352, "fine_tuned_model": null, "hyperparams": { ... }, "organization_id": "org-...", "result_files": [], "status": "pending", "validation_files": [], "training_files": [ { ... } ], "updated_at": 1614807352, }, { ... }, { ... } ] } /fine-tunes/{fine_tune_id}: get: operationId: retrieveFineTune tags: - OpenAI summary: | Gets info about the fine-tune job. [Learn more about Fine-tuning](/docs/guides/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 group: fine-tunes path: retrieve examples: curl: | curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F \ -H "Authorization: Bearer YOUR_API_KEY" python: | import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") openai.FineTune.retrieve(id="ft-AF1WoRqd3aJAHsqc9NY7iL8F") node.js: | const { Configuration, OpenAIApi } = require("openai"); const configuration = new Configuration({ apiKey: process.env.OPENAI_API_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.retrieveFineTune("ft-AF1WoRqd3aJAHsqc9NY7iL8F"); response: | { "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F", "object": "fine-tune", "model": "curi