Giter Club home page Giter Club logo

Comments (36)

acheong08 avatar acheong08 commented on May 22, 2024 1

Example code: #5 (comment)

from chatgpt.

scottleibrand avatar scottleibrand commented on May 22, 2024 1

Opened #23

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

Happy to help, whether that means picking up where you left off or figuring it out from scratch...

A pull request would be much appreciated.

Perhaps there could be another parameter to get_chat_response to specify the return type: text or stream, with text as default

from chatgpt.

scottleibrand avatar scottleibrand commented on May 22, 2024

Ok, I'll try to take a look tomorrow. LMK if you find anything out about how it's done in the browser: I haven't done any research yet.

from chatgpt.

A-kirami avatar A-kirami commented on May 22, 2024

I implemented streaming response, but I don't know how to output it on the console.

from chatgpt.

A-kirami avatar A-kirami commented on May 22, 2024

I implemented streaming response, but I don't know how to output it on the console.

I solved the problem, but the method was ugly.

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

@A-kirami I have written a rough implementation of text streaming. Can you check if it works as intended (It works for me but need verification)

get_chat_response(prompt, output="stream") should yield each message.

if __name__ == "__main__":
    with open("config.json", "r") as f:
        config = json.load(f)
    chatbot = Chatbot(config)
    if 'session_token' in config:
        chatbot.refresh_session()
    while True:
        prompt = input("You: ")
        for message in chatbot.get_chat_response(prompt, output="stream"):
            print(message)

This should print out the message as it streams. I'm not sure how to deal with the console so that it is overwritten as more data comes in.

from chatgpt.

A-kirami avatar A-kirami commented on May 22, 2024

@A-kirami I have written a rough implementation of text streaming. Can you check if it works as intended (It works for me but need verification)

get_chat_response(prompt, output="stream") should yield each message.

if __name__ == "__main__":
    with open("config.json", "r") as f:
        config = json.load(f)
    chatbot = Chatbot(config)
    if 'session_token' in config:
        chatbot.refresh_session()
    while True:
        prompt = input("You: ")
        for message in chatbot.get_chat_response(prompt, output="stream"):
            print(message)

This should print out the message as it streams. I'm not sure how to deal with the console so that it is overwritten as more data comes in.

It works normally. If you need to print it on the console, you can refer to the implementation here.

https://github.com/A-kirami/ChatGPT/blob/main/src/revChatGPT/__main__.py#L69-L81

from chatgpt.

A-kirami avatar A-kirami commented on May 22, 2024

@acheong08

Like this:

demo

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

I am terrible at this. It keeps erasing the lines in my implementation

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

I'll copy your code over and modify it

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

This doesn't work in all terminals:


Detected that the lines of output has been exceeded the height of terminal windows, which                     caused the former output remained and keep adding new lines.
检测到输出过程中, 输出行数曾大于命令行窗口行数, 这会导致输出清除不完整, 而使输出不停增长。请注意控制输出行数

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024
sys.stdout.write("\033[F\033[K")

This doesn't work properly in all terminals either for some reason. My hair is falling off lol

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

The error seems to be that this deletes the number of lines it is aware of but in some terminals, line count is counted differently

from chatgpt.

scottleibrand avatar scottleibrand commented on May 22, 2024

The approach I was attempting (but haven't perfected yet) is to only write a line once it is has completely loaded, rather than deleting lines after they're written. Would that work here?

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

That is what I'm attempting to do. I write the whole message and then when a new one comes in, I try to delete the previous message. It's not clearing the right number of lines though.

from chatgpt.

scottleibrand avatar scottleibrand commented on May 22, 2024

I'm suggesting you not try to delete the previous message (as I did with the please wait prompt), but rather keep track of how many lines you've written, and only write each new line.

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

keep track of how many lines you've written

Tried that. An issue with this is that some environments treat lines differently. For example, my current omz shell treats each new line in the terminal as a new line (which changes depending on window size). However, Python can only see \n as new line

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

I tried counting the characters and saving them, then deleting that number of characters when a new message comes in. However, \b isn't supported in some terminals either.

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

Not even ChatGPT knows the solution to this...

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

I think streaming is more suited for GUI applications. Terminals don't like overwrites

from chatgpt.

scottleibrand avatar scottleibrand commented on May 22, 2024

Do you have a pointer to a commit that has streaming working but doesn't have the terminal stuff solved yet? I can restart my efforts from there.

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

Streaming working on latest commit

from chatgpt.

scottleibrand avatar scottleibrand commented on May 22, 2024

Of main or async-dev?

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

main

from chatgpt.

scottleibrand avatar scottleibrand commented on May 22, 2024

On that commit I'm getting

  File "/Users/sleibrand/src/ChatGPT/src/revChatGPT/__main__.py", line 70, in <module>
    print("Chatbot:", response['message'])
TypeError: 'generator' object is not subscriptable

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

It returns a string. I didn't update the docs yet. You need to call with output="stream"

from chatgpt.

scottleibrand avatar scottleibrand commented on May 22, 2024

I've been running it with python3 -m revChatGPT - is there another command-line you've been using?

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

I've been running it with python3 -m revChatGPT - is there another command-line you've been using?

It can only be implemented custom right now.

from chatgpt.

scottleibrand avatar scottleibrand commented on May 22, 2024

https://github.com/acheong08/ChatGPT/compare/main...scottleibrand:ChatGPT:async?expand=1

~/src/ChatGPT $ python3 -m revChatGPT

    ChatGPT - A command-line interface to OpenAI's ChatGPT (https://chat.openai.com/chat)
    Repo: github.com/acheong08/ChatGPT

Type '!help' to show commands
Press enter twice to submit your question.

You: test

...
I'm sorry, but I'm not sure what you're looking for. Could you please provide
more information or context? I'm a large language model trained by OpenAI, and
I'm here to help with any questions you may have.




You:

Cleaning up, then will PR.

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

@scottleibrand

Chatbot: 
Something went wrong!
name 'formatted_parts' is not defined

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

I ought to have some better way to detect auth errors

from chatgpt.

scottleibrand avatar scottleibrand commented on May 22, 2024

Yeah, that has tripped me up a few times too. Can we store more persistent credentials to allow it to log in again?

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

The thing with the next auth tokens is that it needs to be refreshed every hour via !refresh. It stays valid that way. However, if you don't refresh it, it expires.

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

I haven't figured out their hashing system on the login page. It hashes the password client side

from chatgpt.

acheong08 avatar acheong08 commented on May 22, 2024

I'll open an issue for this

from chatgpt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.