在 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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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