emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/gptel a500c76a68 053/273: Encode a lambda-provided API key


From: ELPA Syncer
Subject: [nongnu] elpa/gptel a500c76a68 053/273: Encode a lambda-provided API key as utf-8
Date: Wed, 1 May 2024 10:01:39 -0400 (EDT)

branch: elpa/gptel
commit a500c76a685c12dd7dc37d3a999eb4d5fbab3152
Author: algal <algal@penguin>
Commit: karthink <karthikchikmagalur@gmail.com>

    Encode a lambda-provided API key as utf-8
    
    If the user provides the OpenAPI key via a function, as is the case by
    default if the user puts credentials in an auth-sources resource like
    .authinfo or .authinfo.gpg, then it is necessary to encode the
    function's returned value into utf-8 before passing it onward to build
    the HTTP request. This commit ensures that happen.
    
    Why is this necessary, given that the API key contains only
    alphanumeric characters and therefore should be byte-for-byte the same
    in utf-8 as in us-acii? I don't know. It may because emacs's
    url-http.el library concats many strings together, and they all need
    to be identically encoded before they can be combined correctly.
    
    Whatever the reason, this fix works and allows you to send prompts
    which include Unicode characters that require multibyte encodings in UTF-8
---
 gptel.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/gptel.el b/gptel.el
index 606bc63a74..bdbd6c0d07 100644
--- a/gptel.el
+++ b/gptel.el
@@ -202,7 +202,9 @@ By default, \"openai.com\" is used as HOST and \"apikey\" 
as USER."
                                     :host (or host "openai.com")
                                     :user (or user "apikey")))
                               :secret)))
-      (if (functionp secret) (funcall secret) secret)
+      (if (functionp secret)
+          (encode-coding-string (funcall secret) 'utf-8)
+        secret)
     (user-error "No `gptel-api-key' found in the auth source")))
 
 (defun gptel--api-key ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]