9
9
from ddtrace .internal .utils .version import parse_version
10
10
from tests .contrib .langchain .utils import get_request_vcr
11
11
from tests .contrib .langchain .utils import long_input_text
12
+ from tests .utils import flaky
12
13
from tests .utils import override_global_config
13
14
14
15
@@ -24,6 +25,7 @@ def request_vcr():
24
25
yield get_request_vcr (subdirectory_name = "langchain" )
25
26
26
27
28
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
27
29
@pytest .mark .parametrize ("ddtrace_config_langchain" , [dict (logs_enabled = True , log_prompt_completion_sample_rate = 1.0 )])
28
30
def test_global_tags (ddtrace_config_langchain , langchain , request_vcr , mock_metrics , mock_logs , mock_tracer ):
29
31
"""
@@ -74,6 +76,7 @@ def test_global_tags(ddtrace_config_langchain, langchain, request_vcr, mock_metr
74
76
)
75
77
76
78
79
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
77
80
@pytest .mark .skipif (PY39 , reason = "Python 3.10+ specific test" )
78
81
@pytest .mark .snapshot (ignores = ["metrics.langchain.tokens.total_cost" , "resource" ])
79
82
def test_openai_llm_sync (langchain , request_vcr ):
@@ -82,6 +85,7 @@ def test_openai_llm_sync(langchain, request_vcr):
82
85
llm ("Can you explain what Descartes meant by 'I think, therefore I am'?" )
83
86
84
87
88
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
85
89
@pytest .mark .skipif (not PY39 , reason = "Python 3.9 specific test" )
86
90
@pytest .mark .snapshot (ignores = ["metrics.langchain.tokens.total_cost" ])
87
91
def test_openai_llm_sync_39 (langchain , request_vcr ):
@@ -90,6 +94,7 @@ def test_openai_llm_sync_39(langchain, request_vcr):
90
94
llm ("Can you explain what Descartes meant by 'I think, therefore I am'?" )
91
95
92
96
97
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
93
98
@pytest .mark .skipif (PY39 , reason = "Python 3.10+ specific test" )
94
99
@pytest .mark .snapshot (ignores = ["resource" ])
95
100
def test_openai_llm_sync_multiple_prompts (langchain , request_vcr ):
@@ -103,6 +108,7 @@ def test_openai_llm_sync_multiple_prompts(langchain, request_vcr):
103
108
)
104
109
105
110
111
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
106
112
@pytest .mark .skipif (not PY39 , reason = "Python 3.9 specific test" )
107
113
@pytest .mark .snapshot
108
114
def test_openai_llm_sync_multiple_prompts_39 (langchain , request_vcr ):
@@ -116,6 +122,7 @@ def test_openai_llm_sync_multiple_prompts_39(langchain, request_vcr):
116
122
)
117
123
118
124
125
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
119
126
@pytest .mark .asyncio
120
127
@pytest .mark .snapshot (ignores = ["resource" , "langchain.request.openai.parameters.request_timeout" ])
121
128
async def test_openai_llm_async (langchain , request_vcr ):
@@ -125,6 +132,7 @@ async def test_openai_llm_async(langchain, request_vcr):
125
132
await llm .agenerate (["Which team won the 2019 NBA finals?" ])
126
133
127
134
135
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
128
136
@pytest .mark .snapshot (ignores = ["meta.error.stack" , "resource" ])
129
137
def test_openai_llm_error (langchain , request_vcr ):
130
138
import openai # Imported here because the os env OPENAI_API_KEY needs to be set via langchain fixture before import
@@ -140,13 +148,15 @@ def test_openai_llm_error(langchain, request_vcr):
140
148
llm .generate ([12345 , 123456 ])
141
149
142
150
151
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
143
152
@pytest .mark .snapshot (ignores = ["resource" ])
144
153
def test_cohere_llm_sync (langchain , request_vcr ):
145
154
llm = langchain .llms .Cohere (cohere_api_key = os .getenv ("COHERE_API_KEY" , "<not-a-real-key>" ))
146
155
with request_vcr .use_cassette ("cohere_completion_sync.yaml" ):
147
156
llm ("What is the secret Krabby Patty recipe?" )
148
157
149
158
159
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
150
160
@pytest .mark .snapshot (ignores = ["resource" ])
151
161
def test_huggingfacehub_llm_sync (langchain , request_vcr ):
152
162
llm = langchain .llms .HuggingFaceHub (
@@ -158,6 +168,7 @@ def test_huggingfacehub_llm_sync(langchain, request_vcr):
158
168
llm ("Why does Mr. Krabs have a whale daughter?" )
159
169
160
170
171
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
161
172
@pytest .mark .snapshot (ignores = ["meta.langchain.response.completions.0.text" , "resource" ])
162
173
def test_ai21_llm_sync (langchain , request_vcr ):
163
174
llm = langchain .llms .AI21 (ai21_api_key = os .getenv ("AI21_API_KEY" , "<not-a-real-key>" ))
@@ -166,6 +177,7 @@ def test_ai21_llm_sync(langchain, request_vcr):
166
177
llm ("Why does everyone in Bikini Bottom hate Plankton?" )
167
178
168
179
180
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
169
181
def test_openai_llm_metrics (langchain , request_vcr , mock_metrics , mock_logs , snapshot_tracer ):
170
182
llm = langchain .llms .OpenAI (model = "text-davinci-003" )
171
183
cassette_name = "openai_completion_sync_39.yaml" if PY39 else "openai_completion_sync.yaml"
@@ -194,6 +206,7 @@ def test_openai_llm_metrics(langchain, request_vcr, mock_metrics, mock_logs, sna
194
206
mock_logs .assert_not_called ()
195
207
196
208
209
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
197
210
@pytest .mark .parametrize (
198
211
"ddtrace_config_langchain" ,
199
212
[dict (metrics_enabled = False , logs_enabled = True , log_prompt_completion_sample_rate = 1.0 )],
@@ -227,6 +240,7 @@ def test_llm_logs(langchain, ddtrace_config_langchain, request_vcr, mock_logs, m
227
240
mock_metrics .count .assert_not_called ()
228
241
229
242
243
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
230
244
@pytest .mark .skipif (PY39 , reason = "Python 3.10+ specific test" )
231
245
@pytest .mark .snapshot (
232
246
token = "tests.contrib.langchain.test_langchain.test_openai_chat_model_call" ,
@@ -238,6 +252,7 @@ def test_openai_chat_model_sync_call(langchain, request_vcr):
238
252
chat (messages = [langchain .schema .HumanMessage (content = "When do you use 'whom' instead of 'who'?" )])
239
253
240
254
255
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
241
256
@pytest .mark .skipif (not PY39 , reason = "Python 3.9 specific test" )
242
257
@pytest .mark .snapshot (ignores = ["metrics.langchain.tokens.total_cost" ])
243
258
def test_openai_chat_model_sync_call_39 (langchain , request_vcr ):
@@ -246,6 +261,7 @@ def test_openai_chat_model_sync_call_39(langchain, request_vcr):
246
261
chat ([langchain .schema .HumanMessage (content = "When do you use 'whom' instead of 'who'?" )])
247
262
248
263
264
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
249
265
@pytest .mark .skipif (PY39 , reason = "Python 3.10+ specific test" )
250
266
@pytest .mark .snapshot (
251
267
token = "tests.contrib.langchain.test_langchain.test_openai_chat_model_generate" ,
@@ -270,6 +286,7 @@ def test_openai_chat_model_sync_generate(langchain, request_vcr):
270
286
)
271
287
272
288
289
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
273
290
@pytest .mark .skipif (not PY39 , reason = "Python 3.9 specific test" )
274
291
@pytest .mark .snapshot (ignores = ["metrics.langchain.tokens.total_cost" ])
275
292
def test_openai_chat_model_sync_generate_39 (langchain , request_vcr ):
@@ -291,6 +308,7 @@ def test_openai_chat_model_sync_generate_39(langchain, request_vcr):
291
308
)
292
309
293
310
311
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
294
312
@pytest .mark .asyncio
295
313
@pytest .mark .snapshot (
296
314
token = "tests.contrib.langchain.test_langchain.test_openai_chat_model_call" ,
@@ -302,6 +320,7 @@ async def test_openai_chat_model_async_call(langchain, request_vcr):
302
320
await chat ._call_async ([langchain .schema .HumanMessage (content = "When do you use 'whom' instead of 'who'?" )])
303
321
304
322
323
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
305
324
@pytest .mark .asyncio
306
325
@pytest .mark .snapshot (
307
326
token = "tests.contrib.langchain.test_langchain.test_openai_chat_model_generate" ,
@@ -326,6 +345,7 @@ async def test_openai_chat_model_async_generate(langchain, request_vcr):
326
345
)
327
346
328
347
348
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
329
349
def test_chat_model_metrics (langchain , request_vcr , mock_metrics , mock_logs , snapshot_tracer ):
330
350
chat = langchain .chat_models .ChatOpenAI (temperature = 0 , max_tokens = 256 )
331
351
cassette_name = "openai_chat_completion_sync_call_39.yaml" if PY39 else "openai_chat_completion_sync_call.yaml"
@@ -354,6 +374,7 @@ def test_chat_model_metrics(langchain, request_vcr, mock_metrics, mock_logs, sna
354
374
mock_logs .assert_not_called ()
355
375
356
376
377
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
357
378
@pytest .mark .parametrize (
358
379
"ddtrace_config_langchain" ,
359
380
[dict (metrics_enabled = False , logs_enabled = True , log_prompt_completion_sample_rate = 1.0 )],
@@ -387,6 +408,7 @@ def test_chat_model_logs(langchain, ddtrace_config_langchain, request_vcr, mock_
387
408
mock_metrics .count .assert_not_called ()
388
409
389
410
411
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
390
412
@pytest .mark .snapshot
391
413
def test_openai_embedding_query (langchain , request_vcr ):
392
414
embeddings = langchain .embeddings .OpenAIEmbeddings ()
@@ -395,6 +417,7 @@ def test_openai_embedding_query(langchain, request_vcr):
395
417
embeddings .embed_query ("this is a test query." )
396
418
397
419
420
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
398
421
@pytest .mark .skip (reason = "Tiktoken request to get model encodings cannot be made in CI" )
399
422
@pytest .mark .snapshot
400
423
def test_openai_embedding_document (langchain , request_vcr ):
@@ -416,6 +439,7 @@ def test_fake_embedding_document(langchain):
416
439
embeddings .embed_documents (texts = ["foo" , "bar" ])
417
440
418
441
442
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
419
443
def test_openai_embedding_metrics (langchain , request_vcr , mock_metrics , mock_logs , snapshot_tracer ):
420
444
embeddings = langchain .embeddings .OpenAIEmbeddings ()
421
445
cassette_name = "openai_embedding_query_39.yaml" if PY39 else "openai_embedding_query.yaml"
@@ -438,6 +462,7 @@ def test_openai_embedding_metrics(langchain, request_vcr, mock_metrics, mock_log
438
462
mock_logs .assert_not_called ()
439
463
440
464
465
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
441
466
@pytest .mark .parametrize (
442
467
"ddtrace_config_langchain" ,
443
468
[dict (metrics_enabled = False , logs_enabled = True , log_prompt_completion_sample_rate = 1.0 )],
@@ -470,6 +495,7 @@ def test_embedding_logs(langchain, ddtrace_config_langchain, request_vcr, mock_l
470
495
mock_metrics .count .assert_not_called ()
471
496
472
497
498
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
473
499
@pytest .mark .snapshot (
474
500
token = "tests.contrib.langchain.test_langchain.test_openai_math_chain" ,
475
501
ignores = ["metrics.langchain.tokens.total_cost" , "resource" ],
@@ -485,6 +511,7 @@ def test_openai_math_chain_sync(langchain, request_vcr):
485
511
chain .run ("what is two raised to the fifty-fourth power?" )
486
512
487
513
514
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
488
515
@pytest .mark .asyncio
489
516
@pytest .mark .snapshot (
490
517
token = "tests.contrib.langchain.test_langchain.test_openai_math_chain" ,
@@ -500,6 +527,7 @@ async def test_openai_math_chain_async(langchain, request_vcr):
500
527
await chain .acall ("what is two raised to the fifty-fourth power?" )
501
528
502
529
530
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
503
531
@pytest .mark .snapshot (token = "tests.contrib.langchain.test_langchain.test_cohere_math_chain" )
504
532
def test_cohere_math_chain_sync (langchain , request_vcr ):
505
533
"""
@@ -513,6 +541,7 @@ def test_cohere_math_chain_sync(langchain, request_vcr):
513
541
chain .run ("what is thirteen raised to the .3432 power?" )
514
542
515
543
544
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
516
545
@pytest .mark .skipif (PY39 , reason = "Requires unnecessary cassette file for Python 3.9" )
517
546
@pytest .mark .snapshot (
518
547
token = "tests.contrib.langchain.test_langchain.test_openai_sequential_chain" ,
@@ -570,6 +599,7 @@ def _transform_func(inputs):
570
599
sequential_chain .run ({"text" : input_text , "style" : "a 90s rapper" })
571
600
572
601
602
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
573
603
@pytest .mark .skipif (PY39 , reason = "Requires unnecessary cassette file for Python 3.9" )
574
604
@pytest .mark .snapshot (ignores = ["langchain.tokens.total_cost" , "resource" ])
575
605
def test_openai_sequential_chain_with_multiple_llm_sync (langchain , request_vcr ):
@@ -599,6 +629,7 @@ def test_openai_sequential_chain_with_multiple_llm_sync(langchain, request_vcr):
599
629
sequential_chain .run ({"input_text" : long_input_text })
600
630
601
631
632
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
602
633
@pytest .mark .asyncio
603
634
@pytest .mark .snapshot (ignores = ["resource" ])
604
635
async def test_openai_sequential_chain_with_multiple_llm_async (langchain , request_vcr ):
@@ -627,6 +658,7 @@ async def test_openai_sequential_chain_with_multiple_llm_async(langchain, reques
627
658
await sequential_chain .acall ({"input_text" : long_input_text })
628
659
629
660
661
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
630
662
def test_openai_chain_metrics (langchain , request_vcr , mock_metrics , mock_logs , snapshot_tracer ):
631
663
chain = langchain .chains .LLMMathChain (llm = langchain .llms .OpenAI (temperature = 0 ))
632
664
cassette_name = "openai_math_chain_sync_39.yaml" if PY39 else "openai_math_chain_sync.yaml"
@@ -655,6 +687,7 @@ def test_openai_chain_metrics(langchain, request_vcr, mock_metrics, mock_logs, s
655
687
mock_logs .assert_not_called ()
656
688
657
689
690
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
658
691
@pytest .mark .parametrize (
659
692
"ddtrace_config_langchain" ,
660
693
[dict (metrics_enabled = False , logs_enabled = True , log_prompt_completion_sample_rate = 1.0 )],
@@ -763,6 +796,7 @@ def test_chat_prompt_template_does_not_parse_template(langchain, mock_tracer):
763
796
assert chain_span .get_tag ("langchain.request.prompt" ) is None
764
797
765
798
799
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
766
800
@pytest .mark .snapshot
767
801
def test_pinecone_vectorstore_similarity_search (langchain , request_vcr ):
768
802
"""
@@ -783,6 +817,7 @@ def test_pinecone_vectorstore_similarity_search(langchain, request_vcr):
783
817
vectorstore .similarity_search ("Who was Alan Turing?" , 1 )
784
818
785
819
820
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
786
821
@pytest .mark .skipif (PY39 , reason = "Cassette specific to Python 3.10+" )
787
822
@pytest .mark .snapshot
788
823
def test_pinecone_vectorstore_retrieval_chain (langchain , request_vcr ):
@@ -808,6 +843,7 @@ def test_pinecone_vectorstore_retrieval_chain(langchain, request_vcr):
808
843
qa_with_sources ("Who was Alan Turing?" )
809
844
810
845
846
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
811
847
@pytest .mark .skipif (not PY39 , reason = "Cassette specific to Python 3.9" )
812
848
@pytest .mark .snapshot
813
849
def test_pinecone_vectorstore_retrieval_chain_39 (langchain , request_vcr ):
@@ -833,6 +869,7 @@ def test_pinecone_vectorstore_retrieval_chain_39(langchain, request_vcr):
833
869
qa_with_sources ("Who was Alan Turing?" )
834
870
835
871
872
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
836
873
def test_vectorstore_similarity_search_metrics (langchain , request_vcr , mock_metrics , mock_logs , snapshot_tracer ):
837
874
import pinecone
838
875
@@ -863,6 +900,7 @@ def test_vectorstore_similarity_search_metrics(langchain, request_vcr, mock_metr
863
900
mock_logs .assert_not_called ()
864
901
865
902
903
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
866
904
@pytest .mark .parametrize (
867
905
"ddtrace_config_langchain" ,
868
906
[dict (metrics_enabled = False , logs_enabled = True , log_prompt_completion_sample_rate = 1.0 )],
@@ -924,6 +962,7 @@ def test_vectorstore_logs(langchain, ddtrace_config_langchain, request_vcr, mock
924
962
mock_metrics .count .assert_not_called ()
925
963
926
964
965
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
927
966
@pytest .mark .skipif (PY39 , reason = "Requires unnecessary cassette file for Python 3.9" )
928
967
@pytest .mark .snapshot (ignores = ["metrics.langchain.tokens.total_cost" , "resource" ])
929
968
def test_openai_integration (langchain , request_vcr , ddtrace_run_python_code_in_subprocess ):
@@ -956,6 +995,7 @@ def test_openai_integration(langchain, request_vcr, ddtrace_run_python_code_in_s
956
995
assert err == b""
957
996
958
997
998
+ @flaky (1835812000 , reason = "broken test that will be fixed soon" )
959
999
@pytest .mark .skipif (PY39 , reason = "Requires unnecessary cassette file for Python 3.9" )
960
1000
@pytest .mark .snapshot (ignores = ["metrics.langchain.tokens.total_cost" , "resource" ])
961
1001
@pytest .mark .parametrize ("schema_version" , [None , "v0" , "v1" ])
0 commit comments