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

[sessions][langchain] capture session and user ids passed into langchain metadata #2761

Closed
Tracked by #2619
axiomofjoy opened this issue Apr 4, 2024 · 3 comments
Closed
Tracked by #2619
Assignees
Labels

Comments

@axiomofjoy
Copy link
Contributor

axiomofjoy commented Apr 4, 2024

LangChain now supports sessions via a key-value pair passed into their metadata. We should parse this data in our LangChainInstrumentor and assign it to the session.id semantic convention. They have three different keys this can be passed in as, so we need to check to make sure we parse all of them. They might also have support for user IDs via the same mechanism.

Code snippet:

from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.messages import HumanMessage
from langchain_core.runnables import RunnableConfig
import uuid

import os


from openinference.instrumentation.langchain import LangChainInstrumentor

LangChainInstrumentor().instrument()


os.environ["LANGCHAIN_PROJECT"] = "sessions"

model = ChatOpenAI(model="gpt-4")
prompt = ChatPromptTemplate.from_messages([
    ("human", "Hello, how are you?"),
    ("ai", "I'm doing well, thanks!"),
    ("human", "That's good to hear."),
])
print(prompt)
chain = prompt | model
messages = [HumanMessage(content="hi! I'm bob")]
config = RunnableConfig(metadata={"conversation_id": str(uuid.uuid4())})
response = chain.invoke({"messages": messages}, config=config)
print(response)
messages = messages + [response, HumanMessage(content="whats my name")]
response = chain.invoke({"messages": messages}, config=config)
print(response)
@github-project-automation github-project-automation bot moved this to 📘 Todo in phoenix Apr 4, 2024
@dosubot dosubot bot added the c/traces label Apr 4, 2024
@axiomofjoy axiomofjoy changed the title [sessions][langchain] capture session ids passed into langchain metadata [sessions][langchain] capture session and user ids passed into langchain metadata Apr 4, 2024
@axiomofjoy
Copy link
Contributor Author

axiomofjoy commented Apr 4, 2024

@anticorrelator Where did we land on how to handle the interaction between LangChain's metadata and our own context managers?

@mikeldking
Copy link
Contributor

Need to support thread_id, session_id, conversation_id

@mikeldking
Copy link
Contributor

@fjcasti1 closing

@github-project-automation github-project-automation bot moved this from 📘 Todo to ✅ Done in phoenix May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

4 participants