azure open ai gpt-4o issue with image analysis and C#

I’m using bot framework sdk with C# to call Azure open AI model gpt-4o for image analysis. i receive following response or variance of it. however when i upload same exact image to azure open ai studio it’s able to analyze it. also when i use python it’s able to analyze it. what could be the issue with this c# code?

`/ Generated with EchoBot .NET Template version v4.22.0

using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
using System;
using Azure;
using Azure.AI.OpenAI;
using System.IO; // Required for working with files
using System.Text; // Required for Base64 encoding
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;

namespace EchoBot.Bots

{
    public class EchoBot : ActivityHandler
    {

        static readonly HttpClient client2 = new HttpClient();
        protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
                // Check if the activity contains any text
            if (!string.IsNullOrEmpty(turnContext.Activity.Text))
                {
                   var replyText = $"Echo: {turnContext.Activity.Text}";
                   await turnContext.SendActivityAsync(MessageFactory.Text(replyText, replyText), cancellationToken);

                    OpenAIClient client = new OpenAIClient(new Uri("https://mct-openai01.openai.azure.com/"),
                     new AzureKeyCredential("xxxxxxxxxxxxxxxxxxxxxxxxx"));

                     Response<ChatCompletions> responseWithoutStream = await client.GetChatCompletionsAsync("mct-gpt4o-01",
                      new ChatCompletionsOptions()
                        {
                           Messages =
                             {
                               new ChatMessage(ChatRole.System, @"You are an AI assistant that helps people find information."),
                                new ChatMessage(ChatRole.User, @"You are an AI assistant that helps people find information."),

                              },
                           Temperature = (float)0.7,
                          MaxTokens = 800,


                          NucleusSamplingFactor = (float)0.95,
                          FrequencyPenalty = 0,
                          PresencePenalty = 0,
                        } );


                    ChatCompletions response = responseWithoutStream.Value;
                    string completionText = response.Choices[0].Message.Content;
                    await turnContext.SendActivityAsync(MessageFactory.Text(completionText, completionText), cancellationToken);

                }
            else if (turnContext.Activity.Attachments.Count > 0)
            {
                // User sent an attachment
                await turnContext.SendActivityAsync(MessageFactory.Text(" I see you sent one!"), cancellationToken);

                    if (turnContext.Activity.Attachments.Count == 1 && turnContext.Activity.Attachments[0].ContentType.StartsWith("image/"))
                        {
                await turnContext.SendActivityAsync(MessageFactory.Text(" starts with image"), cancellationToken);


                           // Only process the first attachment if it's an image
                           var attachment = turnContext.Activity.Attachments[0];

                           if (attachment.ContentType.Contains("image/"))
                             {
                                await turnContext.SendActivityAsync(MessageFactory.Text(" contains"), cancellationToken);

                               var httpClient = new HttpClient();
                               var attachmentUrl = attachment.ContentUrl;

                              try
                                 {
                                      var attachmentResponse = await httpClient.GetAsync(attachmentUrl, cancellationToken);

                                        if (attachmentResponse.IsSuccessStatusCode)
                                           {
                                              using (var memoryStream = new MemoryStream())
                                                 {
                                                     await attachmentResponse.Content.CopyToAsync(memoryStream);
                                                      byte[] imageBytes = memoryStream.ToArray();

                                                     // Convert image to Base64 string
                                                     string base64Image = Convert.ToBase64String(imageBytes);


                                                      // Prepare GPT-4 payload with Base64 image
                                                      ChatCompletionsOptions gpt4Options = new ChatCompletionsOptions()
                                                            {
                                                                Messages =
                                                                        {
                                                                            new ChatMessage(ChatRole.System, @"You are an AI assistant that helps people find information."),
                                                                            new ChatMessage(ChatRole.User, @"Here's an image for you to analyze."),
                                                                            //new ChatMessage(ChatRole.User, base64Image) // Add the base64 image as a user message
                                                                            new ChatMessage(ChatRole.User, $"{{"type": "image_url", "image_url": "data:image/png;base64,{base64Image}"}}") 
                                                                           // $"{{"type": "image_url", "image_url": {{"url": "data:image/png;base64,{base64Image}"}}}}")

                                                                        },



                                                                



                                                                        // ... other options like Temperature, MaxTokens, etc.
                                                            };

                                                                // Send the request with the image data
                                                      OpenAIClient client = new OpenAIClient(new Uri("https://mct-openai01.openai.azure.com/"),
                                                      new AzureKeyCredential("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
                                                      Response<ChatCompletions> gpt4Response = await client.GetChatCompletionsAsync("mct-gpt4o-01", gpt4Options);
                                                      ChatCompletions response = gpt4Response.Value;
                                                      string completionText = response.Choices[0].Message.Content;
                                                      await turnContext.SendActivityAsync(MessageFactory.Text(completionText, completionText), cancellationToken);

                                                 }
                                           }
                                         else
                                           {
                                          // Handle download failure (e.g., inform user)
                                          //await turnContext.SendActivityAsync(MessageFactory.Text("else statment"), cancellationToken);
                                           }
                                  }
                                           catch (Exception)
                                              {
                                              // Handle exceptions during download (e.g., logging)
                                              //await turnContext.SendActivityAsync(MessageFactory.Text("catch statment"), cancellationToken);
                                              }
                              }
                        }

                            
            }
         }
   


 

        protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
        {
            var welcomeText = "Hello and welcome!";
            foreach (var member in membersAdded)
            {
                if (member.Id != turnContext.Activity.Recipient.Id)
                {
                    await turnContext.SendActivityAsync(MessageFactory.Text(welcomeText, welcomeText), cancellationToken);
                }
            }
        }
    
   }
}`

did anyone face same issue with c# ?

New contributor

mahelsay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật