Skip to content

Commit df6f6fa

Browse files
committed
Support for inference attachments
1 parent 390cb13 commit df6f6fa

13 files changed

Lines changed: 1211 additions & 7 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,5 @@ __marimo__/
215215
# Streamlit
216216
.streamlit/secrets.toml
217217
internal/
218+
219+
.DS_Store

examples/attachments_example.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# /// script
2+
# requires-python = ">=3.10"
3+
# dependencies = ["wildedge-sdk"]
4+
#
5+
# [tool.uv.sources]
6+
# wildedge-sdk = { path = "..", editable = true }
7+
# ///
8+
"""
9+
Attachment upload example. Run with: uv run attachments_example.py
10+
11+
Opt-in raw input/output capture. When `attachments_enabled=True` (and the
12+
project has the paid feature turned on), the SDK buffers the raw bytes locally,
13+
writes a reference into the inference event, and uploads the bytes independently
14+
via a presigned URL — the batch flush never waits on the upload.
15+
16+
Attachments are off by default and must be explicitly enabled. Set WILDEDGE_DSN
17+
to see real uploads; otherwise the client runs in no-op mode.
18+
"""
19+
20+
import wildedge
21+
from wildedge import Attachment
22+
23+
24+
# Optional: redact / drop attachments before they are buffered.
25+
def redact(attachments: list[Attachment]) -> list[Attachment]:
26+
return [a for a in attachments if a.content_type != "application/secret"]
27+
28+
29+
client = wildedge.init(
30+
app_version="1.0.0",
31+
attachments_enabled=True,
32+
max_attachments_per_inference=5,
33+
max_attachment_size_bytes=5 * 1024 * 1024,
34+
attachment_storage_strategy="file", # or "inline" for small blobs
35+
attachment_filter=redact,
36+
)
37+
38+
handle = client.register_model(
39+
object(),
40+
model_id="doc-classifier-v1",
41+
source="local",
42+
family="custom",
43+
)
44+
45+
# Pretend these came from a real inference call.
46+
image_bytes = b"\xff\xd8\xff\xe0fake-jpeg-bytes"
47+
answer = "This document is an invoice."
48+
49+
inference_id = handle.track_inference(
50+
duration_ms=120,
51+
input_modality="image",
52+
output_modality="text",
53+
attachments=[
54+
Attachment(content_type="image/jpeg", role="input", data=image_bytes),
55+
Attachment(content_type="text/plain", role="output", data=answer.encode()),
56+
],
57+
)
58+
59+
print(f"tracked inference {inference_id[:8]}… with 2 attachments")
60+
61+
# Bytes upload in the background; flush/close lets buffered events drain.
62+
client.close()

0 commit comments

Comments
 (0)