ztjhz / BetterChatGPT

An amazing UI for OpenAI's ChatGPT (Website + Windows + MacOS + Linux)
http://bettergpt.chat/
Creative Commons Zero v1.0 Universal
7.81k stars 2.64k forks source link

Azure OpenAI API don't work #296

Open othmanelhoufi opened 1 year ago

othmanelhoufi commented 1 year ago

I added the Azure OpenAI Endpoint and Key but get an error:

Message from Better ChatGPT:
Invalid API endpoint! We recommend you to check your free API endpoint.

And I'm sure that my credentials are correct.

othmanelhoufi commented 1 year ago

I just fixed the problem in my fork. Basically you don't take into account the fact that the HTTP request link for Azure OpenAI is different from OpenAI (https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference):

POST https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/chat/completions?api-version={api-version}

As you can see, there are informations about the model used as well as the api version in the HTTP link, so the endpoint only is not enough.

By the way, thank you for this incredible UI ! I hope my solution can help you improve it :)

llegomark commented 1 year ago

For instance, the deployment ID you have created in the OAI Azure Dashboard must match with the deployment ID in betterchatgpt:

chrome_screenshot_oai azure com

const gpt3forAzure = 'gpt35turbo'; // deployment id
const model =
  config.model === 'gpt-3.5-turbo' ? gpt3forAzure : config.model;
const apiVersion = '2023-05-15';
othmanelhoufi commented 1 year ago

You could do a mapping on deployment names to BetterGPT model names in your own fork. Or, to make it even simpler, change the deployment names in your OAI Azure Dashboard. The idea is to have consistency in the naming.

The actual problem that was solved was about the API Request link that was not well implemented in the code. But now it works fine.

detrin commented 3 months ago

I have the same issue, is there any plan to fix this?

detrin commented 3 months ago

Looking at the code I think I know where there could be an issue https://github.com/ztjhz/BetterChatGPT/blob/eb18479a6b32cde25cd61770e8f2cb971418db23/src/api/api.ts#L38 here we see that the endpoint must end with correct API version

const path = `openai/deployments/${model}/chat/completions?api-version=${apiVersion}`

but I have '2024-02-15-preview' where as in the code we see

const apiVersion =
      model === 'gpt-4' || model === 'gpt-4-32k'
        ? '2023-07-01-preview'
        : '2023-03-15-preview';
detrin commented 3 months ago

https://learn.microsoft.com/en-us/azure/ai-services/openai/reference?WT.mc_id=AZ-MVP-5004796 yeah so there are many versions, that are not supported by BetterChatGPT