You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Image_Chat_With_Agent.cs 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Image_Chat_With_Agent.cs
  3. #region Using
  4. using AutoGen.Core;
  5. using AutoGen.OpenAI;
  6. using AutoGen.OpenAI.Extension;
  7. #endregion Using
  8. using FluentAssertions;
  9. namespace AutoGen.Basic.Sample;
  10. public class Image_Chat_With_Agent
  11. {
  12. public static async Task RunAsync()
  13. {
  14. #region Create_Agent
  15. var gpt4o = LLMConfiguration.GetOpenAIGPT4o_mini();
  16. var agent = new OpenAIChatAgent(
  17. chatClient: gpt4o,
  18. name: "agent",
  19. systemMessage: "You are a helpful AI assistant")
  20. .RegisterMessageConnector() // convert OpenAI message to AutoGen message
  21. .RegisterPrintMessage();
  22. #endregion Create_Agent
  23. #region Prepare_Image_Input
  24. var backgoundImagePath = Path.Combine("resource", "images", "background.png");
  25. var imageBytes = File.ReadAllBytes(backgoundImagePath);
  26. var imageMessage = new ImageMessage(Role.User, BinaryData.FromBytes(imageBytes, "image/png"));
  27. #endregion Prepare_Image_Input
  28. #region Prepare_Multimodal_Input
  29. var textMessage = new TextMessage(Role.User, "what's in the picture");
  30. var multimodalMessage = new MultiModalMessage(Role.User, [textMessage, imageMessage]);
  31. #endregion Prepare_Multimodal_Input
  32. #region Chat_With_Agent
  33. var reply = await agent.SendAsync("what's in the picture", chatHistory: [imageMessage]);
  34. // or use multimodal message to generate reply
  35. reply = await agent.SendAsync(multimodalMessage);
  36. #endregion Chat_With_Agent
  37. #region verify_reply
  38. reply.Should().BeOfType<TextMessage>();
  39. #endregion verify_reply
  40. }
  41. }