gptel-gemini: Use permissive API safety settings
* gptel-gemini.el (gptel-make-gemini, gptel--request-data): The Gemini API misclassifies harmless questions (like "What's 2+2", see #208) as harmful. Use the most permissive safety settings the API offers. Also respect the value of `:stream` used when defining Gemini backends.
This commit is contained in:
parent
e2eccd8b08
commit
ef8b9093d2
1 changed files with 21 additions and 8 deletions
|
@ -60,7 +60,15 @@
|
||||||
(cl-defmethod gptel--request-data ((_backend gptel-gemini) prompts)
|
(cl-defmethod gptel--request-data ((_backend gptel-gemini) prompts)
|
||||||
"JSON encode PROMPTS for sending to Gemini."
|
"JSON encode PROMPTS for sending to Gemini."
|
||||||
(let ((prompts-plist
|
(let ((prompts-plist
|
||||||
`(:contents [,@prompts]))
|
`(:contents [,@prompts]
|
||||||
|
:safetySettings [(:category "HARM_CATEGORY_HARASSMENT"
|
||||||
|
:threshold "BLOCK_NONE")
|
||||||
|
(:category "HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
||||||
|
:threshold "BLOCK_NONE")
|
||||||
|
(:category "HARM_CATEGORY_DANGEROUS_CONTENT"
|
||||||
|
:threshold "BLOCK_NONE")
|
||||||
|
(:category "HARM_CATEGORY_HATE_SPEECH"
|
||||||
|
:threshold "BLOCK_NONE")]))
|
||||||
params)
|
params)
|
||||||
(when gptel-temperature
|
(when gptel-temperature
|
||||||
(setq params
|
(setq params
|
||||||
|
@ -103,7 +111,7 @@
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(cl-defun gptel-make-gemini
|
(cl-defun gptel-make-gemini
|
||||||
(name &key header key stream
|
(name &key header key (stream nil)
|
||||||
(host "generativelanguage.googleapis.com")
|
(host "generativelanguage.googleapis.com")
|
||||||
(protocol "https")
|
(protocol "https")
|
||||||
(models '("gemini-pro"))
|
(models '("gemini-pro"))
|
||||||
|
@ -146,12 +154,17 @@ function that returns the key."
|
||||||
:stream stream
|
:stream stream
|
||||||
:key key
|
:key key
|
||||||
:url
|
:url
|
||||||
|
(if stream
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(concat protocol "://" host endpoint
|
(concat protocol "://" host endpoint
|
||||||
(if gptel-stream
|
(if gptel-stream
|
||||||
"streamGenerateContent"
|
"streamGenerateContent"
|
||||||
"generateContent")
|
"generateContent")
|
||||||
"?key=" (gptel--get-api-key))))))
|
"?key=" (gptel--get-api-key)))
|
||||||
|
(lambda ()
|
||||||
|
(concat protocol "://" host endpoint
|
||||||
|
"generateContent" "?key="
|
||||||
|
(gptel--get-api-key)))))))
|
||||||
(prog1 backend
|
(prog1 backend
|
||||||
(setf (alist-get name gptel--known-backends
|
(setf (alist-get name gptel--known-backends
|
||||||
nil nil #'equal)
|
nil nil #'equal)
|
||||||
|
|
Loading…
Add table
Reference in a new issue