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

[REQUEST] How to use the Rich library to stream print the content of the current chatgpt and support markup rendering #3046

Closed
xiaoymin opened this issue Jul 21, 2023 · 3 comments

Comments

@xiaoymin
Copy link

xiaoymin commented Jul 21, 2023

Now,I use live.update method to display content with markdown content by HTTP SSE response ,simple code like:

    console = Console()
    md_content=""
    with Live(console=console, refresh_per_second=4) as live:
        i=0
        for event in response.events():
            if event.event == "add":
                md_content=md_content+event.data
            elif event.event == "error" or event.event == "interrupted":

                md_content=md_content+event.data
            elif event.event == "finish":

                md_content=md_content+event.data
            else:

            md = Markdown(md_content)
            live.update(md)

Now,use like OpenAI api use sse protocol to send data is not all result at onece.so the markdown content i must be concat together and then use Markdown method to init .

this way can resolve my problem. But the screen keeps flashing, and the experience is very poor。

So, may I ask if there is a better way?

Thanks

@github-actions
Copy link

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@willmcgugan
Copy link
Collaborator

You would be better off using Textual (https://github.com/Textualize/textual) for something like this.

@github-actions
Copy link

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

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

No branches or pull requests

2 participants