ChatGPT icon indicating copy to clipboard operation
ChatGPT copied to clipboard

Examples needed for AsyncChatbot usage

Open Oaklight opened this issue 2 years ago • 6 comments

Is your feature request related to a problem? Please describe. Examples needed for AsyncChatbot usage.

Oaklight avatar Dec 14 '22 12:12 Oaklight

May this help you. text mode

        try:
            co = await chatgpt_bot.get_chat_response(question)
            print("Waiting ChatGPT")
            message = co['message']
            print(resp, message)
        except:
            print( "Error on OpenAI by "+ question)

Stream mode:

        print("Try stream")
        try:
            cog = await chatgpt_bot.get_chat_response(question, output="stream")
            i=0
            async for co in cog:
                if i==0:
                    conversation: Union[
                        Room, Contact] = from_contact if room is None else room
                    await conversation.ready()
                    await conversation.say("CHATGPT: waiting...")
                    i += 1
                message = co['message']
                #print(resp, message)
        except Exception as e:
            message = "Error from OpenAI on 【" + question +"】 by 【" + str(e) + "】"

c2j avatar Dec 14 '22 12:12 c2j

I'm wondering in case I have multiple prompts that need to run in parallel (or with non-blocking). Can async do that or should I couple it with multiprocess?

Oaklight avatar Dec 14 '22 12:12 Oaklight

May this help you. text mode

        try:
            co = await chatgpt_bot.get_chat_response(question)
            print("Waiting ChatGPT")
            message = co['message']
            print(resp, message)
        except:
            print( "Error on OpenAI by "+ question)

What is resp in this snippet?

Oaklight avatar Dec 14 '22 12:12 Oaklight

May this help you. text mode

        try:
            co = await chatgpt_bot.get_chat_response(question)
            print("Waiting ChatGPT")
            message = co['message']
            print(resp, message)
        except:
            print( "Error on OpenAI by "+ question)

What is resp in this snippet?

resp and question are the same var.

c2j avatar Dec 14 '22 14:12 c2j

I'm wondering in case I have multiple prompts that need to run in parallel (or with non-blocking). Can async do that or should I couple it with multiprocess?

I Suggest don't call too many times at same time, other wise you will get "Too many requests, please slow down"

c2j avatar Dec 14 '22 14:12 c2j

I see, would regularly refreshing the session instead of reset the chat work better to fool the server?

Oaklight avatar Dec 14 '22 17:12 Oaklight