一个简单且很糙的 ChatGPT TG Bot

2022-12-12 21:37:33 +08:00
 sleeplessy
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
5181 次点击
所在节点    OpenAI
44 条回复
tangneo
2022-12-14 10:29:26 +08:00
有人成功安装吗?所有的软件都已经是最新的了,初始化报错。有成功的分享下经验吧
SaiyanPP
2022-12-14 16:41:49 +08:00
老哥能加一下你的联系方式吗
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
2022-12-15 21:58:28 +08:00
@xxyzuo 这里似乎是调用的 revChatGPT 的报错 KeyError: 'accessToken'了( rev 的作者 8h 前停更了,因为 Cloudflare 的问题暂时没去考虑绕过去),具体可以参考 https://github.com/acheong08/ChatGPT/issues/352 有人也提出了这个最新的 issue

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/902050

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX