Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
isahers1 committed Nov 18, 2024
1 parent 390ac66 commit 523e5d1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 57 deletions.
102 changes: 46 additions & 56 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3373,16 +3373,14 @@ def create_example_from_run(
def upsert_examples_multipart(
self,
*,
upserts: List[ls_schemas.ExampleUpsertWithAttachments] = None,
upserts: List[ls_schemas.ExampleUpsertWithAttachments] = [],
) -> ls_schemas.UpsertExamplesResponse:
"""Upsert examples."""
""" if not (self.info.instance_flags or {}).get(
"examples_multipart_enabled", False
):
raise ValueError("Your LangSmith version does not allow using the multipart examples endpoint, please update to the latest version.")
"""
if upserts is None:
upserts = []
parts: list[MultipartPart] = []

for example in upserts:
Expand All @@ -3401,82 +3399,74 @@ def upsert_examples_multipart(
example_body["split"] = example.split
valb = _dumps_json(example_body)

(
parts.append(
parts.append(
(
f"{example_id}",
(
f"{example_id}",
(
None,
valb,
"application/json",
{},
),
)
),
None,
valb,
"application/json",
{},
),
)
)

inputsb = _dumps_json(example.inputs)

(

parts.append(
(
f"{example_id}.inputs",
(
None,
inputsb,
"application/json",
{},
),
)
)


if example.outputs:
outputsb = _dumps_json(example.outputs)
parts.append(
(
f"{example_id}.inputs",
f"{example_id}.outputs",
(
None,
inputsb,
outputsb,
"application/json",
{},
),
)
),
)

if example.outputs:
outputsb = _dumps_json(example.outputs)
(
parts.append(
(
f"{example_id}.outputs",
(
None,
outputsb,
"application/json",
{},
),
)
),
)

if example.attachments:
for name, attachment in example.attachments.items():
if isinstance(attachment, tuple):
mime_type, data = attachment
(
parts.append(
parts.append(
(
f"{example_id}.attachment.{name}",
(
f"{example_id}.attachment.{name}",
(
None,
data,
f"{mime_type}; length={len(data)}",
{},
),
)
),
None,
data,
f"{mime_type}; length={len(data)}",
{},
),
)
)
else:
(
parts.append(
parts.append(
(
f"{example_id}.attachment.{name}",
(
f"{example_id}.attachment.{name}",
(
None,
attachment.data,
f"{attachment.mime_type}; length={len(attachment.data)}",
{},
),
)
),
None,
attachment.data,
f"{attachment.mime_type}; length={len(attachment.data)}",
{},
),
)
)

encoder = rqtb_multipart.MultipartEncoder(parts, boundary=BOUNDARY)
Expand Down
2 changes: 1 addition & 1 deletion python/langsmith/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ class LangSmithInfo(BaseModel):
"""The time the license will expire."""
batch_ingest_config: Optional[BatchIngestConfig] = None
"""The instance flags."""
instance_flags: dict[str, Any] = None
instance_flags: Optional[dict[str, Any]] = None


Example.update_forward_refs()
Expand Down

0 comments on commit 523e5d1

Please sign in to comment.