langchain-ai / langsmith-sdk

LangSmith Client SDK Implementations
https://docs.smith.langchain.com/
MIT License
412 stars 79 forks source link

Issue: JS Langchain don´t send data to Langsmith #545

Closed halie412 closed 7 months ago

halie412 commented 7 months ago

Issue you'd like to raise.

Hi Langsmith team, i spent 4 hours trying to make work Langsmith before opening this issue

The main problem: Langchain work pretty well but i can´t get data on langsmith, i already test this things: ✔️ Enviroment variables (all work well) ✔️ Langsmith installed (npm install langsmith) ✔️ Project name on UI Langsmith and my code same as variable LANGCHAIN_PROJECT=default ✔️ API key from UI Langsmith same as variable LANGCHAIN_API_KEY=my_key ✔️ Variable LANGCHAIN_TRACING_V2=true ✔️ Variable LANGCHAIN_ENDPOINT=https://api.smith.langchain.com ✔️ Readed couple of time docs and there no mention to import or initialice any thing to make this work

The issue: Langchain work pretty well but not send data to langsmith, this is an example of networks connection at run time image

In console i don´t see any error or warning

This is my package.json { "name": "js-langchain", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "start": "parcel index.html", "build": "parcel build index.html" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "buffer": "^6.0.3", "lite-server": "^2.6.1", "parcel": "^2.12.0", "process": "^0.11.10", "ts-node": "^10.9.2", "typescript": "^5.4.3" }, "dependencies": { "@langchain/anthropic": "^0.1.8", "@langchain/community": "^0.0.41", "@langchain/mistralai": "^0.0.15", "@langchain/openai": "^0.0.23", "axios": "^1.6.8", "cheerio": "^1.0.0-rc.12", "langchain": "^0.1.28", "langsmith": "^0.1.14", "uuid": "^9.0.1" } }

Suggestion:

No response

hinthornw commented 7 months ago

Thank you for raising!

Is this running in a browser? I'll get a team mate more experienced there to weigh in, but env vars may be tricky there (no process.env) meaning it may need to be manually traced with the LangChain tracer.

How are you specifying the environment variables in your runtime?

halie412 commented 7 months ago

Great, thanks for take your time and fast reply, i already have an file .env with my environment variables who works for openai, mistral and pinecone, i excecuted couple of tests and varables are reading pretty well

This is the content of my file .env on root of project

LANGCHAIN_TRACING_V2=true LANGCHAIN_API_KEY=my_key_from_langsmith_ui LANGCHAIN_ENDPOINT=https://api.smith.langchain.com LANGCHAIN_PROJECT=default

PINECONE_API_KEY=pinecone_working_key

OPENAI_API_KEY=openai_working_key

MISTRAL_API_KEY=mistral_working_key

ANTHROPIC_API_KEY=antrhopic_working_key

halie412 commented 7 months ago

@hinthornw Yes this is running in a browser (Chrome) for testing and developing, i use parcel

hinthornw commented 7 months ago

https://docs.smith.langchain.com/tracing/faq/langchain_specific_guides#tracing-without-environment-variables

Does this work?

I'm sure you know what you're doing, but I'd be remiss if I didn't warn that if the app architecture puts a langsmith API key on a user's browser, it means they could get write access to your tenant

halie412 commented 7 months ago

@hinthornw I´m trying to follow your instructions, yes for sure on browser is only for testing, for production will be managed as API, no as UI for browser

That don´t work, i test print in console variable and looks fine:

console.log(process.env.LANGCHAIN_API_KEY);

hinthornw commented 7 months ago

hmm will investigate

hinthornw commented 7 months ago

Could you confirm if you run

import { Client } from "langsmith";

const client = new Client({
      apiUrl: "https://api.smith.langchain.com",
      apiKey: "YOUR_API_KEY_HERE",
    });

await client.createRun({
      name: "test_run",
      run_type: "chaihn",
      inputs: { text: "hello world" },
    });

no request is attempted?

and similarly with this:

import { Client } from "langsmith";
import { LangChainTracer } from "langchain/callbacks";
import { ChatOpenAI } from "@langchain/openai";

const callbacks = [
  new LangChainTracer({
    client: new Client({
      apiUrl: "https://api.smith.langchain.com",
      apiKey: "YOUR_API_KEY_HERE",
    }),
  }),
];
const llm = new ChatOpenAI({});
await llm.invoke("Hello, world!", { callbacks });
hinthornw commented 7 months ago

Feel free to re-open if the issue persists! We have a lot of JS usage so I don't believe this is a fundamental bug in our tracer.