Skip to content

Commit

Permalink
useLLMOutput performance fixes (#261)
Browse files Browse the repository at this point in the history
Performance improvement: Only log console warnings in dev
  • Loading branch information
richardgill committed Jun 1, 2024
1 parent 3a06746 commit 9360d30
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-avocados-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@llm-ui/react": patch
---

Performance improvement: Only log console warnings in dev
3 changes: 2 additions & 1 deletion apps/www/src/components/demo/message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { buttonsJsonBlock as createJsonButtonsBlock } from "@/components/example
import { codeBlockBlock } from "@/components/examples/CodeBlock";
import { Markdown } from "@/components/examples/Markdown";
import { markdownLookBack } from "@llm-ui/markdown";
import { useLLMOutput } from "@llm-ui/react";
import { throttleBasic, useLLMOutput } from "@llm-ui/react";

const buttonsJsonBlock = createJsonButtonsBlock();
const buttonsCsvBlock = createCsvButtonsBlock();
Expand All @@ -21,6 +21,7 @@ export const Message: React.FC<{
},
blocks: [codeBlockBlock, buttonsJsonBlock, buttonsCsvBlock],
isStreamFinished,
throttle: throttleBasic({ targetBufferChars: 60 }),
});

// min-w-0 stops overflows
Expand Down
5 changes: 4 additions & 1 deletion packages/react/src/core/useLLMOutput/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ const matchesWithLookback = ({
isStreamFinished: isStreamFinished,
output: match.match.outputRaw,
});
if (visibleText.length > localVisibleTextLengthTarget) {
if (
visibleText.length > localVisibleTextLengthTarget &&
process.env.NODE_ENV !== "production"
) {
console.warn(
`Visible text length exceeded target for: ${visibleText} has length ${visibleText.length} target: ${localVisibleTextLengthTarget}. Raw output: ${llmOutputRaw}`,
);
Expand Down

0 comments on commit 9360d30

Please sign in to comment.