[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gptel 20af9a8b99 095/273: gptel: curl proxy support (#69)
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gptel 20af9a8b99 095/273: gptel: curl proxy support (#69) |
Date: |
Wed, 1 May 2024 10:01:54 -0400 (EDT) |
branch: elpa/gptel
commit 20af9a8b99c57bc22b8af1e0baa8784b0b521813
Author: Palace <velazquez.andres@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
gptel: curl proxy support (#69)
* gptel.el (gptel-proxy): Support a proxy when interacting with openai
endpoint. In many organizations the openai api can only be accessed
via proxy. This is easily supported by curl.
gptel-curl.el (gptel-curl--get-args): tidy up `gptel-curl--get-args'.
---------
Co-authored-by: PalaceChan <XXX>
---
gptel-curl.el | 28 ++++++++++++++++------------
gptel.el | 7 +++++++
2 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/gptel-curl.el b/gptel-curl.el
index 1eb927c1c7..0d6733f573 100644
--- a/gptel-curl.el
+++ b/gptel-curl.el
@@ -29,6 +29,7 @@
(require 'gptel)
(eval-when-compile
+ (require 'cl-lib)
(require 'subr-x))
(require 'map)
(require 'json)
@@ -40,24 +41,27 @@
"Produce list of arguments for calling Curl.
PROMPTS is the data to send, TOKEN is a unique identifier."
- (let* ((args
- (list "--location" "--silent" "--compressed" "--disable"))
- (url (format "https://%s/v1/chat/completions" gptel-host))
+ (let* ((url (format "https://%s/v1/chat/completions" gptel-host))
(data (encode-coding-string
(json-encode (gptel--request-data prompts))
'utf-8))
(headers
`(("Content-Type" . "application/json")
("Authorization" . ,(concat "Bearer " (gptel--api-key))))))
- (push (format "-X%s" "POST") args)
- (push (format "-w(%s . %%{size_header})" token) args)
- ;; (push (format "--keepalive-time %s" 240) args)
- (push (format "-m%s" 60) args)
- (push "-D-" args)
- (pcase-dolist (`(,key . ,val) headers)
- (push (format "-H%s: %s" key val) args))
- (push (format "-d%s" data) args)
- (nreverse (cons url args))))
+ (append
+ (list "--location" "--silent" "--compressed" "--disable"
+ (format "-X%s" "POST")
+ (format "-w(%s . %%{size_header})" token)
+ (format "-m%s" 60)
+ "-D-"
+ (format "-d%s" data))
+ (when (not (string-empty-p gptel-proxy))
+ (list "--proxy" gptel-proxy
+ "--proxy-negotiate"
+ "--proxy-user" ":"))
+ (cl-loop for (key . val) in headers
+ collect (format "-H%s: %s" key val))
+ (list url))))
;;TODO: The :transformer argument here is an alternate implementation of
;;`gptel-response-filter-functions'. The two need to be unified.
diff --git a/gptel.el b/gptel.el
index 862eb141cd..f0807f9069 100644
--- a/gptel.el
+++ b/gptel.el
@@ -74,6 +74,13 @@
:group 'gptel
:type 'string)
+(defcustom gptel-proxy ""
+ "Path to a proxy to use for gptel interactions.
+Passed to curl via --proxy arg, for example \"proxy.yourorg.com:80\"
+Leave it empty if you don't use a proxy."
+ :group 'gptel
+ :type 'string)
+
(defcustom gptel-api-key #'gptel-api-key-from-auth-source
"An OpenAI API key (string).
- [nongnu] elpa/gptel 6a385ffc2f 199/273: README: Add FAQ entry for OpenAI quota error (#93), (continued)
- [nongnu] elpa/gptel 6a385ffc2f 199/273: README: Add FAQ entry for OpenAI quota error (#93), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 199595b0c8 216/273: gptel: Handle status HTTP 100, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel b634f05fe5 218/273: gptel: Tweak markdown to org conversion, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 2487ada4d6 217/273: gptel-anthropic: Handle missing response chunks (trial), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel e18ceb1f84 226/273: gptel: Improve logging, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel b2985392f4 270/273: gptel: Linting for NonGNU ELPA, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel f0b18c5f8b 113/273: gptel-transient: Exit gptel-system-prompt after selection (#96), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 42d53b25e5 041/273: gptel: Handle insufficient quota and other errors, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 18222818dc 070/273: gptel: Add gptel-request, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 36051b15d5 068/273: gptel: Unify error descriptions, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 20af9a8b99 095/273: gptel: curl proxy support (#69),
ELPA Syncer <=
- [nongnu] elpa/gptel c29e1cd673 079/273: gptel-transient: Minor formatting changes., ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel e0a7898645 108/273: gptel: Add pre-response-hook, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel b2a01b8d65 111/273: README: Explain saving/restoring sessions better, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 6e4d95a70a 112/273: README: Add drawers to installation instructions, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 62a6020302 117/273: gptel, gptel-curl: Allow protocol (https) to be set separately, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 0109d0d1c0 134/273: gptel: API agnostic response error handling, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel de6d8089cd 136/273: gptel-transient: Fix system-message setting function, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 6af89254b7 124/273: README: Document breaking changes (mainly `gptel-host` deprecation), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 84cd7bf5a4 144/273: gptel-gemini: Add Gemini support, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 38095eaed5 146/273: gptel: Fix prompt collection bug + linting, ELPA Syncer, 2024/05/01