karthink / gptel

A simple LLM client for Emacs
GNU General Public License v3.0
1.21k stars 122 forks source link

Request failure when prompt has special characters, like accented characters or cedilla #2

Closed jjnilton closed 1 year ago

jjnilton commented 1 year ago

Here's what I get in the **Messages** buffer:

Querying ChatGPT...
error in process sentinel: url-http-create-request: Multibyte text in HTTP request: POST /v1/chat/completions HTTP/1.1
MIME-Version: 1.0
Connection: keep-alive
Extension: Security/Digest Security/SSL
Host: api.openai.com
Accept-encoding: gzip
Accept: */*
User-Agent: URL/Emacs Emacs/27.1 (X11; x86_64-pc-linux-gnu)
Content-Type: application/json
Authorization: Bearer [token]
Content-length: 104

{"model":"gpt-3.5-turbo","messages":[{"role":"user","content":"qual é o melhor editor, vim ou emacs?"}]}
error in process sentinel: Multibyte text in HTTP request: POST /v1/chat/completions HTTP/1.1

Thanks for sharing the package.

karthink commented 1 year ago

Thanks for the report. It looks like this is related to Emacs Bug 23750. Unfortunately using the solution emacs-devel suggests isn't working for me.

So here's what I'm thinking instead. Do you have curl available on your system? I'll make it so requests are handled by curl if it's available, falling back to Emacs' url-retrieve.

karthink commented 1 year ago

If you have access to curl, this problem should be fixed in 3c10147a, please test?

If you don't have curl, it might take a while before I have time to dig into the multibyte encoding issues.

There are also a few new user options.

jjnilton commented 1 year ago

Thanks, it worked! I had to load the gptel-curl manually, though. package-install-file just let me install the gptel but threw an error for the gptel-curl:

package-buffer-info: Package lacks a "Version" or "Package-Version" header

karthink commented 1 year ago

That's odd, it installed fine using package-install-file for me.

Anyway, I've added the Version header to gptel-curl. When you have time could you try uninstalling and reinstalling the package? No hurry though.

jjnilton commented 1 year ago

I did the following:

  1. Uninstalled gptel with package-delete
  2. Installed gptel with package-install-file
  3. Entered the API key and tried a prompt with special characters, it did not fall back to gptel-curl.
  4. Tried to install gptel-curl with package-install-file and got the error I mentioned in my last comment.

Then I pulled from the repository, and installed gptel and gptel-curl with package-install-file.

I think my issue is that I was expecting gptel-curl to be installed when I installed gptel with package-install-file.

karthink commented 1 year ago

@jjnilton,

I changed how gptel-curl is loaded now. It should not be registered as a separate package with package.el. Could you try once more?

  1. Installed gptel with package-install-file

By this I hope you meant that you ran package-install-file on the directory and not on gptel.el specifically.

jjnilton commented 1 year ago

Thanks, @karthink. Previously, I was running package-install-file in each .el file, as I didn't know I could run it in the directory. This time I ran package-install-file in the directory, and everything seems to be working as expected.

karthink commented 1 year ago

Yeah, package-install-file is a misleading name.

I'll close this issue now since it's working for you, but I have #4 open to eventually fix the url-retrieve issue.