karthink / gptel

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

error: search failed when using Azure OpenAI backend #143

Closed nicehiro closed 6 months ago

nicehiro commented 7 months ago

Hi, thanks for your great work.

I'm using Azure as a backend on Windows 11. My configurations are as follows,

(setq-default gptel-backend
                (gptel-make-azure
                 "Azure-GPT4"
                 :protocol "https"
                 :host "xxxx.openai.azure.com"
                 :endpoint "/openai/deployments/xxxx/chat/completions?api-version=2023-05-15"
                 :stream t
                 :key #'gptel-api-key
                 :models '("gpt-4")))

The error messages:

image

Then I turned on the gptel--debug and found the error was the curl itself on Windows. More details are here.

I solved this issue by using another version of curl rather than default win-32. I'm sharing it here for others' reference.

By the way, Azure endpoint seems not correct here. According to Azure OpenAI documents, the chat API endpoint should be "/openai/deployments/gpt-4/chat/completions?api-version=2023-05-15" and the one show in README is the completion API without "chat".

I can make a PR if you are fine with this.

karthink commented 7 months ago

Thanks for finding the solution! I think I've seen this problem with Curl + Windows + gptel before, I could remove the use of the compressed flag when Emacs is running on Windows.

I can make a PR if you are fine with this.

Is the PR to update the Azure instructions in the README?

nicehiro commented 7 months ago

Is the PR to update the Azure instructions in the README?

Yes. At first, I thought maybe add a notice for Windows users and also update the Azure instructions. But since you are gonna remove the compressed flag, I will only update the Azure instructions.

karthink commented 7 months ago

@nicehiro I've removed the --compressed flag when using Windows. The PR with the correct Azure instructions will be very welcome!

justussc commented 6 months ago

I wonder if url property of the gptel-backend could be allowed to be a function. Because at least in my usage DEPLOYMENT == model on azure. So I currently either have to register one backend per model for azure or resort to some advice hackery. eg one would set url to something like (with host and port replaced by appropriate values)

(lambda ()
      (let ((gptel-model-value (symbol-value 'gptel-model)))
        (replace-regexp-in-string "%DEPLOYMENT%" gptel-model-value "https://host:port/openai/deployments/%DEPLOYMENT%/chat/completions?api-version=2023-09-01-preview" t t)))
karthink commented 6 months ago

@justussc I understand the issue. I'm trying to avoid the functionp check that will be needed for the url with every API call. Can you think of some other way to achieve this?

justussc commented 6 months ago

i don't have a good idea how to get rid of that :( as i already had an advice for gpt-curl--get-args i am currently using that one:

(defun js/gptel-curl--get-args-advice (output)
  (let ((model-string (symbol-value 'gptel-model)))
    (cl-loop for el in ouput
         unless (string= el "--compressed")
         if (string= el "-m300")
         append (list "-y300" "-Y1")
         else
         collect (replace-regex-in-string "%DEPLOYMENT%" model-string el))))
(advice-add 'gptel-curl--get-args :filter-return #js/gptel-curl--get-args-advice)

btw using -y300 -Y1 instead of -m300 might be a good idea for streaming. because as long as you still get new data you probably don't want to time out.

karthink commented 6 months ago

btw using -y300 -Y1 instead of -m300 might be a good idea for streaming. because as long as you still get new data you probably don't want to time out.

Thank you for this suggestion! Changed.