You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
fromlangchain_openaiimportChatOpenAIfromlangchain_core.promptsimportChatPromptTemplatefromlangchain_core.messagesimportHumanMessagefromlangchain_core.runnablesimportRunnableConfigimportuuidimportosfromopeninference.instrumentation.langchainimportLangChainInstrumentorLangChainInstrumentor().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|modelmessages= [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)
The text was updated successfully, but these errors were encountered:
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
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 thesession.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:
The text was updated successfully, but these errors were encountered: