-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprotocol.ts
159 lines (137 loc) · 4.52 KB
/
protocol.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* eslint-disable @typescript-eslint/no-namespace */
export interface ChatCompletionChunk {
/**
* A unique identifier for the chat completion. Each chunk has the same ID.
*/
id: string;
/**
* 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}`.
*/
choices: Array<ChatCompletionChunk.Choice>;
/**
* The Unix timestamp (in seconds) of when the chat completion was created. Each
* chunk has the same timestamp.
*/
created: number;
/**
* The model to generate the completion.
*/
model: string;
/**
* The object type, which is always `chat.completion.chunk`.
*/
object: 'chat.completion.chunk';
/**
* The service tier used for processing the request. This field is only included if
* the `service_tier` parameter is specified in the request.
*/
service_tier?: 'scale' | 'default' | null;
/**
* 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.
*/
system_fingerprint?: string;
}
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace ChatCompletionChunk {
export interface Choice {
/**
* A chat completion delta generated by streamed model responses.
*/
delta: Choice.Delta;
/**
* 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.
*/
finish_reason:
| 'stop'
| 'length'
| 'tool_calls'
| 'content_filter'
| 'function_call'
| null;
/**
* The index of the choice in the list of choices.
*/
index: number;
}
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Choice {
/**
* A chat completion delta generated by streamed model responses.
*/
export interface Delta {
/**
* The contents of the chunk message.
*/
content?: string | null;
/**
* @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of
* a function that should be called, as generated by the model.
*/
function_call?: Delta.FunctionCall;
/**
* The refusal message generated by the model.
*/
refusal?: string | null;
/**
* The role of the author of this message.
*/
role?: 'system' | 'user' | 'assistant' | 'tool';
tool_calls?: Array<Delta.ToolCall>;
}
export namespace Delta {
/**
* @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of
* a function that should be called, as generated by the model.
*/
export interface FunctionCall {
/**
* 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.
*/
arguments?: string;
/**
* The name of the function to call.
*/
name?: string;
}
export interface ToolCall {
index: number;
/**
* The ID of the tool call.
*/
id?: string;
function?: ToolCall.Function;
/**
* The type of the tool. Currently, only `function` is supported.
*/
type?: 'function';
}
export namespace ToolCall {
export interface Function {
/**
* 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.
*/
arguments?: string;
/**
* The name of the function to call.
*/
name?: string;
}
}
}
}
}