πͺ’ 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
fix(markdown-rendering): tighter rendering (#8177)
Nimar846d6e6c37b3
diff --git a/packages/shared/scripts/seeder/utils/markdown.txt b/packages/shared/scripts/seeder/utils/markdown.txtindex b45c71b89b..3cb255000c 100644--- a/packages/shared/scripts/seeder/utils/markdown.txt+++ b/packages/shared/scripts/seeder/utils/markdown.txt@@ -11,29 +11,29 @@## π― Getting Started### Prerequisites-\`\`\`bash-npm install @langfuse/core-pip install langfuse+\`\`\`bash+npm install @langfuse/core+pip install langfuse\`\`\`### Quick Setup1. **Initialize your project**- \`\`\`typescript- import { Langfuse } from 'langfuse'-- const langfuse = new Langfuse({- secretKey: process.env.LANGFUSE_SECRET_KEY,- publicKey: process.env.LANGFUSE_PUBLIC_KEY,- baseUrl: 'https://cloud.langfuse.com'- })+ \`\`\`typescript+ import { Langfuse } from 'langfuse'++ const langfuse = new Langfuse({+ secretKey: process.env.LANGFUSE_SECRET_KEY,+ publicKey: process.env.LANGFUSE_PUBLIC_KEY,+ baseUrl: 'https://cloud.langfuse.com'+ })\`\`\`2. **Create your first trace**- \`\`\`python- from langfuse import Langfuse-- langfuse = Langfuse()- trace = langfuse.trace(name="chat-application")+ \`\`\`python+ from langfuse import Langfuse++ langfuse = Langfuse()+ trace = langfuse.trace(name="chat-application")\`\`\`---@@ -72,75 +72,75 @@ graph TD> **Note:** Traces are the foundation of observability in LLM applications.#### Creating Traces-\`\`\`typescript-// Basic trace creation-const trace = langfuse.trace({- name: "user-query-processing",- userId: "user-123",- sessionId: "session-456",- metadata: {- environment: "production",- version: "2.1.0"- }-})--// Nested observations-const span = trace.span({- name: "document-retrieval",- input: { query: "What is machine learning?" },- metadata: { vectorStore: "pinecone" }-})--const generation = span.generation({- name: "answer-generation",- model: "gpt-4",- input: retrievedDocs,- output: generatedAnswer,- usage: {- promptTokens: 1250,- completionTokens: 420,- totalTokens: 1670- }-})+\`\`\`typescript+// Basic trace creation+const trace = langfuse.trace({+ name: "user-query-processing",+ userId: "user-123",+ sessionId: "session-456",+ metadata: {+ environment: "production",+ version: "2.1.0"+ }+})++// Nested observations+const span = trace.span({+ name: "document-retrieval",+ input: { query: "What is machine learning?" },+ metadata: { vectorStore: "pinecone" }+})++const generation = span.generation({+ name: "answer-generation",+ model: "gpt-4",+ input: retrievedDocs,+ output: generatedAnswer,+ usage: {+ promptTokens: 1250,+ completionTokens: 420,+ totalTokens: 1670+ }+})\`\`\`### Advanced Features#### π Async Processing-\`\`\`python-import asyncio-from langfuse import Langfuse--async def process_batch():- langfuse = Langfuse()-- tasks = []- for item in batch_items:- task = asyncio.create_task(- process_item_with_tracing(langfuse, item)- )- tasks.append(task)-- results = await asyncio.gather(*tasks)- return results+\`\`\`python+import asyncio+from langfuse import Langfuse++async def process_batch():+ langfuse = Langfuse()++ tasks = []+ for item in batch_items:+ task = asyncio.create_task(+ process_item_with_tracing(langfuse, item)+ )+ tasks.append(task)++ results = await asyncio.gather(*tasks)+ return results\`\`\`#### π― Custom Scoring-\`\`\`typescript-// Automated scoring-trace.score({- name: "relevance",- value: 0.95,- comment: "Highly relevant response"-})--// Human feedback scoring-trace.score({- name: "user-satisfaction",- value: 1,- source: "user-feedback",- comment: "User rated 5/5 stars"-})+\`\`\`typescript+// Automated scoring+trace.score({+ name: "relevance",+ value: 0.95,+ comment: "Highly relevant response"+})++// Human feedback scoring+trace.score({+ name: "user-satisfaction",+ value: 1,+ source: "user-feedback",+ comment: "User rated 5/5 stars"+})\`\`\`---@@ -156,20 +156,20 @@ trace.score({- **User Satisfaction**: Quality metrics#### Dashboard Setup-\`\`\`yaml-# monitoring-config.yml-dashboards:- - name: "LLM Performance"- panels:- - type: "time-series"- title: "Response Latency"- query: "avg(response_time) by (model)"- - type: "stat"- title: "Daily Token Usage"- query: "sum(tokens_used)"- - type: "table"- title: "Top Errors"- query: "topk(10, count by (error_type))"+\`\`\`yaml+# monitoring-config.yml+dashboards:+ - name: "LLM Performance"+ panels:+ - type: "time-series"+ title: "Response Latency"+ query: "avg(response_time) by (model)"+ - type: "stat"+ title: "Daily Token Usage"+ query: "sum(tokens_used)"+ - type: "table"+ title: "Top Errors"+ query: "topk(10, count by (error_type))"\`\`\`### π Security Considerations@@ -177,40 +177,40 @@ dashboards:> β οΈ **Important**: Never log sensitive user data in traces#### Data Sanitization-\`\`\`python-def sanitize_input(data):- """Remove PII from trace data"""- sanitized = data.copy()-- # Remove email addresses- sanitized = re.sub(r'\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}\\b',- '[EMAIL_REDACTED]', sanitized)-- # Remove phone numbers- sanitized = re.sub(r'\\b\\d{3}-\\d{3}-\\d{4}\\b',- '[PHONE_REDACTED]', sanitized)-- return sanitized+\`\`\`python+def sanitize_input(data):+ """Remove PII from trace data"""+ sanitized = data.copy()++ # Remove email addresses+ sanitized = re.sub(r'\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}\\b',+ '[EMAIL_REDACTED]', sanitized)++ # Remove phone numbers+ sanitized = re.sub(r'\\b\\d{3}-\\d{3}-\\d{4}\\b',+ '[PHONE_REDACTED]', sanitized)++ return sanitized\`\`\`### π Performance Optimization#### Batch Processing-\`\`\`typescript-// Efficient batch uploads-const batchSize = 100-const traces = []--for (let i = 0; i < data.length; i += batchSize) {- const batch = data.slice(i, i + batchSize)- const processedBatch = await Promise.all(- batch.map(item => processWithLangfuse(item))- )- traces.push(...processedBatch)-}--// Flush all traces at once-await langfuse.flushAsync()+\`\`\`typescript+// Efficient batch uploads+const batchSize = 100+const traces = []++for (let i = 0; i < data.length; i += batchSize) {+ const batch = data.slice(i, i + batchSize)+ const processedBatch = await Promise.all(+ batch.map(item => processWithLangfuse(item))+ )+ traces.push(...processedBatch)+}++// Flush all traces at once+await langfuse.flushAsync()\`\`\`---@@ -219,34 +219,34 @@ await langfuse.flushAsync()### Multi-Agent System Tracing\`\`\`python-class MultiAgentTracer:- def __init__(self):- self.langfuse = Langfuse()-- async def orchestrate_agents(self, task):- # Main orchestration trace- main_trace = self.langfuse.trace(- name="multi-agent-orchestration",- input={"task": task}- )-- # Agent 1: Research- research_span = main_trace.span(name="research-agent")- research_result = await self.research_agent.process(task)- research_span.end(output=research_result)-+class MultiAgentTracer:+ def __init__(self):+ self.langfuse = Langfuse()++ async def orchestrate_agents(self, task):+ # Main orchestration trace+ main_trace = self.langfuse.trace(+ name="multi-agent-orchestration",+ input={"task": task}+ )++ # Agent 1: Research+ research_span = main_trace.span(name="research-agent")+ research_result = await self.research_agent.process(task)+ research_span.end(output=research_result)+# Agent 2: Analysis- analysis_span = main_trace.span(name="analysis-agent")- analysis_result = await self.analysis_agent.process(research_result)- analysis_span.end(output=analysis_result)-- # Agent 3: Synthesis- synthesis_span = main_trace.span(name="synthesis-agent")- final_result = await self.synthesis_agent.process(analysis_result)- synthesis_span.end(output=final_result)-- main_trace.end(output=final_result)- return final_result+ analysis_span = main_trace.span(name="analysis-agent")+ analysis_result = await self.analysis_agent.process(research_result)+ analysis_span.end(output=analysis_result)++ # Agent 3: Synthesis+ synthesis_span = main_trace.span(name="synthesis-agent")+ final_result = await self.synthesis_agent.process(analysis_result)+ synthesis_span.end(output=final_result)++ main_trace.end(output=final_result)+ return final_result\`\`\`---@@ -256,11 +256,11 @@ class MultiAgentTracer:With proper implementation of Langfuse tracing, you can:- β **Monitor** your LLM applications in real-time-- β **Debug** issues with detailed trace information+- β **Debug** issues with detailed trace information- β **Optimize** performance and costs- β **Scale** your applications with confidence### Next Steps1. Review the [official documentation](https://langfuse.com/docs)2. Join our [Discord community](https://discord.gg/langfuse)-3. Check out [example projects](https://github.com/langfuse/langfuse)\ No newline at end of file+3. Check out [example projects](https://github.com/langfuse/langfuse)diff --git a/web/src/components/ui/MarkdownViewer.tsx b/web/src/components/ui/MarkdownViewer.tsxindex f487e628f9..d6c00e6260 100644--- a/web/src/components/ui/MarkdownViewer.tsx+++ b/web/src/components/ui/MarkdownViewer.tsx@@ -123,7 +123,7 @@ function MarkdownRenderer({return (<MemoizedReactMarkdownclassName={cn(- "space-y-2 overflow-x-auto whitespace-pre-wrap break-words text-sm",+ "overflow-x-auto break-words text-sm leading-relaxed",className,)}remarkPlugins={[remarkGfm]}@@ -132,9 +132,7 @@ function MarkdownRenderer({if (isImageNode(node)) {return <>{children}</>;}- return (- <p className="mb-2 whitespace-pre-wrap last:mb-0">{children}</p>- );+ return <p className="mb-2 last:mb-0">{children}</p>;},a({ children, href }) {const safeHref = getSafeUrl(href);@@ -160,10 +158,12 @@ function MarkdownRenderer({if (isChecklist(children))return <ul className="list-none">{children}</ul>;- return <ul className="list-inside list-disc">{children}</ul>;+ return <ul className="mb-1 list-inside list-disc">{children}</ul>;},ol({ children }) {- return <ol className="list-inside list-decimal">{children}</ol>;+ return (+ <ol className="mb-1 list-inside list-decimal">{children}</ol>+ );},li({ children }) {return (@@ -173,22 +173,42 @@ function MarkdownRenderer({);},pre({ children }) {- return <pre className="rounded p-2">{children}</pre>;+ return <pre className="mb-1 rounded p-2">{children}</pre>;},h1({ children }) {- return <h1 className="text-2xl font-bold">{children}</h1>;+ return (+ <h1 className="mb-2 mt-5 border-b pb-2 text-2xl font-bold first:mt-0">+ {children}+ </h1>+ );},h2({ children }) {- return <h2 className="text-xl font-bold">{children}</h2>;+ return (+ <h2 className="mb-2 mt-4 text-xl font-bold first:mt-0">+ {children}+ </h2>+ );},h3({ children }) {- return <h3 className="text-lg font-bold">{children}</h3>;+ return (+ <h3 className="mb-2 mt-3 text-lg font-bold first:mt-0">+ {children}+ </h3>+ );},h4({ children }) {- return <h4 className="text-base font-bold">{children}</h4>;+ return (+ <h4 className="mb-1 mt-2 text-base font-bold first:mt-0">+ {children}+ </h4>+ );},h5({ children }) {- return <h5 className="text-sm font-bold">{children}</h5>;+ return (+ <h5 className="mb-1 mt-1 text-sm font-bold first:mt-0">+ {children}+ </h5>+ );},h6({ children }) {return <h6 className="text-xs font-bold">{children}</h6>;@@ -217,7 +237,7 @@ function MarkdownRenderer({},blockquote({ children }) {return (- <blockquote className="border-l-4 pl-4 italic">+ <blockquote className="mb-1 border-l-4 pl-4 italic">{children}</blockquote>);@@ -230,7 +250,7 @@ function MarkdownRenderer({},table({ children }) {return (- <div className="overflow-x-auto rounded border text-xs">+ <div className="mb-1 overflow-x-auto rounded border text-xs"><table className="min-w-full divide-y">{children}</table></div>);