Skip to content

Commit 391ab6c

Browse files
committed
gptel: Add gptel--request-params for extra request options
* gptel.el (gptel--request-params) (gptel--with-buffer-copy-internal): Add new variable for specifying global/buffer-local/oneshot request-params. Important: It is very easy to break gptel with stale/incompatible request-params. As such, request-params are best specified as backend or model properties. If used, `gptel--request-params' is best set via a preset, and it's the user's responsibility to unset this when switching presets. For this reason it is marked as an internal variable. Really, it is only here because of the unique configuration requirements of John Wiegley. * gptel-anthropic.el (gptel--request-data): Use it in request payload. * gptel-gemini.el (gptel--request-data): Use it in request payload. * gptel-ollama.el (gptel--request-data): Use it in request payload. * gptel-openai.el (gptel--request-data): Use it in request payload. * gptel-kagi.el: Update TODO about request-params support.
1 parent 841dae0 commit 391ab6c

File tree

6 files changed

+15
-2
lines changed

6 files changed

+15
-2
lines changed

gptel-anthropic.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ Mutate state INFO with response metadata."
233233
;; Merge request params with model and backend params.
234234
(gptel--merge-plists
235235
prompts-plist
236+
gptel--request-params
236237
(gptel-backend-request-params gptel-backend)
237238
(gptel--model-request-params gptel-model))))
238239

gptel-gemini.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ list."
151151
;; Merge request params with model and backend params.
152152
(gptel--merge-plists
153153
prompts-plist
154+
gptel--request-params
154155
(gptel-backend-request-params gptel-backend)
155156
(gptel--model-request-params gptel-model))))
156157

gptel-kagi.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
(concat "\n\n" (mapconcat #'identity ref-strings "\n")))))
7272
(concat output references)))
7373

74-
;; TODO: Add model and backend-specific request-params support
74+
;; TODO: Add support for model/backend-specific request-params and
75+
;; gptel--request-params
7576
(cl-defmethod gptel--request-data ((_backend gptel-kagi) prompts)
7677
"JSON encode PROMPTS for Kagi."
7778
(pcase-exhaustive (gptel--model-name gptel-model)

gptel-ollama.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Store response metadata in state INFO."
102102
`(:model ,(gptel--model-name gptel-model)
103103
:messages [,@prompts]
104104
:stream ,(or gptel-stream :json-false))
105+
gptel--request-params
105106
(gptel-backend-request-params gptel-backend)
106107
(gptel--model-request-params gptel-model)))
107108
;; the initial options (if any) from request params

gptel-openai.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ Mutate state INFO with response metadata."
312312
;; Merge request params with model and backend params.
313313
(gptel--merge-plists
314314
prompts-plist
315+
gptel--request-params
315316
(gptel-backend-request-params gptel-backend)
316317
(gptel--model-request-params gptel-model))))
317318

gptel.el

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,14 @@ or
906906
Each entry has the form (PROCESS . (FSM ABORT-CLOSURE))
907907
If the ABORT-CLOSURE is called, it must abort the PROCESS.")
908908

909+
(defvar gptel--request-params nil
910+
"Extra parameters sent with each gptel request.
911+
912+
These parameters are combined with model-specific and backend-specific
913+
:request-params before sending a request, which see. Warning: values
914+
incompatible with the active backend can break gptel. Do not use this
915+
variable unless you know what you're doing!")
916+
909917

910918
;;; Utility functions
911919

@@ -1086,7 +1094,7 @@ For BUF, START, END and BODY-THUNK see `gptel--with-buffer-copy'."
10861094
gptel-mode gptel-track-response gptel-track-media
10871095
gptel-use-tools gptel-tools gptel-use-curl
10881096
gptel-use-context gptel--num-messages-to-send
1089-
gptel-stream gptel-include-reasoning
1097+
gptel-stream gptel-include-reasoning gptel--request-params
10901098
gptel-temperature gptel-max-tokens gptel-cache))
10911099
(set (make-local-variable sym) (buffer-local-value sym buf)))
10921100
(when (and start end) (insert-buffer-substring buf start end))

0 commit comments

Comments
 (0)