langchain-ai / langsmith-sdk

LangSmith Client SDK Implementations
https://smith.langchain.com/
MIT License
346 stars 59 forks source link

Issue: NextJS direct tracing #743

Open anton-sementsov opened 1 month ago

anton-sementsov commented 1 month ago

Issue you'd like to raise.

I am using NextJS with the useCompletion and completion API file from Vercel ai/react to manage AI requests. I tried to trace requests at smith.langchain in different ways but always recive this error Error in handler LangChainTracer, handleLLMEnd: Error: Invalid UUID: d2d2a5d8-4629-411a-9846cf2c71195666 Also when last time tried to trace dinamicaly I recived this one [Error: Failed to batch create run: 401 Unauthorized {"detail":"Invalid token"}]

I’d really appreciate it if you could help me solve this

Using next packages: "next": "13.2.4", "langchain": "^0.2.2", "ai": "^3.1.14", "@langchain/core": "^0.2.2", "@langchain/openai": "^0.0.34",

env file:. (all env I logged, received them properly) LANGCHAIN_TRACING_V2=true LANGCHAIN_ENDPOINT="https://api.smith.langchain.com" LANGCHAIN_APIKEY=lsv2......042f4 OPENAI_API_KEY=sk-V...1OtPnY1

completion.ts file in Next API folder

const model = new ChatOpenAI({
      apiKey: process.env.OPENAI_API_KEY,
      model: 'gpt-3.5-turbo-0125',
      temperature: 0,
    });
   const tracer = new LangChainTracer({ projectName: 'My Project' });

    const stream = await model.stream('Test lang chain', {
      callbacks: [tracer],
    });

    return new StreamingTextResponse(LangChainAdapter.toAIStream(stream));

Suggestion:

No response