From 937d2770f7a70a5e48dc2395afbe1bc83e099bf6 Mon Sep 17 00:00:00 2001 From: Himanshu Neema Date: Thu, 9 Nov 2023 16:10:31 -0800 Subject: [PATCH] updates from spec (#142) * latest spec * fix doc comments from spec --- async-openai/src/types/assistants/run.rs | 2 +- async-openai/src/types/assistants/step.rs | 4 +- async-openai/src/types/types.rs | 9 +- openapi.yaml | 189 ++++++++++++---------- 4 files changed, 118 insertions(+), 86 deletions(-) diff --git a/async-openai/src/types/assistants/run.rs b/async-openai/src/types/assistants/run.rs index 52ad92da..91ff2118 100644 --- a/async-openai/src/types/assistants/run.rs +++ b/async-openai/src/types/assistants/run.rs @@ -12,7 +12,7 @@ use super::AssistantTools; pub struct RunObject { /// The identifier, which can be referenced in API endpoints. pub id: String, - /// The object type, which is always `assistant.run`. + /// The object type, which is always `thread.run`. pub object: String, /// The Unix timestamp (in seconds) for when the run was created. pub created_at: i32, diff --git a/async-openai/src/types/assistants/step.rs b/async-openai/src/types/assistants/step.rs index 23133882..ee03e7d1 100644 --- a/async-openai/src/types/assistants/step.rs +++ b/async-openai/src/types/assistants/step.rs @@ -16,7 +16,7 @@ pub enum RunStepType { pub struct RunStepObject { /// The identifier, which can be referenced in API endpoints. pub id: String, - /// The object type, which is always `assistant.run.step`. + /// The object type, which is always `thread.run.step`. pub object: String, /// The Unix timestamp (in seconds) for when the run step was created. pub created_at: i32, @@ -33,7 +33,7 @@ pub struct RunStepObject { /// The type of run step, which can be either `message_creation` or `tool_calls`. pub r#type: RunStepType, - /// The status of the run, which can be either `in_progress`, `cancelled`, `failed`, `completed`, or `expired`. + /// The status of the run step, which can be either `in_progress`, `cancelled`, `failed`, `completed`, or `expired`. pub status: RunStatus, /// The details of the run step. diff --git a/async-openai/src/types/types.rs b/async-openai/src/types/types.rs index 534c1c5f..fcb734f8 100644 --- a/async-openai/src/types/types.rs +++ b/async-openai/src/types/types.rs @@ -1410,7 +1410,11 @@ pub struct CreateChatCompletionRequest { #[serde(skip_serializing_if = "Option::is_none")] pub presence_penalty: Option, // min: -2.0, max: 2.0, default 0 - /// An object specifying the format that the model must output. Used to enable JSON mode. + /// 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. #[serde(skip_serializing_if = "Option::is_none")] pub response_format: Option, @@ -1575,6 +1579,9 @@ pub struct CreateChatCompletionStreamResponse { pub created: u32, /// The model to generate the completion. pub model: String, + /// 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. + pub system_fingerprint: Option, /// The object type, which is always `chat.completion.chunk`. pub object: String, } diff --git a/openapi.yaml b/openapi.yaml index 7be02646..8974b9dd 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -142,45 +142,73 @@ paths: -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ - "model": "VAR_model_id", + "model": "gpt-4-vision-preview", "messages": [ - { - "role": "system", - "content": "You are a helpful assistant." - }, { "role": "user", - "content": "Hello!" + "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() - completion = client.chat.completions.create( - model="VAR_model_id", - messages=[ - {"role": "system", "content": "You are a helpful assistant."}, - {"role": "user", "content": "Hello!"} - ] + 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(completion.choices[0].message) + print(response.choices[0]) 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", + 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(completion.choices[0]); + console.log(response.choices[0]); } - main(); response: &chat_completion_image_example | { @@ -2593,7 +2621,7 @@ paths: from openai import OpenAI client = OpenAI() - my_assistants = openai.beta.assistants.list( + my_assistants = client.beta.assistants.list( order="desc", limit="20", ) @@ -2699,7 +2727,7 @@ paths: from openai import OpenAI client = OpenAI() - my_assistant = openai.beta.assistants.create( + 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"}], @@ -2758,7 +2786,7 @@ paths: from openai import OpenAI client = OpenAI() - my_assistant = openai.beta.assistants.create( + 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"}], @@ -2840,7 +2868,7 @@ paths: from openai import OpenAI client = OpenAI() - my_assistant = openai.beta.assistants.retrieve("asst_abc123") + my_assistant = client.beta.assistants.retrieve("asst_abc123") print(my_assistant) node.js: |- import OpenAI from "openai"; @@ -2920,7 +2948,8 @@ paths: python: | from openai import OpenAI client = OpenAI() - my_updated_assistant = openai.beta.assistants.update( + + 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", @@ -3009,7 +3038,8 @@ paths: python: | from openai import OpenAI client = OpenAI() - response = openai.beta.assistants.delete("asst_QLoItBbqwyAJEzlTy4y9kOMM") + + response = client.beta.assistants.delete("asst_QLoItBbqwyAJEzlTy4y9kOMM") print(response) node.js: |- import OpenAI from "openai"; @@ -3036,7 +3066,6 @@ paths: - Assistants summary: Create a thread. requestBody: - required: true content: application/json: schema: @@ -3065,7 +3094,7 @@ paths: from openai import OpenAI client = OpenAI() - empty_thread = openai.beta.threads.create() + empty_thread = client.beta.threads.create() print(empty_thread) node.js: |- import OpenAI from "openai"; @@ -3107,7 +3136,7 @@ paths: from openai import OpenAI client = OpenAI() - message_thread = openai.beta.threads.create( + message_thread = client.beta.threads.create( messages=[ { "role": "user", @@ -3189,7 +3218,7 @@ paths: from openai import OpenAI client = OpenAI() - my_thread = openai.beta.threads.retrieve("thread_abc123") + my_thread = client.beta.threads.retrieve("thread_abc123") print(my_thread) node.js: |- import OpenAI from "openai"; @@ -3258,7 +3287,7 @@ paths: from openai import OpenAI client = OpenAI() - my_updated_thread = openai.beta.threads.update( + my_updated_thread = client.beta.threads.update( "thread_abc123", metadata={ "modified": "true", @@ -3328,7 +3357,7 @@ paths: from openai import OpenAI client = OpenAI() - response = openai.beta.threads.delete("thread_abc123") + response = client.beta.threads.delete("thread_abc123") print(response) node.js: |- import OpenAI from "openai"; @@ -3407,7 +3436,7 @@ paths: from openai import OpenAI client = OpenAI() - thread_messages = openai.beta.threads.messages.list("thread_1OWaSqVIxJdy3KYnJLbXEWhy") + thread_messages = client.beta.threads.messages.list("thread_1OWaSqVIxJdy3KYnJLbXEWhy") print(thread_messages.data) node.js: |- import OpenAI from "openai"; @@ -3518,7 +3547,7 @@ paths: from openai import OpenAI client = OpenAI() - thread_message = openai.beta.threads.messages.create( + thread_message = client.beta.threads.messages.create( "thread_abc123", role="user", content="How does AI work? Explain it in simple terms.", @@ -3602,7 +3631,7 @@ paths: from openai import OpenAI client = OpenAI() - message = openai.beta.threads.messages.retrieve( + message = client.beta.threads.messages.retrieve( message_id="msg_abc123", thread_id="thread_abc123", ) @@ -3695,7 +3724,7 @@ paths: from openai import OpenAI client = OpenAI() - message = openai.beta.threads.messages.update( + message = client.beta.threads.messages.update( message_id="msg_abc12", thread_id="thread_abc123", metadata={ @@ -5478,7 +5507,7 @@ components: items: type: object additionalProperties: - type: integer + type: number text: type: string created: @@ -5556,7 +5585,7 @@ components: enum: ["auto", "low", "high"] default: "auto" required: - - data + - url required: - type - image_url @@ -5701,7 +5730,7 @@ components: - name - content - ChatCompletionFunctionParameters: + 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 @@ -5717,7 +5746,7 @@ components: type: string description: The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. parameters: - $ref: "#/components/schemas/ChatCompletionFunctionParameters" + $ref: "#/components/schemas/FunctionParameters" required: - name - parameters @@ -5741,23 +5770,26 @@ components: enum: ["function"] description: The type of the tool. Currently, only `function` is supported. function: - type: object - properties: - description: - type: string - description: A description of what the function does, used by the model to choose when and how to call the function. - name: - type: string - description: The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. - parameters: - $ref: "#/components/schemas/ChatCompletionFunctionParameters" - required: - - name - - parameters + $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. @@ -5939,6 +5971,8 @@ components: - type: string enum: [ + "gpt-4-1106-preview", + "gpt-4-vision-preview", "gpt-4", "gpt-4-0314", "gpt-4-0613", @@ -5995,19 +6029,19 @@ components: description: *completions_presence_penalty_description response_format: type: object - description: An object specifying the format that the model must output. Used to enable JSON mode. + 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: | - Setting to `json_object` enables JSON mode. This guarantees that the message the model generates is valid JSON. - - Note that your system prompt must still instruct the model to produce JSON, and to help ensure you don't forget, the API will throw an error if the string `JSON` does not appear in your system message. Also note that the message content may be partial (i.e. cut off) if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length. - - Must be one of `text` or `json_object`. + description: Must be one of `text` or `json_object`. seed: type: integer minimum: -9223372036854775808 @@ -6279,6 +6313,11 @@ components: 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`. @@ -7116,8 +7155,8 @@ components: description: The name of the model used to generate the embedding. object: type: string - description: The object type, which is always "embedding". - enum: [embedding] + description: The object type, which is always "list". + enum: [list] usage: type: object description: The usage information for the request. @@ -7949,21 +7988,7 @@ components: description: "The type of tool being defined: `function`" enum: ["function"] function: - type: object - description: The function definition. - properties: - description: - type: string - description: A description of what the function does, used by the model to choose when and how to call the function. - name: - type: string - description: The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. - parameters: - $ref: "#/components/schemas/ChatCompletionFunctionParameters" - required: - - name - - parameters - - description + $ref: "#/components/schemas/FunctionObject" required: - type - function @@ -7977,9 +8002,9 @@ components: description: The identifier, which can be referenced in API endpoints. type: string object: - description: The object type, which is always `assistant.run`. + description: The object type, which is always `thread.run`. type: string - enum: ["assistant.run"] + enum: ["thread.run"] created_at: description: The Unix timestamp (in seconds) for when the run was created. type: integer @@ -8678,9 +8703,9 @@ components: description: The identifier of the run step, which can be referenced in API endpoints. type: string object: - description: The object type, which is always `assistant.run.step``. + description: The object type, which is always `thread.run.step``. type: string - enum: ["assistant.run.step"] + enum: ["thread.run.step"] created_at: description: The Unix timestamp (in seconds) for when the run step was created. type: integer @@ -8698,7 +8723,7 @@ components: type: string enum: ["message_creation", "tool_calls"] status: - description: The status of the run, which can be either `in_progress`, `cancelled`, `failed`, `completed`, or `expired`. + 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: