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

题意:

使用OpenAI的Python库以及Azure OpenAI服务时,怎样找出正在使用的GPT-4模型版本?

问题背景:

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 Microsoft Azure because for some Azure OpenAI instances I only have the credentials to use the API but I can't view them on Microsoft Azure)?

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?

问题解决:

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

营赢盈英

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值