Azure OpenAI GPT-4 API Call Error 0 Reputation points

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

    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
    # Accessing environment variables
    # 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
        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(
    # Interacting with the SQL database and learning from the data
    agent_executor.invoke("Describe the playlisttrack table")