skip to Main Content

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


  1. 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,
    )
    
    Login or Signup to reply.
  2. 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:

      openai.runtime.invoke
      openai.runtime.models.list
      
    • Click on the "Save" button.

    • Set the following environment variables in your operating system’s environment variables or in a .env file.

      AZURE_OPENAI_CLIENT_ID=your-client-id
      AZURE_OPENAI_CLIENT_SECRET=your-client-secret
      AZURE_OPENAI_TENANT_ID=your-tenant-id
      
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search