Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved #4: Handles multi-byte characters with url-retrieve (i.e., without the external curl command) #29

Merged
merged 2 commits into from Apr 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions gptel.el
Expand Up @@ -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 ()
Expand Down Expand Up @@ -415,16 +417,15 @@ INFO is a plist with the following keys:
(if-let* ((status (buffer-substring (line-beginning-position) (line-end-position)))
(json-object-type 'plist)
(response (progn (forward-paragraph)
(condition-case nil
(json-read)
(json-readtable-error 'json-read-error)))))
(let ((json-str (decode-coding-string
(buffer-substring-no-properties (point) (point-max))
'utf-8)))
(condition-case nil
(json-read-from-string json-str)
(json-readtable-error 'json-read-error))))))
(cond
((string-match-p "200 OK" status)
(list :content (string-trim
(decode-coding-string
(map-nested-elt
response '(:choices 0 :message :content))
'utf-8))
(list :content (string-trim (map-nested-elt response '(:choices 0 :message :content)))
:status status))
((plist-get response :error)
(let* ((error-plist (plist-get response :error))
Expand Down