File tree 8 files changed +203
-30
lines changed 8 files changed +203
-30
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ profile-background-thread:
22
22
view-profile :
23
23
poetry run snakeviz profiles/${PROFILE_NAME} .prof
24
24
25
+ TEST ?= "tests/unit_tests"
25
26
tests :
26
27
env \
27
28
-u LANGCHAIN_PROJECT \
@@ -30,16 +31,17 @@ tests:
30
31
-u LANGSMITH_TRACING \
31
32
PYTHONDEVMODE=1 \
32
33
PYTHONASYNCIODEBUG=1 \
33
- poetry run python -m pytest --disable-socket --allow-unix-socket -n auto --durations=10 tests/unit_tests
34
+ poetry run python -m pytest --disable-socket --allow-unix-socket -n auto --durations=10 ${TEST}
34
35
35
36
tests_watch :
36
37
poetry run ptw --now . -- -vv -x tests/unit_tests
37
38
39
+ INT_TEST ?= "tests/integration_tests"
38
40
integration_tests :
39
- poetry run python -m pytest -x -v --durations=10 --cov=langsmith --cov-report=term-missing --cov-report=html --cov-config=.coveragerc tests/integration_tests
41
+ poetry run python -m pytest -x -v --durations=10 --cov=langsmith --cov-report=term-missing --cov-report=html --cov-config=.coveragerc ${INT_TEST}
40
42
41
43
integration_tests_fast :
42
- poetry run python -m pytest -x -n auto --durations=10 -v --cov=langsmith --cov-report=term-missing --cov-report=html --cov-config=.coveragerc tests/integration_tests
44
+ poetry run python -m pytest -x -n auto --durations=10 -v --cov=langsmith --cov-report=term-missing --cov-report=html --cov-config=.coveragerc ${INT_TEST}
43
45
44
46
doctest :
45
47
poetry run python -m pytest -n auto -x --durations=10 --doctest-modules langsmith
Original file line number Diff line number Diff line change @@ -217,6 +217,7 @@ def _is_langchain_hosted(url: str) -> bool:
217
217
]
218
218
219
219
220
+ @functools .lru_cache (maxsize = 1 )
220
221
def _default_retry_config () -> Retry :
221
222
"""Get the default retry configuration.
222
223
@@ -7672,6 +7673,8 @@ def _convert_stored_attachments_to_attachments_dict(
7672
7673
attachments_dict = {}
7673
7674
if attachments_key in data and data [attachments_key ]:
7674
7675
for key , value in data [attachments_key ].items ():
7676
+ if not key .startswith ("attachment." ):
7677
+ continue
7675
7678
response = requests .get (value ["presigned_url" ], stream = True )
7676
7679
response .raise_for_status ()
7677
7680
reader = io .BytesIO (response .content )
Original file line number Diff line number Diff line change @@ -1583,8 +1583,12 @@ def _get_inputs_and_attachments_safe(
1583
1583
return {"args" : args , "kwargs" : kwargs }, {}
1584
1584
1585
1585
1586
- def _set_tracing_context (context : Dict [str , Any ]):
1586
+ def _set_tracing_context (context : Optional [ Dict [str , Any ]] = None ):
1587
1587
"""Set the tracing context."""
1588
+ if context is None :
1589
+ for k , v in _CONTEXT_KEYS .items ():
1590
+ v .set (None )
1591
+ return
1588
1592
for k , v in context .items ():
1589
1593
var = _CONTEXT_KEYS [k ]
1590
1594
var .set (v )
Original file line number Diff line number Diff line change 1
1
[tool .poetry ]
2
2
name = " langsmith"
3
- version = " 0.3.20 "
3
+ version = " 0.3.21 "
4
4
description = " Client library to connect to the LangSmith LLM Tracing and Evaluation Platform."
5
5
authors = [
" LangChain <[email protected] >" ]
6
6
license = " MIT"
@@ -76,6 +76,7 @@ multipart = "^1.0.0"
76
76
# TODO: remove
77
77
httpx = " >=0.23.0,<0.28.0"
78
78
rich = " ^13.9.4"
79
+ pytest-retry = " ^1.7.0"
79
80
80
81
[tool .poetry .group .lint .dependencies ]
81
82
openai = " ^1.55"
Original file line number Diff line number Diff line change @@ -925,6 +925,7 @@ def test_multipart_ingest_create_with_attachments_error(
925
925
langchain_client .multipart_ingest (create = runs_to_create , update = [])
926
926
927
927
928
+ @pytest .mark .flaky (retries = 3 )
928
929
def test_multipart_ingest_create_with_attachments (
929
930
langchain_client : Client , caplog : pytest .LogCaptureFixture
930
931
) -> None :
@@ -958,10 +959,13 @@ def test_multipart_ingest_create_with_attachments(
958
959
langchain_client .multipart_ingest (
959
960
create = runs_to_create , update = [], dangerously_allow_filesystem = True
960
961
)
962
+ langchain_client .flush ()
961
963
assert not caplog .records
962
964
wait_for (lambda : _get_run (str (trace_a_id ), langchain_client ))
963
965
created_run = langchain_client .read_run (run_id = str (trace_a_id ))
964
- assert sorted (created_run .attachments .keys ()) == sorted (["foo" , "bar" ])
966
+ assert sorted (created_run .attachments .keys ()) == sorted (
967
+ ["foo" , "bar" ]
968
+ ), f"See failed run at { created_run .url } "
965
969
assert created_run .attachments ["foo" ]["reader" ].read () == b"bar"
966
970
assert (
967
971
created_run .attachments ["bar" ]["reader" ].read ()
Original file line number Diff line number Diff line change @@ -679,6 +679,7 @@ def filter_outputs(outputs: dict):
679
679
assert all ([exp in all_posted for exp in expected ])
680
680
681
681
682
+ @pytest .mark .flaky (retries = 3 )
682
683
def test_client_gc_after_autoscale () -> None :
683
684
session = mock .MagicMock (spec = requests .Session )
684
685
client = Client (
Original file line number Diff line number Diff line change @@ -1731,6 +1731,7 @@ def consume(gen):
1731
1731
assert list (consume (wrapped )) == list (range (5 ))
1732
1732
1733
1733
1734
+ @pytest .mark .flaky (retries = 3 )
1734
1735
def test_traceable_input_attachments ():
1735
1736
with patch .object (ls_client .ls_env , "get_runtime_environment" ) as mock_get_env :
1736
1737
mock_get_env .return_value = {
@@ -1751,14 +1752,17 @@ def my_func(
1751
1752
1752
1753
mock_client = _get_mock_client (
1753
1754
info = ls_schemas .LangSmithInfo (
1755
+ instance_flags = {
1756
+ "zstd_compression_enabled" : False ,
1757
+ },
1754
1758
batch_ingest_config = ls_schemas .BatchIngestConfig (
1755
1759
use_multipart_endpoint = True ,
1756
1760
size_limit_bytes = None , # Note this field is not used here
1757
1761
size_limit = 100 ,
1758
1762
scale_up_nthreads_limit = 16 ,
1759
1763
scale_up_qsize_trigger = 1000 ,
1760
1764
scale_down_nempty_trigger = 4 ,
1761
- )
1765
+ ),
1762
1766
),
1763
1767
)
1764
1768
long_content = b"c" * 20_000_000
@@ -1771,6 +1775,8 @@ def my_func(
1771
1775
)
1772
1776
assert result == "foo"
1773
1777
1778
+ mock_client .flush ()
1779
+
1774
1780
for _ in range (20 ):
1775
1781
calls = _get_calls (mock_client )
1776
1782
datas = _get_multipart_data (calls )
You can’t perform that action at this time.
0 commit comments