🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(ui): add quickstart examples to api key creation popup (#1119)
Richard Krümmeladec1476ea50
diff --git a/src/features/public-api/components/CreateApiKeyButton.tsx b/src/features/public-api/components/CreateApiKeyButton.tsxindex 3daee50e60..b5bffe6932 100644--- a/src/features/public-api/components/CreateApiKeyButton.tsx+++ b/src/features/public-api/components/CreateApiKeyButton.tsx@@ -11,7 +11,7 @@ import {import { CodeView } from "@/src/components/ui/code";import { useHasAccess } from "@/src/features/rbac/utils/checkAccess";import { usePostHog } from "posthog-js/react";-import { env } from "@/src/env.mjs";+import { QuickstartExamples } from "@/src/features/public-api/components/QuickstartExamples";export function CreateApiKeyButton(props: { projectId: string }) {const utils = api.useUtils();@@ -21,8 +21,7 @@ export function CreateApiKeyButton(props: { projectId: string }) {scope: "apiKeys:create",});- const hostname =- env.NEXT_PUBLIC_LANGFUSE_CLOUD_REGION !== "EU" ? window.origin : undefined;+ const hostname = window.origin;const mutCreateApiKey = api.apiKeys.create.useMutation({onSuccess: () => utils.apiKeys.invalidate(),@@ -66,28 +65,15 @@ export function CreateApiKeyButton(props: { projectId: string }) {Create new API keys</Button></DialogTrigger>- <DialogContent onPointerDownOutside={(e) => e.preventDefault()}>- {hostname ? (- <>- <DialogTitle>Hostname</DialogTitle>- <div className="mb-6">- <div className="my-2">- When connecting to Langfuse, use this hostname / baseurl.- </div>- <CodeView content={hostname} />- </div>- </>- ) : null}-+ <DialogContent+ onPointerDownOutside={(e) => e.preventDefault()}+ className="max-w-full md:max-w-xl"+ ><DialogTitle>API Keys</DialogTitle><div className="mb-2"><div className="text-md font-semibold">Secret Key</div><div className="my-2">- Please save this secret key.{" "}- <span className="font-semibold">- You will not be able to view it again- </span>- . If you lose it, you will need to generate a new one.+ This key can only be viewed once. You can always generate a new key.</div><CodeView content={generatedKeys?.secretKey ?? "Loading ..."} /></div>@@ -95,6 +81,20 @@ export function CreateApiKeyButton(props: { projectId: string }) {<div className="text-md mb-2 font-semibold">Public Key</div><CodeView content={generatedKeys?.publicKey ?? "Loading ..."} /></div>+ <div>+ <div className="text-md mb-2 font-semibold">Host</div>+ <CodeView content={hostname} />+ </div>+ {generatedKeys && (+ <div className="mb-2">+ <div className="text-md my-2 font-semibold">Usage</div>+ <QuickstartExamples+ secretKey={generatedKeys.secretKey}+ publicKey={generatedKeys.publicKey}+ host={hostname}+ />+ </div>+ )}</DialogContent></Dialog>);diff --git a/src/features/public-api/components/QuickstartExamples.tsx b/src/features/public-api/components/QuickstartExamples.tsxnew file mode 100644index 0000000000..d00996970e--- /dev/null+++ b/src/features/public-api/components/QuickstartExamples.tsx@@ -0,0 +1,210 @@+import { CodeView } from "@/src/components/ui/code";+import {+ Tabs,+ TabsList,+ TabsContent,+ TabsTrigger,+} from "@/src/components/ui/tabs";++export const QuickstartExamples = ({+ secretKey,+ publicKey,+ host,+}: {+ secretKey: string;+ publicKey: string;+ host: string;+}) => (+ <Tabs defaultValue="python">+ <TabsList>+ <TabsTrigger value="python">Python</TabsTrigger>+ <TabsTrigger value="js">JS/TS</TabsTrigger>+ <TabsTrigger value="openai">OpenAI</TabsTrigger>+ <TabsTrigger value="langchain">Langchain</TabsTrigger>+ <TabsTrigger value="langchain-js">Langchain JS</TabsTrigger>+ <TabsTrigger value="other">Other</TabsTrigger>+ </TabsList>+ <TabsContent value="python">+ <CodeView content="pip install langfuse" className="mb-2 bg-blue-50" />+ <CodeView+ className="bg-blue-50"+ content={`from langfuse import Langfuse\n\nlangfuse = Langfuse(\n secret_key="${secretKey}",\n public_key="${publicKey}",\n host="${host}"\n)`}+ />+ <p className="mt-3 text-xs text-gray-600">+ See{" "}+ <a+ href="https://langfuse.com/docs/get-started"+ className="underline"+ target="_blank"+ rel="noopener noreferrer"+ >+ Quickstart+ </a>{" "}+ and{" "}+ <a+ href="https://langfuse.com/docs/sdk/python"+ className="underline"+ target="_blank"+ rel="noopener noreferrer"+ >+ Python docs+ </a>{" "}+ for more details.+ </p>+ </TabsContent>+ <TabsContent value="js">+ <CodeView content="npm install langfuse" className="mb-2 bg-blue-50" />+ <CodeView+ className="bg-blue-50"+ content={`import { Langfuse } from "langfuse";\n\nconst langfuse = new Langfuse({\n secretKey: "${secretKey}",\n publicKey: "${publicKey}",\n baseUrl: "${host}"\n});`}+ />+ <p className="mt-3 text-xs text-gray-600">+ See{" "}+ <a+ href="https://langfuse.com/docs/get-started"+ className="underline"+ target="_blank"+ rel="noopener noreferrer"+ >+ Quickstart+ </a>{" "}+ and{" "}+ <a+ href="https://langfuse.com/docs/sdk/typescript"+ className="underline"+ target="_blank"+ rel="noopener noreferrer"+ >+ JS/TS docs+ </a>{" "}+ for more details.+ </p>+ </TabsContent>+ <TabsContent value="openai">+ <p className="mt-2 text-xs text-gray-600">+ The integration is a drop-in replacement for the OpenAI Python SDK. By+ changing the import, Langfuse will capture all LLM calls and send them+ to Langfuse asynchronously.+ </p>+ <CodeView content="pip install langfuse" className="my-2 bg-blue-50" />+ <CodeView+ title=".env"+ content={`LANGFUSE_SECRET_KEY=${secretKey};\nLANGFUSE_PUBLIC_KEY=${publicKey};\nLANGFUSE_HOST="${host}";`}+ className="my-2 bg-blue-50"+ />+ <CodeView+ content={`# remove: import openai\n\nfrom langfuse.openai import openai`}+ className="my-2 bg-blue-50"+ />+ <p className="mt-2 text-xs text-gray-600">+ Use the OpenAI SDK as you would normally. See the{" "}+ <a+ href="https://langfuse.com/docs/integrations/openai"+ className="underline"+ target="_blank"+ rel="noopener noreferrer"+ >+ OpenAI Integration docs+ </a>{" "}+ for more details.+ </p>+ </TabsContent>+ <TabsContent value="langchain">+ <p className="mt-2 text-xs text-gray-600">+ The integration uses the Langchain callback system to automatically+ capture detailed traces of your Langchain executions.+ </p>+ <CodeView content="pip install langfuse" className="my-2 bg-blue-50" />+ <CodeView+ title=".env"+ content={`LANGFUSE_SECRET_KEY=${secretKey};\nLANGFUSE_PUBLIC_KEY=${publicKey};\nLANGFUSE_HOST="${host}";`}+ className="my-2 bg-blue-50"+ />+ <CodeView content={LANGCHAIN_PYTHON_CODE} className="my-2 bg-blue-50" />+ <p className="mt-2 text-xs text-gray-600">+ See the{" "}+ <a+ href="https://langfuse.com/docs/integrations/langchain/python"+ className="underline"+ target="_blank"+ rel="noopener noreferrer"+ >+ Langchain Integration docs+ </a>{" "}+ for more details.+ </p>+ </TabsContent>+ <TabsContent value="langchain-js">+ <p className="mt-2 text-xs text-gray-600">+ The integration uses the Langchain callback system to automatically+ capture detailed traces of your Langchain executions.+ </p>+ <CodeView+ content="npm install langfuse-langchain"+ className="my-2 bg-blue-50"+ />+ <CodeView+ title=".env"+ content={`LANGFUSE_SECRET_KEY=${secretKey};\nLANGFUSE_PUBLIC_KEY=${publicKey};\LANGFUSE_BASEURL="${host}";`}+ className="my-2 bg-blue-50"+ />+ <CodeView content={LANGCHAIN_JS_CODE} className="my-2 bg-blue-50" />+ <p className="mt-2 text-xs text-gray-600">+ See the{" "}+ <a+ href="https://langfuse.com/docs/integrations/langchain/typescript"+ className="underline"+ target="_blank"+ rel="noopener noreferrer"+ >+ Langchain Integration docs+ </a>{" "}+ for more details.+ </p>+ </TabsContent>+ <TabsContent value="other">+ <p className="mt-2 text-xs text-gray-600">+ Use the{" "}+ <a+ href="https://api.reference.langfuse.com/"+ className="underline"+ target="_blank"+ rel="noopener noreferrer"+ >+ API+ </a>{" "}+ or one of the{" "}+ <a+ href="https://langfuse.com/docs/integrations"+ className="underline"+ target="_blank"+ rel="noopener noreferrer"+ >+ native integrations+ </a>{" "}+ (e.g. LiteLLM, Flowise, and Langflow) to integrate with Langfuse.+ </p>+ </TabsContent>+ </Tabs>+);++const LANGCHAIN_PYTHON_CODE = `from langfuse.callback import CallbackHandler++# <Your Langchain code here>++# Add handler to run/invoke/call/chat+agent.run("<user_input>", callbacks=[handler])`;++const LANGCHAIN_JS_CODE = `import { CallbackHandler } from "langfuse-langchain";++// Initialize Langfuse callback handler+const handler = new CallbackHandler();++// Your Langchain implementation+const chain = new LLMChain(...);++// Add handler as callback when running the Langchain agent+await chain.call(+ { input: "<user_input>" },+ { callbacks: [handler] }+);`;