| 
									
										
										
										
											2024-10-02 11:42:27 -07:00
										 |  |  | // Copyright (c) Microsoft Corporation. All rights reserved. | 
					
						
							| 
									
										
										
										
											2024-06-20 10:47:31 -07:00
										 |  |  | // Image_Chat_With_Agent.cs | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-25 09:23:24 -07:00
										 |  |  | #region Using | 
					
						
							| 
									
										
										
										
											2024-06-20 10:47:31 -07:00
										 |  |  | using AutoGen.Core; | 
					
						
							| 
									
										
										
										
											2024-08-27 14:37:47 -07:00
										 |  |  | using AutoGen.OpenAI; | 
					
						
							|  |  |  | using AutoGen.OpenAI.Extension; | 
					
						
							| 
									
										
										
										
											2024-06-25 09:23:24 -07:00
										 |  |  | #endregion Using | 
					
						
							| 
									
										
										
										
											2024-06-20 10:47:31 -07:00
										 |  |  | using FluentAssertions; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-28 17:13:36 -05:00
										 |  |  | namespace AutoGen.Basic.Sample; | 
					
						
							| 
									
										
										
										
											2024-06-20 10:47:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | public class Image_Chat_With_Agent | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public static async Task RunAsync() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         #region Create_Agent | 
					
						
							| 
									
										
										
										
											2024-08-27 14:37:47 -07:00
										 |  |  |         var gpt4o = LLMConfiguration.GetOpenAIGPT4o_mini(); | 
					
						
							| 
									
										
										
										
											2024-06-20 10:47:31 -07:00
										 |  |  |         var agent = new OpenAIChatAgent( | 
					
						
							| 
									
										
										
										
											2024-08-27 14:37:47 -07:00
										 |  |  |             chatClient: gpt4o, | 
					
						
							| 
									
										
										
										
											2024-06-20 10:47:31 -07:00
										 |  |  |             name: "agent", | 
					
						
							|  |  |  |             systemMessage: "You are a helpful AI assistant") | 
					
						
							|  |  |  |             .RegisterMessageConnector() // convert OpenAI message to AutoGen message | 
					
						
							|  |  |  |             .RegisterPrintMessage(); | 
					
						
							|  |  |  |         #endregion Create_Agent | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #region Prepare_Image_Input | 
					
						
							|  |  |  |         var backgoundImagePath = Path.Combine("resource", "images", "background.png"); | 
					
						
							|  |  |  |         var imageBytes = File.ReadAllBytes(backgoundImagePath); | 
					
						
							|  |  |  |         var imageMessage = new ImageMessage(Role.User, BinaryData.FromBytes(imageBytes, "image/png")); | 
					
						
							|  |  |  |         #endregion Prepare_Image_Input | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #region Prepare_Multimodal_Input | 
					
						
							|  |  |  |         var textMessage = new TextMessage(Role.User, "what's in the picture"); | 
					
						
							|  |  |  |         var multimodalMessage = new MultiModalMessage(Role.User, [textMessage, imageMessage]); | 
					
						
							|  |  |  |         #endregion Prepare_Multimodal_Input | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-25 09:23:24 -07:00
										 |  |  |         #region Chat_With_Agent | 
					
						
							|  |  |  |         var reply = await agent.SendAsync("what's in the picture", chatHistory: [imageMessage]); | 
					
						
							|  |  |  |         // or use multimodal message to generate reply | 
					
						
							|  |  |  |         reply = await agent.SendAsync(multimodalMessage); | 
					
						
							|  |  |  |         #endregion Chat_With_Agent | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-20 10:47:31 -07:00
										 |  |  |         #region verify_reply | 
					
						
							|  |  |  |         reply.Should().BeOfType<TextMessage>(); | 
					
						
							|  |  |  |         #endregion verify_reply | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |