karthink / gptel

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

support Azure OpenAI api #41

Closed wxxb789 closed 10 months ago

wxxb789 commented 1 year ago

will this package support Azure OpenAI api?

karthink commented 1 year ago

Not explicitly, no. But I had a look at the API:

curl https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/chat/completions?api-version=2023-03-15-preview \
  -H "Content-Type: application/json" \
  -H "api-key: YOUR_API_KEY" \
  -d '{"messages":[{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},{"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},{"role": "user", "content": "Do other Azure Cognitive Services support this too?"}]}'

It looks very similar to the OpenAI API, so you might be able to use gptel with minimal tweaking: Replace the request URL and one of the headers (Authorization: Bearer sk-...api-key: sk-...). If that works I could add a PR.

jcs090218 commented 1 year ago

Maybe worth mentioning, openai.el now supports this. 😄 See https://github.com/emacs-openai/openai/issues/14.

karthink commented 1 year ago

Maybe worth mentioning, openai.el now supports this. smile See emacs-openai/openai#14.

Thanks for the heads-up. If all that's needed is making the base url configurable, this should be simple to add.

TeMPOraL commented 1 year ago

It's not that simple - see https://github.com/emacs-openai/openai/issues/18. Basically, Azure OpenAI API is slightly different:

POST https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/completions?api-version=2022-12-01

In particular, you:

I would dearly love to see this implemented too.

karthink commented 10 months ago

Support for Azure has been implemented in v0.5.0, along with support for local models using GPT4All and Ollama. Please refer to the README for instructions.