mayooear / gpt4-pdf-chatbot-langchain

GPT4 & LangChain Chatbot for large PDF docs
https://www.youtube.com/watch?v=ih9PBGVVOO4
14.86k stars 3.01k forks source link

Azure OpenAI #349

Closed tan-yaka closed 1 year ago

tan-yaka commented 1 year ago

Has anyone got this to work with Azure's OpenAI (javascript)?

I have the AZURE_OPENAI_API_KEY, AZURE_OPENAI_API_INSTANCE_NAME, AZURE_OPENAI_API_DEPLOYMENT_NAME and AZURE_OPENAI_API_VERSION set correctly I believe but get an error 400 when trying to ingest docs. It's works fine when I use my OPENAI_API_KEY.

Is there any extra configuration needed in the Azure portal?

tan-yaka commented 1 year ago

This looks like it's an Azure OpenAI issue according to this langchainjs issue: https://github.com/hwchase17/langchainjs/issues/1571

YIN-Renlong commented 11 months ago

Hi @tan-yaka, have you figured it out? I changed the original code in the.env file to the following code. But the error persists. Have you have any recommendations? Thanks

AZURE_OPENAI_API_KEY= "ss9839j3dh79sjk38ejdd823j" AZURE_OPENAI_API_INSTANCE_NAME= "https://testopenaiinstance1.openai.azure.com/" AZURE_OPENAI_API_DEPLOYMENT_NAME= gpt4chatplaygdepname1 AZURE_OPENAI_API_VERSION= 2023-06-01-preview

replaced the original code #OPENAI_API_KEY= sk-lXEV7XkH.....

the error after running npm run ingest:

/Applications/gpt4-pdf-chatbot-langchain/scripts/ingest-data.ts:46 throw new Error('Failed to ingest your data'); ^

Error: Failed to ingest your data at run (/Applications/gpt4-pdf-chatbot-langchain/scripts/ingest-data.ts:46:11) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at (/Applications/gpt4-pdf-chatbot-langchain/scripts/ingest-data.ts:51:3)

Node.js v18.17.1

tan-yaka commented 11 months ago

@YIN-Renlong it's been a while since I used this but looking back at my code I had these env variables set:

AZURE_OPENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxx
AZURE_OPENAI_API_DEPLOYMENT_NAME=tanyaka-gpt-4
AZURE_OPENAI_API_INSTANCE_NAME=tanyaka-openai
AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME=tanyaka-text-embedding-ada-002
AZURE_OPENAI_API_COMPLETIONS_DEPLOYMENT_NAME=tanyaka-gpt-4
AZURE_OPENAI_API_VERSION=2023-05-15

Not sure if you have to put the full https:// for the instance name as it is inferred. You'll need to create a text-embedding-ada-002 deployment for the ingest to work.

You might want to change your api key as well now that you have published it on github.

YIN-Renlong commented 11 months ago

Hi @tan-yaka, many thanks for helping me out! It works according to how you put it up. Actually, there were two components lacking from my prior setup. Setting up text-embedding-ada-002was the first step (configuration is not necessary while using the OpenAI API, but it is on Azure Openai API), and writing out INSTANCE_NAME alone rather than the complete URL was the second. It may be unnecessary, however "AZURE_OPENAI_API_COMPLETIONS_DEPLOYMENT_NAME" functions properly even if I didn't configure it. Once again, I appreciate your quick message!

tan-yaka commented 5 months ago

Use one of the supported versions in here https://learn.microsoft.com/en-us/azure/ai-services/openai/reference