xhcoding / emacs-aichat

AI Chat in Emacs, including OpenAI and Bing Chat
62 stars 8 forks source link

(error (error Invalid format operation %a)) #8

Closed ziova closed 1 year ago

ziova commented 1 year ago

I get this error when I try to use the aichat-bing function. I am on Windows 10 and emacs 29

xhcoding commented 1 year ago

Please look at https://github.com/xhcoding/emacs-aichat#feedback-issues

ziova commented 1 year ago

The only content in the AICHAT DEBUG buffer is:

====== chathub closed ======

xhcoding commented 1 year ago

Update https://github.com/ahyatt/emacs-websocket to the latest commit

ziova commented 1 year ago

i pulled the latest commit, the error now instead outputs: (error (error Invalid format operation %c))

xhcoding commented 1 year ago

Eval the following code and see if it gives an error

(websocket-create-headers "wss://sydney.bing.com/sydney/ChatHub" "HmPeCcPJY22k6syRwY6bPw==" nil nil aichat-bingai--chathub-headers)
ziova commented 1 year ago

It outputs: Invalid format operation %C

xhcoding commented 1 year ago

Please ensure that your https://github.com/ahyatt/emacs-websocket has been updated to the latest commit.

The definition of websocket-create-header in the latest commit of websocket is as follows:

(defun websocket-create-headers (url key protocol extensions custom-headers-alist)
  "Create connections headers for the given URL, KEY, PROTOCOL, and EXTENSIONS.
Additionally, the CUSTOM-HEADERS-ALIST is passed from the client.
All these parameters are defined as in `websocket-open'."
  (let* ((parsed-url (url-generic-parse-url url))
         (host-port (if (url-port-if-non-default parsed-url)
                        (format "%s:%s" (url-host parsed-url) (url-port parsed-url))
                      (url-host parsed-url)))
         (cookie-header (url-cookie-generate-header-lines
                         host-port (car (url-path-and-query parsed-url))
                         (equal (url-type parsed-url) "wss"))))
    (concat
     (format (concat "Host: %s\r\n"
                     "Upgrade: websocket\r\n"
                     "Connection: Upgrade\r\n"
                     "Sec-WebSocket-Key: %s\r\n"
                     "Sec-WebSocket-Version: 13\r\n"
                     (when protocol
                       (concat
                        (mapconcat
                         (lambda (protocol)
                           (format "Sec-WebSocket-Protocol: %s" protocol))
                         protocol "\r\n")
                        "\r\n"))
                     (when extensions
                       (format "Sec-WebSocket-Extensions: %s\r\n"
                               (mapconcat
                                (lambda (ext)
                                  (concat
                                   (car ext)
                                   (when (cdr ext) "; ")
                                   (when (cdr ext)
                                     (mapconcat 'identity (cdr ext) "; "))))
                                extensions ", "))))
             host-port
             key
             protocol)
     (when cookie-header cookie-header)
     (mapconcat (lambda (cons) (format "%s: %s" (car cons) (cdr cons)))
                custom-headers-alist "\r\n")
     (when custom-headers-alist "\r\n")
     "\r\n")))
ziova commented 1 year ago

perfect, this just solved the problem, thank you