zurawiki / gptcommit

A git prepare-commit-msg hook for authoring commit messages with GPT-3.
MIT License
2.33k stars 78 forks source link

Support Azure OpenAI service #18

Open LayZeeDK opened 1 year ago

LayZeeDK commented 1 year ago

Please add support for Azure OpenAI service that now has General Availability (GA), including the GPT-3 model.

zurawiki commented 1 year ago

Thanks for the suggestion @LayZeeDK. I'm interested by your request. What's motivating it?

I certainly agree that this project should be generalized to support different LLM APIs in the future. If we want to implement Azure, I'd be curious to learn:

LayZeeDK commented 1 year ago

Azure OpenAI service supports enterprise-grade security, policies, compliance, and regional availability. Would you be interested in API access?

LayZeeDK commented 1 year ago

API reference for Azure OpenAI service:

zurawiki commented 1 year ago

Yup this is definitely something I'd be interested in making happen! I tagged the issue as help wanted

LayZeeDK commented 1 year ago

Completions

Request

Endpoint

In https://github.com/zurawiki/gptcommit/blob/6ee5bc587de6b7f2126d1cf073b8dc6e0b4d121c/src/openai.rs#L66-L71

Instead of https://api.openai.com/v1/completions, the endpoint URL would be in the format https://{resource_name}.openai.azure.com/openai/deployments/{deployment_id}/completions?api-version=<api_version> with 2022-12-01 being the latest API version so we must make the endpoint URL for completions configurable.

Headers

Instead of an Authorization header in the format Authorization: Bearer <api_key>, we would have the header api-key: <api_key>

Parameters

In the Azure OpenAI Service API, a completions request does not support a model parameter. Instead, this is represented by the {deployment_id} URL parameter.

Response

The OpenAI API response object has a usage property but the Azure OpenAI Service API does not.

The model property in the example response displays "ada". The models available for the Azure OpenAI Service are listed in Model Summary table and region availability. These are deployed then targeted in the {deployment_id} URL parameter for the completions endpoint. I'm not sure all the models supported by the Azure OpenAI Service are listed in https://github.com/zurawiki/gptcommit/blob/6ee5bc587de6b7f2126d1cf073b8dc6e0b4d121c/src/openai.rs#L91-L101

At least not if "ada" is a valid model response value.

zurawiki commented 1 year ago

Thanks for the context.

Currently, I'm blocked because I don't have access to the Azure OpenAI services. I applied but haven't heard back from Microsoft

zurawiki commented 1 year ago

Currently blocked on async-openai supporting Azure: https://github.com/64bit/async-openai/issues/32

Laisky commented 1 year ago

You can try this project that converts Azure to OpenAI API.

https://github.com/haibbo/cf-openai-azure-proxy/blob/main/README_en.md

then edit the gptchat's config file(~/.config/gptcommit/config.toml)

CleanShot 2023-05-16 at 10 05 50@2x

Note: api_key should be azure openai service's key, not openai's api key.