librechat-data-provider 0.3.3 → 0.3.5
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/dist/index.es.js +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/react-query/index.es.js +1 -1
- package/dist/react-query/index.es.js.map +1 -1
- package/package.json +1 -1
- package/src/api-endpoints.ts +2 -0
- package/src/config.ts +186 -0
- package/src/createPayload.ts +8 -5
- package/src/data-service.ts +4 -0
- package/src/index.ts +6 -1
- package/src/keys.ts +1 -0
- package/src/parsers.ts +225 -0
- package/src/schemas.ts +70 -269
- package/src/types/files.ts +10 -0
- package/src/types.ts +26 -7
package/src/parsers.ts
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import type { TConversation, TPreset } from './schemas';
|
|
2
|
+
import type { TEndpointOption } from './types';
|
|
3
|
+
import {
|
|
4
|
+
EModelEndpoint,
|
|
5
|
+
openAISchema,
|
|
6
|
+
googleSchema,
|
|
7
|
+
bingAISchema,
|
|
8
|
+
anthropicSchema,
|
|
9
|
+
chatGPTBrowserSchema,
|
|
10
|
+
gptPluginsSchema,
|
|
11
|
+
assistantSchema,
|
|
12
|
+
compactOpenAISchema,
|
|
13
|
+
compactGoogleSchema,
|
|
14
|
+
compactAnthropicSchema,
|
|
15
|
+
compactChatGPTSchema,
|
|
16
|
+
compactPluginsSchema,
|
|
17
|
+
} from './schemas';
|
|
18
|
+
import { alternateName } from './config';
|
|
19
|
+
|
|
20
|
+
type EndpointSchema =
|
|
21
|
+
| typeof openAISchema
|
|
22
|
+
| typeof googleSchema
|
|
23
|
+
| typeof bingAISchema
|
|
24
|
+
| typeof anthropicSchema
|
|
25
|
+
| typeof chatGPTBrowserSchema
|
|
26
|
+
| typeof gptPluginsSchema
|
|
27
|
+
| typeof assistantSchema;
|
|
28
|
+
|
|
29
|
+
const endpointSchemas: Record<EModelEndpoint, EndpointSchema> = {
|
|
30
|
+
[EModelEndpoint.openAI]: openAISchema,
|
|
31
|
+
[EModelEndpoint.azureOpenAI]: openAISchema,
|
|
32
|
+
[EModelEndpoint.custom]: openAISchema,
|
|
33
|
+
[EModelEndpoint.google]: googleSchema,
|
|
34
|
+
[EModelEndpoint.bingAI]: bingAISchema,
|
|
35
|
+
[EModelEndpoint.anthropic]: anthropicSchema,
|
|
36
|
+
[EModelEndpoint.chatGPTBrowser]: chatGPTBrowserSchema,
|
|
37
|
+
[EModelEndpoint.gptPlugins]: gptPluginsSchema,
|
|
38
|
+
[EModelEndpoint.assistant]: assistantSchema,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// const schemaCreators: Record<EModelEndpoint, (customSchema: DefaultSchemaValues) => EndpointSchema> = {
|
|
42
|
+
// [EModelEndpoint.google]: createGoogleSchema,
|
|
43
|
+
// };
|
|
44
|
+
|
|
45
|
+
export function getFirstDefinedValue(possibleValues: string[]) {
|
|
46
|
+
let returnValue;
|
|
47
|
+
for (const value of possibleValues) {
|
|
48
|
+
if (value) {
|
|
49
|
+
returnValue = value;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return returnValue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type TPossibleValues = {
|
|
57
|
+
models: string[];
|
|
58
|
+
secondaryModels?: string[];
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const parseConvo = ({
|
|
62
|
+
endpoint,
|
|
63
|
+
endpointType,
|
|
64
|
+
conversation,
|
|
65
|
+
possibleValues,
|
|
66
|
+
}: {
|
|
67
|
+
endpoint: EModelEndpoint;
|
|
68
|
+
endpointType?: EModelEndpoint;
|
|
69
|
+
conversation: Partial<TConversation | TPreset>;
|
|
70
|
+
possibleValues?: TPossibleValues;
|
|
71
|
+
// TODO: POC for default schema
|
|
72
|
+
// defaultSchema?: Partial<EndpointSchema>,
|
|
73
|
+
}) => {
|
|
74
|
+
let schema = endpointSchemas[endpoint];
|
|
75
|
+
|
|
76
|
+
if (!schema && !endpointType) {
|
|
77
|
+
throw new Error(`Unknown endpoint: ${endpoint}`);
|
|
78
|
+
} else if (!schema && endpointType) {
|
|
79
|
+
schema = endpointSchemas[endpointType];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// if (defaultSchema && schemaCreators[endpoint]) {
|
|
83
|
+
// schema = schemaCreators[endpoint](defaultSchema);
|
|
84
|
+
// }
|
|
85
|
+
|
|
86
|
+
const convo = schema.parse(conversation) as TConversation;
|
|
87
|
+
const { models, secondaryModels } = possibleValues ?? {};
|
|
88
|
+
|
|
89
|
+
if (models && convo) {
|
|
90
|
+
convo.model = getFirstDefinedValue(models) ?? convo.model;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (secondaryModels && convo.agentOptions) {
|
|
94
|
+
convo.agentOptions.model = getFirstDefinedValue(secondaryModels) ?? convo.agentOptions.model;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return convo;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const getResponseSender = (endpointOption: TEndpointOption): string => {
|
|
101
|
+
const { model, endpoint, endpointType, modelDisplayLabel, chatGptLabel, modelLabel, jailbreak } =
|
|
102
|
+
endpointOption;
|
|
103
|
+
|
|
104
|
+
if (
|
|
105
|
+
[
|
|
106
|
+
EModelEndpoint.openAI,
|
|
107
|
+
EModelEndpoint.azureOpenAI,
|
|
108
|
+
EModelEndpoint.gptPlugins,
|
|
109
|
+
EModelEndpoint.chatGPTBrowser,
|
|
110
|
+
].includes(endpoint)
|
|
111
|
+
) {
|
|
112
|
+
if (chatGptLabel) {
|
|
113
|
+
return chatGptLabel;
|
|
114
|
+
} else if (model && model.includes('gpt-3')) {
|
|
115
|
+
return 'GPT-3.5';
|
|
116
|
+
} else if (model && model.includes('gpt-4')) {
|
|
117
|
+
return 'GPT-4';
|
|
118
|
+
} else if (model && model.includes('mistral')) {
|
|
119
|
+
return 'Mistral';
|
|
120
|
+
}
|
|
121
|
+
return alternateName[endpoint] ?? 'ChatGPT';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (endpoint === EModelEndpoint.bingAI) {
|
|
125
|
+
return jailbreak ? 'Sydney' : 'BingAI';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (endpoint === EModelEndpoint.anthropic) {
|
|
129
|
+
return modelLabel ?? 'Claude';
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (endpoint === EModelEndpoint.google) {
|
|
133
|
+
if (modelLabel) {
|
|
134
|
+
return modelLabel;
|
|
135
|
+
} else if (model && model.includes('gemini')) {
|
|
136
|
+
return 'Gemini';
|
|
137
|
+
} else if (model && model.includes('code')) {
|
|
138
|
+
return 'Codey';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return 'PaLM2';
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (endpoint === EModelEndpoint.custom || endpointType === EModelEndpoint.custom) {
|
|
145
|
+
if (modelLabel) {
|
|
146
|
+
return modelLabel;
|
|
147
|
+
} else if (chatGptLabel) {
|
|
148
|
+
return chatGptLabel;
|
|
149
|
+
} else if (model && model.includes('mistral')) {
|
|
150
|
+
return 'Mistral';
|
|
151
|
+
} else if (model && model.includes('gpt-3')) {
|
|
152
|
+
return 'GPT-3.5';
|
|
153
|
+
} else if (model && model.includes('gpt-4')) {
|
|
154
|
+
return 'GPT-4';
|
|
155
|
+
} else if (modelDisplayLabel) {
|
|
156
|
+
return modelDisplayLabel;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return 'AI';
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return '';
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
type CompactEndpointSchema =
|
|
166
|
+
| typeof compactOpenAISchema
|
|
167
|
+
| typeof assistantSchema
|
|
168
|
+
| typeof compactGoogleSchema
|
|
169
|
+
| typeof bingAISchema
|
|
170
|
+
| typeof compactAnthropicSchema
|
|
171
|
+
| typeof compactChatGPTSchema
|
|
172
|
+
| typeof compactPluginsSchema;
|
|
173
|
+
|
|
174
|
+
const compactEndpointSchemas: Record<string, CompactEndpointSchema> = {
|
|
175
|
+
openAI: compactOpenAISchema,
|
|
176
|
+
azureOpenAI: compactOpenAISchema,
|
|
177
|
+
custom: compactOpenAISchema,
|
|
178
|
+
assistant: assistantSchema,
|
|
179
|
+
google: compactGoogleSchema,
|
|
180
|
+
/* BingAI needs all fields */
|
|
181
|
+
bingAI: bingAISchema,
|
|
182
|
+
anthropic: compactAnthropicSchema,
|
|
183
|
+
chatGPTBrowser: compactChatGPTSchema,
|
|
184
|
+
gptPlugins: compactPluginsSchema,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
export const parseCompactConvo = ({
|
|
188
|
+
endpoint,
|
|
189
|
+
endpointType,
|
|
190
|
+
conversation,
|
|
191
|
+
possibleValues,
|
|
192
|
+
}: {
|
|
193
|
+
endpoint?: EModelEndpoint;
|
|
194
|
+
endpointType?: EModelEndpoint;
|
|
195
|
+
conversation: Partial<TConversation | TPreset>;
|
|
196
|
+
possibleValues?: TPossibleValues;
|
|
197
|
+
// TODO: POC for default schema
|
|
198
|
+
// defaultSchema?: Partial<EndpointSchema>,
|
|
199
|
+
}) => {
|
|
200
|
+
if (!endpoint) {
|
|
201
|
+
throw new Error(`undefined endpoint: ${endpoint}`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
let schema = compactEndpointSchemas[endpoint];
|
|
205
|
+
|
|
206
|
+
if (!schema && !endpointType) {
|
|
207
|
+
throw new Error(`Unknown endpoint: ${endpoint}`);
|
|
208
|
+
} else if (!schema && endpointType) {
|
|
209
|
+
schema = compactEndpointSchemas[endpointType];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const convo = schema.parse(conversation) as TConversation;
|
|
213
|
+
// const { models, secondaryModels } = possibleValues ?? {};
|
|
214
|
+
const { models } = possibleValues ?? {};
|
|
215
|
+
|
|
216
|
+
if (models && convo) {
|
|
217
|
+
convo.model = getFirstDefinedValue(models) ?? convo.model;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// if (secondaryModels && convo.agentOptions) {
|
|
221
|
+
// convo.agentOptionmodel = getFirstDefinedValue(secondaryModels) ?? convo.agentOptionmodel;
|
|
222
|
+
// }
|
|
223
|
+
|
|
224
|
+
return convo;
|
|
225
|
+
};
|
package/src/schemas.ts
CHANGED
|
@@ -9,75 +9,7 @@ export enum EModelEndpoint {
|
|
|
9
9
|
gptPlugins = 'gptPlugins',
|
|
10
10
|
anthropic = 'anthropic',
|
|
11
11
|
assistant = 'assistant',
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const defaultEndpoints: EModelEndpoint[] = [
|
|
15
|
-
EModelEndpoint.openAI,
|
|
16
|
-
EModelEndpoint.assistant,
|
|
17
|
-
EModelEndpoint.azureOpenAI,
|
|
18
|
-
EModelEndpoint.bingAI,
|
|
19
|
-
EModelEndpoint.chatGPTBrowser,
|
|
20
|
-
EModelEndpoint.gptPlugins,
|
|
21
|
-
EModelEndpoint.google,
|
|
22
|
-
EModelEndpoint.anthropic,
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
export const defaultModels = {
|
|
26
|
-
[EModelEndpoint.google]: [
|
|
27
|
-
'gemini-pro',
|
|
28
|
-
'gemini-pro-vision',
|
|
29
|
-
'chat-bison',
|
|
30
|
-
'chat-bison-32k',
|
|
31
|
-
'codechat-bison',
|
|
32
|
-
'codechat-bison-32k',
|
|
33
|
-
'text-bison',
|
|
34
|
-
'text-bison-32k',
|
|
35
|
-
'text-unicorn',
|
|
36
|
-
'code-gecko',
|
|
37
|
-
'code-bison',
|
|
38
|
-
'code-bison-32k',
|
|
39
|
-
],
|
|
40
|
-
[EModelEndpoint.anthropic]: [
|
|
41
|
-
'claude-2.1',
|
|
42
|
-
'claude-2',
|
|
43
|
-
'claude-1.2',
|
|
44
|
-
'claude-1',
|
|
45
|
-
'claude-1-100k',
|
|
46
|
-
'claude-instant-1',
|
|
47
|
-
'claude-instant-1-100k',
|
|
48
|
-
],
|
|
49
|
-
[EModelEndpoint.openAI]: [
|
|
50
|
-
'gpt-3.5-turbo-16k-0613',
|
|
51
|
-
'gpt-3.5-turbo-16k',
|
|
52
|
-
'gpt-4-1106-preview',
|
|
53
|
-
'gpt-3.5-turbo',
|
|
54
|
-
'gpt-3.5-turbo-1106',
|
|
55
|
-
'gpt-4-vision-preview',
|
|
56
|
-
'gpt-4',
|
|
57
|
-
'gpt-3.5-turbo-instruct-0914',
|
|
58
|
-
'gpt-3.5-turbo-0613',
|
|
59
|
-
'gpt-3.5-turbo-0301',
|
|
60
|
-
'gpt-3.5-turbo-instruct',
|
|
61
|
-
'gpt-4-0613',
|
|
62
|
-
'text-davinci-003',
|
|
63
|
-
'gpt-4-0314',
|
|
64
|
-
],
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export const alternateName = {
|
|
68
|
-
[EModelEndpoint.openAI]: 'OpenAI',
|
|
69
|
-
[EModelEndpoint.assistant]: 'Assistants',
|
|
70
|
-
[EModelEndpoint.azureOpenAI]: 'Azure OpenAI',
|
|
71
|
-
[EModelEndpoint.bingAI]: 'Bing',
|
|
72
|
-
[EModelEndpoint.chatGPTBrowser]: 'ChatGPT',
|
|
73
|
-
[EModelEndpoint.gptPlugins]: 'Plugins',
|
|
74
|
-
[EModelEndpoint.google]: 'Google',
|
|
75
|
-
[EModelEndpoint.anthropic]: 'Anthropic',
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export enum AuthKeys {
|
|
79
|
-
GOOGLE_SERVICE_KEY = 'GOOGLE_SERVICE_KEY',
|
|
80
|
-
GOOGLE_API_KEY = 'GOOGLE_API_KEY',
|
|
12
|
+
custom = 'custom',
|
|
81
13
|
}
|
|
82
14
|
|
|
83
15
|
export const endpointSettings = {
|
|
@@ -116,40 +48,10 @@ export const endpointSettings = {
|
|
|
116
48
|
|
|
117
49
|
const google = endpointSettings[EModelEndpoint.google];
|
|
118
50
|
|
|
119
|
-
export const EndpointURLs: { [key in EModelEndpoint]: string } = {
|
|
120
|
-
[EModelEndpoint.azureOpenAI]: '/api/ask/azureOpenAI',
|
|
121
|
-
[EModelEndpoint.openAI]: '/api/ask/openAI',
|
|
122
|
-
[EModelEndpoint.bingAI]: '/api/ask/bingAI',
|
|
123
|
-
[EModelEndpoint.chatGPTBrowser]: '/api/ask/chatGPTBrowser',
|
|
124
|
-
[EModelEndpoint.google]: '/api/ask/google',
|
|
125
|
-
[EModelEndpoint.gptPlugins]: '/api/ask/gptPlugins',
|
|
126
|
-
[EModelEndpoint.anthropic]: '/api/ask/anthropic',
|
|
127
|
-
[EModelEndpoint.assistant]: '/api/assistants/chat',
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export const modularEndpoints = new Set<EModelEndpoint | string>([
|
|
131
|
-
EModelEndpoint.gptPlugins,
|
|
132
|
-
EModelEndpoint.anthropic,
|
|
133
|
-
EModelEndpoint.google,
|
|
134
|
-
EModelEndpoint.openAI,
|
|
135
|
-
]);
|
|
136
|
-
|
|
137
|
-
export const supportsFiles = {
|
|
138
|
-
[EModelEndpoint.openAI]: true,
|
|
139
|
-
[EModelEndpoint.google]: true,
|
|
140
|
-
[EModelEndpoint.assistant]: true,
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
export const supportsBalanceCheck = {
|
|
144
|
-
[EModelEndpoint.openAI]: true,
|
|
145
|
-
[EModelEndpoint.azureOpenAI]: true,
|
|
146
|
-
[EModelEndpoint.gptPlugins]: true,
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
export const visionModels = ['gpt-4-vision', 'llava-13b', 'gemini-pro-vision'];
|
|
150
|
-
|
|
151
51
|
export const eModelEndpointSchema = z.nativeEnum(EModelEndpoint);
|
|
152
52
|
|
|
53
|
+
export const extendedModelEndpointSchema = z.union([eModelEndpointSchema, z.string()]);
|
|
54
|
+
|
|
153
55
|
export const tPluginAuthConfigSchema = z.object({
|
|
154
56
|
authField: z.string(),
|
|
155
57
|
label: z.string(),
|
|
@@ -204,6 +106,7 @@ export const tAgentOptionsSchema = z.object({
|
|
|
204
106
|
|
|
205
107
|
export const tMessageSchema = z.object({
|
|
206
108
|
messageId: z.string(),
|
|
109
|
+
endpoint: z.string().optional(),
|
|
207
110
|
clientId: z.string().nullable().optional(),
|
|
208
111
|
conversationId: z.string().nullable(),
|
|
209
112
|
parentMessageId: z.string().nullable(),
|
|
@@ -228,7 +131,6 @@ export const tMessageSchema = z.object({
|
|
|
228
131
|
.default(() => new Date().toISOString()),
|
|
229
132
|
current: z.boolean().optional(),
|
|
230
133
|
unfinished: z.boolean().optional(),
|
|
231
|
-
submitting: z.boolean().optional(),
|
|
232
134
|
searchResult: z.boolean().optional(),
|
|
233
135
|
finish_reason: z.string().optional(),
|
|
234
136
|
});
|
|
@@ -253,6 +155,7 @@ export const tConversationSchema = z.object({
|
|
|
253
155
|
title: z.string().nullable().or(z.literal('New Chat')).default('New Chat'),
|
|
254
156
|
user: z.string().optional(),
|
|
255
157
|
endpoint: eModelEndpointSchema.nullable(),
|
|
158
|
+
endpointType: eModelEndpointSchema.optional(),
|
|
256
159
|
suggestions: z.array(z.string()).optional(),
|
|
257
160
|
messages: z.array(z.string()).optional(),
|
|
258
161
|
tools: z.array(tPluginSchema).optional(),
|
|
@@ -297,16 +200,31 @@ export const tPresetSchema = tConversationSchema
|
|
|
297
200
|
})
|
|
298
201
|
.merge(
|
|
299
202
|
z.object({
|
|
300
|
-
conversationId: z.string().optional(),
|
|
203
|
+
conversationId: z.string().nullable().optional(),
|
|
301
204
|
presetId: z.string().nullable().optional(),
|
|
302
205
|
title: z.string().nullable().optional(),
|
|
303
206
|
defaultPreset: z.boolean().optional(),
|
|
304
207
|
order: z.number().optional(),
|
|
208
|
+
endpoint: extendedModelEndpointSchema.nullable(),
|
|
305
209
|
}),
|
|
306
210
|
);
|
|
307
211
|
|
|
212
|
+
export const tConvoUpdateSchema = tConversationSchema.merge(
|
|
213
|
+
z.object({
|
|
214
|
+
endpoint: extendedModelEndpointSchema.nullable(),
|
|
215
|
+
}),
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
export const tPresetUpdateSchema = tConversationSchema.merge(
|
|
219
|
+
z.object({
|
|
220
|
+
endpoint: extendedModelEndpointSchema.nullable(),
|
|
221
|
+
}),
|
|
222
|
+
);
|
|
223
|
+
|
|
308
224
|
export type TPreset = z.infer<typeof tPresetSchema>;
|
|
309
225
|
|
|
226
|
+
// type DefaultSchemaValues = Partial<typeof google>;
|
|
227
|
+
|
|
310
228
|
export const openAISchema = tConversationSchema
|
|
311
229
|
.pick({
|
|
312
230
|
model: true,
|
|
@@ -528,122 +446,6 @@ export const assistantSchema = tConversationSchema
|
|
|
528
446
|
.transform(removeNullishValues)
|
|
529
447
|
.catch(() => ({}));
|
|
530
448
|
|
|
531
|
-
type EndpointSchema =
|
|
532
|
-
| typeof openAISchema
|
|
533
|
-
| typeof googleSchema
|
|
534
|
-
| typeof bingAISchema
|
|
535
|
-
| typeof anthropicSchema
|
|
536
|
-
| typeof chatGPTBrowserSchema
|
|
537
|
-
| typeof gptPluginsSchema
|
|
538
|
-
| typeof assistantSchema;
|
|
539
|
-
|
|
540
|
-
const endpointSchemas: Record<EModelEndpoint, EndpointSchema> = {
|
|
541
|
-
[EModelEndpoint.openAI]: openAISchema,
|
|
542
|
-
[EModelEndpoint.azureOpenAI]: openAISchema,
|
|
543
|
-
[EModelEndpoint.google]: googleSchema,
|
|
544
|
-
[EModelEndpoint.bingAI]: bingAISchema,
|
|
545
|
-
[EModelEndpoint.anthropic]: anthropicSchema,
|
|
546
|
-
[EModelEndpoint.chatGPTBrowser]: chatGPTBrowserSchema,
|
|
547
|
-
[EModelEndpoint.gptPlugins]: gptPluginsSchema,
|
|
548
|
-
[EModelEndpoint.assistant]: assistantSchema,
|
|
549
|
-
};
|
|
550
|
-
|
|
551
|
-
export function getFirstDefinedValue(possibleValues: string[]) {
|
|
552
|
-
let returnValue;
|
|
553
|
-
for (const value of possibleValues) {
|
|
554
|
-
if (value) {
|
|
555
|
-
returnValue = value;
|
|
556
|
-
break;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
return returnValue;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
export type TPossibleValues = {
|
|
563
|
-
models: string[];
|
|
564
|
-
secondaryModels?: string[];
|
|
565
|
-
};
|
|
566
|
-
|
|
567
|
-
export const parseConvo = (
|
|
568
|
-
endpoint: EModelEndpoint,
|
|
569
|
-
conversation: Partial<TConversation | TPreset>,
|
|
570
|
-
possibleValues?: TPossibleValues,
|
|
571
|
-
) => {
|
|
572
|
-
const schema = endpointSchemas[endpoint];
|
|
573
|
-
|
|
574
|
-
if (!schema) {
|
|
575
|
-
throw new Error(`Unknown endpoint: ${endpoint}`);
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
const convo = schema.parse(conversation) as TConversation;
|
|
579
|
-
const { models, secondaryModels } = possibleValues ?? {};
|
|
580
|
-
|
|
581
|
-
if (models && convo) {
|
|
582
|
-
convo.model = getFirstDefinedValue(models) ?? convo.model;
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
if (secondaryModels && convo.agentOptions) {
|
|
586
|
-
convo.agentOptions.model = getFirstDefinedValue(secondaryModels) ?? convo.agentOptions.model;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
return convo;
|
|
590
|
-
};
|
|
591
|
-
|
|
592
|
-
export type TEndpointOption = {
|
|
593
|
-
endpoint: EModelEndpoint;
|
|
594
|
-
model?: string | null;
|
|
595
|
-
promptPrefix?: string;
|
|
596
|
-
temperature?: number;
|
|
597
|
-
chatGptLabel?: string | null;
|
|
598
|
-
modelLabel?: string | null;
|
|
599
|
-
jailbreak?: boolean;
|
|
600
|
-
key?: string | null;
|
|
601
|
-
};
|
|
602
|
-
|
|
603
|
-
export const getResponseSender = (endpointOption: TEndpointOption): string => {
|
|
604
|
-
const { model, endpoint, chatGptLabel, modelLabel, jailbreak } = endpointOption;
|
|
605
|
-
|
|
606
|
-
if (
|
|
607
|
-
[
|
|
608
|
-
EModelEndpoint.openAI,
|
|
609
|
-
EModelEndpoint.azureOpenAI,
|
|
610
|
-
EModelEndpoint.gptPlugins,
|
|
611
|
-
EModelEndpoint.chatGPTBrowser,
|
|
612
|
-
].includes(endpoint)
|
|
613
|
-
) {
|
|
614
|
-
if (chatGptLabel) {
|
|
615
|
-
return chatGptLabel;
|
|
616
|
-
} else if (model && model.includes('gpt-3')) {
|
|
617
|
-
return 'GPT-3.5';
|
|
618
|
-
} else if (model && model.includes('gpt-4')) {
|
|
619
|
-
return 'GPT-4';
|
|
620
|
-
}
|
|
621
|
-
return alternateName[endpoint] ?? 'ChatGPT';
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
if (endpoint === EModelEndpoint.bingAI) {
|
|
625
|
-
return jailbreak ? 'Sydney' : 'BingAI';
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
if (endpoint === EModelEndpoint.anthropic) {
|
|
629
|
-
return modelLabel ?? 'Claude';
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
if (endpoint === EModelEndpoint.google) {
|
|
633
|
-
if (modelLabel) {
|
|
634
|
-
return modelLabel;
|
|
635
|
-
} else if (model && model.includes('gemini')) {
|
|
636
|
-
return 'Gemini';
|
|
637
|
-
} else if (model && model.includes('code')) {
|
|
638
|
-
return 'Codey';
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
return 'PaLM2';
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
return '';
|
|
645
|
-
};
|
|
646
|
-
|
|
647
449
|
export const compactOpenAISchema = tConversationSchema
|
|
648
450
|
.pick({
|
|
649
451
|
model: true,
|
|
@@ -809,53 +611,52 @@ export const compactPluginsSchema = tConversationSchema
|
|
|
809
611
|
})
|
|
810
612
|
.catch(() => ({}));
|
|
811
613
|
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
};
|
|
614
|
+
// const createGoogleSchema = (customGoogle: DefaultSchemaValues) => {
|
|
615
|
+
// const defaults = { ...google, ...customGoogle };
|
|
616
|
+
// return tConversationSchema
|
|
617
|
+
// .pick({
|
|
618
|
+
// model: true,
|
|
619
|
+
// modelLabel: true,
|
|
620
|
+
// promptPrefix: true,
|
|
621
|
+
// examples: true,
|
|
622
|
+
// temperature: true,
|
|
623
|
+
// maxOutputTokens: true,
|
|
624
|
+
// topP: true,
|
|
625
|
+
// topK: true,
|
|
626
|
+
// })
|
|
627
|
+
// .transform((obj) => {
|
|
628
|
+
// const isGeminiPro = obj?.model?.toLowerCase()?.includes('gemini-pro');
|
|
629
|
+
|
|
630
|
+
// const maxOutputTokensMax = isGeminiPro
|
|
631
|
+
// ? defaults.maxOutputTokens.maxGeminiPro
|
|
632
|
+
// : defaults.maxOutputTokens.max;
|
|
633
|
+
// const maxOutputTokensDefault = isGeminiPro
|
|
634
|
+
// ? defaults.maxOutputTokens.defaultGeminiPro
|
|
635
|
+
// : defaults.maxOutputTokens.default;
|
|
636
|
+
|
|
637
|
+
// let maxOutputTokens = obj.maxOutputTokens ?? maxOutputTokensDefault;
|
|
638
|
+
// maxOutputTokens = Math.min(maxOutputTokens, maxOutputTokensMax);
|
|
639
|
+
|
|
640
|
+
// return {
|
|
641
|
+
// ...obj,
|
|
642
|
+
// model: obj.model ?? defaults.model.default,
|
|
643
|
+
// modelLabel: obj.modelLabel ?? null,
|
|
644
|
+
// promptPrefix: obj.promptPrefix ?? null,
|
|
645
|
+
// examples: obj.examples ?? [{ input: { content: '' }, output: { content: '' } }],
|
|
646
|
+
// temperature: obj.temperature ?? defaults.temperature.default,
|
|
647
|
+
// maxOutputTokens,
|
|
648
|
+
// topP: obj.topP ?? defaults.topP.default,
|
|
649
|
+
// topK: obj.topK ?? defaults.topK.default,
|
|
650
|
+
// };
|
|
651
|
+
// })
|
|
652
|
+
// .catch(() => ({
|
|
653
|
+
// model: defaults.model.default,
|
|
654
|
+
// modelLabel: null,
|
|
655
|
+
// promptPrefix: null,
|
|
656
|
+
// examples: [{ input: { content: '' }, output: { content: '' } }],
|
|
657
|
+
// temperature: defaults.temperature.default,
|
|
658
|
+
// maxOutputTokens: defaults.maxOutputTokens.default,
|
|
659
|
+
// topP: defaults.topP.default,
|
|
660
|
+
// topK: defaults.topK.default,
|
|
661
|
+
// }));
|
|
662
|
+
// };
|
package/src/types/files.ts
CHANGED
|
@@ -10,6 +10,10 @@ export type FileUploadResponse = {
|
|
|
10
10
|
width: number;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
export type AvatarUploadResponse = {
|
|
14
|
+
url: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
13
17
|
export type FileUploadBody = {
|
|
14
18
|
formData: FormData;
|
|
15
19
|
file_id: string;
|
|
@@ -21,6 +25,12 @@ export type UploadMutationOptions = {
|
|
|
21
25
|
onError?: (error: unknown, variables: FileUploadBody, context?: unknown) => void;
|
|
22
26
|
};
|
|
23
27
|
|
|
28
|
+
export type UploadAvatarOptions = {
|
|
29
|
+
onSuccess?: (data: AvatarUploadResponse, variables: FormData, context?: unknown) => void;
|
|
30
|
+
onMutate?: (variables: FormData) => void | Promise<unknown>;
|
|
31
|
+
onError?: (error: unknown, variables: FormData, context?: unknown) => void;
|
|
32
|
+
};
|
|
33
|
+
|
|
24
34
|
export type DeleteFilesResponse = {
|
|
25
35
|
message: string;
|
|
26
36
|
result: Record<string, unknown>;
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import OpenAI from 'openai';
|
|
2
|
-
import type { TResPlugin, TMessage, TConversation,
|
|
2
|
+
import type { TResPlugin, TMessage, TConversation, EModelEndpoint } from './schemas';
|
|
3
3
|
|
|
4
4
|
export type TOpenAIMessage = OpenAI.Chat.ChatCompletionMessageParam;
|
|
5
5
|
export type TOpenAIFunction = OpenAI.Chat.ChatCompletionCreateParams.Function;
|
|
@@ -11,6 +11,19 @@ export type TMessages = TMessage[];
|
|
|
11
11
|
|
|
12
12
|
export type TMessagesAtom = TMessages | null;
|
|
13
13
|
|
|
14
|
+
export type TEndpointOption = {
|
|
15
|
+
endpoint: EModelEndpoint;
|
|
16
|
+
endpointType?: EModelEndpoint;
|
|
17
|
+
modelDisplayLabel?: string;
|
|
18
|
+
model?: string | null;
|
|
19
|
+
promptPrefix?: string;
|
|
20
|
+
temperature?: number;
|
|
21
|
+
chatGptLabel?: string | null;
|
|
22
|
+
modelLabel?: string | null;
|
|
23
|
+
jailbreak?: boolean;
|
|
24
|
+
key?: string | null;
|
|
25
|
+
};
|
|
26
|
+
|
|
14
27
|
export type TSubmission = {
|
|
15
28
|
plugin?: TResPlugin;
|
|
16
29
|
plugins?: TResPlugin[];
|
|
@@ -114,17 +127,23 @@ export type TSearchResults = {
|
|
|
114
127
|
};
|
|
115
128
|
|
|
116
129
|
export type TConfig = {
|
|
117
|
-
|
|
118
|
-
|
|
130
|
+
order: number;
|
|
131
|
+
type?: EModelEndpoint;
|
|
132
|
+
azure?: boolean;
|
|
119
133
|
availableTools?: [];
|
|
120
134
|
plugins?: Record<string, string>;
|
|
121
|
-
|
|
122
|
-
|
|
135
|
+
name?: string;
|
|
136
|
+
iconURL?: string;
|
|
137
|
+
modelDisplayLabel?: string;
|
|
138
|
+
userProvide?: boolean | null;
|
|
139
|
+
userProvideURL?: boolean | null;
|
|
123
140
|
};
|
|
124
141
|
|
|
125
|
-
export type
|
|
142
|
+
export type TEndpointsConfig =
|
|
143
|
+
| Record<EModelEndpoint | string, TConfig | null | undefined>
|
|
144
|
+
| undefined;
|
|
126
145
|
|
|
127
|
-
export type
|
|
146
|
+
export type TModelsConfig = Record<string, string[]>;
|
|
128
147
|
|
|
129
148
|
export type TUpdateTokenCountResponse = {
|
|
130
149
|
count: number;
|