c# - How to add image as an input to a ChatMessage with Microsoft.Extensions.AI - Stack Overflow
I'm trying to use Microsoft.Extensions.AI to ask a model hosted in Azure OpenAI to describe an image. I've been able to successfully chat with a gpt-4o-mini model, using the following code:
var message = new ChatMessage(ChatRole.User, "Please describe this image in one sentence");
chatHistory.Add(message);
await foreach (var item in
chatClient.CompleteStreamingAsync(chatHistory))
{
Console.Write(item.Text);
}
However, if I try to add an image to the chat message either locally:
var data = File.ReadAllBytes(@"C:\temp\example.jpg");
message.Contents.Add(new ImageContent(data, "image/jpeg"));
or via a URL:
message.Contents.Add(new ImageContent(new Uri(".jpg")));
Then I get no response from the AI - it just seems to hang for many minutes. I believe that gpt-4o-mini supports image as input. Is what I'm trying to do possible, and if so what is the correct way to add an image to a chat message?
I'm trying to use Microsoft.Extensions.AI to ask a model hosted in Azure OpenAI to describe an image. I've been able to successfully chat with a gpt-4o-mini model, using the following code:
var message = new ChatMessage(ChatRole.User, "Please describe this image in one sentence");
chatHistory.Add(message);
await foreach (var item in
chatClient.CompleteStreamingAsync(chatHistory))
{
Console.Write(item.Text);
}
However, if I try to add an image to the chat message either locally:
var data = File.ReadAllBytes(@"C:\temp\example.jpg");
message.Contents.Add(new ImageContent(data, "image/jpeg"));
or via a URL:
message.Contents.Add(new ImageContent(new Uri("https://example.net/example.jpg")));
Then I get no response from the AI - it just seems to hang for many minutes. I believe that gpt-4o-mini supports image as input. Is what I'm trying to do possible, and if so what is the correct way to add an image to a chat message?
Share Improve this question asked yesterday Mark HeathMark Heath 49.5k29 gold badges143 silver badges200 bronze badges1 Answer
Reset to default 0After trying this in the Chat Playground at ai.azure.com, I found my deployment was being rate-limited. I changed the default of 10K tokens per minute to 40K and the code shown above worked correctly, producing output like:
"A band is performing on stage, featuring instruments like electric guitars, drums, and a keyboard, with a colorful patterned backdrop behind them."
I don't know why the chat client simply hung rather than returning a rate-limit exceeded error.
- 谷歌跟微软干上了:公布更多Windows安全漏洞
- 谷歌无人驾驶汽车或将带来下一轮失业大潮
- 英特尔CEO欧德宁:笔记本与平板电脑终将融合
- 软件主宰世界 如何统治电脑业、数字传媒等行业
- [连载]巨头“心血之作”终失败(二):Google Chromebook
- graphdb - vector embedding on ontotext similarity plugin - Stack Overflow
- python - Implementing multiple live streams at the same time using aiortc - WebRTC - Stack Overflow
- Prisma create: Typescript error in field data - Stack Overflow
- rust - How Can I Efficiently Render an Emulator Framebuffer in an Iced Widget at 60 FPS? - Stack Overflow
- haskell - How to perform beta reduction on a lambda abstraction? - Stack Overflow
- python - Why do I get AttributeError: module 'tensorflow.keras.backend' has no attribute 'placeholder&am
- excel - Add a rule to the VBA to remove filters - Stack Overflow
- node.js - How to Deploy an Angular 19 SSR App on AWS Amplify? - Stack Overflow
- c# - Microsoft.Extensions.Logging.LoggerFactory how to prevent an extra date to be added to the log filename - Stack Overflow
- sockets - PICO WMicropython websocket client can't send to PHP websocket properly - Stack Overflow
- Setting a global property for one web user in server function in Apps Script - Stack Overflow
- swift - Codable class does not conform to protocol Decodable because of TimeStamp, new Error wasn't there before - Stack