在 ASP.NET Core 中使用 ChatGPT4 Vision

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

from openai import OpenAIclient = 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])

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


回答:

文档中包含了一个cURL示例,可以轻松地转换为C#的HttpRequest:

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  }'

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注