Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown streaming puts each token in a separate paragraph #155

Open
nat-n opened this issue Dec 11, 2024 · 0 comments
Open

Markdown streaming puts each token in a separate paragraph #155

nat-n opened this issue Dec 11, 2024 · 0 comments

Comments

@nat-n
Copy link

nat-n commented Dec 11, 2024

I'm hacking together a custom response renderer where I want to be able to have some logic to edit the stream as it is rendered but still benefit from streaming markdown rendering.

He's my attempt to create a component that could allow me to do this:

const CustomResponseRenderer: ResponseRenderer<string> = (props) => {
  let markdownRef = useRef(null)
  let tokenCount = useRef(0)

  let mdStreamParser: MarkdownStreamParser

  if (markdownRef.current && props.content.length) {
    mdStreamParser = createMarkdownStreamParser(markdownRef.current, {
      waitTimeBeforeStreamCompletion: 2000,
    })
  }

  useEffect(() => {
    mdStreamParser?.next(props.content.slice(tokenCount.current).join(''))
    tokenCount.current = props.content.length
  }, [props.content.join('')])

  return (
    <div>
      <div ref={markdownRef} />Y
    </div>
  )
}

The weird this is that what gets rendered into the referenced div is a <p> paragraph per token, that is per call to mdStreamParser?.next. There are no line breaks in the text. Am I doing something wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant