File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 4646 :group 'comm
4747 :link '(url-link :tag " Repository" " https://github.com/emacs-openai/openai" ))
4848
49+ ; ;
50+ ; ;; Logger
51+
52+ (defvar openai--show-log nil
53+ " Get more information from the program." )
54+
55+ (defun openai--log (fmt &rest args )
56+ " Debug message like function `message' with same argument FMT and ARGS."
57+ (when openai--show-log
58+ (apply 'message fmt args)))
59+
4960; ;
5061; ;; Request
5162
@@ -62,8 +73,15 @@ constructing JSON data.
6273
6374The argument OBJECT is an alist that can be construct to JSON data; see function
6475`json-encode' for the detials."
65- (let ((object (cl-remove-if-not (lambda (pair ) (cdr pair)) object)))
66- (json-encode object)))
76+ (let* ((object (cl-remove-if (lambda (pair )
77+ (let ((value (cdr pair)))
78+ (or (null value) ; ignore null
79+ (and (stringp value) ; ignore empty string
80+ (string-empty-p value)))))
81+ object))
82+ (encoded (json-encode object)))
83+ (openai--log " [ENCODED]: %s" encoded)
84+ encoded))
6785
6886(defun openai--handle-error (response )
6987 " Handle error status code from the RESPONSE.
You can’t perform that action at this time.
0 commit comments