librechat-data-provider 0.4.3 → 0.4.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.
@@ -0,0 +1,787 @@
1
+ import type { TAzureGroups } from '../src/config';
2
+ import { validateAzureGroups, mapModelToAzureConfig } 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
+ });
327
+ expect(baseURL).toEqual('https://new-serverless.example.com/v1/completions');
328
+ expect(serverless).toBe(true);
329
+ });
330
+ });
331
+
332
+ describe('validateAzureGroups with modelGroupMap and groupMap', () => {
333
+ const originalEnv = process.env;
334
+
335
+ beforeEach(() => {
336
+ jest.resetModules();
337
+ process.env = { ...originalEnv };
338
+ });
339
+
340
+ afterAll(() => {
341
+ process.env = originalEnv;
342
+ });
343
+
344
+ it('should provide a valid modelGroupMap and groupMap for a correct configuration', () => {
345
+ const validConfigs: TAzureGroups = [
346
+ {
347
+ group: 'us-east',
348
+ apiKey: 'prod-1234',
349
+ instanceName: 'prod-instance',
350
+ deploymentName: 'v1-deployment',
351
+ version: '2023-12-31',
352
+ baseURL: 'https://prod.example.com',
353
+ additionalHeaders: {
354
+ 'X-Custom-Header': 'value',
355
+ },
356
+ models: {
357
+ 'gpt-4-turbo': {
358
+ deploymentName: 'gpt-4-turbo-deployment',
359
+ version: '2023-11-06',
360
+ },
361
+ },
362
+ },
363
+ {
364
+ group: 'us-west',
365
+ apiKey: 'prod-12345',
366
+ instanceName: 'prod-instance',
367
+ deploymentName: 'v1-deployment',
368
+ version: '2023-12-31',
369
+ baseURL: 'https://prod.example.com',
370
+ additionalHeaders: {
371
+ 'X-Custom-Header': 'value',
372
+ },
373
+ models: {
374
+ 'gpt-5-turbo': {
375
+ deploymentName: 'gpt-5-turbo-deployment',
376
+ version: '2023-11-06',
377
+ },
378
+ },
379
+ },
380
+ ];
381
+ const { isValid, modelGroupMap, groupMap } = validateAzureGroups(validConfigs);
382
+ expect(isValid).toBe(true);
383
+ expect(modelGroupMap['gpt-4-turbo']).toBeDefined();
384
+ expect(modelGroupMap['gpt-4-turbo'].group).toBe('us-east');
385
+ expect(groupMap['us-east']).toBeDefined();
386
+ expect(groupMap['us-east'].apiKey).toBe('prod-1234');
387
+ expect(groupMap['us-east'].models['gpt-4-turbo']).toBeDefined();
388
+ const { azureOptions, baseURL, headers } = mapModelToAzureConfig({
389
+ modelName: 'gpt-4-turbo',
390
+ modelGroupMap,
391
+ groupMap,
392
+ });
393
+ expect(azureOptions).toEqual({
394
+ azureOpenAIApiKey: 'prod-1234',
395
+ azureOpenAIApiInstanceName: 'prod-instance',
396
+ azureOpenAIApiDeploymentName: 'gpt-4-turbo-deployment',
397
+ azureOpenAIApiVersion: '2023-11-06',
398
+ });
399
+ expect(baseURL).toBe('https://prod.example.com');
400
+ expect(headers).toEqual({
401
+ 'X-Custom-Header': 'value',
402
+ });
403
+ });
404
+
405
+ it('should not allow duplicate group names', () => {
406
+ const duplicateGroups: TAzureGroups = [
407
+ {
408
+ group: 'us-east',
409
+ apiKey: 'prod-1234',
410
+ instanceName: 'prod-instance',
411
+ deploymentName: 'v1-deployment',
412
+ version: '2023-12-31',
413
+ baseURL: 'https://prod.example.com',
414
+ additionalHeaders: {
415
+ 'X-Custom-Header': 'value',
416
+ },
417
+ models: {
418
+ 'gpt-4-turbo': {
419
+ deploymentName: 'gpt-4-turbo-deployment',
420
+ version: '2023-11-06',
421
+ },
422
+ },
423
+ },
424
+ {
425
+ group: 'us-east',
426
+ apiKey: 'prod-1234',
427
+ instanceName: 'prod-instance',
428
+ deploymentName: 'v1-deployment',
429
+ version: '2023-12-31',
430
+ baseURL: 'https://prod.example.com',
431
+ additionalHeaders: {
432
+ 'X-Custom-Header': 'value',
433
+ },
434
+ models: {
435
+ 'gpt-5-turbo': {
436
+ deploymentName: 'gpt-4-turbo-deployment',
437
+ version: '2023-11-06',
438
+ },
439
+ },
440
+ },
441
+ ];
442
+ const { isValid } = validateAzureGroups(duplicateGroups);
443
+ expect(isValid).toBe(false);
444
+ });
445
+ it('should not allow duplicate models across groups', () => {
446
+ const duplicateGroups: TAzureGroups = [
447
+ {
448
+ group: 'us-east',
449
+ apiKey: 'prod-1234',
450
+ instanceName: 'prod-instance',
451
+ deploymentName: 'v1-deployment',
452
+ version: '2023-12-31',
453
+ baseURL: 'https://prod.example.com',
454
+ additionalHeaders: {
455
+ 'X-Custom-Header': 'value',
456
+ },
457
+ models: {
458
+ 'gpt-4-turbo': {
459
+ deploymentName: 'gpt-4-turbo-deployment',
460
+ version: '2023-11-06',
461
+ },
462
+ },
463
+ },
464
+ {
465
+ group: 'us-west',
466
+ apiKey: 'prod-1234',
467
+ instanceName: 'prod-instance',
468
+ deploymentName: 'v1-deployment',
469
+ version: '2023-12-31',
470
+ baseURL: 'https://prod.example.com',
471
+ additionalHeaders: {
472
+ 'X-Custom-Header': 'value',
473
+ },
474
+ models: {
475
+ 'gpt-4-turbo': {
476
+ deploymentName: 'gpt-4-turbo-deployment',
477
+ version: '2023-11-06',
478
+ },
479
+ },
480
+ },
481
+ ];
482
+ const { isValid } = validateAzureGroups(duplicateGroups);
483
+ expect(isValid).toBe(false);
484
+ });
485
+
486
+ it('should throw an error if environment variables are set but not configured', () => {
487
+ const validConfigs: TAzureGroups = [
488
+ {
489
+ group: 'librechat-westus',
490
+ apiKey: '${WESTUS_API_KEY}',
491
+ instanceName: 'librechat-westus',
492
+ version: '2023-12-01-preview',
493
+ models: {
494
+ 'gpt-4-vision-preview': {
495
+ deploymentName: 'gpt-4-vision-preview',
496
+ version: '2024-02-15-preview',
497
+ },
498
+ 'gpt-3.5-turbo': {
499
+ deploymentName: 'gpt-35-turbo',
500
+ },
501
+ 'gpt-3.5-turbo-1106': {
502
+ deploymentName: 'gpt-35-turbo-1106',
503
+ },
504
+ 'gpt-4': {
505
+ deploymentName: 'gpt-4',
506
+ },
507
+ 'gpt-4-1106-preview': {
508
+ deploymentName: 'gpt-4-1106-preview',
509
+ },
510
+ },
511
+ },
512
+ {
513
+ group: 'librechat-eastus',
514
+ apiKey: '${EASTUS_API_KEY}',
515
+ instanceName: 'librechat-eastus',
516
+ deploymentName: 'gpt-4-turbo',
517
+ version: '2024-02-15-preview',
518
+ models: {
519
+ 'gpt-4-turbo': true,
520
+ },
521
+ },
522
+ ];
523
+ const { isValid, modelGroupMap, groupMap } = validateAzureGroups(validConfigs);
524
+ expect(isValid).toBe(true);
525
+ expect(() =>
526
+ mapModelToAzureConfig({ modelName: 'gpt-4-turbo', modelGroupMap, groupMap }),
527
+ ).toThrow();
528
+ });
529
+
530
+ it('should list all expected models in both modelGroupMap and groupMap', () => {
531
+ process.env.WESTUS_API_KEY = 'westus-key';
532
+ process.env.EASTUS_API_KEY = 'eastus-key';
533
+ process.env.AZURE_MISTRAL_API_KEY = 'mistral-key';
534
+ process.env.AZURE_LLAMA2_70B_API_KEY = 'llama-key';
535
+
536
+ const validConfigs: TAzureGroups = [
537
+ {
538
+ group: 'librechat-westus',
539
+ apiKey: '${WESTUS_API_KEY}',
540
+ instanceName: 'librechat-westus',
541
+ version: '2023-12-01-preview',
542
+ models: {
543
+ 'gpt-4-vision-preview': {
544
+ deploymentName: 'gpt-4-vision-preview',
545
+ version: '2024-02-15-preview',
546
+ },
547
+ 'gpt-3.5-turbo': {
548
+ deploymentName: 'gpt-35-turbo',
549
+ },
550
+ 'gpt-3.5-turbo-1106': {
551
+ deploymentName: 'gpt-35-turbo-1106',
552
+ },
553
+ 'gpt-4': {
554
+ deploymentName: 'gpt-4',
555
+ },
556
+ 'gpt-4-1106-preview': {
557
+ deploymentName: 'gpt-4-1106-preview',
558
+ },
559
+ },
560
+ },
561
+ {
562
+ group: 'librechat-eastus',
563
+ apiKey: '${EASTUS_API_KEY}',
564
+ instanceName: 'librechat-eastus',
565
+ deploymentName: 'gpt-4-turbo',
566
+ version: '2024-02-15-preview',
567
+ models: {
568
+ 'gpt-4-turbo': true,
569
+ },
570
+ baseURL: 'https://eastus.example.com',
571
+ additionalHeaders: {
572
+ 'x-api-key': 'x-api-key-value',
573
+ },
574
+ },
575
+ {
576
+ group: 'mistral-inference',
577
+ apiKey: '${AZURE_MISTRAL_API_KEY}',
578
+ baseURL:
579
+ 'https://Mistral-large-vnpet-serverless.region.inference.ai.azure.com/v1/chat/completions',
580
+ serverless: true,
581
+ models: {
582
+ 'mistral-large': true,
583
+ },
584
+ },
585
+ {
586
+ group: 'llama-70b-chat',
587
+ apiKey: '${AZURE_LLAMA2_70B_API_KEY}',
588
+ baseURL:
589
+ 'https://Llama-2-70b-chat-qmvyb-serverless.region.inference.ai.azure.com/v1/chat/completions',
590
+ serverless: true,
591
+ models: {
592
+ 'llama-70b-chat': true,
593
+ },
594
+ },
595
+ ];
596
+ const { isValid, modelGroupMap, groupMap, modelNames } = validateAzureGroups(validConfigs);
597
+ expect(isValid).toBe(true);
598
+ expect(modelNames).toEqual([
599
+ 'gpt-4-vision-preview',
600
+ 'gpt-3.5-turbo',
601
+ 'gpt-3.5-turbo-1106',
602
+ 'gpt-4',
603
+ 'gpt-4-1106-preview',
604
+ 'gpt-4-turbo',
605
+ 'mistral-large',
606
+ 'llama-70b-chat',
607
+ ]);
608
+
609
+ // Check modelGroupMap
610
+ modelNames.forEach((modelName) => {
611
+ expect(modelGroupMap[modelName]).toBeDefined();
612
+ });
613
+
614
+ // Check groupMap for 'librechat-westus'
615
+ expect(groupMap).toHaveProperty('librechat-westus');
616
+ expect(groupMap['librechat-westus']).toEqual(
617
+ expect.objectContaining({
618
+ apiKey: '${WESTUS_API_KEY}',
619
+ instanceName: 'librechat-westus',
620
+ version: '2023-12-01-preview',
621
+ models: expect.objectContaining({
622
+ 'gpt-4-vision-preview': expect.any(Object),
623
+ 'gpt-3.5-turbo': expect.any(Object),
624
+ 'gpt-3.5-turbo-1106': expect.any(Object),
625
+ 'gpt-4': expect.any(Object),
626
+ 'gpt-4-1106-preview': expect.any(Object),
627
+ }),
628
+ }),
629
+ );
630
+
631
+ // Check groupMap for 'librechat-eastus'
632
+ expect(groupMap).toHaveProperty('librechat-eastus');
633
+ expect(groupMap['librechat-eastus']).toEqual(
634
+ expect.objectContaining({
635
+ apiKey: '${EASTUS_API_KEY}',
636
+ instanceName: 'librechat-eastus',
637
+ deploymentName: 'gpt-4-turbo',
638
+ version: '2024-02-15-preview',
639
+ models: expect.objectContaining({
640
+ 'gpt-4-turbo': true,
641
+ }),
642
+ }),
643
+ );
644
+
645
+ // Check groupMap for 'mistral-inference'
646
+ expect(groupMap).toHaveProperty('mistral-inference');
647
+ expect(groupMap['mistral-inference']).toEqual(
648
+ expect.objectContaining({
649
+ apiKey: '${AZURE_MISTRAL_API_KEY}',
650
+ baseURL:
651
+ 'https://Mistral-large-vnpet-serverless.region.inference.ai.azure.com/v1/chat/completions',
652
+ serverless: true,
653
+ models: expect.objectContaining({
654
+ 'mistral-large': true,
655
+ }),
656
+ }),
657
+ );
658
+
659
+ // Check groupMap for 'llama-70b-chat'
660
+ expect(groupMap).toHaveProperty('llama-70b-chat');
661
+ expect(groupMap['llama-70b-chat']).toEqual(
662
+ expect.objectContaining({
663
+ apiKey: '${AZURE_LLAMA2_70B_API_KEY}',
664
+ baseURL:
665
+ 'https://Llama-2-70b-chat-qmvyb-serverless.region.inference.ai.azure.com/v1/chat/completions',
666
+ serverless: true,
667
+ models: expect.objectContaining({
668
+ 'llama-70b-chat': true,
669
+ }),
670
+ }),
671
+ );
672
+
673
+ const { azureOptions: azureOptions1 } = mapModelToAzureConfig({
674
+ modelName: 'gpt-4-vision-preview',
675
+ modelGroupMap,
676
+ groupMap,
677
+ });
678
+ expect(azureOptions1).toEqual({
679
+ azureOpenAIApiKey: 'westus-key',
680
+ azureOpenAIApiInstanceName: 'librechat-westus',
681
+ azureOpenAIApiDeploymentName: 'gpt-4-vision-preview',
682
+ azureOpenAIApiVersion: '2024-02-15-preview',
683
+ });
684
+
685
+ const {
686
+ azureOptions: azureOptions2,
687
+ baseURL,
688
+ headers,
689
+ } = mapModelToAzureConfig({
690
+ modelName: 'gpt-4-turbo',
691
+ modelGroupMap,
692
+ groupMap,
693
+ });
694
+ expect(azureOptions2).toEqual({
695
+ azureOpenAIApiKey: 'eastus-key',
696
+ azureOpenAIApiInstanceName: 'librechat-eastus',
697
+ azureOpenAIApiDeploymentName: 'gpt-4-turbo',
698
+ azureOpenAIApiVersion: '2024-02-15-preview',
699
+ });
700
+ expect(baseURL).toBe('https://eastus.example.com');
701
+ expect(headers).toEqual({
702
+ 'x-api-key': 'x-api-key-value',
703
+ });
704
+
705
+ const { azureOptions: azureOptions3 } = mapModelToAzureConfig({
706
+ modelName: 'gpt-4',
707
+ modelGroupMap,
708
+ groupMap,
709
+ });
710
+ expect(azureOptions3).toEqual({
711
+ azureOpenAIApiKey: 'westus-key',
712
+ azureOpenAIApiInstanceName: 'librechat-westus',
713
+ azureOpenAIApiDeploymentName: 'gpt-4',
714
+ azureOpenAIApiVersion: '2023-12-01-preview',
715
+ });
716
+
717
+ const { azureOptions: azureOptions4 } = mapModelToAzureConfig({
718
+ modelName: 'gpt-3.5-turbo',
719
+ modelGroupMap,
720
+ groupMap,
721
+ });
722
+ expect(azureOptions4).toEqual({
723
+ azureOpenAIApiKey: 'westus-key',
724
+ azureOpenAIApiInstanceName: 'librechat-westus',
725
+ azureOpenAIApiDeploymentName: 'gpt-35-turbo',
726
+ azureOpenAIApiVersion: '2023-12-01-preview',
727
+ });
728
+
729
+ const { azureOptions: azureOptions5 } = mapModelToAzureConfig({
730
+ modelName: 'gpt-3.5-turbo-1106',
731
+ modelGroupMap,
732
+ groupMap,
733
+ });
734
+ expect(azureOptions5).toEqual({
735
+ azureOpenAIApiKey: 'westus-key',
736
+ azureOpenAIApiInstanceName: 'librechat-westus',
737
+ azureOpenAIApiDeploymentName: 'gpt-35-turbo-1106',
738
+ azureOpenAIApiVersion: '2023-12-01-preview',
739
+ });
740
+
741
+ const { azureOptions: azureOptions6 } = mapModelToAzureConfig({
742
+ modelName: 'gpt-4-1106-preview',
743
+ modelGroupMap,
744
+ groupMap,
745
+ });
746
+ expect(azureOptions6).toEqual({
747
+ azureOpenAIApiKey: 'westus-key',
748
+ azureOpenAIApiInstanceName: 'librechat-westus',
749
+ azureOpenAIApiDeploymentName: 'gpt-4-1106-preview',
750
+ azureOpenAIApiVersion: '2023-12-01-preview',
751
+ });
752
+
753
+ const {
754
+ azureOptions: azureOptions7,
755
+ serverless: serverlessMistral,
756
+ baseURL: mistralEndpoint,
757
+ } = mapModelToAzureConfig({
758
+ modelName: 'mistral-large',
759
+ modelGroupMap,
760
+ groupMap,
761
+ });
762
+ expect(serverlessMistral).toBe(true);
763
+ expect(mistralEndpoint).toBe(
764
+ 'https://Mistral-large-vnpet-serverless.region.inference.ai.azure.com/v1/chat/completions',
765
+ );
766
+ expect(azureOptions7).toEqual({
767
+ azureOpenAIApiKey: 'mistral-key',
768
+ });
769
+
770
+ const {
771
+ azureOptions: azureOptions8,
772
+ serverless: serverlessLlama,
773
+ baseURL: llamaEndpoint,
774
+ } = mapModelToAzureConfig({
775
+ modelName: 'llama-70b-chat',
776
+ modelGroupMap,
777
+ groupMap,
778
+ });
779
+ expect(serverlessLlama).toBe(true);
780
+ expect(llamaEndpoint).toBe(
781
+ 'https://Llama-2-70b-chat-qmvyb-serverless.region.inference.ai.azure.com/v1/chat/completions',
782
+ );
783
+ expect(azureOptions8).toEqual({
784
+ azureOpenAIApiKey: 'llama-key',
785
+ });
786
+ });
787
+ });