@celljs/ai-openai 3.6.2 → 3.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common/api/chat-request.d.ts +2 -10
- package/lib/common/api/chat-request.d.ts.map +1 -1
- package/lib/common/api/chat-request.js +88 -9
- package/lib/common/api/chat-request.js.map +1 -1
- package/lib/common/api/chat-response.d.ts.map +1 -1
- package/lib/common/api/chat-response.js +69 -0
- package/lib/common/api/chat-response.js.map +1 -1
- package/lib/common/api/embeddings-request.d.ts.map +1 -1
- package/lib/common/api/embeddings-request.js +28 -0
- package/lib/common/api/embeddings-request.js.map +1 -1
- package/lib/common/api/embeddings-response.d.ts.map +1 -1
- package/lib/common/api/embeddings-response.js +10 -0
- package/lib/common/api/embeddings-response.js.map +1 -1
- package/lib/common/api/message.d.ts.map +1 -1
- package/lib/common/api/message.js +73 -0
- package/lib/common/api/message.js.map +1 -1
- package/lib/common/api/openai-api.js +3 -3
- package/lib/common/api/openai-api.js.map +1 -1
- package/lib/common/api/response-format.d.ts.map +1 -1
- package/lib/common/api/response-format.js +35 -0
- package/lib/common/api/response-format.js.map +1 -1
- package/lib/common/api/usage.d.ts.map +1 -1
- package/lib/common/api/usage.js +10 -0
- package/lib/common/api/usage.js.map +1 -1
- package/lib/common/model/openai-chat-model.js.map +1 -1
- package/lib/common/model/openai-chat-options.d.ts.map +1 -1
- package/lib/common/model/openai-chat-options.js +19 -0
- package/lib/common/model/openai-chat-options.js.map +1 -1
- package/lib/common/model/openai-embedding-options.d.ts.map +1 -1
- package/lib/common/model/openai-embedding-options.js +12 -0
- package/lib/common/model/openai-embedding-options.js.map +1 -1
- package/package.json +6 -6
- package/src/common/api/chat-request.ts +34 -10
- package/src/common/api/chat-response.ts +24 -0
- package/src/common/api/embeddings-request.ts +7 -0
- package/src/common/api/embeddings-response.ts +5 -1
- package/src/common/api/message.ts +19 -0
- package/src/common/api/openai-api.ts +3 -3
- package/src/common/api/response-format.ts +9 -0
- package/src/common/api/usage.ts +5 -1
- package/src/common/model/openai-chat-model.ts +1 -1
- package/src/common/model/openai-chat-options.ts +8 -1
- package/src/common/model/openai-embedding-options.ts +3 -0
|
@@ -5,16 +5,18 @@ import { ResponseFormat } from './response-format';
|
|
|
5
5
|
export class StreamOptions {
|
|
6
6
|
static INCLUDE_USAGE = new StreamOptions(true);
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
/**
|
|
9
|
+
* includeUsage If set, an additional chunk will be streamed
|
|
10
|
+
* before the data: [DONE] message. The usage field on this chunk
|
|
11
|
+
* shows the token usage statistics for the entire request, and
|
|
12
|
+
* the choices field will always be an empty array. All other chunks
|
|
13
|
+
* will also include a usage field, but with a null value.
|
|
14
|
+
*/
|
|
15
|
+
@Expose({ name: 'include_usage' })
|
|
16
|
+
includeUsage: boolean;
|
|
17
|
+
|
|
18
|
+
constructor(includeUsage: boolean) {
|
|
19
|
+
this.includeUsage = includeUsage;
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
|
|
@@ -22,9 +24,13 @@ export class StreamOptions {
|
|
|
22
24
|
* Function definition.
|
|
23
25
|
*/
|
|
24
26
|
export class Function {
|
|
27
|
+
@Expose()
|
|
25
28
|
description: string;
|
|
29
|
+
@Expose()
|
|
26
30
|
name: string;
|
|
31
|
+
@Expose()
|
|
27
32
|
parameters: Record<string, any>;
|
|
33
|
+
@Expose()
|
|
28
34
|
strict?: boolean;
|
|
29
35
|
|
|
30
36
|
static create(description: string, name: string, parameters: Record<string, any>, strict?: boolean): Function {
|
|
@@ -48,11 +54,14 @@ export class FunctionTool {
|
|
|
48
54
|
/**
|
|
49
55
|
* The type of the tool. Currently, only 'function' is supported.
|
|
50
56
|
*/
|
|
57
|
+
@Expose()
|
|
51
58
|
type: ToolType;
|
|
52
59
|
|
|
53
60
|
/**
|
|
54
61
|
* The function definition.
|
|
55
62
|
*/
|
|
63
|
+
@Type(() => Function)
|
|
64
|
+
@Expose()
|
|
56
65
|
function: Function;
|
|
57
66
|
|
|
58
67
|
static create(func: Function): FunctionTool {
|
|
@@ -92,10 +101,12 @@ export class AudioParameters {
|
|
|
92
101
|
/**
|
|
93
102
|
* Specifies the voice type.
|
|
94
103
|
*/
|
|
104
|
+
@Expose()
|
|
95
105
|
voice?: Voice;
|
|
96
106
|
/**
|
|
97
107
|
* Specifies the output audio format.
|
|
98
108
|
*/
|
|
109
|
+
@Expose({ name: 'response_format' })
|
|
99
110
|
format?: AudioResponseFormat;
|
|
100
111
|
}
|
|
101
112
|
|
|
@@ -106,20 +117,25 @@ export class ChatCompletionRequest {
|
|
|
106
117
|
/**
|
|
107
118
|
* A list of messages comprising the conversation so far.
|
|
108
119
|
*/
|
|
120
|
+
@Type(() => ChatCompletionMessage)
|
|
121
|
+
@Expose()
|
|
109
122
|
messages: ChatCompletionMessage[];
|
|
110
123
|
|
|
111
124
|
/**
|
|
112
125
|
* ID of the model to use.
|
|
113
126
|
*/
|
|
127
|
+
@Expose()
|
|
114
128
|
model: string;
|
|
115
129
|
/**
|
|
116
130
|
* Whether to store the output of this chat completion request for use in OpenAI's model distillation or evals products.
|
|
117
131
|
*/
|
|
132
|
+
@Expose()
|
|
118
133
|
store?: boolean;
|
|
119
134
|
|
|
120
135
|
/**
|
|
121
136
|
* Developer-defined tags and values used for filtering completions in the OpenAI's dashboard.
|
|
122
137
|
*/
|
|
138
|
+
@Expose()
|
|
123
139
|
metadata?: Record<string, any>;
|
|
124
140
|
|
|
125
141
|
/**
|
|
@@ -139,6 +155,7 @@ export class ChatCompletionRequest {
|
|
|
139
155
|
/**
|
|
140
156
|
* Whether to return log probabilities of the output tokens or not.
|
|
141
157
|
*/
|
|
158
|
+
@Expose()
|
|
142
159
|
logprobs?: boolean;
|
|
143
160
|
|
|
144
161
|
/**
|
|
@@ -150,6 +167,7 @@ export class ChatCompletionRequest {
|
|
|
150
167
|
/**
|
|
151
168
|
* @deprecated The maximum number of tokens that can be generated in the chat completion. This value can be used to control costs for text generated via API.
|
|
152
169
|
*/
|
|
170
|
+
@Expose({ name: 'max_tokens' })
|
|
153
171
|
maxTokens?: number;
|
|
154
172
|
|
|
155
173
|
/**
|
|
@@ -161,6 +179,7 @@ export class ChatCompletionRequest {
|
|
|
161
179
|
/**
|
|
162
180
|
* How many chat completion choices to generate for each input message.
|
|
163
181
|
*/
|
|
182
|
+
@Expose()
|
|
164
183
|
n?: number;
|
|
165
184
|
|
|
166
185
|
/**
|
|
@@ -194,6 +213,7 @@ export class ChatCompletionRequest {
|
|
|
194
213
|
* If specified, our system will make a best effort to sample deterministically,
|
|
195
214
|
* such that repeated requests with the same seed and parameters should return the same result.
|
|
196
215
|
*/
|
|
216
|
+
@Expose()
|
|
197
217
|
seed?: number;
|
|
198
218
|
|
|
199
219
|
/**
|
|
@@ -205,11 +225,13 @@ export class ChatCompletionRequest {
|
|
|
205
225
|
/**
|
|
206
226
|
* Up to 4 sequences where the API will stop generating further tokens.
|
|
207
227
|
*/
|
|
228
|
+
@Expose()
|
|
208
229
|
stop?: string[];
|
|
209
230
|
|
|
210
231
|
/**
|
|
211
232
|
* Options for streaming response.
|
|
212
233
|
*/
|
|
234
|
+
@Expose()
|
|
213
235
|
stream?: boolean;
|
|
214
236
|
|
|
215
237
|
/**
|
|
@@ -223,6 +245,7 @@ export class ChatCompletionRequest {
|
|
|
223
245
|
* What sampling temperature to use, between 0 and 1. Higher values like 0.8 will make the output more random,
|
|
224
246
|
* while lower values like 0.2 will make it more focused and deterministic.
|
|
225
247
|
*/
|
|
248
|
+
@Expose()
|
|
226
249
|
temperature?: number;
|
|
227
250
|
|
|
228
251
|
/**
|
|
@@ -254,6 +277,7 @@ export class ChatCompletionRequest {
|
|
|
254
277
|
/**
|
|
255
278
|
* A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
|
|
256
279
|
*/
|
|
280
|
+
@Expose()
|
|
257
281
|
user?: string;
|
|
258
282
|
|
|
259
283
|
/**
|
|
@@ -9,10 +9,12 @@ export class TopLogProbs {
|
|
|
9
9
|
/**
|
|
10
10
|
* The token.
|
|
11
11
|
*/
|
|
12
|
+
@Expose()
|
|
12
13
|
token: string;
|
|
13
14
|
/**
|
|
14
15
|
* The log probability of the token.
|
|
15
16
|
*/
|
|
17
|
+
@Expose()
|
|
16
18
|
logprob: number;
|
|
17
19
|
/**
|
|
18
20
|
* A list of integers representing the UTF-8 bytes
|
|
@@ -32,10 +34,12 @@ export class Content {
|
|
|
32
34
|
/**
|
|
33
35
|
* The token.
|
|
34
36
|
*/
|
|
37
|
+
@Expose()
|
|
35
38
|
token: string;
|
|
36
39
|
/**
|
|
37
40
|
* The log probability of the token.
|
|
38
41
|
*/
|
|
42
|
+
@Expose()
|
|
39
43
|
logprob: number;
|
|
40
44
|
/**
|
|
41
45
|
* A list of integers representing the UTF-8 bytes representation
|
|
@@ -63,11 +67,13 @@ export class LogProbs {
|
|
|
63
67
|
* Message content tokens with log probability information.
|
|
64
68
|
*/
|
|
65
69
|
@Type(() => Content)
|
|
70
|
+
@Expose()
|
|
66
71
|
content: Content[];
|
|
67
72
|
/**
|
|
68
73
|
* Message refusal tokens with log probability information.
|
|
69
74
|
*/
|
|
70
75
|
@Type(() => Content)
|
|
76
|
+
@Expose()
|
|
71
77
|
refusal: Content[];
|
|
72
78
|
}
|
|
73
79
|
|
|
@@ -83,6 +89,7 @@ export class Choice {
|
|
|
83
89
|
/**
|
|
84
90
|
* The index of the choice in the list of choices.
|
|
85
91
|
*/
|
|
92
|
+
@Expose()
|
|
86
93
|
index: number;
|
|
87
94
|
/**
|
|
88
95
|
* A chat completion message generated by the model.
|
|
@@ -92,6 +99,8 @@ export class Choice {
|
|
|
92
99
|
/**
|
|
93
100
|
* Log probability information for the choice.
|
|
94
101
|
*/
|
|
102
|
+
@Type(() => LogProbs)
|
|
103
|
+
@Expose()
|
|
95
104
|
logprobs: LogProbs;
|
|
96
105
|
}
|
|
97
106
|
|
|
@@ -103,21 +112,25 @@ export class ChatCompletion {
|
|
|
103
112
|
/**
|
|
104
113
|
* A unique identifier for the chat completion.
|
|
105
114
|
*/
|
|
115
|
+
@Expose()
|
|
106
116
|
id: string;
|
|
107
117
|
/**
|
|
108
118
|
* A list of chat completion choices. Can be more than one if n is
|
|
109
119
|
* greater than 1.
|
|
110
120
|
*/
|
|
111
121
|
@Type(() => Choice)
|
|
122
|
+
@Expose()
|
|
112
123
|
choices: Choice[];
|
|
113
124
|
/**
|
|
114
125
|
* The Unix timestamp (in seconds) of when the chat completion was
|
|
115
126
|
* created.
|
|
116
127
|
*/
|
|
128
|
+
@Expose()
|
|
117
129
|
created: number;
|
|
118
130
|
/**
|
|
119
131
|
* The model used for the chat completion.
|
|
120
132
|
*/
|
|
133
|
+
@Expose()
|
|
121
134
|
model: string;
|
|
122
135
|
/**
|
|
123
136
|
* The service tier used for processing the request. This field is
|
|
@@ -135,11 +148,13 @@ export class ChatCompletion {
|
|
|
135
148
|
/**
|
|
136
149
|
* The object type, which is always chat.completion.
|
|
137
150
|
*/
|
|
151
|
+
@Expose()
|
|
138
152
|
object: string;
|
|
139
153
|
/**
|
|
140
154
|
* Usage statistics for the completion request.
|
|
141
155
|
*/
|
|
142
156
|
@Type(() => Usage)
|
|
157
|
+
@Expose()
|
|
143
158
|
usage: Usage;
|
|
144
159
|
}
|
|
145
160
|
|
|
@@ -155,16 +170,19 @@ export class ChunkChoice {
|
|
|
155
170
|
/**
|
|
156
171
|
* The index of the choice in the list of choices.
|
|
157
172
|
*/
|
|
173
|
+
@Expose()
|
|
158
174
|
index: number;
|
|
159
175
|
/**
|
|
160
176
|
* A chat completion delta generated by streamed model responses.
|
|
161
177
|
*/
|
|
162
178
|
@Type(() => ChatCompletionMessage)
|
|
179
|
+
@Expose()
|
|
163
180
|
delta: ChatCompletionMessage;
|
|
164
181
|
/**
|
|
165
182
|
* Log probability information for the choice.
|
|
166
183
|
*/
|
|
167
184
|
@Type(() => LogProbs)
|
|
185
|
+
@Expose()
|
|
168
186
|
logprobs: LogProbs;
|
|
169
187
|
}
|
|
170
188
|
|
|
@@ -176,21 +194,25 @@ export class ChatCompletionChunk {
|
|
|
176
194
|
/**
|
|
177
195
|
* A unique identifier for the chat completion. Each chunk has the same ID.
|
|
178
196
|
*/
|
|
197
|
+
@Expose()
|
|
179
198
|
id: string;
|
|
180
199
|
/**
|
|
181
200
|
* A list of chat completion choices. Can be more than one if n is
|
|
182
201
|
* greater than 1.
|
|
183
202
|
*/
|
|
184
203
|
@Type(() => ChunkChoice)
|
|
204
|
+
@Expose()
|
|
185
205
|
choices: ChunkChoice[];
|
|
186
206
|
/**
|
|
187
207
|
* The Unix timestamp (in seconds) of when the chat completion was
|
|
188
208
|
* created. Each chunk has the same timestamp.
|
|
189
209
|
*/
|
|
210
|
+
@Expose()
|
|
190
211
|
created: number;
|
|
191
212
|
/**
|
|
192
213
|
* The model used for the chat completion.
|
|
193
214
|
*/
|
|
215
|
+
@Expose()
|
|
194
216
|
model: string;
|
|
195
217
|
/**
|
|
196
218
|
* The service tier used for processing the request. This field is
|
|
@@ -208,11 +230,13 @@ export class ChatCompletionChunk {
|
|
|
208
230
|
/**
|
|
209
231
|
* The object type, which is always 'chat.completion.chunk'.
|
|
210
232
|
*/
|
|
233
|
+
@Expose()
|
|
211
234
|
object: string;
|
|
212
235
|
/**
|
|
213
236
|
* Usage statistics for the completion request. Present in the last chunk
|
|
214
237
|
* only if the StreamOptions.includeUsage is set to true.
|
|
215
238
|
*/
|
|
216
239
|
@Type(() => Usage)
|
|
240
|
+
@Expose()
|
|
217
241
|
usage: Usage;
|
|
218
242
|
}
|
|
@@ -7,16 +7,19 @@ export class Embedding {
|
|
|
7
7
|
/**
|
|
8
8
|
* The index of the embedding in the list of embeddings.
|
|
9
9
|
*/
|
|
10
|
+
@Expose()
|
|
10
11
|
index: number;
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* The embedding vector, which is a list of floats. The length of vector depends on the model.
|
|
14
15
|
*/
|
|
16
|
+
@Expose()
|
|
15
17
|
embedding: number[];
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* The object type, which is always 'embedding'.
|
|
19
21
|
*/
|
|
22
|
+
@Expose()
|
|
20
23
|
object: string;
|
|
21
24
|
|
|
22
25
|
constructor(index: number, embedding: number[], object = 'embedding') {
|
|
@@ -36,11 +39,13 @@ export class EmbeddingRequest<T> {
|
|
|
36
39
|
* The input must not exceed the max input tokens for the model (8192 tokens for text-embedding-ada-002),
|
|
37
40
|
* cannot be an empty string, and any array must be 2048 dimensions or less.
|
|
38
41
|
*/
|
|
42
|
+
@Expose()
|
|
39
43
|
input: T;
|
|
40
44
|
|
|
41
45
|
/**
|
|
42
46
|
* ID of the model to use.
|
|
43
47
|
*/
|
|
48
|
+
@Expose()
|
|
44
49
|
model: string;
|
|
45
50
|
|
|
46
51
|
/**
|
|
@@ -52,11 +57,13 @@ export class EmbeddingRequest<T> {
|
|
|
52
57
|
/**
|
|
53
58
|
* The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.
|
|
54
59
|
*/
|
|
60
|
+
@Expose()
|
|
55
61
|
dimensions?: number;
|
|
56
62
|
|
|
57
63
|
/**
|
|
58
64
|
* A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
|
|
59
65
|
*/
|
|
66
|
+
@Expose()
|
|
60
67
|
user?: string;
|
|
61
68
|
|
|
62
69
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Type } from 'class-transformer';
|
|
1
|
+
import { Type, Expose } from 'class-transformer';
|
|
2
2
|
import { Embedding } from './embeddings-request';
|
|
3
3
|
import { Usage } from './usage';
|
|
4
4
|
|
|
@@ -11,23 +11,27 @@ export class EmbeddingResponse {
|
|
|
11
11
|
/**
|
|
12
12
|
* Must have value "list".
|
|
13
13
|
*/
|
|
14
|
+
@Expose()
|
|
14
15
|
object: string;
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* List of entities.
|
|
18
19
|
*/
|
|
19
20
|
@Type(() => Embedding)
|
|
21
|
+
@Expose()
|
|
20
22
|
data: Embedding[];
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* ID of the model to use.
|
|
24
26
|
*/
|
|
27
|
+
@Expose()
|
|
25
28
|
model: string;
|
|
26
29
|
|
|
27
30
|
/**
|
|
28
31
|
* Usage statistics for the completion request.
|
|
29
32
|
*/
|
|
30
33
|
@Type(() => Usage)
|
|
34
|
+
@Expose()
|
|
31
35
|
usage: Usage;
|
|
32
36
|
|
|
33
37
|
constructor(
|
|
@@ -52,10 +52,12 @@ export class ChatCompletionFunction {
|
|
|
52
52
|
/**
|
|
53
53
|
* The name of the function.
|
|
54
54
|
*/
|
|
55
|
+
@Expose()
|
|
55
56
|
name: string;
|
|
56
57
|
/**
|
|
57
58
|
* The arguments that the model expects you to pass to the function.
|
|
58
59
|
*/
|
|
60
|
+
@Expose()
|
|
59
61
|
arguments: string;
|
|
60
62
|
}
|
|
61
63
|
|
|
@@ -67,20 +69,25 @@ export class ToolCall {
|
|
|
67
69
|
* The index of the tool call in the list of tool calls. Required in
|
|
68
70
|
* case of streaming.
|
|
69
71
|
*/
|
|
72
|
+
@Expose()
|
|
70
73
|
index?: number;
|
|
71
74
|
/**
|
|
72
75
|
* The ID of the tool call. This ID must be referenced when you submit
|
|
73
76
|
* the tool outputs in using the Submit tool outputs to run endpoint.
|
|
74
77
|
*/
|
|
78
|
+
@Expose()
|
|
75
79
|
id: string;
|
|
76
80
|
/**
|
|
77
81
|
* The type of tool call the output is required for. For now, this is
|
|
78
82
|
* always function.
|
|
79
83
|
*/
|
|
84
|
+
@Expose()
|
|
80
85
|
type: string;
|
|
81
86
|
/**
|
|
82
87
|
* The function definition.
|
|
83
88
|
*/
|
|
89
|
+
@Type(() => ChatCompletionFunction)
|
|
90
|
+
@Expose()
|
|
84
91
|
function: ChatCompletionFunction;
|
|
85
92
|
}
|
|
86
93
|
|
|
@@ -91,10 +98,12 @@ export class AudioOutput {
|
|
|
91
98
|
/**
|
|
92
99
|
* Unique identifier for the audio response from the model.
|
|
93
100
|
*/
|
|
101
|
+
@Expose()
|
|
94
102
|
id?: string;
|
|
95
103
|
/**
|
|
96
104
|
* Audio output from the model.
|
|
97
105
|
*/
|
|
106
|
+
@Expose()
|
|
98
107
|
data?: string;
|
|
99
108
|
/**
|
|
100
109
|
* When the audio content will no longer be available on the server.
|
|
@@ -104,6 +113,7 @@ export class AudioOutput {
|
|
|
104
113
|
/**
|
|
105
114
|
* Transcript of the audio output from the model.
|
|
106
115
|
*/
|
|
116
|
+
@Expose()
|
|
107
117
|
transcript?: string;
|
|
108
118
|
|
|
109
119
|
static create(id?: string, data?: string, expiresAt?: number, transcript?: string): AudioOutput {
|
|
@@ -137,10 +147,12 @@ export class InputAudio {
|
|
|
137
147
|
/**
|
|
138
148
|
* Base64 encoded audio data.
|
|
139
149
|
*/
|
|
150
|
+
@Expose()
|
|
140
151
|
data: string;
|
|
141
152
|
/**
|
|
142
153
|
* The format of the encoded audio data. Currently supports "wav" and "mp3".
|
|
143
154
|
*/
|
|
155
|
+
@Expose()
|
|
144
156
|
format: Format;
|
|
145
157
|
}
|
|
146
158
|
|
|
@@ -153,10 +165,12 @@ export class ImageUrl {
|
|
|
153
165
|
* base64 encoded image data must have a special prefix in the following
|
|
154
166
|
* format: "data:{mimetype};base64,{base64-encoded-image-data}".
|
|
155
167
|
*/
|
|
168
|
+
@Expose()
|
|
156
169
|
url: string;
|
|
157
170
|
/**
|
|
158
171
|
* Specifies the detail level of the image.
|
|
159
172
|
*/
|
|
173
|
+
@Expose()
|
|
160
174
|
detail?: string;
|
|
161
175
|
}
|
|
162
176
|
|
|
@@ -168,10 +182,12 @@ export class MediaContent {
|
|
|
168
182
|
/**
|
|
169
183
|
* Content type, each can be of type text or image_url.
|
|
170
184
|
*/
|
|
185
|
+
@Expose()
|
|
171
186
|
type: string;
|
|
172
187
|
/**
|
|
173
188
|
* The text content of the message.
|
|
174
189
|
*/
|
|
190
|
+
@Expose()
|
|
175
191
|
text: string;
|
|
176
192
|
/**
|
|
177
193
|
* The image content of the message. You can pass multiple images
|
|
@@ -225,12 +241,14 @@ export class ChatCompletionMessage {
|
|
|
225
241
|
* The role of the messages author. Could be one of the {@link Role}
|
|
226
242
|
* types.
|
|
227
243
|
*/
|
|
244
|
+
@Expose()
|
|
228
245
|
role: Role;
|
|
229
246
|
/**
|
|
230
247
|
* An optional name for the participant. Provides the model information to
|
|
231
248
|
* differentiate between participants of the same role. In case of Function calling,
|
|
232
249
|
* the name is the function name that the message is responding to.
|
|
233
250
|
*/
|
|
251
|
+
@Expose()
|
|
234
252
|
name?: string;
|
|
235
253
|
/**
|
|
236
254
|
* Tool call that this message is responding to. Only applicable for
|
|
@@ -248,6 +266,7 @@ export class ChatCompletionMessage {
|
|
|
248
266
|
* The refusal message by the assistant. Applicable only for
|
|
249
267
|
* {@link Role#ASSISTANT} role and null otherwise.
|
|
250
268
|
*/
|
|
269
|
+
@Expose()
|
|
251
270
|
refusal?: string;
|
|
252
271
|
/**
|
|
253
272
|
* Audio response from the model.
|
|
@@ -49,7 +49,7 @@ export class OpenAIAPIImpl implements OpenAIAPI {
|
|
|
49
49
|
const { data, status, headers } = await this.restOperations
|
|
50
50
|
.post(
|
|
51
51
|
this.finalApiOptions.completionsPath,
|
|
52
|
-
instanceToPlain(chatRequest),
|
|
52
|
+
instanceToPlain(chatRequest, { excludeExtraneousValues: true }),
|
|
53
53
|
{
|
|
54
54
|
baseURL: this.finalApiOptions.baseUrl,
|
|
55
55
|
headers: {
|
|
@@ -72,7 +72,7 @@ export class OpenAIAPIImpl implements OpenAIAPI {
|
|
|
72
72
|
const { data, status, headers } = await this.restOperations
|
|
73
73
|
.post<ReadableStream>(
|
|
74
74
|
this.finalApiOptions.completionsPath,
|
|
75
|
-
instanceToPlain(chatRequest),
|
|
75
|
+
instanceToPlain(chatRequest, { excludeExtraneousValues: true }),
|
|
76
76
|
{
|
|
77
77
|
baseURL: this.finalApiOptions.baseUrl,
|
|
78
78
|
headers: {
|
|
@@ -116,7 +116,7 @@ export class OpenAIAPIImpl implements OpenAIAPI {
|
|
|
116
116
|
const { data, status, headers } = await this.restOperations
|
|
117
117
|
.post<EmbeddingResponse>(
|
|
118
118
|
this.finalApiOptions.embeddingsPath,
|
|
119
|
-
instanceToPlain(embeddingRequest),
|
|
119
|
+
instanceToPlain(embeddingRequest, { excludeExtraneousValues: true }),
|
|
120
120
|
{ baseURL: this.finalApiOptions.baseUrl, signal: embeddingRequest.signal });
|
|
121
121
|
return {
|
|
122
122
|
status,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Expose, Type } from 'class-transformer';
|
|
2
|
+
|
|
1
3
|
export enum ResponseFormatType {
|
|
2
4
|
TEXT = 'text',
|
|
3
5
|
JSON_OBJECT = 'json_object',
|
|
@@ -5,8 +7,11 @@ export enum ResponseFormatType {
|
|
|
5
7
|
}
|
|
6
8
|
|
|
7
9
|
export class JsonSchema {
|
|
10
|
+
@Expose()
|
|
8
11
|
name: string;
|
|
12
|
+
@Expose()
|
|
9
13
|
schema: Map<string, any>;
|
|
14
|
+
@Expose()
|
|
10
15
|
strict: boolean;
|
|
11
16
|
constructor(name: string, schema: Map<string, any>, strict: boolean) {
|
|
12
17
|
this.name = name;
|
|
@@ -59,18 +64,22 @@ export class ResponseFormat {
|
|
|
59
64
|
/**
|
|
60
65
|
* Type Must be one of 'text', 'json_object' or 'json_schema'.
|
|
61
66
|
*/
|
|
67
|
+
@Expose()
|
|
62
68
|
type: ResponseFormatType;
|
|
63
69
|
|
|
64
70
|
/**
|
|
65
71
|
* JSON schema object that describes the format of the JSON object. Only applicable
|
|
66
72
|
* when type is 'json_schema'.
|
|
67
73
|
*/
|
|
74
|
+
@Type(() => JsonSchema)
|
|
75
|
+
@Expose()
|
|
68
76
|
schema?: JsonSchema;
|
|
69
77
|
|
|
70
78
|
/**
|
|
71
79
|
* Whether the model must strictly adhere to the schema. Only applicable when type is
|
|
72
80
|
* 'json_schema'.
|
|
73
81
|
*/
|
|
82
|
+
@Expose()
|
|
74
83
|
strict?: boolean;
|
|
75
84
|
|
|
76
85
|
constructor(type: ResponseFormatType, schema?: JsonSchema, strict?: boolean) {
|
package/src/common/api/usage.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Usage as IUsage } from '@celljs/ai-core';
|
|
2
|
-
import { Expose } from 'class-transformer';
|
|
2
|
+
import { Expose, Type } from 'class-transformer';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Breakdown of tokens used in the prompt.
|
|
@@ -71,12 +71,14 @@ export class EmbeddingsResponse {
|
|
|
71
71
|
/**
|
|
72
72
|
* The model used for generating the embeddings.
|
|
73
73
|
*/
|
|
74
|
+
@Expose()
|
|
74
75
|
model: string;
|
|
75
76
|
|
|
76
77
|
/**
|
|
77
78
|
* The list of embeddings generated from the model.
|
|
78
79
|
* Each embedding (list of doubles) corresponds to a single input text.
|
|
79
80
|
*/
|
|
81
|
+
@Expose()
|
|
80
82
|
embeddings: number[][];
|
|
81
83
|
|
|
82
84
|
constructor(model: string, embeddings: number[][]) {
|
|
@@ -110,12 +112,14 @@ export class Usage implements IUsage {
|
|
|
110
112
|
/**
|
|
111
113
|
* Breakdown of tokens used in the prompt.
|
|
112
114
|
*/
|
|
115
|
+
@Type(() => PromptTokensDetails)
|
|
113
116
|
@Expose({ name: 'prompt_tokens_details' })
|
|
114
117
|
promptTokensDetails?: PromptTokensDetails;
|
|
115
118
|
|
|
116
119
|
/**
|
|
117
120
|
* Breakdown of tokens used in a completion.
|
|
118
121
|
*/
|
|
122
|
+
@Type(() => CompletionTokenDetails)
|
|
119
123
|
@Expose({ name: 'completion_tokens_details' })
|
|
120
124
|
completionTokenDetails?: CompletionTokenDetails;
|
|
121
125
|
|
|
@@ -153,7 +153,7 @@ export class OpenAIChatModel implements ChatModel {
|
|
|
153
153
|
throw new IllegalArgumentError('ToolResponseMessage must have an id');
|
|
154
154
|
}
|
|
155
155
|
});
|
|
156
|
-
return
|
|
156
|
+
return message.responses.map(tr => {
|
|
157
157
|
const chatCompletionMessage = ChatCompletionMessage.create(tr.responseData, Role.TOOL);
|
|
158
158
|
chatCompletionMessage.name = tr.name;
|
|
159
159
|
chatCompletionMessage.toolCallId = tr.id;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FunctionCallback, FunctionCallingOptions } from '@celljs/ai-core';
|
|
2
|
-
import { Expose, Exclude } from 'class-transformer';
|
|
2
|
+
import { Expose, Exclude, Type } from 'class-transformer';
|
|
3
3
|
import { OpenAIModel } from '../api/openai-model';
|
|
4
4
|
import { Constant } from '@celljs/core';
|
|
5
5
|
import { AudioParameters, FunctionTool, ResponseFormat, StreamOptions } from '../api';
|
|
@@ -96,12 +96,14 @@ export class OpenAIChatOptions implements FunctionCallingOptions {
|
|
|
96
96
|
* An object specifying the format that the model must output. Setting to { "type":
|
|
97
97
|
* "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON.
|
|
98
98
|
*/
|
|
99
|
+
@Type(() => ResponseFormat)
|
|
99
100
|
@Expose({ name: 'response_format' })
|
|
100
101
|
responseFormat?: ResponseFormat;
|
|
101
102
|
|
|
102
103
|
/**
|
|
103
104
|
* Options for streaming response. Included in the API only if streaming-mode completion is requested.
|
|
104
105
|
*/
|
|
106
|
+
@Type(() => StreamOptions)
|
|
105
107
|
@Expose({ name: 'stream_options' })
|
|
106
108
|
streamOptions?: StreamOptions;
|
|
107
109
|
|
|
@@ -109,17 +111,21 @@ export class OpenAIChatOptions implements FunctionCallingOptions {
|
|
|
109
111
|
* This feature is in Beta. If specified, our system will make a best effort to sample
|
|
110
112
|
* deterministically, such that repeated requests with the same seed and parameters should return the same result.
|
|
111
113
|
*/
|
|
114
|
+
@Expose()
|
|
112
115
|
seed?: number;
|
|
113
116
|
|
|
114
117
|
/**
|
|
115
118
|
* Up to 4 sequences where the API will stop generating further tokens.
|
|
116
119
|
*/
|
|
120
|
+
@Expose()
|
|
117
121
|
stop?: string[];
|
|
118
122
|
|
|
119
123
|
/**
|
|
120
124
|
* A list of tools the model may call. Currently, only functions are supported as a tool. Use this to
|
|
121
125
|
* provide a list of functions the model may generate JSON inputs for.
|
|
122
126
|
*/
|
|
127
|
+
@Type(() => FunctionTool)
|
|
128
|
+
@Expose()
|
|
123
129
|
tools?: FunctionTool[];
|
|
124
130
|
|
|
125
131
|
/**
|
|
@@ -131,6 +137,7 @@ export class OpenAIChatOptions implements FunctionCallingOptions {
|
|
|
131
137
|
/**
|
|
132
138
|
* A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
|
|
133
139
|
*/
|
|
140
|
+
@Expose()
|
|
134
141
|
user?: string;
|
|
135
142
|
|
|
136
143
|
/**
|
|
@@ -10,6 +10,7 @@ export class OpenAIEmbeddingOptions implements EmbeddingOptions {
|
|
|
10
10
|
/**
|
|
11
11
|
* ID of the model to use.
|
|
12
12
|
*/
|
|
13
|
+
@Expose()
|
|
13
14
|
model?: string;
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -22,11 +23,13 @@ export class OpenAIEmbeddingOptions implements EmbeddingOptions {
|
|
|
22
23
|
* The number of dimensions the resulting output embeddings should have.
|
|
23
24
|
* Only supported in text-embedding-3 and later models.
|
|
24
25
|
*/
|
|
26
|
+
@Expose()
|
|
25
27
|
dimensions?: number;
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
|
|
29
31
|
*/
|
|
32
|
+
@Expose()
|
|
30
33
|
user?: string;
|
|
31
34
|
|
|
32
35
|
copy(): OpenAIEmbeddingOptions {
|