branch: elpa/gptel commit 90b41b1e45c91d2f02df886c6b86cc8bdb52090a Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
gptel: Improve JSON schema parsing and URL response handling * gptel.el (gptel--dispatch-schema-type): Handle trailing whitespace in short-form JSON schema specifications correctly. * test: Test for whitespace handling in JSON schema dispatch. --- gptel.el | 10 ++++++---- test | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/gptel.el b/gptel.el index 0492e965a12..44e28a3659f 100644 --- a/gptel.el +++ b/gptel.el @@ -1660,7 +1660,8 @@ SCHEMA can be specified in several ways: (if (= (char-after) ?{) (setq schema (gptel--json-read)) ;Assume serialized JSON schema, we're done (when (= (char-after) ?\[) ;Shorthand: assume array top-level type - (save-excursion (goto-char (point-max)) (delete-char -1)) + (save-excursion + (goto-char (point-max)) (skip-chars-backward " \n\r\t") (delete-char -1)) (delete-char 1) ;Delete array markers [ and ] (setq wrap-in-array t)) (let ( props types descriptions ;Nested object and array types are disallowed in shorthand @@ -1692,7 +1693,8 @@ SCHEMA can be specified in several ways: (cl-mapcan (lambda (prop type desc) `(,(intern (concat ":" prop)) - (:type ,type ,@(when desc (list :description desc))))) + (:type ,type ,@(when desc + (list :description (string-trim desc)))))) (nreverse props) (nreverse types) (nreverse descriptions))))) (setq schema (if wrap-in-array (list :type "array" :items object) object)))))))) @@ -3202,9 +3204,9 @@ the response is inserted into the current buffer after point." (callback (or (plist-get info :callback) ;if not the first run #'gptel--insert-response)) ;default callback (url-request-data - (encode-coding-string + (decode-coding-string (gptel--json-encode (plist-get info :data)) - 'utf-8))) + 'utf-8 t))) (when (with-current-buffer (plist-get info :buffer) (and (derived-mode-p 'org-mode) gptel-org-convert-response)) diff --git a/test b/test index 00c8e27ee58..712151ee061 160000 --- a/test +++ b/test @@ -1 +1 @@ -Subproject commit 00c8e27ee58a074e494a376b8724f5daa37abc99 +Subproject commit 712151ee061ac9813332e060f63c61fb66fb06ca