Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
isahers1 committed Jan 10, 2025
1 parent 943be92 commit 98ecb0a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3903,7 +3903,7 @@ def read_example(
attachments[key.removeprefix("attachment.")] = {
"presigned_url": value["presigned_url"],
"reader": reader,
"mime_type": value["mime_type"],
"mime_type": value.get("mime_type"),
}

return ls_schemas.Example(
Expand Down Expand Up @@ -3990,7 +3990,7 @@ def list_examples(
attachments[key.removeprefix("attachment.")] = {
"presigned_url": value["presigned_url"],
"reader": reader,
"mime_type": value["mime_type"],
"mime_type": value.get("mime_type"),
}

yield ls_schemas.Example(
Expand Down
37 changes: 19 additions & 18 deletions python/tests/integration_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ def test_list_examples_attachments_keys(langchain_client: Client) -> None:

langchain_client.delete_dataset(dataset_id=dataset.id)

@pytest.mark.skip(reason="Need to land https://github.com/langchain-ai/langchainplus/pull/7415 first")

def test_mime_type_is_propogated(langchain_client: Client) -> None:
"""Test that the mime type is propogated correctly."""
dataset_name = "__test_mime_type_is_propogated" + uuid4().hex[:4]
Expand All @@ -1272,15 +1272,17 @@ def test_mime_type_is_propogated(langchain_client: Client) -> None:
],
)

example = next(langchain_client.list_examples(dataset_id=dataset.id))
example = next(
langchain_client.list_examples(dataset_id=dataset.id, include_attachments=True)
)
assert example.attachments["test_file"]["mime_type"] == "text/plain"

example = langchain_client.read_example(example_id=example.id)
assert example.attachments["test_file"]["mime_type"] == "text/plain"

langchain_client.delete_dataset(dataset_id=dataset.id)

@pytest.mark.skip(reason="Need to land https://github.com/langchain-ai/langchainplus/pull/7415 first")

def test_evaluate_mime_type_is_propogated(langchain_client: Client) -> None:
"""Test that the mime type is propogated correctly when evaluating."""
dataset_name = "__test_evaluate_mime_type_is_propogated" + uuid4().hex[:4]
Expand All @@ -1304,7 +1306,9 @@ def target(inputs: Dict[str, Any], attachments: Dict[str, Any]) -> Dict[str, Any
assert attachments["test_file"]["mime_type"] == "text/plain"
return {"answer": "hi there"}

def evaluator(outputs: dict, reference_outputs: dict, attachments: dict) -> Dict[str, Any]:
def evaluator(
outputs: dict, reference_outputs: dict, attachments: dict
) -> Dict[str, Any]:
# Verify we receive the attachment data
assert attachments["test_file"]["mime_type"] == "text/plain"
return {
Expand All @@ -1313,16 +1317,12 @@ def evaluator(outputs: dict, reference_outputs: dict, attachments: dict) -> Dict
)
}

langchain_client.evaluate(
target,
data=dataset_name,
evaluators=[evaluator]
)
langchain_client.evaluate(target, data=dataset_name, evaluators=[evaluator])

langchain_client.delete_dataset(dataset_name=dataset_name)

@pytest.mark.skip(reason="Need to land https://github.com/langchain-ai/langchainplus/pull/7415 first")
async def test_evaluate_mime_type_is_propogated(langchain_client: Client) -> None:

async def test_aevaluate_mime_type_is_propogated(langchain_client: Client) -> None:
"""Test that the mime type is propogated correctly when evaluating."""
dataset_name = "__test_evaluate_mime_type_is_propogated" + uuid4().hex[:4]
dataset = langchain_client.create_dataset(dataset_name=dataset_name)
Expand All @@ -1340,12 +1340,16 @@ async def test_evaluate_mime_type_is_propogated(langchain_client: Client) -> Non
],
)

async def target(inputs: Dict[str, Any], attachments: Dict[str, Any]) -> Dict[str, Any]:
async def target(
inputs: Dict[str, Any], attachments: Dict[str, Any]
) -> Dict[str, Any]:
# Verify we receive the attachment data
assert attachments["test_file"]["mime_type"] == "text/plain"
return {"answer": "hi there"}

async def evaluator(outputs: dict, reference_outputs: dict, attachments: dict) -> Dict[str, Any]:
async def evaluator(
outputs: dict, reference_outputs: dict, attachments: dict
) -> Dict[str, Any]:
# Verify we receive the attachment data
assert attachments["test_file"]["mime_type"] == "text/plain"
return {
Expand All @@ -1354,14 +1358,11 @@ async def evaluator(outputs: dict, reference_outputs: dict, attachments: dict) -
)
}

await langchain_client.aevaluate(
target,
data=dataset_name,
evaluators=[evaluator]
)
await langchain_client.aevaluate(target, data=dataset_name, evaluators=[evaluator])

langchain_client.delete_dataset(dataset_name=dataset_name)


def test_evaluate_with_attachments_multiple_evaluators(
langchain_client: Client,
) -> None:
Expand Down

0 comments on commit 98ecb0a

Please sign in to comment.