Skip to content

Commit 43f625e

Browse files
authored
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.
1 parent 226f8f0 commit 43f625e

5 files changed

+24
-6
lines changed

gptel-curl.el

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ PROMPTS is the data to send, TOKEN is a unique identifier."
6666
(gptel--log data "request body"))
6767
(append
6868
gptel-curl--common-args
69+
(gptel-backend-curl-args gptel-backend)
6970
(list (format "-w(%s . %%{size_header})" token))
7071
(if (length< data gptel-curl-file-size-threshold)
7172
(list (format "-d%s" data))

gptel-gemini.el

+4-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111

112112
;;;###autoload
113113
(cl-defun gptel-make-gemini
114-
(name &key header key (stream nil)
114+
(name &key curl-args header key (stream nil)
115115
(host "generativelanguage.googleapis.com")
116116
(protocol "https")
117117
(models '("gemini-pro"))
@@ -121,6 +121,8 @@
121121
122122
Keyword arguments:
123123
124+
CURL-ARGS (optional) is a list of additional Curl arguments.
125+
124126
HOST (optional) is the API host, defaults to
125127
\"generativelanguage.googleapis.com\".
126128
@@ -145,6 +147,7 @@ KEY (optional) is a variable whose value is the API key, or
145147
function that returns the key."
146148
(declare (indent 1))
147149
(let ((backend (gptel--make-gemini
150+
:curl-args curl-args
148151
:name name
149152
:host host
150153
:header header

gptel-kagi.el

+4-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120

121121
;;;###autoload
122122
(cl-defun gptel-make-kagi
123-
(name &key stream key
123+
(name &key curl-args stream key
124124
(host "kagi.com")
125125
(header (lambda () `(("Authorization" . ,(concat "Bot " (gptel--get-api-key))))))
126126
(models '("fastgpt"
@@ -132,6 +132,8 @@
132132
133133
Keyword arguments:
134134
135+
CURL-ARGS (optional) is a list of additional Curl arguments.
136+
135137
HOST is the Kagi host (with port), defaults to \"kagi.com\".
136138
137139
MODELS is a list of available Kagi models: only fastgpt is supported.
@@ -159,6 +161,7 @@ Example:
159161
(declare (indent 1))
160162
stream ;Silence byte-compiler
161163
(let ((backend (gptel--make-kagi
164+
:curl-args curl-args
162165
:name name
163166
:host host
164167
:header header

gptel-ollama.el

+4-1
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,16 @@ Ollama models.")
101101

102102
;;;###autoload
103103
(cl-defun gptel-make-ollama
104-
(name &key header key models stream
104+
(name &key curl-args header key models stream
105105
(host "localhost:11434")
106106
(protocol "http")
107107
(endpoint "/api/generate"))
108108
"Register an Ollama backend for gptel with NAME.
109109
110110
Keyword arguments:
111111
112+
CURL-ARGS (optional) is a list of additional Curl arguments.
113+
112114
HOST is where Ollama runs (with port), defaults to localhost:11434
113115
114116
MODELS is a list of available model names.
@@ -140,6 +142,7 @@ Example:
140142
:stream t)"
141143
(declare (indent 1))
142144
(let ((backend (gptel--make-ollama
145+
:curl-args curl-args
143146
:name name
144147
:host host
145148
:header header

gptel-openai.el

+11-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
(gptel-backend (:constructor gptel--make-backend)
5050
(:copier gptel--copy-backend))
5151
name host header protocol stream
52-
endpoint key models url)
52+
endpoint key models url curl-args)
5353

5454
;;; OpenAI (ChatGPT)
5555
(cl-defstruct (gptel-openai (:constructor gptel--make-openai)
@@ -115,7 +115,7 @@
115115

116116
;;;###autoload
117117
(cl-defun gptel-make-openai
118-
(name &key models stream key
118+
(name &key curl-args models stream key
119119
(header
120120
(lambda () (when-let (key (gptel--get-api-key))
121121
`(("Authorization" . ,(concat "Bearer " key))))))
@@ -126,6 +126,8 @@
126126
127127
Keyword arguments:
128128
129+
CURL-ARGS (optional) is a list of additional Curl arguments.
130+
129131
HOST (optional) is the API host, typically \"api.openai.com\".
130132
131133
MODELS is a list of available model names.
@@ -147,6 +149,7 @@ KEY (optional) is a variable whose value is the API key, or
147149
function that returns the key."
148150
(declare (indent 1))
149151
(let ((backend (gptel--make-openai
152+
:curl-args curl-args
150153
:name name
151154
:host host
152155
:header header
@@ -166,7 +169,7 @@ function that returns the key."
166169
;;; Azure
167170
;;;###autoload
168171
(cl-defun gptel-make-azure
169-
(name &key host
172+
(name &key curl-args host
170173
(protocol "https")
171174
(header (lambda () `(("api-key" . ,(gptel--get-api-key)))))
172175
(key 'gptel-api-key)
@@ -175,6 +178,8 @@ function that returns the key."
175178
176179
Keyword arguments:
177180
181+
CURL-ARGS (optional) is a list of additional Curl arguments.
182+
178183
HOST is the API host.
179184
180185
MODELS is a list of available model names.
@@ -207,6 +212,7 @@ Example:
207212
:models \\='(\"gpt-3.5-turbo\" \"gpt-4\"))"
208213
(declare (indent 1))
209214
(let ((backend (gptel--make-openai
215+
:curl-args curl-args
210216
:name name
211217
:host host
212218
:header header
@@ -230,6 +236,8 @@ Example:
230236
231237
Keyword arguments:
232238
239+
CURL-ARGS (optional) is a list of additional Curl arguments.
240+
233241
HOST is where GPT4All runs (with port), typically localhost:8491
234242
235243
MODELS is a list of available model names.

0 commit comments

Comments
 (0)