j178 / chatgpt

An elegant interactive CLI for ChatGPT
693 stars 52 forks source link

bug report #91

Closed jglwiz closed 3 months ago

jglwiz commented 3 months ago

最新版本.

  1. 单次运行正确
  2. 连续对话报错. 使用的是claude的兼容api. 使用的是openai-hk.com的openai兼容api.

Caught panic:

runtime error: invalid memory address or nil pointer dereference

Restoring terminal...

goroutine 1 [running]: runtime/debug.Stack() runtime/debug/stack.go:24 +0x5e runtime/debug.PrintStack() runtime/debug/stack.go:16 +0x13 github.com/charmbracelet/bubbletea.(Program).Run.func1() github.com/charmbracelet/bubbletea@v0.24.2/tea.go:440 +0x91 panic({0x117fa20?, 0x196eb40?}) runtime/panic.go:920 +0x270 github.com/pkoukk/tiktoken-go.(Tiktoken).Encode(0x0, {0x1205af6, 0x6}, {0x0?, 0x1?, 0x10?}, {0x0, 0x0, 0x2264e609a98?}) github.com/pkoukk/tiktoken-go@v0.1.6/tiktoken.go:81 +0x372 github.com/j178/chatgpt/tokenizer.CountTokens({0xc0000be510, 0x18}, {0x1205af6, 0x6}) github.com/j178/chatgpt/tokenizer/tokenize.go:16 +0xd0 github.com/j178/chatgpt/tokenizer.CountMessagesTokens({0xc0000be510, 0x18}, {0xc000348f00, 0x1, 0x8?}) github.com/j178/chatgpt/tokenizer/tokenize.go:37 +0x1b1 github.com/j178/chatgpt.(Conversation).GetContextTokens(0xc000122880) github.com/j178/chatgpt/conversation.go:222 +0x49 github.com/j178/chatgpt/ui.Model.RenderFooter({0x78, 0x1e, 0x0, 0x0, {0x0, 0x0}, {{{0xc0003f2ed0, 0x1, 0x1}, {{...}, ...}, ...}, ...}, ...}) github.com/j178/chatgpt/ui/ui.go:430 +0x867 github.com/j178/chatgpt/ui.Model.View({0x78, 0x1e, 0x0, 0x0, {0x0, 0x0}, {{{0xc0003f2ed0, 0x1, 0x1}, {{...}, ...}, ...}, ...}, ...}) github.com/j178/chatgpt/ui/ui.go:476 +0xe5 github.com/charmbracelet/bubbletea.(Program).eventLoop(0xc0000fe480, {0x144eb10?, 0xc0004c9980?}, 0xc0005fc450?) github.com/charmbracelet/bubbletea@v0.24.2/tea.go:375 +0x678 github.com/charmbracelet/bubbletea.(*Program).Run(0xc0000fe480) github.com/charmbracelet/bubbletea@v0.24.2/tea.go:503 +0x85c main.main() github.com/j178/chatgpt/cmd/chatgpt/main.go:124 +0x8e5

j178 commented 3 months ago

Hi, 能贴一下 chatgpt -v 的输出,以及你的 config.json 配置吗(注意去掉敏感信息)?

jglwiz commented 3 months ago

chatgpt -v 1.3.1 commit: d217301f775bd1ec882cc18b00d6954364f9ddea built at: 2023-11-08T05:38:15Z goos: windows goarch: amd64

apikey是测试key, 可以直接使用.

config:

{ "api_key": "hk-cfhc0u100000324777082b21bcd1c40d1e075db67c6a092f", "endpoint": "https://api.openai-hk.com/v1", "api_type": "OPEN_AI", "prompts": { "default": "You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.", "shell": "Return a one-line bash command with the functionality I will describe. Return ONLY the command ready to run in the terminal. The command should do the following:", "powershell": "Return just a one-line powershell command with the functionality I will describe. Return ONLY the command ready to run in the terminal. The command should do the following:", "en": "I want you to act as an English translator, spelling corrector and improver. I will speak to you in any language and you will detect the language, translate it and answer in the corrected and improved version of my text, in English. I want you to replace my simplified A0-level words and sentences with more beautiful and elegant, upper level English words and sentences. The translation should be natural, easy to understand, and concise. Keep the meaning same, but make them more literary. I want you to only reply the correction, the improvements and nothing else, do not write explanations.", "ch": "I want you to act as an Chinese translator, spelling corrector and improver. I will speak to you in any language and you will detect the language, translate it and answer in the corrected and improved version of my text, in Chinese. I want you to replace my simplified A0-level words and sentences with more beautiful and elegant, upper level Chinese words and sentences. The translation should be natural, easy to understand, and concise. Keep the meaning same, but make them more literary. I want you to only reply the correction, the improvements and nothing else, do not write explanations." }, "conversation": { "prompt": "default", "context_length": 6, "model": "claude-3-sonnet-20240229", "stream": true, "temperature": 0.1, "max_tokens": 2000 }, "key_map": { "switch_multiline": [ "ctrl+j" ], "submit": [ "enter" ], "multiline_submit": [ "ctrl+d" ], "insert_newline": [ "ctrl+d" ], "multiline_insert_newline": [ "enter" ], "help": [ "ctrl+h" ], "quit": [ "esc", "ctrl+c" ], "copy_last_answer": [ "ctrl+y" ], "previous_question": [ "ctrl+p" ], "next_question": [ "ctrl+n" ], "new_conversation": [ "ctrl+t" ], "previous_conversation": [ "ctrl+left", "ctrl+g" ], "next_conversation": [ "ctrl+right", "ctrl+o" ], "remove_conversation": [ "ctrl+r" ], "forget_context": [ "ctrl+x" ] } }

j178 commented 3 months ago

目前 chatgpt 还只支持 OpenAI 的标准 model,使用非标准 model v1.3.1 版本会有 panic,v1.3.4 会预先检查 model 合法性。

在当前最新的开发中的 master 分支,会添加更多 LLM 以及取消 model 的限制,不过还需要一些时间才会发布。