Search code examples
azureopenai-apilangchainazure-openai

PermissionError while executing langchain with AzureOpenAI


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.


Solution

  • enter image description here

    your code runs smoothly! Below my llm config. Other variables are set with .env

    llm=AzureChatOpenAI(
        deployment_name=AZURE_OPENAI_CHATGPT_DEPLOYMENT,
        temperature=0.0,
    )