branch: elpa/gptel
commit 391ab6c61683bd99b7760496b1855379da199a19
Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>

    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.
---
 gptel-anthropic.el |  1 +
 gptel-gemini.el    |  1 +
 gptel-kagi.el      |  3 ++-
 gptel-ollama.el    |  1 +
 gptel-openai.el    |  1 +
 gptel.el           | 10 +++++++++-
 6 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/gptel-anthropic.el b/gptel-anthropic.el
index 69ee494c5c..48714dc0e3 100644
--- a/gptel-anthropic.el
+++ b/gptel-anthropic.el
@@ -233,6 +233,7 @@ Mutate state INFO with response metadata."
     ;; Merge request params with model and backend params.
     (gptel--merge-plists
      prompts-plist
+     gptel--request-params
      (gptel-backend-request-params gptel-backend)
      (gptel--model-request-params  gptel-model))))
 
diff --git a/gptel-gemini.el b/gptel-gemini.el
index add1e2b46d..f29e32324b 100644
--- a/gptel-gemini.el
+++ b/gptel-gemini.el
@@ -151,6 +151,7 @@ list."
     ;; Merge request params with model and backend params.
     (gptel--merge-plists
      prompts-plist
+     gptel--request-params
      (gptel-backend-request-params gptel-backend)
      (gptel--model-request-params  gptel-model))))
 
diff --git a/gptel-kagi.el b/gptel-kagi.el
index e8955246bd..c1647654d1 100644
--- a/gptel-kagi.el
+++ b/gptel-kagi.el
@@ -71,7 +71,8 @@
                      (concat "\n\n" (mapconcat #'identity ref-strings "\n")))))
     (concat output references)))
 
-;; TODO: Add model and backend-specific request-params support
+;; TODO: Add support for model/backend-specific request-params and
+;; gptel--request-params
 (cl-defmethod gptel--request-data ((_backend gptel-kagi) prompts)
   "JSON encode PROMPTS for Kagi."
   (pcase-exhaustive (gptel--model-name gptel-model)
diff --git a/gptel-ollama.el b/gptel-ollama.el
index 929e9c215a..26b4b75d01 100644
--- a/gptel-ollama.el
+++ b/gptel-ollama.el
@@ -102,6 +102,7 @@ Store response metadata in state INFO."
            `(:model ,(gptel--model-name gptel-model)
              :messages [,@prompts]
              :stream ,(or gptel-stream :json-false))
+           gptel--request-params
            (gptel-backend-request-params gptel-backend)
            (gptel--model-request-params  gptel-model)))
          ;; the initial options (if any) from request params
diff --git a/gptel-openai.el b/gptel-openai.el
index 6460811168..689c715330 100644
--- a/gptel-openai.el
+++ b/gptel-openai.el
@@ -312,6 +312,7 @@ Mutate state INFO with response metadata."
     ;; Merge request params with model and backend params.
     (gptel--merge-plists
      prompts-plist
+     gptel--request-params
      (gptel-backend-request-params gptel-backend)
      (gptel--model-request-params  gptel-model))))
 
diff --git a/gptel.el b/gptel.el
index 25028a192d..947d996f4f 100644
--- a/gptel.el
+++ b/gptel.el
@@ -906,6 +906,14 @@ or
 Each entry has the form (PROCESS . (FSM ABORT-CLOSURE))
 If the ABORT-CLOSURE is called, it must abort the PROCESS.")
 
+(defvar gptel--request-params nil
+  "Extra parameters sent with each gptel request.
+
+These parameters are combined with model-specific and backend-specific
+:request-params before sending a request, which see.  Warning: values
+incompatible with the active backend can break gptel.  Do not use this
+variable unless you know what you're doing!")
+
 
 ;;; Utility functions
 
@@ -1086,7 +1094,7 @@ For BUF, START, END and BODY-THUNK see 
`gptel--with-buffer-copy'."
                       gptel-mode gptel-track-response gptel-track-media
                       gptel-use-tools gptel-tools gptel-use-curl
                       gptel-use-context gptel--num-messages-to-send
-                      gptel-stream gptel-include-reasoning
+                      gptel-stream gptel-include-reasoning 
gptel--request-params
                       gptel-temperature gptel-max-tokens gptel-cache))
         (set (make-local-variable sym) (buffer-local-value sym buf)))
       (when (and start end) (insert-buffer-substring buf start end))

Reply via email to