diff --git a/docs/evaluation/how_to_guides/evaluate_with_attachments.mdx b/docs/evaluation/how_to_guides/evaluate_with_attachments.mdx index 7ba65cda..2405b679 100644 --- a/docs/evaluation/how_to_guides/evaluate_with_attachments.mdx +++ b/docs/evaluation/how_to_guides/evaluate_with_attachments.mdx @@ -37,17 +37,18 @@ All of the below features are available in the following SDK versions: diff --git a/docs/observability/how_to_guides/tracing/upload_files_with_traces.mdx b/docs/observability/how_to_guides/tracing/upload_files_with_traces.mdx index 47df26f7..1d601ebb 100644 --- a/docs/observability/how_to_guides/tracing/upload_files_with_traces.mdx +++ b/docs/observability/how_to_guides/tracing/upload_files_with_traces.mdx @@ -32,8 +32,11 @@ This guide explains how to define and trace attachments using the `Attachment` t tabs={[ PythonBlock( `from langsmith import traceable -from langsmith.schemas import Attachment\n\n -@traceable +from langsmith.schemas import Attachment +from pathlib import Path +import os\n\n +# Must set dangerously_allow_filesystem to True if you want to use file paths +@traceable(dangerously_allow_filesystem=True) def trace_with_attachments( val: int, text: str, @@ -53,12 +56,11 @@ image_data = load_file("my_image.png") audio_data = load_file("my_mp3.mp3") video_data = load_file("my_video.mp4") pdf_data = load_file("my_document.pdf") -csv_data = load_file("my_csv.csv") image_attachment = Attachment(mime_type="image/png", data=image_data) audio_attachment = Attachment(mime_type="audio/mpeg", data=audio_data) video_attachment = Attachment(mime_type="video/mp4", data=video_data) -pdf_attachment = Attachment(mime_type="application/pdf", data=pdf_data) -csv_attachment = Attachment(mime_type="text/csv", data=csv_data) +pdf_attachment = ("application/pdf", pdf_data) # Can just define as tuple of (mime_type, data) +csv_attachment = Attachment(mime_type="text/csv", data=Path(os.getcwd()) / "my_csv.csv") # Define other parameters @@ -80,8 +82,10 @@ csv=csv_attachment, Each \`Attachment\` requires:\n - \`mime_type\` (str): The MIME type of the file (e.g., \`"image/png"\`). -- \`data\` (bytes): The binary content of the file.\n - Simply decorate a function with \`@traceable\` and include your \`Attachment\` instances as arguments.`), +- \`data\` (bytes | Path): The binary content of the file, or the file path.\n + You can also define an attachment with a tuple tuple of the form \`(mime_type, data)\` for convenience. \n + Simply decorate a function with \`@traceable\` and include your \`Attachment\` instances as arguments. + Note that to use the file path instead of the raw bytes, you need to set the \`dangerously_allow_filesystem\` flag to \`True\` in your traceable decorator.\n`), TypeScriptBlock(`import { traceable } from "langsmith/traceable";\n const traceableWithAttachments = traceable( ( @@ -135,6 +139,7 @@ TypeScriptBlock(`import { traceable } from "langsmith/traceable";\n - \`ArrayBuffer\`: Represents fixed-length binary data, which can be converted to \`Uint8Array\` as needed.\n Wrap your function with \`traceable\` and include your attachments within the \`extractAttachments\` option.\n In the TypeScript SDK, the \`extractAttachments\` function is an optional parameter in the \`traceable\` configuration. When the traceable-wrapped function is invoked, it extracts binary data (e.g., images, audio files) from your inputs and logs them alongside other trace data, specifying their MIME types.\n + Note that you cannot directly pass in a file path in the TypeScript SDK, as accessing local files is not supported in all runtime environments.\n \`\`\` type AttachmentData = Uint8Array | ArrayBuffer; type Attachments = Record;\n