Skip to content

Commit

Permalink
Merge branch 'isaac/multipartstuff' of github.com:langchain-ai/langsm…
Browse files Browse the repository at this point in the history
…ith-sdk into isaac/multipartstuff
  • Loading branch information
baskaryan committed Dec 9, 2024
2 parents 0daf245 + 2b385b6 commit 04a5496
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3833,21 +3833,21 @@ def read_example(
)

example = response.json()
attachment_urls = {}
attachments = {}
if example["attachment_urls"]:
for key, value in example["attachment_urls"].items():
response = requests.get(value["presigned_url"], stream=True)
response.raise_for_status()
reader = io.BytesIO(response.content)
attachment_urls[key.split(".")[1]] = {
attachments[key.split(".")[1]] = {
"presigned_url": value["presigned_url"],
"reader": reader,
}
del example["attachment_urls"]

return ls_schemas.Example(
**example,
attachment_urls=attachment_urls,
attachments=attachments,
_host_url=self._host_url,
_tenant_id=self._get_optional_tenant_id(),
)
Expand Down Expand Up @@ -3920,21 +3920,21 @@ def list_examples(
for i, example in enumerate(
self._get_paginated_list("/examples", params=params)
):
attachment_urls = {}
attachments = {}
if example["attachment_urls"]:
for key, value in example["attachment_urls"].items():
response = requests.get(value["presigned_url"], stream=True)
response.raise_for_status()
reader = io.BytesIO(response.content)
attachment_urls[key.split(".")[1]] = {
attachments[key.split(".")[1]] = {
"presigned_url": value["presigned_url"],
"reader": reader,
}
del example["attachment_urls"]

yield ls_schemas.Example(
**example,
attachment_urls=attachment_urls,
attachments=attachments,
_host_url=self._host_url,
_tenant_id=self._get_optional_tenant_id(),
)
Expand Down
8 changes: 4 additions & 4 deletions python/langsmith/evaluation/_arunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ def _get_run(r: run_trees.RunTree) -> None:
with rh.tracing_context(enabled=True):
try:
args = (
(example.inputs, example.attachment_urls)
(example.inputs, example.attachments)
if include_attachments
else (example.inputs,)
)
Expand All @@ -1044,9 +1044,9 @@ def _get_run(r: run_trees.RunTree) -> None:
client=client,
),
)
if include_attachments and example.attachment_urls is not None:
for attachment in example.attachment_urls:
reader = example.attachment_urls[attachment]["reader"]
if include_attachments and example.attachments is not None:
for attachment in example.attachments:
reader = example.attachments[attachment]["reader"]
reader.seek(0)
except Exception as e:
logger.error(
Expand Down
8 changes: 4 additions & 4 deletions python/langsmith/evaluation/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1834,17 +1834,17 @@ def _get_run(r: rt.RunTree) -> None:
)
try:
args = (
(example.inputs, example.attachment_urls)
(example.inputs, example.attachments)
if include_attachments
else (example.inputs,)
)
fn(
*args,
langsmith_extra=langsmith_extra,
)
if include_attachments and example.attachment_urls is not None:
for attachment in example.attachment_urls:
reader = example.attachment_urls[attachment]["reader"]
if include_attachments and example.attachments is not None:
for attachment in example.attachments:
reader = example.attachments[attachment]["reader"]
reader.seek(0)
except Exception as e:
logger.error(
Expand Down
2 changes: 1 addition & 1 deletion python/langsmith/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Example(ExampleBase):
modified_at: Optional[datetime] = Field(default=None)
runs: List[Run] = Field(default_factory=list)
source_run_id: Optional[UUID] = None
attachment_urls: Optional[Dict[str, AttachmentInfo]] = Field(default=None)
attachments: Optional[Dict[str, AttachmentInfo]] = Field(default=None)
"""Dictionary with attachment names as keys and a tuple of the S3 url
and a reader of the data for the file."""
_host_url: Optional[str] = PrivateAttr(default=None)
Expand Down
8 changes: 4 additions & 4 deletions python/tests/integration_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,17 @@ def test_upload_examples_multipart(langchain_client: Client):
# Verify example with ID was created with correct ID
example_with_id = [ex for ex in examples if ex.id == example_id][0]
assert example_with_id.inputs["text"] == "hello world"
assert "test_file" in example_with_id.attachment_urls
assert "test_file" in example_with_id.attachments

# Verify example with outputs and multiple attachments
example_with_outputs = next(
ex
for ex in examples
if ex.outputs and ex.outputs.get("response") == "test response"
)
assert len(example_with_outputs.attachment_urls) == 2
assert "file1" in example_with_outputs.attachment_urls
assert "file2" in example_with_outputs.attachment_urls
assert len(example_with_outputs.attachments) == 2
assert "file1" in example_with_outputs.attachments
assert "file2" in example_with_outputs.attachments

# Test uploading to non-existent dataset fails
fake_id = uuid4()
Expand Down

0 comments on commit 04a5496

Please sign in to comment.