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

fix(weave): add attributes to langchain integration calls #3521

Merged
merged 6 commits into from
Feb 4, 2025

Conversation

parambharat
Copy link
Contributor

@parambharat parambharat commented Jan 29, 2025

WB-22340

Description

This PR enables to attribute tracking in the langchain tracer integration. This simplest way to highlight the fix is the following code snippet. Now we should be able to track the {"tag": "good_tag"} attribute in trace op for the the langchain calls.

import weave
from langchain_core.prompts import PromptTemplate
from langchain_openai import ChatOpenAI

# Initialize Weave with your project name
weave.init("langchain_test")

llm = ChatOpenAI()
prompt = PromptTemplate.from_template("1 + {number} = ")

llm_chain = prompt | llm
with weave.attributes({"tag": "good_tag"}):
    output = llm_chain.invoke({"number": 2})

print(output)

Testing

Included vcr cassette and unit test to verify that the user-added attributes are present in the call attributes.

@circle-job-mirror
Copy link

circle-job-mirror bot commented Jan 29, 2025



data: {"id":"chatcmpl-9jicpaVkXi2nrE0R4SNVFeCGQ0blB","object":"chat.completion.chunk","created":1720683327,"model":"gpt-3.5-turbo-0125","system_fingerprint":null,"choices":[{"index":0,"delta":{"function_call":{"arguments":"{\""}},"logprobs":null,"finish_reason":null}],"usage":null}
data: {"id":"chatcmpl-Av0tQ435mNvqfk5c4Mtjr8c2ogJPI","object":"chat.completion.chunk","created":1738151492,"model":"gpt-4o-mini-2024-07-18","service_tier":"default","system_fingerprint":"fp_72ed7ab54c","choices":[{"index":0,"delta":{"function_call":{"arguments":"{\""}},"logprobs":null,"finish_reason":null}],"usage":null}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove fingerprints

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 removed

@parambharat parambharat marked this pull request as ready for review January 29, 2025 14:06
@parambharat parambharat requested a review from a team as a code owner January 29, 2025 14:06
@ayulockin
Copy link
Member

@parambharat can you make the CI green and merge this PR.

@parambharat parambharat changed the title fix(integration): add attribute langchain calls fix(weave): add attributes to langchain integration calls Feb 4, 2025
@parambharat
Copy link
Contributor Author

@ayulockin, The CI is now 🟢 . But I can't merge the PR since I don't have write access to the repo 🤔

@ayulockin ayulockin merged commit 460c0ad into master Feb 4, 2025
126 of 127 checks passed
@ayulockin ayulockin deleted the chore/attribute-lc-calls branch February 4, 2025 05:27
@github-actions github-actions bot locked and limited conversation to collaborators Feb 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants