107
107
@validate_custom_event_count (count = 3 )
108
108
@background_task ()
109
109
def test_chat_completion_invalid_request_error_no_model (set_trace_info , sync_openai_client ):
110
+ set_trace_info ()
110
111
with pytest .raises (TypeError ):
111
- set_trace_info ()
112
112
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
113
113
with WithLlmCustomAttributes ({"context" : "attr" }):
114
114
sync_openai_client .chat .completions .create (
@@ -134,8 +134,8 @@ def test_chat_completion_invalid_request_error_no_model(set_trace_info, sync_ope
134
134
@validate_custom_event_count (count = 3 )
135
135
@background_task ()
136
136
def test_chat_completion_invalid_request_error_no_model_no_content (set_trace_info , sync_openai_client ):
137
+ set_trace_info ()
137
138
with pytest .raises (TypeError ):
138
- set_trace_info ()
139
139
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
140
140
sync_openai_client .chat .completions .create (
141
141
messages = _test_openai_chat_completion_messages , temperature = 0.7 , max_tokens = 100
@@ -160,8 +160,8 @@ def test_chat_completion_invalid_request_error_no_model_no_content(set_trace_inf
160
160
@validate_custom_event_count (count = 3 )
161
161
@background_task ()
162
162
def test_chat_completion_invalid_request_error_no_model_async (loop , set_trace_info , async_openai_client ):
163
+ set_trace_info ()
163
164
with pytest .raises (TypeError ):
164
- set_trace_info ()
165
165
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
166
166
167
167
with WithLlmCustomAttributes ({"context" : "attr" }):
@@ -190,8 +190,8 @@ def test_chat_completion_invalid_request_error_no_model_async(loop, set_trace_in
190
190
@validate_custom_event_count (count = 3 )
191
191
@background_task ()
192
192
def test_chat_completion_invalid_request_error_no_model_async_no_content (loop , set_trace_info , async_openai_client ):
193
+ set_trace_info ()
193
194
with pytest .raises (TypeError ):
194
- set_trace_info ()
195
195
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
196
196
loop .run_until_complete (
197
197
async_openai_client .chat .completions .create (
@@ -255,8 +255,8 @@ def test_chat_completion_invalid_request_error_no_model_async_no_content(loop, s
255
255
@validate_custom_event_count (count = 2 )
256
256
@background_task ()
257
257
def test_chat_completion_invalid_request_error_invalid_model (set_trace_info , sync_openai_client ):
258
+ set_trace_info ()
258
259
with pytest .raises (openai .NotFoundError ):
259
- set_trace_info ()
260
260
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
261
261
sync_openai_client .chat .completions .create (
262
262
model = "does-not-exist" ,
@@ -286,8 +286,8 @@ def test_chat_completion_invalid_request_error_invalid_model(set_trace_info, syn
286
286
@validate_custom_event_count (count = 2 )
287
287
@background_task ()
288
288
def test_chat_completion_invalid_request_error_invalid_model_with_token_count (set_trace_info , sync_openai_client ):
289
+ set_trace_info ()
289
290
with pytest .raises (openai .NotFoundError ):
290
- set_trace_info ()
291
291
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
292
292
sync_openai_client .chat .completions .create (
293
293
model = "does-not-exist" ,
@@ -316,8 +316,8 @@ def test_chat_completion_invalid_request_error_invalid_model_with_token_count(se
316
316
@validate_custom_event_count (count = 2 )
317
317
@background_task ()
318
318
def test_chat_completion_invalid_request_error_invalid_model_async (loop , set_trace_info , async_openai_client ):
319
+ set_trace_info ()
319
320
with pytest .raises (openai .NotFoundError ):
320
- set_trace_info ()
321
321
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
322
322
loop .run_until_complete (
323
323
async_openai_client .chat .completions .create (
@@ -351,8 +351,8 @@ def test_chat_completion_invalid_request_error_invalid_model_async(loop, set_tra
351
351
def test_chat_completion_invalid_request_error_invalid_model_with_token_count_async (
352
352
loop , set_trace_info , async_openai_client
353
353
):
354
+ set_trace_info ()
354
355
with pytest .raises (openai .NotFoundError ):
355
- set_trace_info ()
356
356
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
357
357
loop .run_until_complete (
358
358
async_openai_client .chat .completions .create (
@@ -419,9 +419,9 @@ def test_chat_completion_invalid_request_error_invalid_model_with_token_count_as
419
419
@validate_custom_event_count (count = 2 )
420
420
@background_task ()
421
421
def test_chat_completion_wrong_api_key_error (monkeypatch , set_trace_info , sync_openai_client ):
422
+ set_trace_info ()
423
+ monkeypatch .setattr (sync_openai_client , "api_key" , "DEADBEEF" )
422
424
with pytest .raises (openai .AuthenticationError ):
423
- set_trace_info ()
424
- monkeypatch .setattr (sync_openai_client , "api_key" , "DEADBEEF" )
425
425
sync_openai_client .chat .completions .create (
426
426
model = "gpt-3.5-turbo" ,
427
427
messages = ({"role" : "user" , "content" : "Invalid API key." },),
@@ -451,9 +451,9 @@ def test_chat_completion_wrong_api_key_error(monkeypatch, set_trace_info, sync_o
451
451
@validate_custom_event_count (count = 2 )
452
452
@background_task ()
453
453
def test_chat_completion_wrong_api_key_error_async (loop , monkeypatch , set_trace_info , async_openai_client ):
454
+ set_trace_info ()
455
+ monkeypatch .setattr (async_openai_client , "api_key" , "DEADBEEF" )
454
456
with pytest .raises (openai .AuthenticationError ):
455
- set_trace_info ()
456
- monkeypatch .setattr (async_openai_client , "api_key" , "DEADBEEF" )
457
457
loop .run_until_complete (
458
458
async_openai_client .chat .completions .create (
459
459
model = "gpt-3.5-turbo" ,
@@ -482,8 +482,8 @@ def test_chat_completion_wrong_api_key_error_async(loop, monkeypatch, set_trace_
482
482
@validate_custom_event_count (count = 3 )
483
483
@background_task ()
484
484
def test_chat_completion_invalid_request_error_no_model_with_raw_response (set_trace_info , sync_openai_client ):
485
+ set_trace_info ()
485
486
with pytest .raises (TypeError ):
486
- set_trace_info ()
487
487
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
488
488
sync_openai_client .chat .completions .with_raw_response .create (
489
489
messages = _test_openai_chat_completion_messages , temperature = 0.7 , max_tokens = 100
@@ -511,8 +511,8 @@ def test_chat_completion_invalid_request_error_no_model_with_raw_response(set_tr
511
511
def test_chat_completion_invalid_request_error_no_model_no_content_with_raw_response (
512
512
set_trace_info , sync_openai_client
513
513
):
514
+ set_trace_info ()
514
515
with pytest .raises (TypeError ):
515
- set_trace_info ()
516
516
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
517
517
sync_openai_client .chat .completions .with_raw_response .create (
518
518
messages = _test_openai_chat_completion_messages , temperature = 0.7 , max_tokens = 100
@@ -539,8 +539,8 @@ def test_chat_completion_invalid_request_error_no_model_no_content_with_raw_resp
539
539
def test_chat_completion_invalid_request_error_no_model_async_with_raw_response (
540
540
loop , set_trace_info , async_openai_client
541
541
):
542
+ set_trace_info ()
542
543
with pytest .raises (TypeError ):
543
- set_trace_info ()
544
544
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
545
545
loop .run_until_complete (
546
546
async_openai_client .chat .completions .with_raw_response .create (
@@ -570,8 +570,8 @@ def test_chat_completion_invalid_request_error_no_model_async_with_raw_response(
570
570
def test_chat_completion_invalid_request_error_no_model_async_no_content_with_raw_response (
571
571
loop , set_trace_info , async_openai_client
572
572
):
573
+ set_trace_info ()
573
574
with pytest .raises (TypeError ):
574
- set_trace_info ()
575
575
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
576
576
loop .run_until_complete (
577
577
async_openai_client .chat .completions .with_raw_response .create (
@@ -599,8 +599,8 @@ def test_chat_completion_invalid_request_error_no_model_async_no_content_with_ra
599
599
@validate_custom_event_count (count = 2 )
600
600
@background_task ()
601
601
def test_chat_completion_invalid_request_error_invalid_model_with_raw_response (set_trace_info , sync_openai_client ):
602
+ set_trace_info ()
602
603
with pytest .raises (openai .NotFoundError ):
603
- set_trace_info ()
604
604
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
605
605
sync_openai_client .chat .completions .with_raw_response .create (
606
606
model = "does-not-exist" ,
@@ -632,8 +632,8 @@ def test_chat_completion_invalid_request_error_invalid_model_with_raw_response(s
632
632
def test_chat_completion_invalid_request_error_invalid_model_with_token_count_with_raw_response (
633
633
set_trace_info , sync_openai_client
634
634
):
635
+ set_trace_info ()
635
636
with pytest .raises (openai .NotFoundError ):
636
- set_trace_info ()
637
637
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
638
638
sync_openai_client .chat .completions .with_raw_response .create (
639
639
model = "does-not-exist" ,
@@ -664,8 +664,8 @@ def test_chat_completion_invalid_request_error_invalid_model_with_token_count_wi
664
664
def test_chat_completion_invalid_request_error_invalid_model_async_with_raw_response (
665
665
loop , set_trace_info , async_openai_client
666
666
):
667
+ set_trace_info ()
667
668
with pytest .raises (openai .NotFoundError ):
668
- set_trace_info ()
669
669
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
670
670
loop .run_until_complete (
671
671
async_openai_client .chat .completions .with_raw_response .create (
@@ -699,8 +699,8 @@ def test_chat_completion_invalid_request_error_invalid_model_async_with_raw_resp
699
699
def test_chat_completion_invalid_request_error_invalid_model_with_token_count_async_with_raw_response (
700
700
loop , set_trace_info , async_openai_client
701
701
):
702
+ set_trace_info ()
702
703
with pytest .raises (openai .NotFoundError ):
703
- set_trace_info ()
704
704
add_custom_attribute ("llm.conversation_id" , "my-awesome-id" )
705
705
loop .run_until_complete (
706
706
async_openai_client .chat .completions .with_raw_response .create (
@@ -733,9 +733,9 @@ def test_chat_completion_invalid_request_error_invalid_model_with_token_count_as
733
733
@validate_custom_event_count (count = 2 )
734
734
@background_task ()
735
735
def test_chat_completion_wrong_api_key_error_with_raw_response (monkeypatch , set_trace_info , sync_openai_client ):
736
+ set_trace_info ()
737
+ monkeypatch .setattr (sync_openai_client , "api_key" , "DEADBEEF" )
736
738
with pytest .raises (openai .AuthenticationError ):
737
- set_trace_info ()
738
- monkeypatch .setattr (sync_openai_client , "api_key" , "DEADBEEF" )
739
739
sync_openai_client .chat .completions .with_raw_response .create (
740
740
model = "gpt-3.5-turbo" ,
741
741
messages = ({"role" : "user" , "content" : "Invalid API key." },),
@@ -767,9 +767,9 @@ def test_chat_completion_wrong_api_key_error_with_raw_response(monkeypatch, set_
767
767
def test_chat_completion_wrong_api_key_error_async_with_raw_response (
768
768
loop , monkeypatch , set_trace_info , async_openai_client
769
769
):
770
+ set_trace_info ()
771
+ monkeypatch .setattr (async_openai_client , "api_key" , "DEADBEEF" )
770
772
with pytest .raises (openai .AuthenticationError ):
771
- set_trace_info ()
772
- monkeypatch .setattr (async_openai_client , "api_key" , "DEADBEEF" )
773
773
loop .run_until_complete (
774
774
async_openai_client .chat .completions .with_raw_response .create (
775
775
model = "gpt-3.5-turbo" ,
0 commit comments