Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对输入换行和程序崩溃问题做了一些初步的处理 #6

Merged
merged 9 commits into from
Mar 26, 2023

Conversation

lvyonghuan
Copy link
Collaborator

@lvyonghuan lvyonghuan commented Mar 25, 2023

纯新手,也只是参考chatgpt的意见大概处理了一下,不过确实能换行输入了。在chatgp.go中把传入的text里的“/n”和“/r”做了替换,程序就可以正确处理换行了。在处理一些其他输入信息的时候还是会有些问题,比如输入一大段c语言代码的时候还是会报错。应该还是转化成JSON格式的时候出了问题。
(注:去问了下chatgpt,现在已经解决了JSON格式化的时候出现的转义问题了)
另外有时候会出现这个问题(我也不太清楚是为什么,所以只是做了一个错误的处理,防止程序因为空指针崩溃):

2023/03/25 12:55:23 chatgpt.go:72: Post "https://api.openai.com/v1/chat/completions": read tcp 127.0.0.1:40578->127.0.0.1:7890: read: connection reset by peer
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x6fc4b3]

goroutine 747 [running]:
QQ-ChatGPT-Bot/cmd/chatgpt.GenerateText({0xc0000a4350, 0x3})
/home/runner/work/QQ-ChatGPT-Bot/QQ-ChatGPT-Bot/cmd/chatgpt/chatgpt.go:74 +0x5b3
QQ-ChatGPT-Bot/cmd/cqhttp.(*Bot).HandleMsg(0xa06720, 0x0, {{0xc0000a4018, 0x7}, {0xc0000a4070, 0x7}, 0x641e7eb6, 0x76cd0a6f, {0xc0000a4078, 0x6}, ...})
/home/runner/work/QQ-ChatGPT-Bot/QQ-ChatGPT-Bot/cmd/cqhttp/message.go:51 +0x267
created by QQ-ChatGPT-Bot/cmd/cqhttp.(*Bot).Read
/home/runner/work/QQ-ChatGPT-Bot/QQ-ChatGPT-Bot/cmd/cqhttp/login.go:65 +0x2b6

所以在chatgpt.go的一些地方加了return语句,并且做了一个判断。如果返回“”就给用户发送生成失败,防止程序直接崩溃掉(免得我每次都自己动手去重启程序)。
不过之后没有遇到过上面的那个问题了,所以也没检验过这么做行不行。
(刚刚遇到了,确实行)

增加对生成文本时出错的处理
大概是有效的,无效到时候再说
大概解决掉输入换行的问题了
但是看起来没有完全解决完
This reverts commit 4ec6ddf.
This reverts commit f4e006a.
修正了一下群发消息的问题
解决了JSON格式化出现的问题
@SuInk SuInk merged commit 1cf5659 into SuInk:main Mar 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants