@@ -237,6 +237,30 @@ func TestCallOpenAIProxy(t *testing.T) {
237
237
238
238
expStatus : http .StatusOK ,
239
239
},
240
+ {
241
+ name : "openai - empty model" ,
242
+
243
+ settings : Settings {
244
+ OpenAI : OpenAISettings {
245
+ OrganizationID : "myOrg" ,
246
+ Provider : openAIProviderOpenAI ,
247
+ },
248
+ },
249
+ apiKey : "abcd1234" ,
250
+
251
+ method : http .MethodPost ,
252
+ path : "/openai/v1/chat/completions" ,
253
+ body : []byte (`{"messages": [{"content":"some stuff"}]}` ),
254
+
255
+ expReqHeaders : http.Header {
256
+ "Authorization" : {"Bearer abcd1234" },
257
+ "OpenAI-Organization" : {"myOrg" },
258
+ },
259
+ expReqPath : "/v1/chat/completions" ,
260
+ expReqBody : []byte (`{"model": "gpt-3.5-turbo", "messages": [{"content":"some stuff"}]}` ),
261
+
262
+ expStatus : http .StatusOK ,
263
+ },
240
264
{
241
265
name : "openai - streaming" ,
242
266
@@ -265,6 +289,34 @@ func TestCallOpenAIProxy(t *testing.T) {
265
289
// newlines (required by the SSE spec) are escaped.
266
290
expBody : []byte ("data: {\" id\" :\" \" ,\" object\" :\" \" ,\" created\" :0,\" model\" :\" \" ,\" choices\" :null,\" system_fingerprint\" :\" \" }\n \n data: [DONE]\n \n " ),
267
291
},
292
+ {
293
+ name : "openai - streaming - empty model" ,
294
+
295
+ settings : Settings {
296
+ OpenAI : OpenAISettings {
297
+ OrganizationID : "myOrg" ,
298
+ Provider : openAIProviderOpenAI ,
299
+ },
300
+ },
301
+ apiKey : "abcd1234" ,
302
+
303
+ method : http .MethodPost ,
304
+ path : "/openai/v1/chat/completions" ,
305
+ body : []byte (`{"stream": true, "messages": [{"content":"some stuff"}]}` ),
306
+
307
+ expReqHeaders : http.Header {
308
+ "Authorization" : {"Bearer abcd1234" },
309
+ "OpenAI-Organization" : {"myOrg" },
310
+ },
311
+ expReqPath : "/v1/chat/completions" ,
312
+ expReqBody : []byte (`{"model": "gpt-3.5-turbo", "stream": true, "messages": [{"content":"some stuff"}]}` ),
313
+
314
+ expStatus : http .StatusOK ,
315
+
316
+ // We need to use regular strings rather than raw strings here otherwise the double
317
+ // newlines (required by the SSE spec) are escaped.
318
+ expBody : []byte ("data: {\" id\" :\" \" ,\" object\" :\" \" ,\" created\" :0,\" model\" :\" \" ,\" choices\" :null,\" system_fingerprint\" :\" \" }\n \n data: [DONE]\n \n " ),
319
+ },
268
320
{
269
321
name : "azure" ,
270
322
@@ -293,6 +345,62 @@ func TestCallOpenAIProxy(t *testing.T) {
293
345
294
346
expStatus : http .StatusOK ,
295
347
},
348
+ {
349
+ name : "azure - abstract model" ,
350
+
351
+ settings : Settings {
352
+ OpenAI : OpenAISettings {
353
+ OrganizationID : "myOrg" ,
354
+ Provider : openAIProviderAzure ,
355
+ AzureMapping : [][]string {
356
+ {"gpt-3.5-turbo" , "gpt-35-turbo" },
357
+ },
358
+ },
359
+ },
360
+
361
+ apiKey : "abcd1234" ,
362
+
363
+ method : http .MethodPost ,
364
+ path : "/openai/v1/chat/completions" ,
365
+ body : []byte (`{"model": "base", "messages": [{"content":"some stuff"}]}` ),
366
+
367
+ expReqHeaders : http.Header {
368
+ "api-key" : {"abcd1234" },
369
+ },
370
+ expReqPath : "/openai/deployments/gpt-35-turbo/chat/completions" ,
371
+ // the 'model' field should have been removed.
372
+ expReqBody : []byte (`{"messages":[{"content":"some stuff"}]}` ),
373
+
374
+ expStatus : http .StatusOK ,
375
+ },
376
+ {
377
+ name : "azure - empty model" ,
378
+
379
+ settings : Settings {
380
+ OpenAI : OpenAISettings {
381
+ OrganizationID : "myOrg" ,
382
+ Provider : openAIProviderAzure ,
383
+ AzureMapping : [][]string {
384
+ {"gpt-3.5-turbo" , "gpt-35-turbo" },
385
+ },
386
+ },
387
+ },
388
+
389
+ apiKey : "abcd1234" ,
390
+
391
+ method : http .MethodPost ,
392
+ path : "/openai/v1/chat/completions" ,
393
+ body : []byte (`{"messages": [{"content":"some stuff"}]}` ),
394
+
395
+ expReqHeaders : http.Header {
396
+ "api-key" : {"abcd1234" },
397
+ },
398
+ expReqPath : "/openai/deployments/gpt-35-turbo/chat/completions" ,
399
+ // the 'model' field should have been removed.
400
+ expReqBody : []byte (`{"messages":[{"content":"some stuff"}]}` ),
401
+
402
+ expStatus : http .StatusOK ,
403
+ },
296
404
{
297
405
name : "azure invalid deployment" ,
298
406
@@ -310,7 +418,7 @@ func TestCallOpenAIProxy(t *testing.T) {
310
418
method : http .MethodPost ,
311
419
path : "/openai/v1/chat/completions" ,
312
420
// note no gpt-4 in AzureMapping.
313
- body : []byte (`{"model": "gpt-4", "messages": [{"content":"some stuff"}]}` ),
421
+ body : []byte (`{"model": "gpt-4-turbo ", "messages": [{"content":"some stuff"}]}` ),
314
422
315
423
expNilRequest : true ,
316
424
@@ -364,6 +472,31 @@ func TestCallOpenAIProxy(t *testing.T) {
364
472
expReqPath : "/llm/openai/v1/chat/completions" ,
365
473
expReqBody : []byte (`{"model": "gpt-3.5-turbo", "messages": [{"content":"some stuff"]}}` ),
366
474
475
+ expStatus : http .StatusOK ,
476
+ },
477
+ {
478
+ name : "grafana-managed llm gateway - empty model" ,
479
+
480
+ settings : Settings {
481
+ Tenant : "123" ,
482
+ GrafanaComAPIKey : "abcd1234" ,
483
+ OpenAI : OpenAISettings {
484
+ Provider : openAIProviderGrafana ,
485
+ },
486
+ },
487
+ apiKey : "abcd1234" ,
488
+
489
+ method : http .MethodPost ,
490
+ path : "/openai/v1/chat/completions" ,
491
+ body : []byte (`{"messages": [{"content":"some stuff"}]}` ),
492
+
493
+ expReqHeaders : http.Header {
494
+ "Authorization" : {"Bearer 123:abcd1234" },
495
+ "X-Scope-OrgID" : {"123" },
496
+ },
497
+ expReqPath : "/llm/openai/v1/chat/completions" ,
498
+ expReqBody : []byte (`{"model": "gpt-3.5-turbo", "messages": [{"content":"some stuff"]}}` ),
499
+
367
500
expStatus : http .StatusOK ,
368
501
},
369
502
} {
0 commit comments