nek0us / ChatGPT

a ChatGPT api,no web ui
GNU General Public License v3.0
11 stars 3 forks source link

cannot access local variable 'page' #1

Closed 3mora2 closed 7 months ago

3mora2 commented 7 months ago
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3.2\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
           ^^^^^^
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3.2\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "E:\Projects\Python\GPT4\test_ChatGPTWeb.py", line 56, in <module>
    loop.run_until_complete(main())
  File "C:\Users\ammar\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "E:\Projects\Python\GPT4\test_ChatGPTWeb.py", line 51, in main
    data = await chat.continue_chat(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Projects\Python\GPT4\venvtest\Lib\site-packages\ChatGPTWeb\ChatGPTWeb.py", line 547, in continue_chat
    msg_data = await self.send_msg(msg_data,page,token,context_num)
                                   ^^^^^^^^
UnboundLocalError: cannot access local variable 'page' where it is not associated with a value
nek0us commented 7 months ago

can u post the code to call "chat.continue_chat"

3mora2 commented 7 months ago

same in __main__.py

from ChatGPTWeb.ChatGPTWeb import chatgpt
from ChatGPTWeb.config import Personality, MsgData
import asyncio
import aioconsole

 session_token = [ "" ]

personality_definition = Personality(
    [
        {
            "name": "Programmer",
            'value': 'You are python Programmer'
        },

    ])

chat = chatgpt(session_token=session_token, headless=False, begin_sleep_time=False)

# ,log_status=False
async def main():
    c_id = await aioconsole.ainput("your conversation_id if you have:")
    p_id = await aioconsole.ainput("your parent_message_id if you have:")
    data: MsgData = MsgData(conversation_id=c_id, p_msg_id=p_id)
    while 1:
        print("\n------------------------------")
        data.msg_send = await aioconsole.ainput("input:")
        print("------------------------------\n")
        if data.msg_send == "quit":
            break
        elif data.msg_send == "re":
            data.msg_type = "back_loop"
            data.p_msg_id = await aioconsole.ainput("your parent_message_id if you go back:")
        elif data.msg_send == "reset":
            data = await chat.back_init_personality(data)
            print(f"ChatGPT:{data.msg_recv}")
            continue
        elif data.msg_send == "init_personality":
            data.msg_send = "your ..."
            data = await chat.init_personality(data)
            print(f"ChatGPT:{data.msg_recv}")
            continue
        elif data.msg_send == "history":
            print(await chat.show_chat_history(data))
            continue
        elif data.msg_send == "status":
            print(await chat.token_status())
            continue
        data = await chat.continue_chat(data)
        print(f"ChatGPT:{data.msg_recv}")

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
nek0us commented 7 months ago

Did you enter a non-existent conversation_id during startup?

When starting, it will first prompt "your conversation_id if you have:". If not, just press the enter key. The second prompt "your parent_message_id if you have:" will do the same until it prompts "input:".

But sometimes the log will affect the vision.

The incorrect conversation_id problem will be fixed in the near future. Some new parameter descriptions will also be added.

3mora2 commented 7 months ago

now it work fine, thinks