librechat-data-provider 0.8.402 → 0.8.403

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.
Files changed (103) hide show
  1. package/dist/types/accessPermissions.d.ts +744 -0
  2. package/dist/types/actions.d.ts +118 -0
  3. package/dist/types/api-endpoints.d.ts +149 -0
  4. package/dist/types/artifacts.d.ts +97 -0
  5. package/dist/types/azure.d.ts +22 -0
  6. package/dist/types/bedrock.d.ts +1220 -0
  7. package/dist/types/config.d.ts +13916 -0
  8. package/dist/types/config.spec.d.ts +1 -0
  9. package/dist/types/createPayload.d.ts +5 -0
  10. package/dist/types/data-service.d.ts +284 -0
  11. package/dist/types/feedback.d.ts +36 -0
  12. package/dist/types/file-config.d.ts +263 -0
  13. package/dist/types/file-config.spec.d.ts +1 -0
  14. package/dist/types/generate.d.ts +597 -0
  15. package/dist/types/headers-helpers.d.ts +2 -0
  16. package/{src/index.ts → dist/types/index.d.ts} +0 -15
  17. package/dist/types/keys.d.ts +92 -0
  18. package/dist/types/mcp.d.ts +2760 -0
  19. package/dist/types/messages.d.ts +10 -0
  20. package/dist/types/models.d.ts +1677 -0
  21. package/dist/types/parameterSettings.d.ts +69 -0
  22. package/dist/types/parsers.d.ts +110 -0
  23. package/dist/types/permissions.d.ts +522 -0
  24. package/dist/types/react-query/react-query-service.d.ts +85 -0
  25. package/dist/types/request.d.ts +25 -0
  26. package/dist/types/roles.d.ts +554 -0
  27. package/dist/types/roles.spec.d.ts +1 -0
  28. package/dist/types/schemas.d.ts +4815 -0
  29. package/dist/types/schemas.spec.d.ts +1 -0
  30. package/dist/types/types/agents.d.ts +433 -0
  31. package/dist/types/types/assistants.d.ts +547 -0
  32. package/dist/types/types/files.d.ts +172 -0
  33. package/dist/types/types/graph.d.ts +135 -0
  34. package/{src/types/mcpServers.ts → dist/types/types/mcpServers.d.ts} +12 -18
  35. package/dist/types/types/mutations.d.ts +209 -0
  36. package/dist/types/types/queries.d.ts +169 -0
  37. package/dist/types/types/runs.d.ts +36 -0
  38. package/dist/types/types/web.d.ts +520 -0
  39. package/dist/types/types.d.ts +503 -0
  40. package/dist/types/utils.d.ts +12 -0
  41. package/package.json +4 -1
  42. package/babel.config.js +0 -4
  43. package/check_updates.sh +0 -52
  44. package/jest.config.js +0 -19
  45. package/react-query/package-lock.json +0 -292
  46. package/react-query/package.json +0 -10
  47. package/rollup.config.js +0 -74
  48. package/server-rollup.config.js +0 -40
  49. package/specs/actions.spec.ts +0 -2533
  50. package/specs/api-endpoints-subdir.spec.ts +0 -140
  51. package/specs/api-endpoints.spec.ts +0 -74
  52. package/specs/azure.spec.ts +0 -844
  53. package/specs/bedrock.spec.ts +0 -862
  54. package/specs/filetypes.spec.ts +0 -175
  55. package/specs/generate.spec.ts +0 -770
  56. package/specs/headers-helpers.spec.ts +0 -24
  57. package/specs/mcp.spec.ts +0 -147
  58. package/specs/openapiSpecs.ts +0 -524
  59. package/specs/parsers.spec.ts +0 -601
  60. package/specs/request-interceptor.spec.ts +0 -304
  61. package/specs/utils.spec.ts +0 -196
  62. package/src/accessPermissions.ts +0 -346
  63. package/src/actions.ts +0 -813
  64. package/src/api-endpoints.ts +0 -440
  65. package/src/artifacts.ts +0 -3104
  66. package/src/azure.ts +0 -328
  67. package/src/bedrock.ts +0 -425
  68. package/src/config.spec.ts +0 -315
  69. package/src/config.ts +0 -2006
  70. package/src/createPayload.ts +0 -46
  71. package/src/data-service.ts +0 -1087
  72. package/src/feedback.ts +0 -141
  73. package/src/file-config.spec.ts +0 -1248
  74. package/src/file-config.ts +0 -764
  75. package/src/generate.ts +0 -634
  76. package/src/headers-helpers.ts +0 -13
  77. package/src/keys.ts +0 -99
  78. package/src/mcp.ts +0 -271
  79. package/src/messages.ts +0 -50
  80. package/src/models.ts +0 -69
  81. package/src/parameterSettings.ts +0 -1111
  82. package/src/parsers.ts +0 -563
  83. package/src/permissions.ts +0 -188
  84. package/src/react-query/react-query-service.ts +0 -566
  85. package/src/request.ts +0 -171
  86. package/src/roles.spec.ts +0 -132
  87. package/src/roles.ts +0 -225
  88. package/src/schemas.spec.ts +0 -355
  89. package/src/schemas.ts +0 -1234
  90. package/src/types/agents.ts +0 -470
  91. package/src/types/assistants.ts +0 -654
  92. package/src/types/files.ts +0 -191
  93. package/src/types/graph.ts +0 -145
  94. package/src/types/mutations.ts +0 -422
  95. package/src/types/queries.ts +0 -208
  96. package/src/types/runs.ts +0 -40
  97. package/src/types/web.ts +0 -588
  98. package/src/types.ts +0 -676
  99. package/src/utils.ts +0 -85
  100. package/tsconfig.json +0 -28
  101. package/tsconfig.spec.json +0 -10
  102. /package/{src/react-query/index.ts → dist/types/react-query/index.d.ts} +0 -0
  103. /package/{src/types/index.ts → dist/types/types/index.d.ts} +0 -0
@@ -1,844 +0,0 @@
1
- import type { TAzureGroups } from '../src/config';
2
- import { validateAzureGroups, mapModelToAzureConfig, mapGroupToAzureConfig } from '../src/azure';
3
-
4
- describe('validateAzureGroups', () => {
5
- it('should validate a correct configuration', () => {
6
- const configs = [
7
- {
8
- group: 'us-east',
9
- apiKey: 'prod-1234',
10
- instanceName: 'prod-instance',
11
- deploymentName: 'v1-deployment',
12
- version: '2023-12-31',
13
- baseURL: 'https://prod.example.com',
14
- additionalHeaders: {
15
- 'X-Custom-Header': 'value',
16
- },
17
- models: {
18
- 'gpt-4-turbo': {
19
- deploymentName: 'gpt-4-turbo-deployment',
20
- version: '2023-11-06',
21
- },
22
- },
23
- },
24
- ];
25
- const { isValid, modelNames, modelGroupMap, groupMap } = validateAzureGroups(configs);
26
- expect(isValid).toBe(true);
27
- expect(modelNames).toEqual(['gpt-4-turbo']);
28
-
29
- const { azureOptions, baseURL, headers } = mapModelToAzureConfig({
30
- modelName: 'gpt-4-turbo',
31
- modelGroupMap,
32
- groupMap,
33
- });
34
- expect(azureOptions).toEqual({
35
- azureOpenAIApiKey: 'prod-1234',
36
- azureOpenAIApiInstanceName: 'prod-instance',
37
- azureOpenAIApiDeploymentName: 'gpt-4-turbo-deployment',
38
- azureOpenAIApiVersion: '2023-11-06',
39
- });
40
- expect(baseURL).toBe('https://prod.example.com');
41
- expect(headers).toEqual({
42
- 'X-Custom-Header': 'value',
43
- });
44
- });
45
-
46
- it('should return invalid for a configuration missing deploymentName at the model level where required', () => {
47
- const configs = [
48
- {
49
- group: 'us-west',
50
- apiKey: 'us-west-key-5678',
51
- instanceName: 'us-west-instance',
52
- models: {
53
- 'gpt-5': {
54
- version: '2023-12-01', // Missing deploymentName
55
- },
56
- },
57
- },
58
- ];
59
- const { isValid, errors } = validateAzureGroups(configs);
60
- expect(isValid).toBe(false);
61
- expect(errors.length).toBe(1);
62
- });
63
-
64
- it('should return invalid for a configuration with a boolean model where group lacks deploymentName and version', () => {
65
- const configs = [
66
- {
67
- group: 'sweden-central',
68
- apiKey: 'sweden-central-9012',
69
- instanceName: 'sweden-central-instance',
70
- models: {
71
- 'gpt-35-turbo': true, // The group lacks deploymentName and version
72
- },
73
- },
74
- ];
75
- const { isValid, errors } = validateAzureGroups(configs);
76
- expect(isValid).toBe(false);
77
- expect(errors.length).toBe(1);
78
- });
79
-
80
- it('should allow a boolean model when group has both deploymentName and version', () => {
81
- const configs = [
82
- {
83
- group: 'japan-east',
84
- apiKey: 'japan-east-3456',
85
- instanceName: 'japan-east-instance',
86
- deploymentName: 'default-deployment',
87
- version: '2023-04-01',
88
- models: {
89
- 'gpt-5-turbo': true,
90
- },
91
- },
92
- ];
93
- const { isValid, modelNames, modelGroupMap, groupMap } = validateAzureGroups(configs);
94
- expect(isValid).toBe(true);
95
- const modelGroup = modelGroupMap['gpt-5-turbo'];
96
- expect(modelGroup).toBeDefined();
97
- expect(modelGroup?.group).toBe('japan-east');
98
- expect(groupMap[modelGroup?.group ?? '']).toBeDefined();
99
- expect(modelNames).toContain('gpt-5-turbo');
100
- const { azureOptions } = mapModelToAzureConfig({
101
- modelName: 'gpt-5-turbo',
102
- modelGroupMap,
103
- groupMap,
104
- });
105
- expect(azureOptions).toEqual({
106
- azureOpenAIApiKey: 'japan-east-3456',
107
- azureOpenAIApiInstanceName: 'japan-east-instance',
108
- azureOpenAIApiDeploymentName: 'default-deployment',
109
- azureOpenAIApiVersion: '2023-04-01',
110
- });
111
- });
112
-
113
- it('should validate correctly when optional fields are missing', () => {
114
- const configs = [
115
- {
116
- group: 'canada-central',
117
- apiKey: 'canada-key',
118
- instanceName: 'canada-instance',
119
- models: {
120
- 'gpt-6': {
121
- deploymentName: 'gpt-6-deployment',
122
- version: '2023-01-01',
123
- },
124
- },
125
- },
126
- ];
127
- const { isValid, modelNames, modelGroupMap, groupMap } = validateAzureGroups(configs);
128
- expect(isValid).toBe(true);
129
- expect(modelNames).toEqual(['gpt-6']);
130
- const { azureOptions } = mapModelToAzureConfig({ modelName: 'gpt-6', modelGroupMap, groupMap });
131
- expect(azureOptions).toEqual({
132
- azureOpenAIApiKey: 'canada-key',
133
- azureOpenAIApiInstanceName: 'canada-instance',
134
- azureOpenAIApiDeploymentName: 'gpt-6-deployment',
135
- azureOpenAIApiVersion: '2023-01-01',
136
- });
137
- });
138
-
139
- it('should return invalid for configurations with incorrect types', () => {
140
- const configs = [
141
- {
142
- group: 123, // incorrect type
143
- apiKey: 'key123',
144
- instanceName: 'instance123',
145
- models: {
146
- 'gpt-7': true,
147
- },
148
- },
149
- ];
150
- // @ts-expect-error This error is expected because the 'group' property should be a string.
151
- const { isValid, errors } = validateAzureGroups(configs);
152
- expect(isValid).toBe(false);
153
- expect(errors.length).toBe(1);
154
- });
155
-
156
- it('should correctly handle a mix of valid and invalid model configurations', () => {
157
- const configs = [
158
- {
159
- group: 'australia-southeast',
160
- apiKey: 'australia-key',
161
- instanceName: 'australia-instance',
162
- models: {
163
- 'valid-model': {
164
- deploymentName: 'valid-deployment',
165
- version: '2023-02-02',
166
- },
167
- 'invalid-model': true, // Invalid because the group lacks deploymentName and version
168
- },
169
- },
170
- ];
171
- const { isValid, modelNames, errors } = validateAzureGroups(configs);
172
- expect(isValid).toBe(false);
173
- expect(modelNames).toEqual(expect.arrayContaining(['valid-model', 'invalid-model']));
174
- expect(errors.length).toBe(1);
175
- });
176
-
177
- it('should return invalid for configuration missing required fields at the group level', () => {
178
- const configs = [
179
- {
180
- group: 'brazil-south',
181
- apiKey: 'brazil-key',
182
- // Missing instanceName
183
- models: {
184
- 'gpt-8': {
185
- deploymentName: 'gpt-8-deployment',
186
- version: '2023-03-03',
187
- },
188
- },
189
- },
190
- ];
191
- const { isValid, errors } = validateAzureGroups(configs);
192
- expect(isValid).toBe(false);
193
- expect(errors.length).toBe(1);
194
- });
195
- });
196
-
197
- describe('validateAzureGroups for Serverless Configurations', () => {
198
- const originalEnv = process.env;
199
-
200
- beforeEach(() => {
201
- jest.resetModules();
202
- process.env = { ...originalEnv };
203
- });
204
-
205
- afterAll(() => {
206
- process.env = originalEnv;
207
- });
208
-
209
- it('should validate a correct serverless configuration', () => {
210
- const configs = [
211
- {
212
- group: 'serverless-group',
213
- apiKey: '${SERVERLESS_API_KEY}',
214
- baseURL: 'https://serverless.example.com/v1/completions',
215
- serverless: true,
216
- models: {
217
- 'model-serverless': true,
218
- },
219
- },
220
- ];
221
-
222
- const { isValid, errors } = validateAzureGroups(configs);
223
-
224
- expect(isValid).toBe(true);
225
- expect(errors.length).toBe(0);
226
- });
227
-
228
- it('should return invalid for a serverless configuration missing baseURL', () => {
229
- const configs = [
230
- {
231
- group: 'serverless-group',
232
- apiKey: '${SERVERLESS_API_KEY}',
233
- serverless: true,
234
- models: {
235
- 'model-serverless': true,
236
- },
237
- },
238
- ];
239
-
240
- const { isValid, errors } = validateAzureGroups(configs);
241
- expect(isValid).toBe(false);
242
- expect(errors).toEqual(
243
- expect.arrayContaining([
244
- expect.stringContaining(
245
- 'Group "serverless-group" is serverless but missing mandatory "baseURL."',
246
- ),
247
- ]),
248
- );
249
- });
250
-
251
- it('should throw an error when environment variable for apiKey is not set', () => {
252
- process.env.SERVERLESS_API_KEY = '';
253
-
254
- expect(() => {
255
- mapModelToAzureConfig({
256
- modelName: 'model-serverless',
257
- modelGroupMap: {
258
- 'model-serverless': {
259
- group: 'serverless-group',
260
- },
261
- },
262
- groupMap: {
263
- 'serverless-group': {
264
- apiKey: '${SERVERLESS_API_KEY}',
265
- baseURL: 'https://serverless.example.com/v1/completions',
266
- serverless: true,
267
- models: { 'model-serverless': true },
268
- },
269
- },
270
- });
271
- }).toThrow('Azure configuration environment variable "${SERVERLESS_API_KEY}" was not found.');
272
- });
273
-
274
- it('should correctly extract environment variables and prepare serverless config', () => {
275
- process.env.SERVERLESS_API_KEY = 'abc123';
276
-
277
- const { azureOptions, baseURL, serverless } = mapModelToAzureConfig({
278
- modelName: 'model-serverless',
279
- modelGroupMap: {
280
- 'model-serverless': {
281
- group: 'serverless-group',
282
- },
283
- },
284
- groupMap: {
285
- 'serverless-group': {
286
- apiKey: '${SERVERLESS_API_KEY}',
287
- baseURL: 'https://serverless.example.com/v1/completions',
288
- serverless: true,
289
- models: { 'model-serverless': true },
290
- },
291
- },
292
- });
293
-
294
- expect(azureOptions.azureOpenAIApiKey).toEqual('abc123');
295
- expect(baseURL).toEqual('https://serverless.example.com/v1/completions');
296
- expect(serverless).toBe(true);
297
- });
298
-
299
- it('should ensure serverless flag triggers appropriate validations and mappings', () => {
300
- const configs = [
301
- {
302
- group: 'serverless-group-2',
303
- apiKey: '${NEW_SERVERLESS_API_KEY}',
304
- baseURL: 'https://new-serverless.example.com/v1/completions',
305
- serverless: true,
306
- models: {
307
- 'new-model-serverless': true,
308
- },
309
- },
310
- ];
311
-
312
- process.env.NEW_SERVERLESS_API_KEY = 'def456';
313
-
314
- const { isValid, errors, modelGroupMap, groupMap } = validateAzureGroups(configs);
315
- expect(isValid).toBe(true);
316
- expect(errors.length).toBe(0);
317
-
318
- const { azureOptions, baseURL, serverless } = mapModelToAzureConfig({
319
- modelName: 'new-model-serverless',
320
- modelGroupMap,
321
- groupMap,
322
- });
323
-
324
- expect(azureOptions).toEqual({
325
- azureOpenAIApiKey: 'def456',
326
- azureOpenAIApiVersion: '',
327
- });
328
- expect(baseURL).toEqual('https://new-serverless.example.com/v1/completions');
329
- expect(serverless).toBe(true);
330
- });
331
- });
332
-
333
- describe('validateAzureGroups with modelGroupMap and groupMap', () => {
334
- const originalEnv = process.env;
335
-
336
- beforeEach(() => {
337
- jest.resetModules();
338
- process.env = { ...originalEnv };
339
- });
340
-
341
- afterAll(() => {
342
- process.env = originalEnv;
343
- });
344
-
345
- it('should provide a valid modelGroupMap and groupMap for a correct configuration', () => {
346
- const validConfigs: TAzureGroups = [
347
- {
348
- group: 'us-east',
349
- apiKey: 'prod-1234',
350
- instanceName: 'prod-instance',
351
- deploymentName: 'v1-deployment',
352
- version: '2023-12-31',
353
- baseURL: 'https://prod.example.com',
354
- additionalHeaders: {
355
- 'X-Custom-Header': 'value',
356
- },
357
- models: {
358
- 'gpt-4-turbo': {
359
- deploymentName: 'gpt-4-turbo-deployment',
360
- version: '2023-11-06',
361
- },
362
- },
363
- },
364
- {
365
- group: 'us-west',
366
- apiKey: 'prod-12345',
367
- instanceName: 'prod-instance',
368
- deploymentName: 'v1-deployment',
369
- version: '2023-12-31',
370
- baseURL: 'https://prod.example.com',
371
- additionalHeaders: {
372
- 'X-Custom-Header': 'value',
373
- },
374
- models: {
375
- 'gpt-5-turbo': {
376
- deploymentName: 'gpt-5-turbo-deployment',
377
- version: '2023-11-06',
378
- },
379
- },
380
- },
381
- ];
382
- const { isValid, modelGroupMap, groupMap } = validateAzureGroups(validConfigs);
383
- expect(isValid).toBe(true);
384
- expect(modelGroupMap['gpt-4-turbo']).toBeDefined();
385
- expect(modelGroupMap['gpt-4-turbo']?.group).toBe('us-east');
386
- expect(groupMap['us-east']).toBeDefined();
387
- expect(groupMap['us-east']?.apiKey).toBe('prod-1234');
388
- expect(groupMap['us-east']?.models['gpt-4-turbo']).toBeDefined();
389
- const { azureOptions, baseURL, headers } = mapModelToAzureConfig({
390
- modelName: 'gpt-4-turbo',
391
- modelGroupMap,
392
- groupMap,
393
- });
394
- expect(azureOptions).toEqual({
395
- azureOpenAIApiKey: 'prod-1234',
396
- azureOpenAIApiInstanceName: 'prod-instance',
397
- azureOpenAIApiDeploymentName: 'gpt-4-turbo-deployment',
398
- azureOpenAIApiVersion: '2023-11-06',
399
- });
400
- expect(baseURL).toBe('https://prod.example.com');
401
- expect(headers).toEqual({
402
- 'X-Custom-Header': 'value',
403
- });
404
- });
405
-
406
- it('should not allow duplicate group names', () => {
407
- const duplicateGroups: TAzureGroups = [
408
- {
409
- group: 'us-east',
410
- apiKey: 'prod-1234',
411
- instanceName: 'prod-instance',
412
- deploymentName: 'v1-deployment',
413
- version: '2023-12-31',
414
- baseURL: 'https://prod.example.com',
415
- additionalHeaders: {
416
- 'X-Custom-Header': 'value',
417
- },
418
- models: {
419
- 'gpt-4-turbo': {
420
- deploymentName: 'gpt-4-turbo-deployment',
421
- version: '2023-11-06',
422
- },
423
- },
424
- },
425
- {
426
- group: 'us-east',
427
- apiKey: 'prod-1234',
428
- instanceName: 'prod-instance',
429
- deploymentName: 'v1-deployment',
430
- version: '2023-12-31',
431
- baseURL: 'https://prod.example.com',
432
- additionalHeaders: {
433
- 'X-Custom-Header': 'value',
434
- },
435
- models: {
436
- 'gpt-5-turbo': {
437
- deploymentName: 'gpt-4-turbo-deployment',
438
- version: '2023-11-06',
439
- },
440
- },
441
- },
442
- ];
443
- const { isValid } = validateAzureGroups(duplicateGroups);
444
- expect(isValid).toBe(false);
445
- });
446
- it('should not allow duplicate models across groups', () => {
447
- const duplicateGroups: TAzureGroups = [
448
- {
449
- group: 'us-east',
450
- apiKey: 'prod-1234',
451
- instanceName: 'prod-instance',
452
- deploymentName: 'v1-deployment',
453
- version: '2023-12-31',
454
- baseURL: 'https://prod.example.com',
455
- additionalHeaders: {
456
- 'X-Custom-Header': 'value',
457
- },
458
- models: {
459
- 'gpt-4-turbo': {
460
- deploymentName: 'gpt-4-turbo-deployment',
461
- version: '2023-11-06',
462
- },
463
- },
464
- },
465
- {
466
- group: 'us-west',
467
- apiKey: 'prod-1234',
468
- instanceName: 'prod-instance',
469
- deploymentName: 'v1-deployment',
470
- version: '2023-12-31',
471
- baseURL: 'https://prod.example.com',
472
- additionalHeaders: {
473
- 'X-Custom-Header': 'value',
474
- },
475
- models: {
476
- 'gpt-4-turbo': {
477
- deploymentName: 'gpt-4-turbo-deployment',
478
- version: '2023-11-06',
479
- },
480
- },
481
- },
482
- ];
483
- const { isValid } = validateAzureGroups(duplicateGroups);
484
- expect(isValid).toBe(false);
485
- });
486
-
487
- it('should throw an error if environment variables are set but not configured', () => {
488
- const validConfigs: TAzureGroups = [
489
- {
490
- group: 'librechat-westus',
491
- apiKey: '${WESTUS_API_KEY}',
492
- instanceName: 'librechat-westus',
493
- version: '2023-12-01-preview',
494
- models: {
495
- 'gpt-4-vision-preview': {
496
- deploymentName: 'gpt-4-vision-preview',
497
- version: '2024-02-15-preview',
498
- },
499
- 'gpt-3.5-turbo': {
500
- deploymentName: 'gpt-35-turbo',
501
- },
502
- 'gpt-3.5-turbo-1106': {
503
- deploymentName: 'gpt-35-turbo-1106',
504
- },
505
- 'gpt-4': {
506
- deploymentName: 'gpt-4',
507
- },
508
- 'gpt-4-1106-preview': {
509
- deploymentName: 'gpt-4-1106-preview',
510
- },
511
- },
512
- },
513
- {
514
- group: 'librechat-eastus',
515
- apiKey: '${EASTUS_API_KEY}',
516
- instanceName: 'librechat-eastus',
517
- deploymentName: 'gpt-4-turbo',
518
- version: '2024-02-15-preview',
519
- models: {
520
- 'gpt-4-turbo': true,
521
- },
522
- },
523
- ];
524
- const { isValid, modelGroupMap, groupMap } = validateAzureGroups(validConfigs);
525
- expect(isValid).toBe(true);
526
- expect(() =>
527
- mapModelToAzureConfig({ modelName: 'gpt-4-turbo', modelGroupMap, groupMap }),
528
- ).toThrow();
529
- });
530
-
531
- it('should list all expected models in both modelGroupMap and groupMap', () => {
532
- process.env.WESTUS_API_KEY = 'westus-key';
533
- process.env.EASTUS_API_KEY = 'eastus-key';
534
- process.env.AZURE_MISTRAL_API_KEY = 'mistral-key';
535
- process.env.AZURE_LLAMA2_70B_API_KEY = 'llama-key';
536
-
537
- const validConfigs: TAzureGroups = [
538
- {
539
- group: 'librechat-westus',
540
- apiKey: '${WESTUS_API_KEY}',
541
- instanceName: 'librechat-westus',
542
- version: '2023-12-01-preview',
543
- models: {
544
- 'gpt-4-vision-preview': {
545
- deploymentName: 'gpt-4-vision-preview',
546
- version: '2024-02-15-preview',
547
- },
548
- 'gpt-3.5-turbo': {
549
- deploymentName: 'gpt-35-turbo',
550
- },
551
- 'gpt-3.5-turbo-1106': {
552
- deploymentName: 'gpt-35-turbo-1106',
553
- },
554
- 'gpt-4': {
555
- deploymentName: 'gpt-4',
556
- },
557
- 'gpt-4-1106-preview': {
558
- deploymentName: 'gpt-4-1106-preview',
559
- },
560
- },
561
- },
562
- {
563
- group: 'librechat-eastus',
564
- apiKey: '${EASTUS_API_KEY}',
565
- instanceName: 'librechat-eastus',
566
- deploymentName: 'gpt-4-turbo',
567
- version: '2024-02-15-preview',
568
- models: {
569
- 'gpt-4-turbo': true,
570
- },
571
- baseURL: 'https://eastus.example.com',
572
- additionalHeaders: {
573
- 'x-api-key': 'x-api-key-value',
574
- },
575
- },
576
- {
577
- group: 'mistral-inference',
578
- apiKey: '${AZURE_MISTRAL_API_KEY}',
579
- baseURL:
580
- 'https://Mistral-large-vnpet-serverless.region.inference.ai.azure.com/v1/chat/completions',
581
- serverless: true,
582
- models: {
583
- 'mistral-large': true,
584
- },
585
- },
586
- {
587
- group: 'llama-70b-chat',
588
- apiKey: '${AZURE_LLAMA2_70B_API_KEY}',
589
- baseURL:
590
- 'https://Llama-2-70b-chat-qmvyb-serverless.region.inference.ai.azure.com/v1/chat/completions',
591
- serverless: true,
592
- models: {
593
- 'llama-70b-chat': true,
594
- },
595
- },
596
- ];
597
- const { isValid, modelGroupMap, groupMap, modelNames } = validateAzureGroups(validConfigs);
598
- expect(isValid).toBe(true);
599
- expect(modelNames).toEqual([
600
- 'gpt-4-vision-preview',
601
- 'gpt-3.5-turbo',
602
- 'gpt-3.5-turbo-1106',
603
- 'gpt-4',
604
- 'gpt-4-1106-preview',
605
- 'gpt-4-turbo',
606
- 'mistral-large',
607
- 'llama-70b-chat',
608
- ]);
609
-
610
- // Check modelGroupMap
611
- modelNames.forEach((modelName) => {
612
- expect(modelGroupMap[modelName]).toBeDefined();
613
- });
614
-
615
- // Check groupMap for 'librechat-westus'
616
- expect(groupMap).toHaveProperty('librechat-westus');
617
- expect(groupMap['librechat-westus']).toEqual(
618
- expect.objectContaining({
619
- apiKey: '${WESTUS_API_KEY}',
620
- instanceName: 'librechat-westus',
621
- version: '2023-12-01-preview',
622
- models: expect.objectContaining({
623
- 'gpt-4-vision-preview': expect.any(Object),
624
- 'gpt-3.5-turbo': expect.any(Object),
625
- 'gpt-3.5-turbo-1106': expect.any(Object),
626
- 'gpt-4': expect.any(Object),
627
- 'gpt-4-1106-preview': expect.any(Object),
628
- }),
629
- }),
630
- );
631
-
632
- // Check groupMap for 'librechat-eastus'
633
- expect(groupMap).toHaveProperty('librechat-eastus');
634
- expect(groupMap['librechat-eastus']).toEqual(
635
- expect.objectContaining({
636
- apiKey: '${EASTUS_API_KEY}',
637
- instanceName: 'librechat-eastus',
638
- deploymentName: 'gpt-4-turbo',
639
- version: '2024-02-15-preview',
640
- models: expect.objectContaining({
641
- 'gpt-4-turbo': true,
642
- }),
643
- }),
644
- );
645
-
646
- // Check groupMap for 'mistral-inference'
647
- expect(groupMap).toHaveProperty('mistral-inference');
648
- expect(groupMap['mistral-inference']).toEqual(
649
- expect.objectContaining({
650
- apiKey: '${AZURE_MISTRAL_API_KEY}',
651
- baseURL:
652
- 'https://Mistral-large-vnpet-serverless.region.inference.ai.azure.com/v1/chat/completions',
653
- serverless: true,
654
- models: expect.objectContaining({
655
- 'mistral-large': true,
656
- }),
657
- }),
658
- );
659
-
660
- // Check groupMap for 'llama-70b-chat'
661
- expect(groupMap).toHaveProperty('llama-70b-chat');
662
- expect(groupMap['llama-70b-chat']).toEqual(
663
- expect.objectContaining({
664
- apiKey: '${AZURE_LLAMA2_70B_API_KEY}',
665
- baseURL:
666
- 'https://Llama-2-70b-chat-qmvyb-serverless.region.inference.ai.azure.com/v1/chat/completions',
667
- serverless: true,
668
- models: expect.objectContaining({
669
- 'llama-70b-chat': true,
670
- }),
671
- }),
672
- );
673
-
674
- const { azureOptions: azureOptions1 } = mapModelToAzureConfig({
675
- modelName: 'gpt-4-vision-preview',
676
- modelGroupMap,
677
- groupMap,
678
- });
679
- expect(azureOptions1).toEqual({
680
- azureOpenAIApiKey: 'westus-key',
681
- azureOpenAIApiInstanceName: 'librechat-westus',
682
- azureOpenAIApiDeploymentName: 'gpt-4-vision-preview',
683
- azureOpenAIApiVersion: '2024-02-15-preview',
684
- });
685
-
686
- const {
687
- azureOptions: azureOptions2,
688
- baseURL,
689
- headers,
690
- } = mapModelToAzureConfig({
691
- modelName: 'gpt-4-turbo',
692
- modelGroupMap,
693
- groupMap,
694
- });
695
- expect(azureOptions2).toEqual({
696
- azureOpenAIApiKey: 'eastus-key',
697
- azureOpenAIApiInstanceName: 'librechat-eastus',
698
- azureOpenAIApiDeploymentName: 'gpt-4-turbo',
699
- azureOpenAIApiVersion: '2024-02-15-preview',
700
- });
701
- expect(baseURL).toBe('https://eastus.example.com');
702
- expect(headers).toEqual({
703
- 'x-api-key': 'x-api-key-value',
704
- });
705
-
706
- const { azureOptions: azureOptions3 } = mapModelToAzureConfig({
707
- modelName: 'gpt-4',
708
- modelGroupMap,
709
- groupMap,
710
- });
711
- expect(azureOptions3).toEqual({
712
- azureOpenAIApiKey: 'westus-key',
713
- azureOpenAIApiInstanceName: 'librechat-westus',
714
- azureOpenAIApiDeploymentName: 'gpt-4',
715
- azureOpenAIApiVersion: '2023-12-01-preview',
716
- });
717
-
718
- const { azureOptions: azureOptions4 } = mapModelToAzureConfig({
719
- modelName: 'gpt-3.5-turbo',
720
- modelGroupMap,
721
- groupMap,
722
- });
723
- expect(azureOptions4).toEqual({
724
- azureOpenAIApiKey: 'westus-key',
725
- azureOpenAIApiInstanceName: 'librechat-westus',
726
- azureOpenAIApiDeploymentName: 'gpt-35-turbo',
727
- azureOpenAIApiVersion: '2023-12-01-preview',
728
- });
729
-
730
- const { azureOptions: azureOptions5 } = mapModelToAzureConfig({
731
- modelName: 'gpt-3.5-turbo-1106',
732
- modelGroupMap,
733
- groupMap,
734
- });
735
- expect(azureOptions5).toEqual({
736
- azureOpenAIApiKey: 'westus-key',
737
- azureOpenAIApiInstanceName: 'librechat-westus',
738
- azureOpenAIApiDeploymentName: 'gpt-35-turbo-1106',
739
- azureOpenAIApiVersion: '2023-12-01-preview',
740
- });
741
-
742
- const { azureOptions: azureOptions6 } = mapModelToAzureConfig({
743
- modelName: 'gpt-4-1106-preview',
744
- modelGroupMap,
745
- groupMap,
746
- });
747
- expect(azureOptions6).toEqual({
748
- azureOpenAIApiKey: 'westus-key',
749
- azureOpenAIApiInstanceName: 'librechat-westus',
750
- azureOpenAIApiDeploymentName: 'gpt-4-1106-preview',
751
- azureOpenAIApiVersion: '2023-12-01-preview',
752
- });
753
-
754
- const {
755
- azureOptions: azureOptions7,
756
- serverless: serverlessMistral,
757
- baseURL: mistralEndpoint,
758
- } = mapModelToAzureConfig({
759
- modelName: 'mistral-large',
760
- modelGroupMap,
761
- groupMap,
762
- });
763
- expect(serverlessMistral).toBe(true);
764
- expect(mistralEndpoint).toBe(
765
- 'https://Mistral-large-vnpet-serverless.region.inference.ai.azure.com/v1/chat/completions',
766
- );
767
- expect(azureOptions7).toEqual({
768
- azureOpenAIApiKey: 'mistral-key',
769
- azureOpenAIApiVersion: '',
770
- });
771
-
772
- const {
773
- azureOptions: azureOptions8,
774
- serverless: serverlessLlama,
775
- baseURL: llamaEndpoint,
776
- } = mapModelToAzureConfig({
777
- modelName: 'llama-70b-chat',
778
- modelGroupMap,
779
- groupMap,
780
- });
781
- expect(serverlessLlama).toBe(true);
782
- expect(llamaEndpoint).toBe(
783
- 'https://Llama-2-70b-chat-qmvyb-serverless.region.inference.ai.azure.com/v1/chat/completions',
784
- );
785
- expect(azureOptions8).toEqual({
786
- azureOpenAIApiKey: 'llama-key',
787
- azureOpenAIApiVersion: '',
788
- });
789
- });
790
- });
791
-
792
- describe('mapGroupToAzureConfig', () => {
793
- // Test setup for a basic config with 2 groups
794
- const groupMap = {
795
- group1: {
796
- apiKey: 'key-for-group1',
797
- instanceName: 'instance-group1',
798
- models: {
799
- model1: { deploymentName: 'deployment1', version: '1.0' },
800
- },
801
- },
802
- group2: {
803
- apiKey: 'key-for-group2',
804
- instanceName: 'instance-group2',
805
- serverless: true,
806
- baseURL: 'https://group2.example.com',
807
- models: {
808
- model2: true, // demonstrating a boolean style model configuration
809
- },
810
- },
811
- };
812
-
813
- it('should successfully map non-serverless group configuration', () => {
814
- const groupName = 'group1';
815
- const result = mapGroupToAzureConfig({ groupName, groupMap });
816
- expect(result).toEqual({
817
- azureOptions: expect.objectContaining({
818
- azureOpenAIApiKey: 'key-for-group1',
819
- azureOpenAIApiInstanceName: 'instance-group1',
820
- azureOpenAIApiDeploymentName: expect.any(String),
821
- azureOpenAIApiVersion: expect.any(String),
822
- }),
823
- });
824
- });
825
-
826
- it('should successfully map serverless group configuration', () => {
827
- const groupName = 'group2';
828
- const result = mapGroupToAzureConfig({ groupName, groupMap });
829
- expect(result).toEqual({
830
- azureOptions: expect.objectContaining({
831
- azureOpenAIApiKey: 'key-for-group2',
832
- }),
833
- baseURL: 'https://group2.example.com',
834
- serverless: true,
835
- });
836
- });
837
-
838
- it('should throw error for nonexistent group name', () => {
839
- const groupName = 'nonexistent-group';
840
- expect(() => {
841
- mapGroupToAzureConfig({ groupName, groupMap });
842
- }).toThrow(`Group named "${groupName}" not found in configuration.`);
843
- });
844
- });