OperationNotSupported when trying to fun completion with gpt-4o

Romanowski, Tomasz 25 Reputation points
2024-06-07T16:20:51.8433333+00:00

I've created a gpt-4o deployment and now trying to run a test program generated here:

https://learn.microsoft.com/en-us/azure/ai-services/openai/quickstart?pivots=programming-language-python&tabs=command-line%2Cpython-new

import os
from openai import AzureOpenAI
    
client = AzureOpenAI(
    api_key=os.getenv("AZURE_OPENAI_API_KEY"),  
    api_version="2024-02-01",
    azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
    )
    
deployment_name='REPLACE_WITH_YOUR_DEPLOYMENT_NAME' #This will correspond to the custom name you chose for your deployment when you deployed a model. Use a gpt-35-turbo-instruct deployment. 
    
# Send a completion call to generate an answer
print('Sending a test completion job')
start_phrase = 'Write a tagline for an ice cream shop. '
response = client.completions.create(model=deployment_name, prompt=start_phrase, max_tokens=10)
print(start_phrase+response.choices[0].text)

However I'm getting an error:

openai.BadRequestError: Error code: 400 - {'error': {'code': 'OperationNotSupported', 'message': 'The completion operation does not work with the specified model, gpt-4o. Please choose different model and try again. You can learn more about which models can be used with each operation here: https://go.microsoft.com/fwlink/?linkid=2197993.'}}
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,421 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 5,306 Reputation points
    2024-06-08T13:32:57.52+00:00

    Hello Romanowski, Tomasz,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you are having issue with running a completion operation on a GPT-4o model deployed in Azure OpenAI Service and this makes you to request for an assistance in identifying a suitable model and modifying your code to work with the model.

    Solution

    The error message you're seeing indicates that the gpt-4o model does not support the completion operation you're trying to perform. This is a known limitation of the gpt-4o model in the Azure OpenAI service and you can read more from this Azure OpenAI documentation: https://go.microsoft.com/fwlink/?linkid=2197993

    To resolve this issue, you need to ensure that you are using a model that supports the completion operation. According to the Azure OpenAI documentation, certain models like gpt-35-turbo-instruct are recommended for such tasks. This is how you can modify your code to use the gpt-35-turbo model:

    import os
    from openai import AzureOpenAI
    # Set environment variables
    os.environ["AZURE_OPENAI_API_KEY"] = "your_azure_openai_api_key"
    os.environ["AZURE_OPENAI_ENDPOINT"] = "your_azure_openai_endpoint"
    # Initialize the client
    client = AzureOpenAI(
        api_key=os.getenv("AZURE_OPENAI_API_KEY"),
        api_version="2024-02-01",
        azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT")
    )
    # Use the correct deployment name for a supported model
    deployment_name = 'gpt-35-turbo-instruct-deployment'  # Replace with your deployment name
    # Send a completion call to generate an answer
    print('Sending a test completion job')
    start_phrase = 'Write a tagline for an ice cream shop. '
    response = client.completions.create(model=deployment_name, prompt=start_phrase, max_tokens=10)
    print(start_phrase + response.choices[0].text)
    

    I replaced gpt-35-turbo with your actual deployment name if you have deployed the gpt-35-turbo model. If you haven't, you might need to deploy it first.

    References

    Source: This is the current limitation. Assistants doesn't support GPT-4o yet. Accessed, 6/8/2024.

    Source: Work with the GPT-35-Turbo and GPT-4 models - Azure OpenAI Service. Accessed, 6/8/2024.

    Source: [Azure OpenAI documentation.] Accessed, 6/8/2024.

    Accept Answer

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.

    Best Regards,

    Sina Salam

    0 comments No comments