最近通过gptel使用gemini flash模型经常报错,一直没找到原因,发在这里
请各位道友帮忙看看有没有办法
** 通过openrouter api
model配置如下
(use-package gptel
:ensure t
:config
(setq gptel-model 'deepseek/deepseek-chat)
(setq gptel-use-curl nil)
(setq gptel-default-mode 'org-mode)
(setq gptel-backend
(gptel-make-openai “OpenRouter”
:key “XXX”
:models '(
“deepseek/deepseek-chat”
“qwen/qwen-2.5-coder-32b-instruct”
“qwen/qwq-32b-preview”
“google/gemini-2.0-flash-exp:free”
“google/gemini-2.0-flash-thinking-exp:free”
“meta-llama/llama-3.2-3b-instruct:free”)
:host “openrouter.ai”
:endpoint “/api/v1/chat/completions”)))
偶尔gemini flash能返回响应,但是大部分时间报错如下
#+begin_src
string-trim-right: Wrong type argument: stringp, nil
#+end_src
并且重复gptel-send的话有一定概率正常回应
奇怪的是同样openrouter使用其它家的模型就没报错这样的错。
所以有些怀疑是通过gtpel访问gemini才有的问题
为了证实怀疑,实验了一下 直接通过gemini api
** 直接通过gemini api
结果是同样的报错
error in process filter: string-trim-right: Wrong type argument: stringp, nil
error in process filter: Wrong type argument: stringp, nil
以下打印了一些调试信息
#+begin_src
Debugger entered–Lisp error: (wrong-type-argument stringp nil)
string-match(“\(?:[ \11\n\15]+\)\'” nil nil t)
string-trim-right(nil nil)
string-trim(nil)
gptel–url-parse-response(#s (gptel-gemini :name “Gemini” :host “generativelanguage.googleapis.com ” :header nil :protocol “https” :stream t :endpoint “/v1beta/models/gemini-pro:” :key “XXX” :models (“gemini-2.0-flash-exp” “gemini-2.0-flash-thinking-exp-1219”) :url #f (compiled-function () #<bytecode -0x1e22031a28eb34f5>) :curl-args nil) #<buffer http generativelanguage.googleapis.com:443 -467335>)
。。。
。。。
url-http-activate-callback()
url-http-chunked-encoding-after-change-function(1020 1025 5)
url-http-generic-filter(# “0\15\n\15\n”)
#+end_src
如果你是Windows用户,如果直接调用 gpel-request 可以参考这个链接解决方法,当初我偶然发现的:
已打开 02:42PM - 21 May 24 UTC
已关闭 04:37PM - 07 Nov 24 UTC
bug
Hello, thank you for the wonderful package. I am running into an error attemptin… g to run a function that uses gptel-request (using Windows 11 OS). Here is my config setup:
```lisp
(use-package gptel
:config
;; Set the default model to use
(setq-default gptel-model "gpt-3.5-turbo")
;; set API key
(setq gptel-api-key "____________"))
(defun gptel-rewrite-and-replace (bounds &optional directive)
(interactive
(list
(cond
((use-region-p) (cons (region-beginning) (region-end)))
((derived-mode-p 'text-mode)
(list (bounds-of-thing-at-point 'sentence)))
(t (cons (line-beginning-position) (line-end-position))))
(and current-prefix-arg
(read-string "ChatGPT Directive: "
"You are a prose editor. Rewrite my prompt more professionally."))))
(gptel-request
(buffer-substring-no-properties (car bounds) (cdr bounds)) ;the prompt
:system (or directive "You are a prose editor. Rewrite my prompt more professionally.")
:buffer (current-buffer)
:context (cons (set-marker (make-marker) (car bounds))
(set-marker (make-marker) (cdr bounds)))
:callback
(lambda (response info)
(if (not response)
(message "ChatGPT response failed with: %s" (plist-get info :status))
(let* ((bounds (plist-get info :context))
(beg (car bounds))
(end (cdr bounds))
(buf (plist-get info :buffer)))
(with-current-buffer buf
(save-excursion
(goto-char beg)
(kill-region beg end)
(insert response)
(set-marker beg nil)
(set-marker end nil)
(message "Rewrote line. Original line saved to kill-ring."))))))))
```
The `gptel-rewrite-and-replace` function, which was borrowed from example 2 on the gptel wiki page, throws the following error:
```
error in process sentinel: gptel-curl--parse-response: Wrong type argument: stringp, nil
error in process sentinel: Wrong type argument: stringp, nil
```
`gptel-send` works just fine as does sending requests through curl directly. I can send the debug/log output if needed. Thanks in advance!
原因还是因为windows换行符的原因,貌似最新版gptel有所改善
还有,我也是windows用户使用在gptel的buffer中使用中文询问时,也是会有这种错误,只能正常回一次,后面就是错误了
1 个赞
我平常用linux更多些。不过这听上去确定是gptel的问题了
问题还在,不过有一些新发现
当更新gptel.el到最新后,直接使用gemini api,虽然也有新的报错,但是可以返回响应
但是通过openrouter使用gemini flash模型还是老样子,经常报错无返回偶尔返回响应
chuck
2025 年1 月 10 日 09:23
5
(setq gptel-model 'gemini-1.5-flash
gptel-backend (gptel-make-gemini "Gemini"
:key "you-key"
:stream nil)
gptel-use-curl nil)
目前这样使用比较稳定
是的,直接使用gemini api,基本可稳定使用
所以问题出在gptel通过openrouter api使用gemini的模型时。
而且我使用gptel通过openrouter api使用其它家的模型时,都没报过此类错误
当然无论怎样先要把gptel.el本身及时更新。
我有个习惯,一旦某个插件装好能用上后,就不太想更新,怕冒出新问题没法用了。现在看这种习惯要改,一则是AI相关使用方式本身就变化非常快,求稳定是不可能的,另则是有了AI,再出错也不是很怕了,AI CHATGPT帮解决各种疑难杂症还是B很有用的