[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gptel d5949ef428 140/273: gptel-curl: handle large Curl pa
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gptel d5949ef428 140/273: gptel-curl: handle large Curl payloads with a temp file (#137) |
Date: |
Wed, 1 May 2024 10:02:15 -0400 (EDT) |
branch: elpa/gptel
commit d5949ef428be5feac2168223d091d1842085988c
Author: Karim Aziiev <karim.aziiev@gmail.com>
Commit: GitHub <noreply@github.com>
gptel-curl: handle large Curl payloads with a temp file (#137)
gptel-curl.el (gptel-curl--get-args,
gptel-curl-file-size-threshold): Use temporary file for curl data.
Ensure curl uses a temporary file for binary data to prevent
issues with large payloads and special characters:
- Add a new defcustom `gptel-curl-file-size-threshold` to
determine when to use a temporary file for passing data to Curl.
- Use `--data-binary` with a temp file for data larger than the
specified threshold, improving handling of large data payloads in
GPTel queries.
- Reliably clean up temporary files created for Curl requests
exceeding the size threshold. Add a function to
`gptel-post-response-hook` to delete the file post-Curl execution
and remove itself from the hook, preventing temporary file
accumulation.
---
gptel-curl.el | 14 ++++++++++++--
gptel.el | 19 +++++++++++++++++++
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/gptel-curl.el b/gptel-curl.el
index 8f5e070b80..027dfb5c36 100644
--- a/gptel-curl.el
+++ b/gptel-curl.el
@@ -61,8 +61,18 @@ PROMPTS is the data to send, TOKEN is a unique identifier."
backend-header)))))
(append
gptel-curl--common-args
- (list (format "-w(%s . %%{size_header})" token)
- (format "-d%s" data))
+ (list (format "-w(%s . %%{size_header})" token))
+ (if (length< data gptel-curl-file-size-threshold)
+ (list (format "-d%s" data))
+ (letrec
+ ((temp-filename (make-temp-file "gptel-curl-data" nil ".json" data))
+ (cleanup-fn (lambda ()
+ (when (file-exists-p temp-filename)
+ (delete-file temp-filename)
+ (remove-hook 'gptel-post-response-hook
cleanup-fn)))))
+ (add-hook 'gptel-post-response-hook cleanup-fn)
+ (list "--data-binary"
+ (format "@%s" temp-filename))))
(when (not (string-empty-p gptel-proxy))
(list "--proxy" gptel-proxy
"--proxy-negotiate"
diff --git a/gptel.el b/gptel.el
index 40b0c1b30e..17d55641d3 100644
--- a/gptel.el
+++ b/gptel.el
@@ -163,6 +163,25 @@ all at once. This wait is asynchronous.
:group 'gptel
:type 'boolean)
+(defcustom gptel-curl-file-size-threshold 130000
+ "Size threshold for using file input with Curl.
+
+Specifies the size threshold for when to use a temporary file to pass data to
+Curl in GPTel queries. If the size of the data to be sent exceeds this
+threshold, the data is written to a temporary file and passed to Curl using the
+`--data-binary' option with a file reference. Otherwise, the data is passed
+directly as a command-line argument.
+
+The value is an integer representing the number of bytes.
+
+Adjusting this value may be necessary depending on the environment
+and the typical size of the data being sent in GPTel queries.
+A larger value may improve performance by avoiding the overhead of creating
+temporary files for small data payloads, while a smaller value may be needed
+if the command-line argument size is limited by the operating system."
+ :group 'gptel
+ :type 'integer)
+
(defcustom gptel-response-filter-functions
'(gptel--convert-org)
"Abnormal hook for transforming the response from ChatGPT.
- [nongnu] elpa/gptel f218388d4d 082/273: gptel-transient: Fix bug when sending in existing session, (continued)
- [nongnu] elpa/gptel f218388d4d 082/273: gptel-transient: Fix bug when sending in existing session, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 30700cc88a 096/273: README: Mention extensions, gptel-proxy, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 09729ee718 089/273: gptel: Create customization group, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel ac754ceb2a 086/273: gptel: Handle read-only gptel-buffers, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel cc6c5e7321 104/273: gptel: saving and restoring state, and limiting context, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 24add64455 114/273: gptel: Adjust how gptel--system-message is set, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 17a58d38e7 135/273: gptel: Fix bug in url-retrieve setup, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 61c0df5e19 119/273: gptel, gptel-curl: Make the gptel text-property non-sticky, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 50a2498259 126/273: README: Tweak instructions for local LLMs, mention #120, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel ec0e461b35 128/273: gptel-curl: Increased curl timeout (#127), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel d5949ef428 140/273: gptel-curl: handle large Curl payloads with a temp file (#137),
ELPA Syncer <=
- [nongnu] elpa/gptel 0ea3c7fb15 143/273: gptel-transient: Improve suffix message editor, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel ce75072f9d 152/273: gptel: Bump version, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 3af2650342 170/273: gptel-transient: save window state when ediff, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel e67ed41e31 173/273: README: Specify: no key needed for llama backend, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 1fcb4606a2 184/273: Fix compilation warning in gptel-openai.el, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel b3d028d074 185/273: Add .gitignore, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 5465271541 207/273: gptel: Add gpt-4-0125-preview to model list (Fix #215), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 43f625ecb9 209/273: gptel-openai: curl-args slot in gptel-backend (#221), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel d502ad8ecb 222/273: test-gptel-org: Add markdown conversion tests, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 9925dc91b4 223/273: gptel: Improve markdown converter, ELPA Syncer, 2024/05/01