在 ASP.NET Core 中使用 ChatGPT4 Vision

问题描述 投票:0回答:1

我正在开发一个与 openai 集成的 Web 应用程序。我已实现标准聊天提示和响应,但在访问视觉 API 时遇到问题。我能找到的所有例子都是用Python编写的。我快速启动了 Jupyter Notebook,并使用我的 api 密钥调用了视觉模型,效果非常好。寻找一种方法将此代码转换为 C# 或可行的解决方案以在我的应用程序中使用该代码。

from openai import OpenAI

client = OpenAI(api_key="___")

response = client.chat.completions.create(
    model="gpt-4-vision-preview",
    messages=[
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "Does this image show a Fender Stratocaster Electric Guitar?        Respond with yes or no."},
        {
          "type": "image_url",
          "image_url": {
            "url": "https://toneshapers.com/cdn/shop/files/Les-Paul-Standard-Front.jpg",
          },
        },
      ],
    }
  ],
  max_tokens=300,
)

print(response.choices[0])

我尝试从 C# 中的 openai 实例访问“chat.completions”,但它们似乎不存在。

c# asp.net-core openai-api vision chat-gpt-4
1个回答
0
投票

该文档包含一个可转换为 C# 的 cURL 示例:

curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-4-vision-preview",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "What’s in this image?"
          },
          {
            "type": "image_url",
            "image_url": {
              "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
            }
          }
        ]
      }
    ],
    "max_tokens": 300
  }'
© www.soinside.com 2019 - 2024. All rights reserved.