pythonversionopenai-apiazure-openaigpt-4

How can I find out the GPT-4 model version when using openai Python library and Azure OpenAI?


I use GPT-4 via openai Python library and Azure OpenAI. How can I find out the GPT-4 model version by using the openai Python library (and not looking at https://portal.azure.com/ because for some Azure OpenAI instances I only have the credentials to use the API but I can't view them on https://portal.azure.com/)?

I read:

https://platform.openai.com/docs/models/continuous-model-upgrades:

You can verify this by looking at the response object after sending a request. The response will include the specific model version used (e.g. gpt-3.5-turbo-0613).

https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo:

gpt-4 currently points to gpt-4-0613.


However, I tried calling gpt-4 version 0314 and gpt-4 version 0125-preview: for both of them, the response object after sending a request only contains gpt-4:

ChatCompletion(
    id='chatcmpl-8slN5Cbbsdf16s51sdf8yZpRXZM1R', 
    choices=[
        Choice(
            finish_reason='stop', 
            index=0, 
            logprobs=None, 
            message=ChatCompletionMessage(
                content='blahblah', 
                role='assistant', 
                function_call=None, 
                tool_calls=None
            ), 
            content_filter_results={
                'hate': {'filtered': False, 'severity': 'safe'}, 
                'self_harm': {'filtered': False, 'severity': 'safe'}, 
                'sexual': {'filtered': False, 'severity': 'safe'}, 
                'violence': {'filtered': False, 'severity': 'safe'}
            }
        )
    ], 
    created=1708062499, 
    model='gpt-4', 
    object='chat.completion', 
    system_fingerprint='fp_8absdfsdsfs',
    usage=CompletionUsage(
        completion_tokens=185, 
        prompt_tokens=4482, 
        total_tokens=4667
    ), 
    prompt_filter_results=[
        {
            'prompt_index': 0, 
            'content_filter_results': {
                'hate': {'filtered': False, 'severity': 'safe'}, 
                'self_harm': {'filtered': False, 'severity': 'safe'}, 
                'sexual': {'filtered': False, 'severity': 'safe'}, 
                'violence': {'filtered': False, 'severity': 'safe'}
            }
        }
    ]
)

How can I find out the GPT-4 model version when using openai Python library and Azure OpenAI?


Solution

  • The issue is fixed with newer versions of GPT.

    Full example:

    #Note: This code sample was tested with OpenAI Python library version 1.35.13 or higher. It does not work with openai==1.8.0 as it is missing the function `.to_json()`.
    import json
    import pprint
    from openai import AzureOpenAI
    
    client = AzureOpenAI(
      azure_endpoint = "https://xxxxxx.openai.azure.com/",
      api_key='xxxxxxxxxxxxxxxxxxxxx',
      api_version="2023-07-01-preview"
    )
    
    message_text = [{"role":"system","content":"You are an AI assistant that helps people find information."}]
    completion = client.chat.completions.create(
      model="gpt-4xxxxxxxx", 
      messages = message_text,
      temperature=0.7,
      max_tokens=800,
      top_p=0.95,
      frequency_penalty=0,
      presence_penalty=0,
      stop=None
    )
    
    print('completion:\n')
    print(completion.to_json())
    

    Outputs:

    {
      "id": "chatcmpl-9jzBinihKrewxh4PIZjd3Z0h6ZaUP",
      "choices": [
        {
          "finish_reason": "stop",
          "index": 0,
          "logprobs": null,
          "message": {
            "content": "Sure, I'd be happy to help! What information are you looking for?",
            "role": "assistant"
          },
          "content_filter_results": {
            "hate": {
              "filtered": false,
              "severity": "safe"
            },
            "self_harm": {
              "filtered": false,
              "severity": "safe"
            },
            "sexual": {
              "filtered": false,
              "severity": "safe"
            },
            "violence": {
              "filtered": false,
              "severity": "safe"
            }
          }
        }
      ],
      "created": 1720746994,
      "model": "gpt-4o-2024-05-13",
      "object": "chat.completion",
      "system_fingerprint": "fp_abc28019ad",
      "usage": {
        "completion_tokens": 15,
        "prompt_tokens": 18,
        "total_tokens": 33
      },
      "prompt_filter_results": [
        {
          "prompt_index": 0,
          "content_filter_results": {}
        }
      ]
    }
    

    Notice the "model": "gpt-4o-2024-05-13" in the output.