From 3bbc26bd740ecd9c4d76af02adb981e914ebac05 Mon Sep 17 00:00:00 2001 From: Brian Zhang Date: Tue, 30 Apr 2024 17:48:34 -0700 Subject: [PATCH] Add stream_options param; add usage in ChatCompletionChunk --- openapi.yaml | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/openapi.yaml b/openapi.yaml index 8f3f3ef2..b0437f6e 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -7212,6 +7212,8 @@ components: type: boolean nullable: true default: false + stream_options: + $ref: "#/components/schemas/ChatCompletionStreamOptions" suffix: description: | The suffix that comes after a completion of inserted text. @@ -7697,6 +7699,18 @@ components: - tool - function + ChatCompletionStreamOptions: + description: | + Options for streaming response. Only set this when you set `stream: true`. + type: object + nullable: true + default: null + properties: + include_usage: + type: boolean + description: | + If set, an additional chunk will be streamed before the `data: [DONE]` message. The `usage` field on this chunk shows the token usage statistics for the entire request, and the `choices` field will always be an empty array. All other chunks will also include a `usage` field, but with a null value. + ChatCompletionResponseMessage: type: object description: A chat completion message generated by the model. @@ -7891,6 +7905,8 @@ components: type: boolean nullable: true default: false + stream_options: + $ref: "#/components/schemas/ChatCompletionStreamOptions" temperature: type: number minimum: 0 @@ -8150,7 +8166,9 @@ components: 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. + description: | + A list of chat completion choices. Can contain more than one elements if `n` is greater than 1. Can also be empty for the + last chunk if you set `stream_options: {"include_usage": true}`. items: type: object required: @@ -8191,6 +8209,25 @@ components: type: string description: The object type, which is always `chat.completion.chunk`. enum: [chat.completion.chunk] + usage: + type: object + description: | + An optional field that will only be present when you set `stream_options: {"include_usage": true}` in your request. + When present, it contains a null value except for the last chunk which contains the token usage statistics for the entire 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 required: - choices - created