diff --git a/python/langsmith/evaluation/evaluator.py b/python/langsmith/evaluation/evaluator.py index fc1f07685..3a11fd292 100644 --- a/python/langsmith/evaluation/evaluator.py +++ b/python/langsmith/evaluation/evaluator.py @@ -667,15 +667,17 @@ async def awrapper( "example": example, "inputs": example.inputs if example else {}, "outputs": run.outputs or {}, - "attachments": { - name: { - "presigned_url": value["presigned_url"], - "reader": io.BytesIO(value["reader"].getvalue()), + "attachments": ( + { + name: { + "presigned_url": value["presigned_url"], + "reader": io.BytesIO(value["reader"].getvalue()), + } + for name, value in (example.attachments or {}).items() } - for name, value in (example.attachments or {}).items() - } - if example - else {}, + if example + else {} + ), "reference_outputs": example.outputs or {} if example else {}, } args = (arg_map[arg] for arg in positional_args) diff --git a/python/tests/integration_tests/test_client.py b/python/tests/integration_tests/test_client.py index 8e3e5cd8d..28a38602b 100644 --- a/python/tests/integration_tests/test_client.py +++ b/python/tests/integration_tests/test_client.py @@ -1490,10 +1490,10 @@ async def test_aevaluate_with_attachments(langchain_client: Client) -> None: examples = [ ExampleUploadWithAttachments( - inputs={"question": "What is shown in the image?"}, + inputs={"question": "What is shown in the image?", "index": i}, outputs={"answer": "test image"}, attachments={ - "image": ("image/png", b"fake image data for testing"), + "image": ("text/plain", bytes(f"data: {i}", "utf-8")), }, ) for i in range(10) @@ -1508,16 +1508,16 @@ async def target( assert "image" in attachments assert "presigned_url" in attachments["image"] image_data = attachments["image"]["reader"] - assert image_data.read() == b"fake image data for testing" + assert image_data.read() == bytes(f"data: {inputs['index']}", "utf-8") return {"answer": "test image"} async def evaluator_1( - outputs: dict, reference_outputs: dict, attachments: dict + inputs: dict, outputs: dict, reference_outputs: dict, attachments: dict ) -> Dict[str, Any]: assert "image" in attachments assert "presigned_url" in attachments["image"] image_data = attachments["image"]["reader"] - assert image_data.read() == b"fake image data for testing" + assert image_data.read() == bytes(f"data: {inputs['index']}", "utf-8") return { "score": float( reference_outputs.get("answer") == outputs.get("answer") # type: ignore @@ -1525,12 +1525,12 @@ async def evaluator_1( } async def evaluator_2( - outputs: dict, reference_outputs: dict, attachments: dict + inputs: dict, outputs: dict, reference_outputs: dict, attachments: dict ) -> Dict[str, Any]: assert "image" in attachments assert "presigned_url" in attachments["image"] image_data = attachments["image"]["reader"] - assert image_data.read() == b"fake image data for testing" + assert image_data.read() == bytes(f"data: {inputs['index']}", "utf-8") return { "score": float( reference_outputs.get("answer") == outputs.get("answer") # type: ignore