Skip to content

Commit 0299738

Browse files
authored
add chat completion stream types to spec (64bit#92)
1 parent 4573e31 commit 0299738

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

async-openai/src/types/types.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -871,26 +871,26 @@ pub type ChatCompletionResponseStream =
871871
// For reason (not documented by OpenAI) the response from stream is different
872872

873873
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
874-
pub struct ChatCompletionResponseStreamMessage {
875-
pub content: Option<String>,
874+
pub struct ChatCompletionStreamResponseDelta {
876875
pub role: Option<Role>,
876+
pub content: Option<String>,
877+
pub function_call: Option<FunctionCall>,
877878
}
878879

879880
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
880-
pub struct ChatChoiceDelta {
881+
pub struct ChatCompletionResponseStreamMessage {
881882
pub index: u32,
882-
pub delta: ChatCompletionResponseStreamMessage,
883+
pub delta: ChatCompletionStreamResponseDelta,
883884
pub finish_reason: Option<String>,
884885
}
885886

886887
#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
887888
pub struct CreateChatCompletionStreamResponse {
888-
pub id: Option<String>,
889+
pub id: String,
889890
pub object: String,
890891
pub created: u32,
891892
pub model: String,
892-
pub choices: Vec<ChatChoiceDelta>,
893-
pub usage: Option<Usage>,
893+
pub choices: Vec<ChatCompletionResponseStreamMessage>,
894894
}
895895

896896
#[derive(Debug, Default, Clone, PartialEq)]

openapi.yaml

+52
Original file line numberDiff line numberDiff line change
@@ -2369,6 +2369,28 @@ components:
23692369
required:
23702370
- role
23712371

2372+
ChatCompletionStreamResponseDelta:
2373+
type: object
2374+
properties:
2375+
role:
2376+
type: string
2377+
enum: ["system", "user", "assistant", "function"]
2378+
description: The role of the author of this message.
2379+
content:
2380+
type: string
2381+
description: The contents of the chunk message.
2382+
nullable: true
2383+
function_call:
2384+
type: object
2385+
description: The name and arguments of a function that should be called, as generated by the model.
2386+
properties:
2387+
name:
2388+
type: string
2389+
description: The name of the function to call.
2390+
arguments:
2391+
type: string
2392+
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.
2393+
23722394
CreateChatCompletionRequest:
23732395
type: object
23742396
properties:
@@ -2519,6 +2541,36 @@ components:
25192541
- model
25202542
- choices
25212543

2544+
CreateChatCompletionStreamResponse:
2545+
type: object
2546+
properties:
2547+
id:
2548+
type: string
2549+
object:
2550+
type: string
2551+
created:
2552+
type: integer
2553+
model:
2554+
type: string
2555+
choices:
2556+
type: array
2557+
items:
2558+
type: object
2559+
properties:
2560+
index:
2561+
type: integer
2562+
delta:
2563+
$ref: '#/components/schemas/ChatCompletionStreamResponseDelta'
2564+
finish_reason:
2565+
type: string
2566+
enum: ["stop", "length", "function_call"]
2567+
required:
2568+
- id
2569+
- object
2570+
- created
2571+
- model
2572+
- choices
2573+
25222574
CreateEditRequest:
25232575
type: object
25242576
properties:

0 commit comments

Comments
 (0)