V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
sleeplessy
V2EX  ›  OpenAI

一个简单且很糙的 ChatGPT TG Bot

  •  1
     
  •   sleeplessy · 2022-12-12 21:37:33 +08:00 · 5133 次点击
    这是一个创建于 712 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Repo: https://github.com/code-monad/ChatGPTBot
    功能要点:

    1. 支持回滚。 使用指令`/rollback`可以反悔,让 ChatGPT 忘记当前 session 下的上一条你的 prompt
    2. 支持保存对话网络,支持历史加载(快速加载调教效果)。程序关闭时会把你保存的历史记录保存在本地目录的`memories.sav`下,启动时会自动加载。效果如下图:
    3. 支持代理设置。需要在配置文件中配置相关的字段。因为 api 相关问题,你可能还需要额外传`HTTPS_PROX=xxx`环境变量运行。

    https://imgur.com/a/FhEbrF3
    https://imgur.com/a/PByivQK
    https://imgur.com/a/PQu3afm


    很久没写 py 了,代码毕竟糙,不过能跑,逻辑应该理解起来也不难,比网页的体验要好不少,关键是方便。做了最简单的 debug/error handle ,出了问题的时候请尽量先自己查
    https://github.com/acheong08/ChatGPT/wiki
    为了防止一键滥用,目前默认是白名单模式,只会回复配置文件中 `allow` 字段配置的 tg 用户 ID 。
    关于如何获取你的 tg ID:tg 中搜索 @userinfobot
    第 1 条附言  ·  2022-12-12 22:54:49 +08:00
    实际测试之后,很适合拿来对话重现、分区里老哥们喜欢的人格快速重载,降低重复调教的过程。
    因为没有复数个账户,尚不清楚能否使用 id 来跨账户复现热载。
    另外在 OpenAI 加入 CF 之后,一堆 bot 死了,滥用的情况缓解了很多,服务相对应可用度也高了。
    我这个 bot 里所使用的是逆向 API lib( https://github.com/acheong08/ChatGPT),不会依赖 chromium 之类,也不会像 star 最多的 go 的那个一样高频度挂掉,就算 error 了,基本上大部分的场景都能直接继续。
    第 2 条附言  ·  2022-12-13 13:00:31 +08:00
    Update: 最近的更新为了适应 CF 相关的变更,已经需要依赖 undetected_chrome 了,也就是你需要安装 chrome 使用。详情看我在 #21 楼的回复( https://v2ex.com/t/902050#r_12458444)
    第 3 条附言  ·  2022-12-13 13:19:25 +08:00
    2022/12/13 13:00 该项目目前结合最新的 revChatGPT 是可以正常运作的,不需要修改代码、配置。
    PS:如果我的这个 Project 有帮助到你们,还请点个 Star !谢谢!
    44 条回复    2022-12-15 21:58:28 +08:00
    sleeplessy
        1
    sleeplessy  
    OP
       2022-12-12 21:58:30 +08:00
    最简单的测试方法:
    先让 ChatGPT 给你更换一个称呼、或者是让它在文中加入某些文字、符号。
    保存并刷新后,ai 不记得前后文。重新加载后,重新出现你曾经留下过的标记。刷新后
    sleeplessy
        2
    sleeplessy  
    OP
       2022-12-13 01:04:07 +08:00
    增加了一些方便使用的指令。大部分的加载、重试都简化成了点击按钮。
    /reroll 可以让 ai 忘记并重新生成上一句回复。
    结合 tg 的 menu 菜单,体验暴增…
    sleeplessy
        3
    sleeplessy  
    OP
       2022-12-13 03:52:50 +08:00 via iPhone
    https://i.imgur.com/NeKcNnN_d.webp

    自己玩自己的 bot 上头了。果然涉及到 xp 人就容易嗨过头呢(笑)
    看着这堆列表,有种人格收集、调教记录簿的感觉。我可以从任意一个人格的任意一个阶段介入,尝试不同的逻辑、手段对 ai 人格的影响。
    这个中间可能会有意想不到的收获,当然 18 禁也自然是少不了的。
    总之,自己的 xp 得到了大满足。
    genhikari
        4
    genhikari  
       2022-12-13 08:22:10 +08:00
    大佬你好,我是纯小白,我也想做到人格快速重载,但是只看这些我还是不懂应该怎么操作。请问方便的话能否讲一下操作步骤,不方便的话就不多加打扰了,谢谢。
    sleeplessy
        5
    sleeplessy  
    OP
       2022-12-13 08:36:56 +08:00 via iPhone
    @genhikari 你有 chatgpt 账号吗?我开发的这个是一个 tg bot ,所以除此之外你还需要一个正常的 tg 账号。如果这两个你都有的情况下,操作其实还是挺简单的
    genhikari
        6
    genhikari  
       2022-12-13 09:33:07 +08:00
    chatgpt 账号我有,刚刚在手机上注册了 tg 账号,请问可以吗?
    sleeplessy
        7
    sleeplessy  
    OP
       2022-12-13 09:58:52 +08:00   ❤️ 1
    @genhikari
    1. 首先参考 https://github.com/acheong08/ChatGPT/wiki/Setup#getting-the-details ,在浏览器中用开发者模式(在 chatGPT 的页面按 F12 ,找到下面这两个 cookies: __Secure-next-auth.session-token 和 cf_clearance 。

    2. 另外在你的浏览器的网络请求界面查看你的 UA ,比如我的就是“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.46”,这个必须跟你拿 cookies 的浏览器一致,所以不要复制我的。大概这样看: https://imgur.com/a/jpSbi88

    3. 申请 tgbot 。在 tg 里面搜索用户(@BotFather), 或者用这个链接: https://t.me/BotFather 。对它发送 /newbot, 然后根据它的提示一步一步回复 显示名称、用户名,它会提示你创建成功,复制 Use this token to access the HTTP API:下面那行蓝色的字符,它就是你的 bot KEY 。

    4. 获取你的 userID 。在 tg 里搜索用户(@userinfobot),或者用这个链接: https://t.me/userinfobot 。它会对你回复你的用户信息,复制它回复你的 Id: xxxx 的这个值。

    5. 克隆我的这个项目。你可以在有 git 的机器上上运行下面这行命令:
    git clone https://github.com/code-monad/ChatGPTBot.git
    也可以使用 https://github.com/code-monad/ChatGPTBot/archive/refs/heads/master.zip 下载解压。
    记得你的运行环境上要安装 python 。我觉得你在 v2 的话应该知道如何处理。
    确认你的运行环境没问题,执行下面几步(我默认你是 linux 或者 mac 了):
    # Install telegram bot library
    git clone https://github.com/python-telegram-bot/python-telegram-bot
    cd python-telegram-bot && python setup.py install --user
    # For proxy support
    pip install httpx[socks]

    # Install ChatGPT API
    git clone https://github.com/acheong08/ChatGPT
    cd ChatGPT && python setup.py install --user
    # Install other requirements
    pip install toml emoji loguru

    #-------------------------------

    上面前 4 步分别拿到了 5 个东西,他们在配置文件 config.toml 里的对应关系是:
    __Secure-next-auth.session-token 对应配置模板里的 <OPENAI_SESSION_TOKEN>,https://github.com/code-monad/ChatGPTBot/blob/master/config.example.toml#L6
    cf_clearance 对应配置模板里的 <OPENAI_SESSION_CF_CLEARANCE>,https://github.com/code-monad/ChatGPTBot/blob/master/config.example.toml#L7
    UA 对应对应配置模板里的<YOUR_BROWSER'S_UA>,https://github.com/code-monad/ChatGPTBot/blob/master/config.example.toml#L8
    bot KEY 对应配置模板里的 TELEGRAM_BOT_TOKEN ,https://github.com/code-monad/ChatGPTBot/blob/master/config.example.toml#L2
    userID 对应配置模板里的 <TELEGRAM_USER_ID>, https://github.com/code-monad/ChatGPTBot/blob/master/config.example.toml#L3
    把它们一一替换进去,然后把文件保存为 config.toml ,这个文件应该与 main.py 在同一目录下。
    如果你运行的环境不需要代理,记得把[proxy]之下的内容删掉。
    然后运行 python main.py
    如果没有任何报错,你就可以跟你的 bot 对话了。

    Bot 的快捷菜单可以在 BotFather 那里设置,通过对 BotFather 发送 /setcommands ,然后选择你的 bot ,回复指令描述就行。下面是我的设置:
    reroll - 刷新回复
    start - 初始化
    list - 列出回忆
    reborn - 重生
    rollback - 忘记上一条
    sleeplessy
        8
    sleeplessy  
    OP
       2022-12-13 10:03:11 +08:00
    你要记得 openai 的 session-token ,cf_clearance 都只有半个小时的有效时间,我已经在 bot 里把自动刷新、保存的逻辑做了,但如果你启动的时候提示错误 Wrong response code ,那可能是你写在配置里的这两个值已经过期了,重新拿一下就好。只要正常运行起来之后,就可以一直稳定运行了。如果提示类似 Invalid data 、not Json 之类的错误的时候,有两种情况。一种是 openai 的负载太高导致响应失败了,另一种是你触发了风控,不管是哪种,你重发一下信息应该能正常回复,较小的概率会持续失败。遇到这种情况,先保存一下当前人格(使用 /reborn 指令并保存),然后重新初始化一下基本上能解决。
    genhikari
        9
    genhikari  
       2022-12-13 10:03:38 +08:00
    谢谢大佬,我试一试
    tangneo
        10
    tangneo  
       2022-12-13 10:10:44 +08:00
    大佬,这个问题该如何处理?

    正在初始化……
    An exception was raised while handling an update
    Traceback (most recent call last):
    File "/root/chatgpt/ChatGPTBot-master/main.py", line 123, in start
    chatbot = Chatbot(config, conversation_id=None)
    File "/root/.local/lib/python3.10/site-packages/revChatGPT-0.0.38.8-py3.10.egg/revChatGPT/revChatGPT.py", line 96, in __init__
    self.refresh_session()
    File "/root/.local/lib/python3.10/site-packages/revChatGPT-0.0.38.8-py3.10.egg/revChatGPT/revChatGPT.py", line 308, in refresh_session
    raise Exception("Wrong response code")
    Exception: Wrong response code

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/ext/_application.py", line 1057, in process_update
    await coroutine
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/ext/_handler.py", line 143, in handle_update
    return await self.callback(update, context)
    File "/root/chatgpt/ChatGPTBot-master/main.py", line 127, in start
    await update.message.reply_text(emojize(":sweat_drops:初始化失败! 原因: `{}` ".format(e)),
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/_message.py", line 875, in reply_text
    return await self.get_bot().send_message(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/ext/_extbot.py", line 2482, in send_message
    return await super().send_message(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/_bot.py", line 313, in decorator
    result = await func(*args, **kwargs) # skipcq: PYL-E1102
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/_bot.py", line 734, in send_message
    return await self._send_message( # type: ignore[return-value]
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/ext/_extbot.py", line 485, in _send_message
    result = await super()._send_message(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/_bot.py", line 486, in _send_message
    result = await self._post(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/_bot.py", line 395, in _post
    return await self._do_post(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/ext/_extbot.py", line 306, in _do_post
    return await super()._do_post(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/_bot.py", line 426, in _do_post
    return await request.post(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/request/_baserequest.py", line 167, in post
    result = await self._request_wrapper(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/request/_baserequest.py", line 330, in _request_wrapper
    raise BadRequest(message)
    telegram.error.BadRequest: Can't parse entities: can't find end of italic entity at byte offset 6
    sleeplessy
        11
    sleeplessy  
    OP
       2022-12-13 10:13:48 +08:00
    @yaovenus 你获取的 session-token, cf_clearance 过期了,或者不合法。
    你获取的时候浏览器的 IP 应该与你的 vps IP 一致。最简单的仿佛就是开浏览器代理
    tangneo
        12
    tangneo  
       2022-12-13 10:30:30 +08:00
    @sleeplessy 重新获取的 session-token, cf_clearance 还是报一样的错误。IP 地址没问题,查了一下。
    sleeplessy
        13
    sleeplessy  
    OP
       2022-12-13 10:39:40 +08:00
    @yaovenus UA 也需要一致。另外你可能需要对这个网站请求的所有资源都使用 proxy 。logout 再重新 login 一次,然后获取,关闭网页,不要再通过网页来使用了。
    sleeplessy
        14
    sleeplessy  
    OP
       2022-12-13 10:47:11 +08:00
    @yaovenus 此外。我刚检查了下 issue ,似乎是 CF 的验证流程改了。可能需要稍微等待一下修改更新(
    tangneo
        15
    tangneo  
       2022-12-13 10:49:17 +08:00
    @sleeplessy 不知道哪里出问题了,还是报一样的错。我把 config.toml 里的代理关了,不会是这里的问题吧?
    sleeplessy
        16
    sleeplessy  
    OP
       2022-12-13 11:03:02 +08:00
    @yaovenus 看上一条回复。其实应该不是配置问题,只是刚好赶上 OpenAI 改 CF 验证流程的时间节点了。需要修改下模拟登录的过程。需要等待一下后续更新。我简单反扒了一下,应该是小变动,但是比较烦。我自己探索一下有没有其他的验证手段。
    tangneo
        17
    tangneo  
       2022-12-13 11:04:34 +08:00
    @sleeplessy 好的,大佬
    xiaoz
        18
    xiaoz  
       2022-12-13 11:31:58 +08:00
    @sleeplessy #14,去这里 https://github.com/acheong08/ChatGPT/issues/261 查看到有人讨论,今天验证又升级,貌似用不了了。
    sleeplessy
        19
    sleeplessy  
    OP
       2022-12-13 12:45:30 +08:00
    Update: 最新的的主分支已经可以 working 了。
    如果你是在本地部署运行的,那你可能不需要进行任何调整,只需要确保你本机有 chrome 安装就行了(是的,现在引入 chromedriver 才是过 cf 的最佳手段了。)运行后会弹出一个登录界面,登录后便会关闭(一切都只是为了拿 cf 相关的验证 cookies ,以及刷新。)
    如果你是部署在远程 server 上的,你可以像我一样使用 x11-forwarding,即: 把 server 端 sshd_config 的 X11Forwarding 改为 yes 。然后使用 ssh -Y user@server 连接。这样的话在 /start 的之后会弹出一个网页,这个网页你点一下登录就行了。之后放后台运行即可。

    @xiaoz 现在已经可以恢复使用了。
    xiaoz
        20
    xiaoz  
       2022-12-13 12:52:24 +08:00
    @sleeplessy #19 ,这个方案 Cookie 会很快过期吧,我看评论里面作者说:我将使用 chrome 驱动程序允许用户通过网站登录并从那里自动提取会话令牌,不过这个还没实现出来。
    sleeplessy
        21
    sleeplessy  
    OP
       2022-12-13 12:57:00 +08:00
    @xiaoz 已经在 main branch 了,他前不久合并更新的。我上一条回复说的就是这个更新后的一些变更。
    genhikari
        22
    genhikari  
       2022-12-13 16:55:17 +08:00
    大佬,抱歉,我基本没接触过编程之类的东西。V2 也是我搜索时无意发现的,并不知道它是什么性质的论坛。折腾了一天,前面四步我百度后都完成了,但是用 idle 运行 Chatgpt-main 中的 setup.py 它会显示 Traceback (most recent call last):
    File "C:\Users\Administrator\Desktop\chatgpt\ChatGPT-main\setup.py", line 20, in <module>
    long_description=open(" README.md", encoding="utf-8").read(),
    FileNotFoundError: [Errno 2] No such file or directory: ' README.md'
    而运行 python-telegram-bot-master 的 setup.py 它会显示 SystemExit: usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
    or: setup.py --help [cmd1 cmd2 ...]
    or: setup.py --help-commands
    or: setup.py cmd --help

    error: no commands supplied
    请问该怎么解决啊?
    limon
        23
    limon  
       2022-12-13 19:09:37 +08:00
    2022-12-13 19:05:34.778 | INFO | __main__:<module>:290 - Loading memories from memories.sav
    2022-12-13 19:05:34.778 | INFO | __main__:<module>:292 - Memories:{}
    /home/limon/project/ChatGPTBot/main.py:317: PTBUserWarning: No `JobQueue` set up. To use `JobQueue`, you must install PTB via `pip install python-telegram-bot[job_queue]`.
    application.job_queue.run_repeating(refresh_session, interval=20 * 60, first=20 * 60)
    Traceback (most recent call last):
    File "/home/limon/project/ChatGPTBot/main.py", line 317, in <module>
    application.job_queue.run_repeating(refresh_session, interval=20 * 60, first=20 * 60)
    AttributeError: 'NoneType' object has no attribute 'run_repeating'
    2022-12-13 19:05:34.790 | INFO | __main__:save_datas:258 - Saving datas...
    2022-12-13 19:05:34.790 | INFO | __main__:save_datas:259 - Updating memories..
    2022-12-13 19:05:34.791 | INFO | __main__:save_datas:264 - Updating Session keys...
    limon
        24
    limon  
       2022-12-13 19:12:40 +08:00
    @limon 没事了,pip install 'python-telegram-bot[all]' 就好了
    l1ve
        25
    l1ve  
       2022-12-13 20:16:26 +08:00
    M1 mac 是不能用 chrome 登录吗。。。
    sleeplessy
        26
    sleeplessy  
    OP
       2022-12-13 20:54:53 +08:00 via iPhone
    @l1ve 暂时没测试过,理论上应该没有问题,不过可能需要设置下 binary 地址
    sleeplessy
        27
    sleeplessy  
    OP
       2022-12-13 20:57:03 +08:00 via iPhone
    @genhikari 你如果不明白的话,建议你安装 git for windows ,然后复制我发的那段命令
    tangneo
        28
    tangneo  
       2022-12-13 21:36:12 +08:00
    @sleeplessy 大佬,我那个初始化问题,暂时无解吗?
    sleeplessy
        29
    sleeplessy  
    OP
       2022-12-13 22:01:47 +08:00 via iPhone
    @yaovenus 更新所有依赖到最新版就行了
    sleeplessy
        30
    sleeplessy  
    OP
       2022-12-13 22:07:24 +08:00 via iPhone
    @genhikari
    python setup.py install
    genhikari
        31
    genhikari  
       2022-12-13 23:13:40 +08:00
    用 git for windows 它说 bash: python: command not found
    用 cmd 它一直提示找不到 READ.md
    XiaoBaiYa
        32
    XiaoBaiYa  
       2022-12-14 00:01:38 +08:00
    期待 docker 版本
    m1s4k1
        33
    m1s4k1  
       2022-12-14 03:55:15 +08:00
    部署在远端 server
    Playwright 这个库一直在抛出异常,最终.....

    ```
    An exception was raised while handling an update
    Traceback (most recent call last):
    File "/home/ubuntu/.local/lib/python3.10/site-packages/revChatGPT/revChatGPT.py", line 318, in refresh_session
    asyncio.run(self.get_cf_cookies())
    File "/usr/local/lib/python3.10/dist-packages/nest_asyncio-1.5.6-py3.10.egg/nest_asyncio.py", line 35, in run
    return loop.run_until_complete(task)
    File "/usr/local/lib/python3.10/dist-packages/nest_asyncio-1.5.6-py3.10.egg/nest_asyncio.py", line 90, in run_until_complete
    return f.result()
    File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception.with_traceback(self._exception_tb)
    File "/usr/lib/python3.10/asyncio/tasks.py", line 232, in __step
    result = coro.send(None)
    File "/home/ubuntu/.local/lib/python3.10/site-packages/revChatGPT/revChatGPT.py", line 368, in get_cf_cookies
    browser = await p.chromium.launch(headless=False)
    File "/usr/local/lib/python3.10/dist-packages/playwright-1.28.0-py3.10-linux-x86_64.egg/playwright/async_api/_generated.py", line 12809, in launch
    await self._impl_obj.launch(
    File "/usr/local/lib/python3.10/dist-packages/playwright-1.28.0-py3.10-linux-x86_64.egg/playwright/_impl/_browser_type.py", line 93, in launch
    Browser, from_channel(await self._channel.send("launch", params))
    File "/usr/local/lib/python3.10/dist-packages/playwright-1.28.0-py3.10-linux-x86_64.egg/playwright/_impl/_connection.py", line 44, in send
    return await self._connection.wrap_api_call(
    File "/usr/local/lib/python3.10/dist-packages/playwright-1.28.0-py3.10-linux-x86_64.egg/playwright/_impl/_connection.py", line 419, in wrap_api_call
    return await cb()
    File "/usr/local/lib/python3.10/dist-packages/playwright-1.28.0-py3.10-linux-x86_64.egg/playwright/_impl/_connection.py", line 79, in inner_send
    result = next(iter(done)).result()
    File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception.with_traceback(self._exception_tb)
    playwright._impl._api_types.Error:
    ╔════════════════════════════════════════════════════════════════════════════════════════════════╗
    ║ Looks like you launched a headed browser without having a XServer running. ║
    ║ Set either 'headless: true' or use 'xvfb-run <your-playwright-app>' before running Playwright. ║
    ║ ║
    ║ <3 Playwright Team ║
    ╚════════════════════════════════════════════════════════════════════
    ```
    sleeplessy
        34
    sleeplessy  
    OP
       2022-12-14 04:04:20 +08:00
    @m1s4k1 这个库最新的版本依赖非 headless 的 Chome ,你可能需要在服务器上安装 xvfb 来模拟一个假的 xserver 。
    安装后用 xvfb-run python main.py 即可
    m1s4k1
        35
    m1s4k1  
       2022-12-14 04:14:28 +08:00
    @sleeplessy 帅气, 已解决
    tangneo
        36
    tangneo  
       2022-12-14 08:48:44 +08:00
    @sleeplessy 大佬,我重新下载后安装了一遍。还是报错初始化失败呢。
    sleeplessy
        37
    sleeplessy  
    OP
       2022-12-14 09:25:24 +08:00
    @yaovenus 更新最新的 revChatGPT:
    pip3 install git+http://github.com/acheong08/ChatGPT
    同时更新我最新的代码即可。
    meiweijia
        38
    meiweijia  
       2022-12-14 09:37:22 +08:00
    Playwright 是这个的原因吗?
    ```
    An exception was raised while handling an update
    Traceback (most recent call last):
    File "/mnt/hdd/code/ChatGPTBot/main.py", line 124, in start
    chatbot = Chatbot(config, conversation_id=None, request_timeout=300)
    File "/home/mei/.local/lib/python3.10/site-packages/revChatGPT/revChatGPT.py", line 114, in __init__
    self.refresh_session()
    File "/home/mei/.local/lib/python3.10/site-packages/revChatGPT/revChatGPT.py", line 293, in refresh_session
    asyncio.run(self.get_cf_cookies())
    File "/home/mei/.local/lib/python3.10/site-packages/nest_asyncio.py", line 35, in run
    return loop.run_until_complete(task)
    File "/home/mei/.local/lib/python3.10/site-packages/nest_asyncio.py", line 90, in run_until_complete
    return f.result()
    File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception.with_traceback(self._exception_tb)
    File "/usr/lib/python3.10/asyncio/tasks.py", line 232, in __step
    result = coro.send(None)
    File "/home/mei/.local/lib/python3.10/site-packages/revChatGPT/revChatGPT.py", line 368, in get_cf_cookies
    browser = await p.chromium.launch(headless=False)
    File "/home/mei/.local/lib/python3.10/site-packages/playwright/async_api/_generated.py", line 12809, in launch
    await self._impl_obj.launch(
    File "/home/mei/.local/lib/python3.10/site-packages/playwright/_impl/_browser_type.py", line 93, in launch
    Browser, from_channel(await self._channel.send("launch", params))
    File "/home/mei/.local/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 44, in send
    return await self._connection.wrap_api_call(
    File "/home/mei/.local/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 419, in wrap_api_call
    return await cb()
    File "/home/mei/.local/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 79, in inner_send
    result = next(iter(done)).result()
    File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception.with_traceback(self._exception_tb)
    playwright._impl._api_types.Error: Executable doesn't exist at /home/mei/.cache/ms-playwright/chromium-1033/chrome-linux/chrome
    ╔════════════════════════════════════════════════════════════╗
    ║ Looks like Playwright was just installed or updated. ║
    ║ Please run the following command to download new browsers: ║
    ║ ║
    ║ playwright install ║
    ║ ║
    ║ <3 Playwright Team ║
    ╚════════════════════════════════════════════════════════════╝

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/home/mei/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/ext/_application.py", line 1057, in process_update
    await coroutine
    File "/home/mei/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/ext/_handler.py", line 143, in handle_update
    return await self.callback(update, context)
    File "/mnt/hdd/code/ChatGPTBot/main.py", line 128, in start
    await update.message.reply_text(emojize(":sweat_drops:初始化失败! 原因: `{}` ".format(e)),
    File "/home/mei/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/_message.py", line 875, in reply_text
    return await self.get_bot().send_message(
    File "/home/mei/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/ext/_extbot.py", line 2482, in send_message
    return await super().send_message(
    File "/home/mei/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/_bot.py", line 313, in decorator
    result = await func(*args, **kwargs) # skipcq: PYL-E1102
    File "/home/mei/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/_bot.py", line 734, in send_message
    return await self._send_message( # type: ignore[retu
    ```
    sleeplessy
        39
    sleeplessy  
    OP
       2022-12-14 09:46:37 +08:00
    @meiweijia 参考我前面的消息。
    最简单的修复方式,安装 xvfb(可以通过 apt,pacman 之类的安装)运行下面这个命令:
    python3 -m playwright install
    然后启动命令改成:
    xvfb-run +命令
    meiweijia
        40
    meiweijia  
       2022-12-14 09:52:13 +08:00
    @sleeplessy 好的,谢谢。
    tangneo
        41
    tangneo  
       2022-12-14 10:29:26 +08:00 via Android
    有人成功安装吗?所有的软件都已经是最新的了,初始化报错。有成功的分享下经验吧
    SaiyanPP
        42
    SaiyanPP  
       2022-12-14 16:41:49 +08:00
    老哥能加一下你的联系方式吗
    xxyzuo
        43
    xxyzuo  
       2022-12-14 17:49:05 +08:00
    初始化报错,能看一下吗
    An exception was raised while handling an update
    Traceback (most recent call last):
    File "/usr/local/lib/python3.10/dist-packages/revChatGPT/revChatGPT.py", line 339, in refresh_session
    self.config["Authorization"] = response.json()["accessToken"]
    KeyError: 'accessToken'

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
    File "/root/ChatGPTBot/main.py", line 124, in start
    chatbot = Chatbot(config, conversation_id=None, request_timeout=300)
    File "/usr/local/lib/python3.10/dist-packages/revChatGPT/revChatGPT.py", line 116, in __init__
    self.refresh_session()
    File "/usr/local/lib/python3.10/dist-packages/revChatGPT/revChatGPT.py", line 355, in refresh_session
    raise Exception("Failed to refresh session") from exc
    Exception: Failed to refresh session

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/ext/_application.py", line 1057, in process_update
    await coroutine
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/ext/_handler.py", line 143, in handle_update
    return await self.callback(update, context)
    File "/root/ChatGPTBot/main.py", line 128, in start
    await update.message.reply_text(emojize(":sweat_drops:初始化失败! 原因: `{}` ".format(e)),
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/_message.py", line 875, in reply_text
    return await self.get_bot().send_message(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/ext/_extbot.py", line 2482, in send_message
    return await super().send_message(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/_bot.py", line 313, in decorator
    result = await func(*args, **kwargs) # skipcq: PYL-E1102
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/_bot.py", line 734, in send_message
    return await self._send_message( # type: ignore[return-value]
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/ext/_extbot.py", line 485, in _send_message
    result = await super()._send_message(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/_bot.py", line 486, in _send_message
    result = await self._post(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/_bot.py", line 395, in _post
    return await self._do_post(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/ext/_extbot.py", line 306, in _do_post
    return await super()._do_post(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/_bot.py", line 426, in _do_post
    return await request.post(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/request/_baserequest.py", line 167, in post
    result = await self._request_wrapper(
    File "/root/.local/lib/python3.10/site-packages/python_telegram_bot-20.0a6-py3.10.egg/telegram/request/_baserequest.py", line 330, in _request_wrapper
    raise BadRequest(message)
    telegram.error.BadRequest: Can't parse entities: can't find end of italic entity at byte offset 6
    cwzsquare
        44
    cwzsquare  
       2022-12-15 21:58:28 +08:00
    @xxyzuo 这里似乎是调用的 revChatGPT 的报错 KeyError: 'accessToken'了( rev 的作者 8h 前停更了,因为 Cloudflare 的问题暂时没去考虑绕过去),具体可以参考 https://github.com/acheong08/ChatGPT/issues/352 有人也提出了这个最新的 issue
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2677 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 03:05 · PVG 11:05 · LAX 19:05 · JFK 22:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.