I’m working with AzureOpenAI and langchain, constantly getting hit by PermissionError
. This mostly could be due to the proxy, but can someone please check the code —
from langchain.llms import OpenAI, AzureOpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
llm = AzureOpenAI(openai_api_type="", openai_api_base="", deployment_name="", model_name="", openai_api_key="", openai_api_version="")
template = """"
Translate the following text from {source_lang} to {dest_lang}: {source_text}
"""
prompt_name = PromptTemplate(input_variables=["source_lang", "dest_lang", "source_text"], template=template)
chain = LLMChain(llm=llm, prompt=prompt_name)
chain.predict(source_lang="English", dest_lang="Spanish", source_text="How are you?")
chain(inputs={"source_lang": "English", "dest_lang": "Spanish", "source_text": "How are you"})
I also tried the additional openai_proxy
parameter without much luck.
2
Answers
your code runs smoothly! Below my llm config. Other variables are set with
.env
To fix this permission error, you need to create a service principal and assign it the appropriate permissions. Follow the below steps to create a service principal,
Go to the Azure portal and create a new service principal.
In the service principal blade, select the "API permissions" tab.
Click on the "Add permission" button and select the "Azure OpenAI" API.
Select the "Delegated permissions" tab and select the following permissions:
Click on the "Save" button.
Set the following environment variables in your operating system’s environment variables or in a .env file.