Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(quickstart): update js examples (#8918)

Hassieb Pakzad521be4e0b65f
diff --git a/web/src/features/prompts/components/prompt-detail.tsx b/web/src/features/prompts/components/prompt-detail.tsx
index e954e16320..a2c524c4ce 100644
--- a/web/src/features/prompts/components/prompt-detail.tsx
+++ b/web/src/features/prompts/components/prompt-detail.tsx
@@ -86,20 +86,20 @@ const getJsCode = (
name: string,
version: number,
labels: string[],
-) => `import { Langfuse } from "langfuse";
+) => `import { LangfuseClient } from "@langfuse/client";
// Initialize the Langfuse client
-const langfuse = new Langfuse();
+const langfuse = new LangfuseClient();
// Get production prompt
-const prompt = await langfuse.getPrompt("${name}");
+const prompt = await langfuse.prompt.get("${name}");
// Get by label
// You can use as many labels as you'd like to identify different deployment targets
-${labels.length > 0 ? labels.map((label) => `const prompt = await langfuse.getPrompt("${name}", undefined, { label: "${label}" })`).join("\n") : ""}
+${labels.length > 0 ? labels.map((label) => `const prompt = await langfuse.prompt.get("${name}", { label: "${label}" })`).join("\n") : ""}
// Get by version number, usually not recommended as it requires code changes to deploy new prompt versions
-langfuse.getPrompt("${name}", ${version})
+await langfuse.prompt.get("${name}", { version: ${version} })
`;
export const PromptDetail = ({
diff --git a/web/src/features/public-api/components/QuickstartExamples.tsx b/web/src/features/public-api/components/QuickstartExamples.tsx
index 793aeee29c..6cc3d78940 100644
--- a/web/src/features/public-api/components/QuickstartExamples.tsx
+++ b/web/src/features/public-api/components/QuickstartExamples.tsx
@@ -94,9 +94,9 @@ export const QuickstartExamples = (p: {
</p>
</TabsContent>
<TabsContent value="js">
- <CodeView content="npm install langfuse" className="mb-2" />
+ <CodeView content="npm install @langfuse/client" className="mb-2" />
<CodeView
- content={`import { Langfuse } from "langfuse";\n\nconst langfuse = new Langfuse({\n secretKey: "${secretKey}",\n publicKey: "${publicKey}",\n baseUrl: "${host}"\n});`}
+ content={`import { LangfuseClient } from "@langfuse/client";\n\nconst langfuse = new LangfuseClient({\n secretKey: "${secretKey}",\n publicKey: "${publicKey}",\n baseUrl: "${host}"\n});`}
/>
<p className="mt-3 text-xs text-muted-foreground">
See{" "}
@@ -178,10 +178,7 @@ export const QuickstartExamples = (p: {
capture detailed traces of your Langchain executions.
</p>
<CodeView content="npm install langfuse-langchain" className="my-2" />
- <CodeView
- content={LANGCHAIN_JS_CODE({ publicKey, secretKey, host })}
- className="my-2"
- />
+ <CodeView content={LANGCHAIN_JS_CODE()} className="my-2" />
<p className="mt-2 text-xs text-muted-foreground">
See the{" "}
<a
@@ -272,18 +269,14 @@ langfuse_handler = CallbackHandler()
# Add handler to run/invoke/call/chat
chain.invoke({"input": "<user_input>"}, config={"callbacks": [langfuse_handler]})`;
-const LANGCHAIN_JS_CODE = (p: {
- publicKey: string;
- secretKey: string;
- host: string;
-}) => `import { CallbackHandler } from "langfuse-langchain";
+const LANGCHAIN_JS_CODE =
+ () => `import { CallbackHandler } from "@langfuse/langchain";
+
+// Make sure you have OpenTelemetry set up
+// https://langfuse.com/docs/observability/sdk/typescript/setup#initialize-opentelemetry
// Initialize Langfuse callback handler
-const langfuseHandler = new CallbackHandler({
- publicKey: "${p.publicKey}",
- secretKey: "${p.secretKey}",
- baseUrl: "${p.host}"
-});
+const langfuseHandler = new CallbackHandler();
// Your Langchain implementation
const chain = new LLMChain(...);