gptel-openai: curl-args slot in gptel-backend (#221)
gptel-openai.el (gptel-backend, gptel-make-openai, gptel-make-azure): Add a curl-args slot to the backend struct for additional Curl arguments. Usage example: This can be used to set the `--cert` and `--key` options in a custom backend that uses mutal TLS to communicate with an OpenAI proxy/gateway. gptel-curl.el (gptel-curl--get-args): Add backend-specific curl-args when creating HTTP requests. gptel-gemini.el (gptel-make-gemini): Add a curl-args slot to the constructor. gptel-kagi.el (gptel-make-kagi): Ditto. gptel-ollama.el (gptel-make-ollama): Ditto.
This commit is contained in:
parent
226f8f0d90
commit
43f625ecb9
5 changed files with 24 additions and 6 deletions
|
@ -66,6 +66,7 @@ PROMPTS is the data to send, TOKEN is a unique identifier."
|
|||
(gptel--log data "request body"))
|
||||
(append
|
||||
gptel-curl--common-args
|
||||
(gptel-backend-curl-args gptel-backend)
|
||||
(list (format "-w(%s . %%{size_header})" token))
|
||||
(if (length< data gptel-curl-file-size-threshold)
|
||||
(list (format "-d%s" data))
|
||||
|
|
|
@ -111,7 +111,7 @@
|
|||
|
||||
;;;###autoload
|
||||
(cl-defun gptel-make-gemini
|
||||
(name &key header key (stream nil)
|
||||
(name &key curl-args header key (stream nil)
|
||||
(host "generativelanguage.googleapis.com")
|
||||
(protocol "https")
|
||||
(models '("gemini-pro"))
|
||||
|
@ -121,6 +121,8 @@
|
|||
|
||||
Keyword arguments:
|
||||
|
||||
CURL-ARGS (optional) is a list of additional Curl arguments.
|
||||
|
||||
HOST (optional) is the API host, defaults to
|
||||
\"generativelanguage.googleapis.com\".
|
||||
|
||||
|
@ -145,6 +147,7 @@ KEY (optional) is a variable whose value is the API key, or
|
|||
function that returns the key."
|
||||
(declare (indent 1))
|
||||
(let ((backend (gptel--make-gemini
|
||||
:curl-args curl-args
|
||||
:name name
|
||||
:host host
|
||||
:header header
|
||||
|
|
|
@ -120,7 +120,7 @@
|
|||
|
||||
;;;###autoload
|
||||
(cl-defun gptel-make-kagi
|
||||
(name &key stream key
|
||||
(name &key curl-args stream key
|
||||
(host "kagi.com")
|
||||
(header (lambda () `(("Authorization" . ,(concat "Bot " (gptel--get-api-key))))))
|
||||
(models '("fastgpt"
|
||||
|
@ -132,6 +132,8 @@
|
|||
|
||||
Keyword arguments:
|
||||
|
||||
CURL-ARGS (optional) is a list of additional Curl arguments.
|
||||
|
||||
HOST is the Kagi host (with port), defaults to \"kagi.com\".
|
||||
|
||||
MODELS is a list of available Kagi models: only fastgpt is supported.
|
||||
|
@ -159,6 +161,7 @@ Example:
|
|||
(declare (indent 1))
|
||||
stream ;Silence byte-compiler
|
||||
(let ((backend (gptel--make-kagi
|
||||
:curl-args curl-args
|
||||
:name name
|
||||
:host host
|
||||
:header header
|
||||
|
|
|
@ -101,7 +101,7 @@ Ollama models.")
|
|||
|
||||
;;;###autoload
|
||||
(cl-defun gptel-make-ollama
|
||||
(name &key header key models stream
|
||||
(name &key curl-args header key models stream
|
||||
(host "localhost:11434")
|
||||
(protocol "http")
|
||||
(endpoint "/api/generate"))
|
||||
|
@ -109,6 +109,8 @@ Ollama models.")
|
|||
|
||||
Keyword arguments:
|
||||
|
||||
CURL-ARGS (optional) is a list of additional Curl arguments.
|
||||
|
||||
HOST is where Ollama runs (with port), defaults to localhost:11434
|
||||
|
||||
MODELS is a list of available model names.
|
||||
|
@ -140,6 +142,7 @@ Example:
|
|||
:stream t)"
|
||||
(declare (indent 1))
|
||||
(let ((backend (gptel--make-ollama
|
||||
:curl-args curl-args
|
||||
:name name
|
||||
:host host
|
||||
:header header
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
(gptel-backend (:constructor gptel--make-backend)
|
||||
(:copier gptel--copy-backend))
|
||||
name host header protocol stream
|
||||
endpoint key models url)
|
||||
endpoint key models url curl-args)
|
||||
|
||||
;;; OpenAI (ChatGPT)
|
||||
(cl-defstruct (gptel-openai (:constructor gptel--make-openai)
|
||||
|
@ -115,7 +115,7 @@
|
|||
|
||||
;;;###autoload
|
||||
(cl-defun gptel-make-openai
|
||||
(name &key models stream key
|
||||
(name &key curl-args models stream key
|
||||
(header
|
||||
(lambda () (when-let (key (gptel--get-api-key))
|
||||
`(("Authorization" . ,(concat "Bearer " key))))))
|
||||
|
@ -126,6 +126,8 @@
|
|||
|
||||
Keyword arguments:
|
||||
|
||||
CURL-ARGS (optional) is a list of additional Curl arguments.
|
||||
|
||||
HOST (optional) is the API host, typically \"api.openai.com\".
|
||||
|
||||
MODELS is a list of available model names.
|
||||
|
@ -147,6 +149,7 @@ KEY (optional) is a variable whose value is the API key, or
|
|||
function that returns the key."
|
||||
(declare (indent 1))
|
||||
(let ((backend (gptel--make-openai
|
||||
:curl-args curl-args
|
||||
:name name
|
||||
:host host
|
||||
:header header
|
||||
|
@ -166,7 +169,7 @@ function that returns the key."
|
|||
;;; Azure
|
||||
;;;###autoload
|
||||
(cl-defun gptel-make-azure
|
||||
(name &key host
|
||||
(name &key curl-args host
|
||||
(protocol "https")
|
||||
(header (lambda () `(("api-key" . ,(gptel--get-api-key)))))
|
||||
(key 'gptel-api-key)
|
||||
|
@ -175,6 +178,8 @@ function that returns the key."
|
|||
|
||||
Keyword arguments:
|
||||
|
||||
CURL-ARGS (optional) is a list of additional Curl arguments.
|
||||
|
||||
HOST is the API host.
|
||||
|
||||
MODELS is a list of available model names.
|
||||
|
@ -207,6 +212,7 @@ Example:
|
|||
:models \\='(\"gpt-3.5-turbo\" \"gpt-4\"))"
|
||||
(declare (indent 1))
|
||||
(let ((backend (gptel--make-openai
|
||||
:curl-args curl-args
|
||||
:name name
|
||||
:host host
|
||||
:header header
|
||||
|
@ -230,6 +236,8 @@ Example:
|
|||
|
||||
Keyword arguments:
|
||||
|
||||
CURL-ARGS (optional) is a list of additional Curl arguments.
|
||||
|
||||
HOST is where GPT4All runs (with port), typically localhost:8491
|
||||
|
||||
MODELS is a list of available model names.
|
||||
|
|
Loading…
Add table
Reference in a new issue