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

feat(js): add session id parsing to langchain instrumentation #1151

Merged
merged 3 commits into from
Dec 5, 2024

Conversation

cephalization
Copy link
Contributor

Parses metadata with key name in (session_id, thread_id, conversation_id) into semantic conventions session id

Parses metadata with key name in (session_id, thread_id, conversation_id) into semantic conventions session id
@cephalization cephalization requested a review from a team as a code owner December 5, 2024 21:43
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Dec 5, 2024
Comment on lines +4 to +28
import { HumanMessage } from "@langchain/core/messages";

const main = async () => {
const chatModel = new ChatOpenAI({
openAIApiKey: process.env.OPENAI_API_KEY,
metadata: {
session_id: "test-session-123",
},
});

const response = await chatModel.invoke("Hello! How are you?");
const request = new HumanMessage("Hello! How are you?");

const response = await chatModel.invoke([request]);

// get a new response, including a greeting in the message history
const finalResponse = await chatModel.invoke([
request,
response,
new HumanMessage("That is great to hear!"),
]);

// eslint-disable-next-line no-console
console.log(response.content);
console.log(finalResponse.content);

return response;
return finalResponse;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to revert these changes if they seem too complex for generic example code

@cephalization cephalization merged commit 8182c3a into main Dec 5, 2024
3 checks passed
@cephalization cephalization deleted the cephalization/js/5085-langchain-thread-support branch December 5, 2024 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants