Azure OpenAI GPT-4 API Call Error

Affpilot.com 0 Reputation points
2024-04-19T16:42:24.43+00:00

I'm able to deploy GPT-4 Turbo model. But the problem is I'm getting this error when I'm going to with API.

Error: openai.error.InvalidRequestError: The completion operation does not work with the specified model, gpt-4. Please choose different model and try again.

In playground I can use GPT-4 but when I'm trying with Python programming code (API Call), it gives me error.

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,303 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Diego Martos 5 Reputation points Microsoft Employee
    2024-04-19T17:05:30.3666667+00:00

    Hi, I've faced same issues with a python script calling a resource, on my environment, the following helped me to deploy in python, but, when using Langchain as the Agent to massage my skills.


    # Loading Azure Open AI Resource environment and keys in non-secure way expose solution to security risk as variables from ".env" file outside the code under the same project directory
    
    # Recommended to replace with Azure Key Valt if aiming for production, current solution is not secure but good enough for a short-term learning and early testing
    
    #System Variables
    import os
    from dotenv import load_dotenv
    load_dotenv()
    
    # Accessing environment variables
    os.environ["OPENAI_API_TYPE"] 
    os.environ["OPENAI_API_VERSION"] 
    os.environ["AZURE_OPENAI_ENDPOINT"] 
    os.environ["OPENAI_API_KEY"] 
    os.environ["AZURE_COGS_KEY"] 
    os.environ["AZURE_COGS_ENDPOINT"] 
    os.environ["AZURE_COGS_REGION"] 
    
    # Importing AzureChatOpenAI from langchain_openai
    from langchain_openai import AzureChatOpenAI
    
    # Creating an instance of AzureChatOpenAI
    llm = AzureChatOpenAI(
        deployment_name='gpt-4-deployment', #Replace with the name given for your GTP-4 deployment
        openai_api_type="azure",
        temperature = 0
    )
    
    # Importing necessary modules for creating SQL agent from langchain
    from langchain.agents import create_sql_agent
    from langchain.agents.agent_toolkits import SQLDatabaseToolkit
    from langchain.sql_database import SQLDatabase
    from langchain.llms.openai import OpenAI
    from langchain.agents import AgentExecutor
    from langchain.agents.agent_types import AgentType
    from langchain.chat_models import ChatOpenAI
    
    # Creating an instance of SQLDatabase pointing to a local database on the same resource location where application also exist.
    db = SQLDatabase.from_uri('sqlite:///chinook.db')
    
    # Creating an instance of SQLDatabaseToolkit
    toolkit = SQLDatabaseToolkit(db=db, llm=llm)
    
    # Creating an instance of AgentExecutor
    agent_executor = create_sql_agent(
        llm=llm,
        toolkit=toolkit,
        verbose=True,
        agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    )
    
    # Interacting with the SQL database and learning from the data
    agent_executor.invoke("Describe the playlisttrack table")