@narrative.io/data-collaboration-sdk-ts 0.0.81 → 0.0.83
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/build/index.d.ts +2 -1
- package/build/index.js +2 -1
- package/build/rosetta/types.d.ts +709 -0
- package/build/rosetta/types.js +163 -0
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -25,8 +25,9 @@ import { convertNqlObjectToForecastBody } from './nql/DataRulesConverter';
|
|
|
25
25
|
import { AuthenticationApi, type LoginRequest, type LoginResponse, type RegisterRequest, type RegisterResponse, type LoggedInUser, type StytchToken, type ApiToken, type UserRole, type RegistrationStatus, type RegistrationStatusRequest, type RegistrationStatusResponse } from './authentication';
|
|
26
26
|
import { AppsApi, type App } from './apps';
|
|
27
27
|
import type { ForecastBody } from './nql/types';
|
|
28
|
+
import { type ConversationMessageRole, isConversationMessageRole, type ConversationMessageName, isConversationMessageName, type ConversationUserMessage, isConversationUserMessage, type ConversationAssistantMessage, isConversationAssistantMessage, type ConversationSystemMessage, isConversationSystemMessage, type ConversationFunctionMessage, isConversationFunctionMessage, type ConversationMessage, isConversationMessage, type ConversationIOtMessage, isConversationInputMessage, type ConversationMessages, isConversationMessages, isType, type RosettaMessageEvent, type RosettaResponseMessageEvent, type ConversationMessageFunctionCall, isConversationMessageFunctionCall, type ConversationAssistantMessageWithFunctionCall, isConversationAssistantMessageWithFunctionCall } from './rosetta/types';
|
|
28
29
|
declare class NarrativeApi extends BaseApi {
|
|
29
30
|
}
|
|
30
31
|
interface NarrativeApi extends BaseApi, HealthCheckApi, DatasetApi, RosettaStoneApi, AttributeApi, PingApi, CompanyInfoApi, InstallationsApi, UploadsApi, ResourceApi, NqlApi, DataStreamsApi, ForecastApi, ContractsApi, AuthenticationApi {
|
|
31
32
|
}
|
|
32
|
-
export { NarrativeApi, AttributeApi, HealthCheckApi, DatasetApi, PingApi, ProductsApi, CompanyInfoApi, InstallationsApi, UploadsApi, ResourceApi, NqlApi, DataStreamsApi, ForecastApi, ContractsApi, AuthenticationApi, AppsApi, type App, type Resource, type UploadsResponse, type PingStatus, type Attribute, type RefAttribute, type SubAttribute, type Environment, type Config, type ApiRecords, type Dataset, type HealthCheckResult, type SampleRecords, type DatasetTableSummary, type DatasetTableSummaryAPIResponse, type Product, type MonetaryAmount, type CompanyInfo, type Installation, type FilePerSnapshotResponse, type BucketCreationRequest, type UpdateAccessTypeRequest, type Nql, type NqlField, type NqlResult, type NqlQueryInput, type NqlCompileResult, type NqlExpression, type NqlWhere, type NqlFilterExpression, type NqlBooleanExpression, type NqlFilterBinaryExpression, type NqlFilterUnaryExpression, type DataStream, type ForecastRequest, type ForecastResponse, type CostForecastRequest, type CostForecastResponse, type JobState, type ContractDetails, type CustomerContract, type PaymentMethod, type ContractRateView, type LoginRequest, type LoginResponse, type RegisterRequest, type RegisterResponse, type LoggedInUser, type StytchToken, type ApiToken, type UserRole, type RegistrationStatus, type RegistrationStatusRequest, type RegistrationStatusResponse,
|
|
33
|
+
export { NarrativeApi, AttributeApi, HealthCheckApi, DatasetApi, PingApi, ProductsApi, CompanyInfoApi, InstallationsApi, UploadsApi, ResourceApi, NqlApi, DataStreamsApi, ForecastApi, ContractsApi, AuthenticationApi, AppsApi, getNqlObject, buildNql, convertNqlObjectToForecastBody, isConversationAssistantMessage, isConversationFunctionMessage, isConversationInputMessage, isConversationMessage, isConversationMessageName, isConversationMessageRole, isConversationMessages, isConversationSystemMessage, isConversationUserMessage, isType, isConversationMessageFunctionCall, isConversationAssistantMessageWithFunctionCall, type App, type Resource, type UploadsResponse, type PingStatus, type Attribute, type RefAttribute, type SubAttribute, type Environment, type Config, type ApiRecords, type Dataset, type HealthCheckResult, type SampleRecords, type DatasetTableSummary, type DatasetTableSummaryAPIResponse, type Product, type MonetaryAmount, type CompanyInfo, type Installation, type FilePerSnapshotResponse, type BucketCreationRequest, type UpdateAccessTypeRequest, type Nql, type NqlField, type NqlResult, type NqlQueryInput, type NqlCompileResult, type NqlExpression, type NqlWhere, type NqlFilterExpression, type NqlBooleanExpression, type NqlFilterBinaryExpression, type NqlFilterUnaryExpression, type DataStream, type ForecastRequest, type ForecastResponse, type CostForecastRequest, type CostForecastResponse, type JobState, type ContractDetails, type CustomerContract, type PaymentMethod, type ContractRateView, type LoginRequest, type LoginResponse, type RegisterRequest, type RegisterResponse, type LoggedInUser, type StytchToken, type ApiToken, type UserRole, type RegistrationStatus, type RegistrationStatusRequest, type RegistrationStatusResponse, type ForecastBody, type ConversationAssistantMessage, type ConversationFunctionMessage, type ConversationIOtMessage, type ConversationMessage, type ConversationMessageName, type ConversationMessageRole, type ConversationMessages, type ConversationSystemMessage, type ConversationUserMessage, type RosettaMessageEvent, type RosettaResponseMessageEvent, type ConversationMessageFunctionCall, type ConversationAssistantMessageWithFunctionCall };
|
package/build/index.js
CHANGED
|
@@ -18,7 +18,8 @@ import { getNqlObject, buildNql } from './nql/NQLParser';
|
|
|
18
18
|
import { convertNqlObjectToForecastBody } from './nql/DataRulesConverter';
|
|
19
19
|
import { AuthenticationApi } from './authentication';
|
|
20
20
|
import { AppsApi } from './apps';
|
|
21
|
+
import { isConversationMessageRole, isConversationMessageName, isConversationUserMessage, isConversationAssistantMessage, isConversationSystemMessage, isConversationFunctionMessage, isConversationMessage, isConversationInputMessage, isConversationMessages, isType, isConversationMessageFunctionCall, isConversationAssistantMessageWithFunctionCall } from './rosetta/types';
|
|
21
22
|
class NarrativeApi extends BaseApi {
|
|
22
23
|
}
|
|
23
24
|
applyMixins(NarrativeApi, [BaseApi, HealthCheckApi, DatasetApi, RosettaStoneApi, AttributeApi, PingApi, CompanyInfoApi, InstallationsApi, UploadsApi, ResourceApi, NqlApi, DataStreamsApi, ForecastApi, ContractsApi, AuthenticationApi]);
|
|
24
|
-
export { NarrativeApi, AttributeApi, HealthCheckApi, DatasetApi, PingApi, ProductsApi, CompanyInfoApi, InstallationsApi, UploadsApi, ResourceApi, NqlApi, DataStreamsApi, ForecastApi, ContractsApi, AuthenticationApi, AppsApi, getNqlObject, buildNql, convertNqlObjectToForecastBody };
|
|
25
|
+
export { NarrativeApi, AttributeApi, HealthCheckApi, DatasetApi, PingApi, ProductsApi, CompanyInfoApi, InstallationsApi, UploadsApi, ResourceApi, NqlApi, DataStreamsApi, ForecastApi, ContractsApi, AuthenticationApi, AppsApi, getNqlObject, buildNql, convertNqlObjectToForecastBody, isConversationAssistantMessage, isConversationFunctionMessage, isConversationInputMessage, isConversationMessage, isConversationMessageName, isConversationMessageRole, isConversationMessages, isConversationSystemMessage, isConversationUserMessage, isType, isConversationMessageFunctionCall, isConversationAssistantMessageWithFunctionCall };
|
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
declare const ChatCompletionRequestMessageRoleEnum: z.ZodEnum<["system", "user", "assistant", "function"]>;
|
|
3
|
+
type ConversationMessageRole = z.infer<typeof ChatCompletionRequestMessageRoleEnum>;
|
|
4
|
+
declare const isConversationMessageRole: (input: unknown) => input is "function" | "system" | "user" | "assistant";
|
|
5
|
+
declare const ChatCompletionRequestMessageName: z.ZodEffects<z.ZodString, string, string>;
|
|
6
|
+
type ConversationMessageName = z.infer<typeof ChatCompletionRequestMessageName>;
|
|
7
|
+
declare const isConversationMessageName: (input: unknown) => input is string;
|
|
8
|
+
declare const ChatCompletionRequestUserMessageSchema: z.ZodObject<{
|
|
9
|
+
role: z.ZodEnum<["user"]>;
|
|
10
|
+
content: z.ZodString;
|
|
11
|
+
name: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
12
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
role: "user";
|
|
15
|
+
content: string;
|
|
16
|
+
name?: string | undefined;
|
|
17
|
+
timestamp?: number | undefined;
|
|
18
|
+
}, {
|
|
19
|
+
role: "user";
|
|
20
|
+
content: string;
|
|
21
|
+
name?: string | undefined;
|
|
22
|
+
timestamp?: number | undefined;
|
|
23
|
+
}>;
|
|
24
|
+
type ConversationUserMessage = z.infer<typeof ChatCompletionRequestUserMessageSchema>;
|
|
25
|
+
declare const isConversationUserMessage: (input: unknown) => input is {
|
|
26
|
+
role: "user";
|
|
27
|
+
content: string;
|
|
28
|
+
name?: string | undefined;
|
|
29
|
+
timestamp?: number | undefined;
|
|
30
|
+
};
|
|
31
|
+
declare const ChatCompletionRequestMessageFunctionCall: z.ZodObject<{
|
|
32
|
+
name: z.ZodString;
|
|
33
|
+
arguments: z.ZodString;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
name: string;
|
|
36
|
+
arguments: string;
|
|
37
|
+
}, {
|
|
38
|
+
name: string;
|
|
39
|
+
arguments: string;
|
|
40
|
+
}>;
|
|
41
|
+
type ConversationMessageFunctionCall = z.infer<typeof ChatCompletionRequestMessageFunctionCall>;
|
|
42
|
+
declare const isConversationMessageFunctionCall: (input: unknown) => input is {
|
|
43
|
+
name: string;
|
|
44
|
+
arguments: string;
|
|
45
|
+
};
|
|
46
|
+
declare const ChatCompletionRequestAssistantMessageWithFunctionCall: z.ZodObject<{
|
|
47
|
+
role: z.ZodEnum<["assistant"]>;
|
|
48
|
+
content: z.ZodUnion<[z.ZodNull, z.ZodString]>;
|
|
49
|
+
function_call: z.ZodObject<{
|
|
50
|
+
name: z.ZodString;
|
|
51
|
+
arguments: z.ZodString;
|
|
52
|
+
}, "strip", z.ZodTypeAny, {
|
|
53
|
+
name: string;
|
|
54
|
+
arguments: string;
|
|
55
|
+
}, {
|
|
56
|
+
name: string;
|
|
57
|
+
arguments: string;
|
|
58
|
+
}>;
|
|
59
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
60
|
+
}, "strict", z.ZodTypeAny, {
|
|
61
|
+
role: "assistant";
|
|
62
|
+
content: string | null;
|
|
63
|
+
function_call: {
|
|
64
|
+
name: string;
|
|
65
|
+
arguments: string;
|
|
66
|
+
};
|
|
67
|
+
timestamp?: number | undefined;
|
|
68
|
+
}, {
|
|
69
|
+
role: "assistant";
|
|
70
|
+
content: string | null;
|
|
71
|
+
function_call: {
|
|
72
|
+
name: string;
|
|
73
|
+
arguments: string;
|
|
74
|
+
};
|
|
75
|
+
timestamp?: number | undefined;
|
|
76
|
+
}>;
|
|
77
|
+
type ConversationAssistantMessageWithFunctionCall = z.infer<typeof ChatCompletionRequestAssistantMessageWithFunctionCall>;
|
|
78
|
+
declare const isConversationAssistantMessageWithFunctionCall: (input: unknown) => input is {
|
|
79
|
+
role: "assistant";
|
|
80
|
+
content: string | null;
|
|
81
|
+
function_call: {
|
|
82
|
+
name: string;
|
|
83
|
+
arguments: string;
|
|
84
|
+
};
|
|
85
|
+
timestamp?: number | undefined;
|
|
86
|
+
};
|
|
87
|
+
declare const ChatCompletionAssistantMessage: z.ZodUnion<[z.ZodObject<{
|
|
88
|
+
role: z.ZodEnum<["assistant"]>;
|
|
89
|
+
content: z.ZodString;
|
|
90
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
91
|
+
}, "strict", z.ZodTypeAny, {
|
|
92
|
+
role: "assistant";
|
|
93
|
+
content: string;
|
|
94
|
+
timestamp?: number | undefined;
|
|
95
|
+
}, {
|
|
96
|
+
role: "assistant";
|
|
97
|
+
content: string;
|
|
98
|
+
timestamp?: number | undefined;
|
|
99
|
+
}>, z.ZodObject<{
|
|
100
|
+
role: z.ZodEnum<["assistant"]>;
|
|
101
|
+
content: z.ZodUnion<[z.ZodNull, z.ZodString]>;
|
|
102
|
+
function_call: z.ZodObject<{
|
|
103
|
+
name: z.ZodString;
|
|
104
|
+
arguments: z.ZodString;
|
|
105
|
+
}, "strip", z.ZodTypeAny, {
|
|
106
|
+
name: string;
|
|
107
|
+
arguments: string;
|
|
108
|
+
}, {
|
|
109
|
+
name: string;
|
|
110
|
+
arguments: string;
|
|
111
|
+
}>;
|
|
112
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
113
|
+
}, "strict", z.ZodTypeAny, {
|
|
114
|
+
role: "assistant";
|
|
115
|
+
content: string | null;
|
|
116
|
+
function_call: {
|
|
117
|
+
name: string;
|
|
118
|
+
arguments: string;
|
|
119
|
+
};
|
|
120
|
+
timestamp?: number | undefined;
|
|
121
|
+
}, {
|
|
122
|
+
role: "assistant";
|
|
123
|
+
content: string | null;
|
|
124
|
+
function_call: {
|
|
125
|
+
name: string;
|
|
126
|
+
arguments: string;
|
|
127
|
+
};
|
|
128
|
+
timestamp?: number | undefined;
|
|
129
|
+
}>]>;
|
|
130
|
+
type ConversationAssistantMessage = z.infer<typeof ChatCompletionAssistantMessage>;
|
|
131
|
+
declare const isConversationAssistantMessage: (input: unknown) => input is {
|
|
132
|
+
role: "assistant";
|
|
133
|
+
content: string | null;
|
|
134
|
+
function_call: {
|
|
135
|
+
name: string;
|
|
136
|
+
arguments: string;
|
|
137
|
+
};
|
|
138
|
+
timestamp?: number | undefined;
|
|
139
|
+
} | {
|
|
140
|
+
role: "assistant";
|
|
141
|
+
content: string;
|
|
142
|
+
timestamp?: number | undefined;
|
|
143
|
+
};
|
|
144
|
+
declare const ChatCompletionSystemMessageSchema: z.ZodObject<{
|
|
145
|
+
role: z.ZodEnum<["system"]>;
|
|
146
|
+
content: z.ZodString;
|
|
147
|
+
}, "strip", z.ZodTypeAny, {
|
|
148
|
+
role: "system";
|
|
149
|
+
content: string;
|
|
150
|
+
}, {
|
|
151
|
+
role: "system";
|
|
152
|
+
content: string;
|
|
153
|
+
}>;
|
|
154
|
+
type ConversationSystemMessage = z.infer<typeof ChatCompletionSystemMessageSchema>;
|
|
155
|
+
declare const isConversationSystemMessage: (input: unknown) => input is {
|
|
156
|
+
role: "system";
|
|
157
|
+
content: string;
|
|
158
|
+
};
|
|
159
|
+
declare const ChatCompletionFunctionMessageSchema: z.ZodObject<{
|
|
160
|
+
role: z.ZodEnum<["function"]>;
|
|
161
|
+
content: z.ZodString;
|
|
162
|
+
name: z.ZodString;
|
|
163
|
+
}, "strip", z.ZodTypeAny, {
|
|
164
|
+
name: string;
|
|
165
|
+
role: "function";
|
|
166
|
+
content: string;
|
|
167
|
+
}, {
|
|
168
|
+
name: string;
|
|
169
|
+
role: "function";
|
|
170
|
+
content: string;
|
|
171
|
+
}>;
|
|
172
|
+
type ConversationFunctionMessage = z.infer<typeof ChatCompletionFunctionMessageSchema>;
|
|
173
|
+
declare const isConversationFunctionMessage: (input: unknown) => input is {
|
|
174
|
+
name: string;
|
|
175
|
+
role: "function";
|
|
176
|
+
content: string;
|
|
177
|
+
};
|
|
178
|
+
declare const ChatCompletionRequestMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
179
|
+
role: z.ZodEnum<["user"]>;
|
|
180
|
+
content: z.ZodString;
|
|
181
|
+
name: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
182
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
183
|
+
}, "strip", z.ZodTypeAny, {
|
|
184
|
+
role: "user";
|
|
185
|
+
content: string;
|
|
186
|
+
name?: string | undefined;
|
|
187
|
+
timestamp?: number | undefined;
|
|
188
|
+
}, {
|
|
189
|
+
role: "user";
|
|
190
|
+
content: string;
|
|
191
|
+
name?: string | undefined;
|
|
192
|
+
timestamp?: number | undefined;
|
|
193
|
+
}>, z.ZodUnion<[z.ZodObject<{
|
|
194
|
+
role: z.ZodEnum<["assistant"]>;
|
|
195
|
+
content: z.ZodString;
|
|
196
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
197
|
+
}, "strict", z.ZodTypeAny, {
|
|
198
|
+
role: "assistant";
|
|
199
|
+
content: string;
|
|
200
|
+
timestamp?: number | undefined;
|
|
201
|
+
}, {
|
|
202
|
+
role: "assistant";
|
|
203
|
+
content: string;
|
|
204
|
+
timestamp?: number | undefined;
|
|
205
|
+
}>, z.ZodObject<{
|
|
206
|
+
role: z.ZodEnum<["assistant"]>;
|
|
207
|
+
content: z.ZodUnion<[z.ZodNull, z.ZodString]>;
|
|
208
|
+
function_call: z.ZodObject<{
|
|
209
|
+
name: z.ZodString;
|
|
210
|
+
arguments: z.ZodString;
|
|
211
|
+
}, "strip", z.ZodTypeAny, {
|
|
212
|
+
name: string;
|
|
213
|
+
arguments: string;
|
|
214
|
+
}, {
|
|
215
|
+
name: string;
|
|
216
|
+
arguments: string;
|
|
217
|
+
}>;
|
|
218
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
219
|
+
}, "strict", z.ZodTypeAny, {
|
|
220
|
+
role: "assistant";
|
|
221
|
+
content: string | null;
|
|
222
|
+
function_call: {
|
|
223
|
+
name: string;
|
|
224
|
+
arguments: string;
|
|
225
|
+
};
|
|
226
|
+
timestamp?: number | undefined;
|
|
227
|
+
}, {
|
|
228
|
+
role: "assistant";
|
|
229
|
+
content: string | null;
|
|
230
|
+
function_call: {
|
|
231
|
+
name: string;
|
|
232
|
+
arguments: string;
|
|
233
|
+
};
|
|
234
|
+
timestamp?: number | undefined;
|
|
235
|
+
}>]>, z.ZodObject<{
|
|
236
|
+
role: z.ZodEnum<["system"]>;
|
|
237
|
+
content: z.ZodString;
|
|
238
|
+
}, "strip", z.ZodTypeAny, {
|
|
239
|
+
role: "system";
|
|
240
|
+
content: string;
|
|
241
|
+
}, {
|
|
242
|
+
role: "system";
|
|
243
|
+
content: string;
|
|
244
|
+
}>, z.ZodObject<{
|
|
245
|
+
role: z.ZodEnum<["function"]>;
|
|
246
|
+
content: z.ZodString;
|
|
247
|
+
name: z.ZodString;
|
|
248
|
+
}, "strip", z.ZodTypeAny, {
|
|
249
|
+
name: string;
|
|
250
|
+
role: "function";
|
|
251
|
+
content: string;
|
|
252
|
+
}, {
|
|
253
|
+
name: string;
|
|
254
|
+
role: "function";
|
|
255
|
+
content: string;
|
|
256
|
+
}>]>;
|
|
257
|
+
type ConversationMessage = z.infer<typeof ChatCompletionRequestMessageSchema>;
|
|
258
|
+
declare const isConversationMessage: (input: unknown) => input is {
|
|
259
|
+
role: "user";
|
|
260
|
+
content: string;
|
|
261
|
+
name?: string | undefined;
|
|
262
|
+
timestamp?: number | undefined;
|
|
263
|
+
} | {
|
|
264
|
+
role: "assistant";
|
|
265
|
+
content: string | null;
|
|
266
|
+
function_call: {
|
|
267
|
+
name: string;
|
|
268
|
+
arguments: string;
|
|
269
|
+
};
|
|
270
|
+
timestamp?: number | undefined;
|
|
271
|
+
} | {
|
|
272
|
+
role: "assistant";
|
|
273
|
+
content: string;
|
|
274
|
+
timestamp?: number | undefined;
|
|
275
|
+
} | {
|
|
276
|
+
role: "system";
|
|
277
|
+
content: string;
|
|
278
|
+
} | {
|
|
279
|
+
name: string;
|
|
280
|
+
role: "function";
|
|
281
|
+
content: string;
|
|
282
|
+
};
|
|
283
|
+
declare const ChatCompletionRequestMessagesSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodArray<z.ZodUnion<[z.ZodObject<{
|
|
284
|
+
role: z.ZodEnum<["user"]>;
|
|
285
|
+
content: z.ZodString;
|
|
286
|
+
name: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
287
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
288
|
+
}, "strip", z.ZodTypeAny, {
|
|
289
|
+
role: "user";
|
|
290
|
+
content: string;
|
|
291
|
+
name?: string | undefined;
|
|
292
|
+
timestamp?: number | undefined;
|
|
293
|
+
}, {
|
|
294
|
+
role: "user";
|
|
295
|
+
content: string;
|
|
296
|
+
name?: string | undefined;
|
|
297
|
+
timestamp?: number | undefined;
|
|
298
|
+
}>, z.ZodUnion<[z.ZodObject<{
|
|
299
|
+
role: z.ZodEnum<["assistant"]>;
|
|
300
|
+
content: z.ZodString;
|
|
301
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
302
|
+
}, "strict", z.ZodTypeAny, {
|
|
303
|
+
role: "assistant";
|
|
304
|
+
content: string;
|
|
305
|
+
timestamp?: number | undefined;
|
|
306
|
+
}, {
|
|
307
|
+
role: "assistant";
|
|
308
|
+
content: string;
|
|
309
|
+
timestamp?: number | undefined;
|
|
310
|
+
}>, z.ZodObject<{
|
|
311
|
+
role: z.ZodEnum<["assistant"]>;
|
|
312
|
+
content: z.ZodUnion<[z.ZodNull, z.ZodString]>;
|
|
313
|
+
function_call: z.ZodObject<{
|
|
314
|
+
name: z.ZodString;
|
|
315
|
+
arguments: z.ZodString;
|
|
316
|
+
}, "strip", z.ZodTypeAny, {
|
|
317
|
+
name: string;
|
|
318
|
+
arguments: string;
|
|
319
|
+
}, {
|
|
320
|
+
name: string;
|
|
321
|
+
arguments: string;
|
|
322
|
+
}>;
|
|
323
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
324
|
+
}, "strict", z.ZodTypeAny, {
|
|
325
|
+
role: "assistant";
|
|
326
|
+
content: string | null;
|
|
327
|
+
function_call: {
|
|
328
|
+
name: string;
|
|
329
|
+
arguments: string;
|
|
330
|
+
};
|
|
331
|
+
timestamp?: number | undefined;
|
|
332
|
+
}, {
|
|
333
|
+
role: "assistant";
|
|
334
|
+
content: string | null;
|
|
335
|
+
function_call: {
|
|
336
|
+
name: string;
|
|
337
|
+
arguments: string;
|
|
338
|
+
};
|
|
339
|
+
timestamp?: number | undefined;
|
|
340
|
+
}>]>, z.ZodObject<{
|
|
341
|
+
role: z.ZodEnum<["system"]>;
|
|
342
|
+
content: z.ZodString;
|
|
343
|
+
}, "strip", z.ZodTypeAny, {
|
|
344
|
+
role: "system";
|
|
345
|
+
content: string;
|
|
346
|
+
}, {
|
|
347
|
+
role: "system";
|
|
348
|
+
content: string;
|
|
349
|
+
}>, z.ZodObject<{
|
|
350
|
+
role: z.ZodEnum<["function"]>;
|
|
351
|
+
content: z.ZodString;
|
|
352
|
+
name: z.ZodString;
|
|
353
|
+
}, "strip", z.ZodTypeAny, {
|
|
354
|
+
name: string;
|
|
355
|
+
role: "function";
|
|
356
|
+
content: string;
|
|
357
|
+
}, {
|
|
358
|
+
name: string;
|
|
359
|
+
role: "function";
|
|
360
|
+
content: string;
|
|
361
|
+
}>]>, "many">, ({
|
|
362
|
+
role: "user";
|
|
363
|
+
content: string;
|
|
364
|
+
name?: string | undefined;
|
|
365
|
+
timestamp?: number | undefined;
|
|
366
|
+
} | {
|
|
367
|
+
role: "assistant";
|
|
368
|
+
content: string | null;
|
|
369
|
+
function_call: {
|
|
370
|
+
name: string;
|
|
371
|
+
arguments: string;
|
|
372
|
+
};
|
|
373
|
+
timestamp?: number | undefined;
|
|
374
|
+
} | {
|
|
375
|
+
role: "assistant";
|
|
376
|
+
content: string;
|
|
377
|
+
timestamp?: number | undefined;
|
|
378
|
+
} | {
|
|
379
|
+
role: "system";
|
|
380
|
+
content: string;
|
|
381
|
+
} | {
|
|
382
|
+
name: string;
|
|
383
|
+
role: "function";
|
|
384
|
+
content: string;
|
|
385
|
+
})[], ({
|
|
386
|
+
role: "user";
|
|
387
|
+
content: string;
|
|
388
|
+
name?: string | undefined;
|
|
389
|
+
timestamp?: number | undefined;
|
|
390
|
+
} | {
|
|
391
|
+
role: "assistant";
|
|
392
|
+
content: string | null;
|
|
393
|
+
function_call: {
|
|
394
|
+
name: string;
|
|
395
|
+
arguments: string;
|
|
396
|
+
};
|
|
397
|
+
timestamp?: number | undefined;
|
|
398
|
+
} | {
|
|
399
|
+
role: "assistant";
|
|
400
|
+
content: string;
|
|
401
|
+
timestamp?: number | undefined;
|
|
402
|
+
} | {
|
|
403
|
+
role: "system";
|
|
404
|
+
content: string;
|
|
405
|
+
} | {
|
|
406
|
+
name: string;
|
|
407
|
+
role: "function";
|
|
408
|
+
content: string;
|
|
409
|
+
})[]>, ({
|
|
410
|
+
role: "user";
|
|
411
|
+
content: string;
|
|
412
|
+
name?: string | undefined;
|
|
413
|
+
timestamp?: number | undefined;
|
|
414
|
+
} | {
|
|
415
|
+
role: "assistant";
|
|
416
|
+
content: string | null;
|
|
417
|
+
function_call: {
|
|
418
|
+
name: string;
|
|
419
|
+
arguments: string;
|
|
420
|
+
};
|
|
421
|
+
timestamp?: number | undefined;
|
|
422
|
+
} | {
|
|
423
|
+
role: "assistant";
|
|
424
|
+
content: string;
|
|
425
|
+
timestamp?: number | undefined;
|
|
426
|
+
} | {
|
|
427
|
+
role: "system";
|
|
428
|
+
content: string;
|
|
429
|
+
} | {
|
|
430
|
+
name: string;
|
|
431
|
+
role: "function";
|
|
432
|
+
content: string;
|
|
433
|
+
})[], ({
|
|
434
|
+
role: "user";
|
|
435
|
+
content: string;
|
|
436
|
+
name?: string | undefined;
|
|
437
|
+
timestamp?: number | undefined;
|
|
438
|
+
} | {
|
|
439
|
+
role: "assistant";
|
|
440
|
+
content: string | null;
|
|
441
|
+
function_call: {
|
|
442
|
+
name: string;
|
|
443
|
+
arguments: string;
|
|
444
|
+
};
|
|
445
|
+
timestamp?: number | undefined;
|
|
446
|
+
} | {
|
|
447
|
+
role: "assistant";
|
|
448
|
+
content: string;
|
|
449
|
+
timestamp?: number | undefined;
|
|
450
|
+
} | {
|
|
451
|
+
role: "system";
|
|
452
|
+
content: string;
|
|
453
|
+
} | {
|
|
454
|
+
name: string;
|
|
455
|
+
role: "function";
|
|
456
|
+
content: string;
|
|
457
|
+
})[]>, ({
|
|
458
|
+
role: "user";
|
|
459
|
+
content: string;
|
|
460
|
+
name?: string | undefined;
|
|
461
|
+
timestamp?: number | undefined;
|
|
462
|
+
} | {
|
|
463
|
+
role: "assistant";
|
|
464
|
+
content: string | null;
|
|
465
|
+
function_call: {
|
|
466
|
+
name: string;
|
|
467
|
+
arguments: string;
|
|
468
|
+
};
|
|
469
|
+
timestamp?: number | undefined;
|
|
470
|
+
} | {
|
|
471
|
+
role: "assistant";
|
|
472
|
+
content: string;
|
|
473
|
+
timestamp?: number | undefined;
|
|
474
|
+
} | {
|
|
475
|
+
role: "system";
|
|
476
|
+
content: string;
|
|
477
|
+
} | {
|
|
478
|
+
name: string;
|
|
479
|
+
role: "function";
|
|
480
|
+
content: string;
|
|
481
|
+
})[], ({
|
|
482
|
+
role: "user";
|
|
483
|
+
content: string;
|
|
484
|
+
name?: string | undefined;
|
|
485
|
+
timestamp?: number | undefined;
|
|
486
|
+
} | {
|
|
487
|
+
role: "assistant";
|
|
488
|
+
content: string | null;
|
|
489
|
+
function_call: {
|
|
490
|
+
name: string;
|
|
491
|
+
arguments: string;
|
|
492
|
+
};
|
|
493
|
+
timestamp?: number | undefined;
|
|
494
|
+
} | {
|
|
495
|
+
role: "assistant";
|
|
496
|
+
content: string;
|
|
497
|
+
timestamp?: number | undefined;
|
|
498
|
+
} | {
|
|
499
|
+
role: "system";
|
|
500
|
+
content: string;
|
|
501
|
+
} | {
|
|
502
|
+
name: string;
|
|
503
|
+
role: "function";
|
|
504
|
+
content: string;
|
|
505
|
+
})[]>, ({
|
|
506
|
+
role: "user";
|
|
507
|
+
content: string;
|
|
508
|
+
name?: string | undefined;
|
|
509
|
+
timestamp?: number | undefined;
|
|
510
|
+
} | {
|
|
511
|
+
role: "assistant";
|
|
512
|
+
content: string | null;
|
|
513
|
+
function_call: {
|
|
514
|
+
name: string;
|
|
515
|
+
arguments: string;
|
|
516
|
+
};
|
|
517
|
+
timestamp?: number | undefined;
|
|
518
|
+
} | {
|
|
519
|
+
role: "assistant";
|
|
520
|
+
content: string;
|
|
521
|
+
timestamp?: number | undefined;
|
|
522
|
+
} | {
|
|
523
|
+
role: "system";
|
|
524
|
+
content: string;
|
|
525
|
+
} | {
|
|
526
|
+
name: string;
|
|
527
|
+
role: "function";
|
|
528
|
+
content: string;
|
|
529
|
+
})[], ({
|
|
530
|
+
role: "user";
|
|
531
|
+
content: string;
|
|
532
|
+
name?: string | undefined;
|
|
533
|
+
timestamp?: number | undefined;
|
|
534
|
+
} | {
|
|
535
|
+
role: "assistant";
|
|
536
|
+
content: string | null;
|
|
537
|
+
function_call: {
|
|
538
|
+
name: string;
|
|
539
|
+
arguments: string;
|
|
540
|
+
};
|
|
541
|
+
timestamp?: number | undefined;
|
|
542
|
+
} | {
|
|
543
|
+
role: "assistant";
|
|
544
|
+
content: string;
|
|
545
|
+
timestamp?: number | undefined;
|
|
546
|
+
} | {
|
|
547
|
+
role: "system";
|
|
548
|
+
content: string;
|
|
549
|
+
} | {
|
|
550
|
+
name: string;
|
|
551
|
+
role: "function";
|
|
552
|
+
content: string;
|
|
553
|
+
})[]>;
|
|
554
|
+
type ConversationMessages = z.infer<typeof ChatCompletionRequestMessagesSchema>;
|
|
555
|
+
declare const isConversationMessages: (input: unknown) => input is ({
|
|
556
|
+
role: "user";
|
|
557
|
+
content: string;
|
|
558
|
+
name?: string | undefined;
|
|
559
|
+
timestamp?: number | undefined;
|
|
560
|
+
} | {
|
|
561
|
+
role: "assistant";
|
|
562
|
+
content: string | null;
|
|
563
|
+
function_call: {
|
|
564
|
+
name: string;
|
|
565
|
+
arguments: string;
|
|
566
|
+
};
|
|
567
|
+
timestamp?: number | undefined;
|
|
568
|
+
} | {
|
|
569
|
+
role: "assistant";
|
|
570
|
+
content: string;
|
|
571
|
+
timestamp?: number | undefined;
|
|
572
|
+
} | {
|
|
573
|
+
role: "system";
|
|
574
|
+
content: string;
|
|
575
|
+
} | {
|
|
576
|
+
name: string;
|
|
577
|
+
role: "function";
|
|
578
|
+
content: string;
|
|
579
|
+
})[];
|
|
580
|
+
declare const ChatCompletionRequestInputMessageSchema: z.ZodUnion<[z.ZodObject<{
|
|
581
|
+
role: z.ZodEnum<["user"]>;
|
|
582
|
+
content: z.ZodString;
|
|
583
|
+
name: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
584
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
585
|
+
}, "strip", z.ZodTypeAny, {
|
|
586
|
+
role: "user";
|
|
587
|
+
content: string;
|
|
588
|
+
name?: string | undefined;
|
|
589
|
+
timestamp?: number | undefined;
|
|
590
|
+
}, {
|
|
591
|
+
role: "user";
|
|
592
|
+
content: string;
|
|
593
|
+
name?: string | undefined;
|
|
594
|
+
timestamp?: number | undefined;
|
|
595
|
+
}>, z.ZodUnion<[z.ZodObject<{
|
|
596
|
+
role: z.ZodEnum<["assistant"]>;
|
|
597
|
+
content: z.ZodString;
|
|
598
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
599
|
+
}, "strict", z.ZodTypeAny, {
|
|
600
|
+
role: "assistant";
|
|
601
|
+
content: string;
|
|
602
|
+
timestamp?: number | undefined;
|
|
603
|
+
}, {
|
|
604
|
+
role: "assistant";
|
|
605
|
+
content: string;
|
|
606
|
+
timestamp?: number | undefined;
|
|
607
|
+
}>, z.ZodObject<{
|
|
608
|
+
role: z.ZodEnum<["assistant"]>;
|
|
609
|
+
content: z.ZodUnion<[z.ZodNull, z.ZodString]>;
|
|
610
|
+
function_call: z.ZodObject<{
|
|
611
|
+
name: z.ZodString;
|
|
612
|
+
arguments: z.ZodString;
|
|
613
|
+
}, "strip", z.ZodTypeAny, {
|
|
614
|
+
name: string;
|
|
615
|
+
arguments: string;
|
|
616
|
+
}, {
|
|
617
|
+
name: string;
|
|
618
|
+
arguments: string;
|
|
619
|
+
}>;
|
|
620
|
+
timestamp: z.ZodOptional<z.ZodNumber>;
|
|
621
|
+
}, "strict", z.ZodTypeAny, {
|
|
622
|
+
role: "assistant";
|
|
623
|
+
content: string | null;
|
|
624
|
+
function_call: {
|
|
625
|
+
name: string;
|
|
626
|
+
arguments: string;
|
|
627
|
+
};
|
|
628
|
+
timestamp?: number | undefined;
|
|
629
|
+
}, {
|
|
630
|
+
role: "assistant";
|
|
631
|
+
content: string | null;
|
|
632
|
+
function_call: {
|
|
633
|
+
name: string;
|
|
634
|
+
arguments: string;
|
|
635
|
+
};
|
|
636
|
+
timestamp?: number | undefined;
|
|
637
|
+
}>]>, z.ZodObject<{
|
|
638
|
+
role: z.ZodEnum<["function"]>;
|
|
639
|
+
content: z.ZodString;
|
|
640
|
+
name: z.ZodString;
|
|
641
|
+
}, "strip", z.ZodTypeAny, {
|
|
642
|
+
name: string;
|
|
643
|
+
role: "function";
|
|
644
|
+
content: string;
|
|
645
|
+
}, {
|
|
646
|
+
name: string;
|
|
647
|
+
role: "function";
|
|
648
|
+
content: string;
|
|
649
|
+
}>]>;
|
|
650
|
+
type ConversationIOtMessage = z.infer<typeof ChatCompletionRequestInputMessageSchema>;
|
|
651
|
+
declare const isConversationInputMessage: (input: unknown) => input is {
|
|
652
|
+
role: "user";
|
|
653
|
+
content: string;
|
|
654
|
+
name?: string | undefined;
|
|
655
|
+
timestamp?: number | undefined;
|
|
656
|
+
} | {
|
|
657
|
+
role: "assistant";
|
|
658
|
+
content: string | null;
|
|
659
|
+
function_call: {
|
|
660
|
+
name: string;
|
|
661
|
+
arguments: string;
|
|
662
|
+
};
|
|
663
|
+
timestamp?: number | undefined;
|
|
664
|
+
} | {
|
|
665
|
+
role: "assistant";
|
|
666
|
+
content: string;
|
|
667
|
+
timestamp?: number | undefined;
|
|
668
|
+
} | {
|
|
669
|
+
name: string;
|
|
670
|
+
role: "function";
|
|
671
|
+
content: string;
|
|
672
|
+
};
|
|
673
|
+
interface AddMessageEvent {
|
|
674
|
+
type: 'addMessage';
|
|
675
|
+
data: ConversationIOtMessage;
|
|
676
|
+
}
|
|
677
|
+
interface PingEvent {
|
|
678
|
+
type: 'ping';
|
|
679
|
+
}
|
|
680
|
+
interface ClearHistoryEvent {
|
|
681
|
+
type: 'clearHistory';
|
|
682
|
+
}
|
|
683
|
+
interface HistoryEvent {
|
|
684
|
+
type: 'history';
|
|
685
|
+
}
|
|
686
|
+
type RosettaRequestMessage = AddMessageEvent | PingEvent | ClearHistoryEvent | HistoryEvent;
|
|
687
|
+
interface RosettaMessageEvent extends MessageEvent {
|
|
688
|
+
data: RosettaRequestMessage;
|
|
689
|
+
}
|
|
690
|
+
interface AddMessageResponse {
|
|
691
|
+
type: 'newMessage';
|
|
692
|
+
data: ConversationIOtMessage;
|
|
693
|
+
}
|
|
694
|
+
interface HistoryResponse {
|
|
695
|
+
type: 'history';
|
|
696
|
+
data: ConversationIOtMessage[];
|
|
697
|
+
}
|
|
698
|
+
interface ClearHistoryResponse {
|
|
699
|
+
type: 'historyCleared';
|
|
700
|
+
}
|
|
701
|
+
interface PingResponse {
|
|
702
|
+
type: 'pong';
|
|
703
|
+
}
|
|
704
|
+
type RosettaResponseMessage = AddMessageResponse | HistoryResponse | ClearHistoryResponse | PingResponse;
|
|
705
|
+
interface RosettaResponseMessageEvent extends MessageEvent {
|
|
706
|
+
data: RosettaResponseMessage;
|
|
707
|
+
}
|
|
708
|
+
declare function isType<T>(input: unknown, schema: z.ZodType<T>): input is T;
|
|
709
|
+
export { type ConversationMessageRole, isConversationMessageRole, type ConversationMessageName, isConversationMessageName, type ConversationUserMessage, isConversationUserMessage, type ConversationAssistantMessage, isConversationAssistantMessage, type ConversationSystemMessage, isConversationSystemMessage, type ConversationFunctionMessage, isConversationFunctionMessage, type ConversationMessage, isConversationMessage, type ConversationIOtMessage, isConversationInputMessage, type ConversationMessages, isConversationMessages, isType, type RosettaMessageEvent, type RosettaResponseMessageEvent, type ConversationMessageFunctionCall, isConversationMessageFunctionCall, type ConversationAssistantMessageWithFunctionCall, isConversationAssistantMessageWithFunctionCall };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
/// ///////////////////
|
|
3
|
+
// Role Enum
|
|
4
|
+
/// ///////////////////
|
|
5
|
+
const ChatCompletionRequestMessageRoleEnum = z.enum(['system', 'user', 'assistant', 'function']);
|
|
6
|
+
const isConversationMessageRole = (input) => {
|
|
7
|
+
return ChatCompletionRequestMessageRoleEnum.safeParse(input).success;
|
|
8
|
+
};
|
|
9
|
+
/// ///////////////////
|
|
10
|
+
// Name Type
|
|
11
|
+
/// ///////////////////
|
|
12
|
+
const ChatCompletionRequestMessageName = z.string().max(64).refine((value) => /^[\w]*$/.test(value), {
|
|
13
|
+
message: 'String may only contain a-z, A-Z, 0-9, and underscores'
|
|
14
|
+
});
|
|
15
|
+
const isConversationMessageName = (input) => {
|
|
16
|
+
return ChatCompletionRequestMessageName.safeParse(input).success;
|
|
17
|
+
};
|
|
18
|
+
// Valid timestampes for Rosetta AI Messages
|
|
19
|
+
const ChatCompletionRequestMessageTimestamp = z.number().int().min(1670112000000).max(Date.now() + (1000 * 60 * 60 * 24));
|
|
20
|
+
/// ///////////////////
|
|
21
|
+
// User Message
|
|
22
|
+
/// ///////////////////
|
|
23
|
+
const ChatCompletionRequestUserMessageSchema = z.object({
|
|
24
|
+
role: z.enum(['user']),
|
|
25
|
+
content: z.string().min(1),
|
|
26
|
+
name: ChatCompletionRequestMessageName.optional(),
|
|
27
|
+
timestamp: ChatCompletionRequestMessageTimestamp.optional()
|
|
28
|
+
});
|
|
29
|
+
const isConversationUserMessage = (input) => {
|
|
30
|
+
return ChatCompletionRequestUserMessageSchema.safeParse(input).success;
|
|
31
|
+
};
|
|
32
|
+
/// ///////////////////
|
|
33
|
+
// Function Call
|
|
34
|
+
/// ///////////////////
|
|
35
|
+
const ChatCompletionRequestMessageFunctionCall = z.object({
|
|
36
|
+
name: z.string(),
|
|
37
|
+
arguments: z.string()
|
|
38
|
+
});
|
|
39
|
+
const isConversationMessageFunctionCall = (input) => {
|
|
40
|
+
return ChatCompletionRequestMessageFunctionCall.safeParse(input).success;
|
|
41
|
+
};
|
|
42
|
+
/// ///////////////////
|
|
43
|
+
// Assistant Message
|
|
44
|
+
/// ///////////////////
|
|
45
|
+
const ChatCompletionRequestAssistantMessageWithFunctionCall = z.object({
|
|
46
|
+
role: z.enum(['assistant']),
|
|
47
|
+
content: z.null().or(z.string()),
|
|
48
|
+
function_call: ChatCompletionRequestMessageFunctionCall,
|
|
49
|
+
timestamp: ChatCompletionRequestMessageTimestamp.optional()
|
|
50
|
+
}).strict();
|
|
51
|
+
const isConversationAssistantMessageWithFunctionCall = (input) => {
|
|
52
|
+
return ChatCompletionRequestAssistantMessageWithFunctionCall.safeParse(input).success;
|
|
53
|
+
};
|
|
54
|
+
const ChatCompletionRequestAssistantMessage = z.object({
|
|
55
|
+
role: z.enum(['assistant']),
|
|
56
|
+
content: z.string(),
|
|
57
|
+
timestamp: ChatCompletionRequestMessageTimestamp.optional()
|
|
58
|
+
}).strict();
|
|
59
|
+
const ChatCompletionAssistantMessage = ChatCompletionRequestAssistantMessage.or(ChatCompletionRequestAssistantMessageWithFunctionCall);
|
|
60
|
+
const isConversationAssistantMessage = (input) => {
|
|
61
|
+
return ChatCompletionAssistantMessage.safeParse(input).success;
|
|
62
|
+
};
|
|
63
|
+
/// ///////////////////
|
|
64
|
+
// System Message
|
|
65
|
+
/// ///////////////////
|
|
66
|
+
const ChatCompletionSystemMessageSchema = z.object({
|
|
67
|
+
role: z.enum(['system']),
|
|
68
|
+
content: z.string()
|
|
69
|
+
});
|
|
70
|
+
const isConversationSystemMessage = (input) => {
|
|
71
|
+
return ChatCompletionSystemMessageSchema.safeParse(input).success;
|
|
72
|
+
};
|
|
73
|
+
/// ///////////////////
|
|
74
|
+
// Function Message
|
|
75
|
+
/// ///////////////////
|
|
76
|
+
const ChatCompletionFunctionMessageSchema = z.object({
|
|
77
|
+
role: z.enum(['function']),
|
|
78
|
+
content: z.string(),
|
|
79
|
+
name: z.string()
|
|
80
|
+
});
|
|
81
|
+
const isConversationFunctionMessage = (input) => {
|
|
82
|
+
return ChatCompletionFunctionMessageSchema.safeParse(input).success;
|
|
83
|
+
};
|
|
84
|
+
/// ///////////////////
|
|
85
|
+
// Conversation Message
|
|
86
|
+
/// ///////////////////
|
|
87
|
+
const ChatCompletionRequestMessageSchema = z.union([
|
|
88
|
+
ChatCompletionRequestUserMessageSchema,
|
|
89
|
+
ChatCompletionAssistantMessage,
|
|
90
|
+
ChatCompletionSystemMessageSchema,
|
|
91
|
+
ChatCompletionFunctionMessageSchema
|
|
92
|
+
]);
|
|
93
|
+
const isConversationMessage = (input) => {
|
|
94
|
+
return ChatCompletionRequestMessageSchema.safeParse(input).success;
|
|
95
|
+
};
|
|
96
|
+
/// ///////////////////
|
|
97
|
+
// Conversation Messages
|
|
98
|
+
/// ///////////////////
|
|
99
|
+
function validateFunctionOrder(messages) {
|
|
100
|
+
for (let i = 1; i < messages.length; i++) {
|
|
101
|
+
// Start from the second element
|
|
102
|
+
if (messages[i].role === 'function') {
|
|
103
|
+
const previousMessage = messages[i - 1];
|
|
104
|
+
if (!(previousMessage.role === 'assistant' && 'function_call' in previousMessage)) {
|
|
105
|
+
console.error('A message with role `function` must directly follow a message with role `assistant` and function_call not undefined', JSON.stringify(messages[i], null, 2), JSON.stringify(previousMessage, null, 2));
|
|
106
|
+
return { valid: false, error: 'A message with role `function` must directly follow a message with role `assistant` and function_call not undefined', index: i };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return { valid: true };
|
|
111
|
+
}
|
|
112
|
+
const ChatCompletionRequestMessagesSchema = z.array(ChatCompletionRequestMessageSchema).min(1)
|
|
113
|
+
.refine(
|
|
114
|
+
// We should have at most one system message
|
|
115
|
+
(data) => {
|
|
116
|
+
const systemMessageCount = data.filter((message) => message.role === 'system').length;
|
|
117
|
+
return systemMessageCount <= 1;
|
|
118
|
+
}, {
|
|
119
|
+
message: 'The message array can have at most one system message'
|
|
120
|
+
})
|
|
121
|
+
.refine(
|
|
122
|
+
// If there is a system message it should be the first message
|
|
123
|
+
(data) => {
|
|
124
|
+
const systemMessageIndex = data.findIndex((message) => message.role === 'system');
|
|
125
|
+
return systemMessageIndex === 0 || systemMessageIndex === -1;
|
|
126
|
+
}, {
|
|
127
|
+
message: 'The system message needs to be the first message in the array'
|
|
128
|
+
})
|
|
129
|
+
.refine(
|
|
130
|
+
// We should have at most one system message
|
|
131
|
+
(data) => {
|
|
132
|
+
const userMessageCount = data.find((message) => message.role === 'user');
|
|
133
|
+
return userMessageCount !== undefined;
|
|
134
|
+
}, {
|
|
135
|
+
message: 'The message array must have at least one user message'
|
|
136
|
+
})
|
|
137
|
+
.refine((data) => {
|
|
138
|
+
return validateFunctionOrder(data).valid;
|
|
139
|
+
});
|
|
140
|
+
const isConversationMessages = (input) => {
|
|
141
|
+
return ChatCompletionRequestMessagesSchema.safeParse(input).success;
|
|
142
|
+
};
|
|
143
|
+
/// ///////////////////
|
|
144
|
+
// Input Conversation Message
|
|
145
|
+
/// ///////////////////
|
|
146
|
+
const ChatCompletionRequestInputMessageSchema = z.union([
|
|
147
|
+
ChatCompletionRequestUserMessageSchema,
|
|
148
|
+
ChatCompletionAssistantMessage,
|
|
149
|
+
ChatCompletionFunctionMessageSchema
|
|
150
|
+
]);
|
|
151
|
+
const isConversationInputMessage = (input) => {
|
|
152
|
+
return ChatCompletionRequestInputMessageSchema.safeParse(input).success;
|
|
153
|
+
};
|
|
154
|
+
/// ///////////////////
|
|
155
|
+
// Utilities
|
|
156
|
+
/// ///////////////////
|
|
157
|
+
function isType(input, schema) {
|
|
158
|
+
return schema.safeParse(input).success;
|
|
159
|
+
}
|
|
160
|
+
/// ///////////////////
|
|
161
|
+
// Exports
|
|
162
|
+
/// ///////////////////
|
|
163
|
+
export { isConversationMessageRole, isConversationMessageName, isConversationUserMessage, isConversationAssistantMessage, isConversationSystemMessage, isConversationFunctionMessage, isConversationMessage, isConversationInputMessage, isConversationMessages, isType, isConversationMessageFunctionCall, isConversationAssistantMessageWithFunctionCall };
|