hello, i have an error when i run a code to use AzureOpenai APIkey. please give me reason and what is the correct form of my code?

mohammad ghasemifard 0 Reputation points
2024-04-18T11:28:56.9566667+00:00
import os
from openai import AzureOpenAI
api_type = "azure"
api_endpoint = 'https://---.openai.azure.com/'
api_version = "2023-05-15"
#openai.api_version = '2023-12-01-preview'
openai.api_key = 'c-----'

client = AzureOpenAI(
    api_key= api_key,
    api_version= api_version,
    azure_endpoint= api_endpoint
)
OpenAIError                               Traceback (most recent call last)
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,170 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sreeju Nair 11,611 Reputation points
    2024-04-18T11:38:52.6366667+00:00

    try the below.

    Note:- Your API key is visible in the error message you posted. If it is actual, edit your question and hide it.

    
    import os
    from openai import AzureOpenAI
    api_type = "azure"
    api_endpoint = 'https://---.openai.azure.com/'
    api_version = "2023-05-15"
    api_key = 'c-----'
    
    client = AzureOpenAI(
        api_key= api_key,
        api_version= api_version,
        azure_endpoint= api_endpoint
    )
    
    
    

  2. mohammad ghasemifard 0 Reputation points
    2024-04-18T13:34:47.8166667+00:00

    another question that i have is:

    my following code has this error:

    
    
    
    TypeError                                 Traceback (most recent call last)
    <ipython-input-35-442464444aeb>
    
    TypeError: Transcriptions.create() got an unexpected keyword argument 'deployment_id'
    
    
    
    
    model_name = "whisper-1"
    deployment_id = "whisper"
    audio_language="en"
    audio_test_file = "/content/english.mp3"
    result = client.audio.transcriptions.create(
                file=open(audio_test_file, "rb"),
                model=model_name,
                deployment_id=deployment_id
            )
    
    print(result.text)