Skip to content

Commit 9894d7b

Browse files
patch[python]: Use multipart EP for feedback creation (#1655)
### Purpose All feedback ingest should go through multipart, in order to do this, we need to set the`trace_id`.
1 parent f5d642d commit 9894d7b

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

python/langsmith/testing/_internal.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -464,13 +464,13 @@ def _end_tests(test_suite: _LangSmithTestSuite):
464464
test_suite.client.update_dataset_tag(
465465
dataset_id=dataset_id,
466466
as_of=dataset_version,
467-
tag=f'git:commit:{git_info["commit"]}',
467+
tag=f"git:commit:{git_info['commit']}",
468468
)
469469
if dataset_version and git_info["branch"] is not None:
470470
test_suite.client.update_dataset_tag(
471471
dataset_id=dataset_id,
472472
as_of=dataset_version,
473-
tag=f'git:branch:{git_info["branch"]}',
473+
tag=f"git:branch:{git_info['branch']}",
474474
)
475475

476476

@@ -560,7 +560,9 @@ def submit_result(
560560
self._executor.submit(self._submit_result, run_id, score)
561561

562562
def _submit_result(self, run_id: uuid.UUID, score: Optional[int]) -> None:
563-
self.client.create_feedback(run_id, key="pass", score=score)
563+
# trace_id will always be run_id here because the feedback is on the root
564+
# test run
565+
self.client.create_feedback(run_id, key="pass", score=score, trace_id=run_id)
564566

565567
def sync_example(
566568
self,
@@ -635,7 +637,9 @@ def _submit_feedback(
635637
)
636638

637639
def _create_feedback(self, run_id: ID_TYPE, feedback: dict, **kwargs: Any) -> None:
638-
self.client.create_feedback(run_id, **feedback, **kwargs)
640+
# trace_id will always be run_id here because the feedback is on the root
641+
# test run
642+
self.client.create_feedback(run_id, **feedback, **kwargs, trace_id=run_id)
639643

640644
def shutdown(self):
641645
self._executor.shutdown()
@@ -914,10 +918,11 @@ def _test():
914918
"reference_example_id": str(test_case.example_id),
915919
},
916920
}
917-
with rh.tracing_context(
918-
**{**current_context, "metadata": metadata}
919-
), ls_utils.with_optional_cache(
920-
cache_path, ignore_hosts=[test_case.test_suite.client.api_url]
921+
with (
922+
rh.tracing_context(**{**current_context, "metadata": metadata}),
923+
ls_utils.with_optional_cache(
924+
cache_path, ignore_hosts=[test_case.test_suite.client.api_url]
925+
),
921926
):
922927
_test()
923928

@@ -982,10 +987,11 @@ async def _test():
982987
"reference_example_id": str(test_case.example_id),
983988
},
984989
}
985-
with rh.tracing_context(
986-
**{**current_context, "metadata": metadata}
987-
), ls_utils.with_optional_cache(
988-
cache_path, ignore_hosts=[test_case.test_suite.client.api_url]
990+
with (
991+
rh.tracing_context(**{**current_context, "metadata": metadata}),
992+
ls_utils.with_optional_cache(
993+
cache_path, ignore_hosts=[test_case.test_suite.client.api_url]
994+
),
989995
):
990996
await _test()
991997

@@ -1020,9 +1026,7 @@ def test_foo() -> None:
10201026
assert foo(x, y) == 2
10211027
"""
10221028
if ls_utils.test_tracking_is_disabled():
1023-
logger.info(
1024-
"LANGSMITH_TEST_TRACKING is set to 'false'." " Skipping log_inputs."
1025-
)
1029+
logger.info("LANGSMITH_TEST_TRACKING is set to 'false'. Skipping log_inputs.")
10261030
return
10271031
run_tree = rh.get_current_run_tree()
10281032
test_case = _TEST_CASE.get()
@@ -1064,9 +1068,7 @@ def test_foo() -> None:
10641068
assert result == 2
10651069
"""
10661070
if ls_utils.test_tracking_is_disabled():
1067-
logger.info(
1068-
"LANGSMITH_TEST_TRACKING is set to 'false'." " Skipping log_outputs."
1069-
)
1071+
logger.info("LANGSMITH_TEST_TRACKING is set to 'false'. Skipping log_outputs.")
10701072
return
10711073
run_tree = rh.get_current_run_tree()
10721074
test_case = _TEST_CASE.get()
@@ -1110,8 +1112,7 @@ def test_foo() -> None:
11101112
"""
11111113
if ls_utils.test_tracking_is_disabled():
11121114
logger.info(
1113-
"LANGSMITH_TEST_TRACKING is set to 'false'."
1114-
" Skipping log_reference_outputs."
1115+
"LANGSMITH_TEST_TRACKING is set to 'false'. Skipping log_reference_outputs."
11151116
)
11161117
return
11171118
test_case = _TEST_CASE.get()
@@ -1164,9 +1165,7 @@ def test_foo() -> None:
11641165
assert result == expected
11651166
"""
11661167
if ls_utils.test_tracking_is_disabled():
1167-
logger.info(
1168-
"LANGSMITH_TEST_TRACKING is set to 'false'." " Skipping log_feedback."
1169-
)
1168+
logger.info("LANGSMITH_TEST_TRACKING is set to 'false'. Skipping log_feedback.")
11701169
return
11711170
if feedback and any((key, score, value)):
11721171
msg = "Must specify one of 'feedback' and ('key', 'score', 'value'), not both."
@@ -1270,9 +1269,7 @@ def test_openai_says_hello():
12701269
assert "hello" in response.choices[0].message.content.lower()
12711270
""" # noqa: E501
12721271
if ls_utils.test_tracking_is_disabled():
1273-
logger.info(
1274-
"LANGSMITH_TEST_TRACKING is set to 'false'." " Skipping log_feedback."
1275-
)
1272+
logger.info("LANGSMITH_TEST_TRACKING is set to 'false'. Skipping log_feedback.")
12761273
yield None
12771274
return
12781275
parent_run = rh.get_current_run_tree()

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "langsmith"
3-
version = "0.3.29"
3+
version = "0.3.30"
44
description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform."
55
authors = ["LangChain <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)