Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support setting attachments through the RunTree object #1206

Open
oegeshipster opened this issue Nov 12, 2024 · 0 comments
Open

support setting attachments through the RunTree object #1206

oegeshipster opened this issue Nov 12, 2024 · 0 comments

Comments

@oegeshipster
Copy link

oegeshipster commented Nov 12, 2024

Feature request

so what i would like to do is the following inside a function that has a traceable decorator:

rt = get_current_run_tree()
pdf_attachment = Attachment(mime_type="application/pdf", data=pdf_data)
rt.attachments["pdf"] = pdf_attachment

but that currently does not work and the attachments do not show up in the dashboard.

So this this current example from the docs does work:

from langsmith import traceable, get_current_run_tree
from langsmith.schemas import Attachment


@traceable
def trace_with_attachments(
    val: int,
    text: str,
    pdf: Attachment,
):
    return f"Processed: {val}, {text},{len(pdf.data)}"


# Helper function to load files as bytes
def load_file(file_path: str) -> bytes:
    with open(file_path, "rb") as f:
        return f.read()


pdf_data = load_file(
    pdf_path
)
pdf_attachment = Attachment(mime_type="application/pdf", data=pdf_data)
# Define other parameters
val = 42
text = "Hello, world!"
# Call the function with traced attachments
result = trace_with_attachments(
    val=val,
    text=text,
    pdf=pdf_attachment,
)

but this does not:

@traceable
def trace_with_attachments(
    val: int,
    text: str,
    pdf_path: str,
):
    pdf_data = load_file(pdf_path)
    rt = get_current_run_tree()
    pdf_attachment = Attachment(mime_type="application/pdf", data=pdf_data)
    rt.attachments["pdf"] = pdf_attachment
    return f"Processed: {val}, {text},{len(pdf_data)}"

val = 42
text = "Hello, world!"
result = trace_with_attachments(
    val=val,
    text=text,
    pdf_path=pdf_path,
)

Motivation

currently I basically need to define a seperate wrapper function with Attachment parameters just to store the attachments.
This adds wrapper functions and complication to my codebase, and makes it hard to use the traceable decorator directly on a fastapi route for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant