ztjhz / BetterChatGPT

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

Please add default support for Azure endpoints #208

Closed magedhelmy1 closed 1 year ago

magedhelmy1 commented 1 year ago

Please add support to support OpenAI endpoints from Azure.

Thank you

ztjhz commented 1 year ago

Currently, you can use a custom api endpoint in the api settings. Is the Azure endpoint not working as a custom endpoint?

keita commented 1 year ago

Currently, you can use a custom api endpoint in the api settings. Is the Azure endpoint not working as a custom endpoint?

It seems that Azure's API specification requires sending the key with "api-key: TOKEN" in the header instead of "Authorization: Bearer TOKEN". Therefore, even if you set up the Azure endpoint, it will result in a 401 unauthorized error.

magedhelmy1 commented 1 year ago

~In addition, here is an example - we need to include the engine parameters:~

ztjhz commented 1 year ago

We will add support for the api-key: TOKEN in the headers for azure endpoints. I believe that the engine parameter is for the python usage method. In the REST method, there is no engine parameter.

magedhelmy1 commented 1 year ago

Hi, thanks for adding that! I see that the following in your code is being executed when I set the custom API to Azure:

export const isAzureEndpoint = (endpoint: string) => {
  return endpoint.includes('openai.azure.com');
};

However I still get the following Error

api.ts:48          POST https://researchproject.openai.azure.com/ 404
getChatCompletionStream @ api.ts:48
handleSubmit @ useSubmit.ts:91
handleSaveAndSubmit @ MessageContent.tsx:409
callCallback2 @ react-dom.development.js:4164
invokeGuardedCallbackDev @ react-dom.development.js:4213
invokeGuardedCallback @ react-dom.development.js:4277
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:4291
executeDispatch @ react-dom.development.js:9041
processDispatchQueueItemsInOrder @ react-dom.development.js:9073
processDispatchQueue @ react-dom.development.js:9086
dispatchEventsForPlugins @ react-dom.development.js:9097
(anonymous) @ react-dom.development.js:9288
batchedUpdates$1 @ react-dom.development.js:26140
batchedUpdates @ react-dom.development.js:3991
dispatchEventForPluginEventSystem @ react-dom.development.js:9287
dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay @ react-dom.development.js:6465
dispatchEvent @ react-dom.development.js:6457
dispatchDiscreteEvent @ react-dom.development.js:6430
useSubmit.ts:175 Message from Better ChatGPT:
Invalid API endpoint! We recommend you to check your free API endpoint.

I am sure that the API Key and Endpoint is correct on my end.

I think the issue is specifically in the Rest code below and it is in the example of the Rest on the website

curl $OPENAI_API_BASE/openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-03-15-preview \ -H "Content-Type: application/json" \ -H "api-key: $OPENAI_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?"}]}'

I should be able to insert the gpt-35-turbo and api-version=2023-03-15-preview from the frontend of BetterGPT. The gpt-35-turbo is the deployment name and that is different for different users and similarly with the api-version, that is different. On the BetterChatGPT frontend these fields can be added for Azure?

Thanks again.

ztjhz commented 1 year ago

You can try adding the entire thing $OPENAI_API_BASE/openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-03-15-preview to the custom endpoint, instead of just https://researchproject.openai.azure.com/.

keita commented 1 year ago

We will add support for the api-key: TOKEN in the headers for azure endpoints. I believe that the engine parameter is for the python usage method. In the REST method, there is no engine parameter.

Thank you for your work. I have confirmed that it works without any issues using the Azure OpenAI Service endpoint.

hawktang commented 1 year ago
image

keep show error when use $OPENAI_API_BASE/openai/deployments/GPT4/chat/completions?api-version=2023-06-01-preview

It is working for my own python script with this api url

hawktang commented 1 year ago

没有到密码验证, 似乎直接判断格式不对, mac 客户端

hawktang commented 1 year ago

看code似乎是因为 model name 写死了..., azure api的deployments_id 不是确定的.

我们GPT4只能部署一个model, 我没办法改名字了