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.

Chat_With_LLaVA.cs 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Chat_With_LLaVA.cs
  3. #region Using
  4. using AutoGen.Core;
  5. using AutoGen.Ollama.Extension;
  6. #endregion Using
  7. namespace AutoGen.Ollama.Sample;
  8. public class Chat_With_LLaVA
  9. {
  10. public static async Task RunAsync()
  11. {
  12. #region Create_Ollama_Agent
  13. using var httpClient = new HttpClient()
  14. {
  15. BaseAddress = new Uri("http://localhost:11434"),
  16. };
  17. var ollamaAgent = new OllamaAgent(
  18. httpClient: httpClient,
  19. name: "ollama",
  20. modelName: "llava:latest",
  21. systemMessage: "You are a helpful AI assistant")
  22. .RegisterMessageConnector()
  23. .RegisterPrintMessage();
  24. #endregion Create_Ollama_Agent
  25. #region Send_Message
  26. var image = Path.Combine("resource", "images", "background.png");
  27. var binaryData = BinaryData.FromBytes(File.ReadAllBytes(image), "image/png");
  28. var imageMessage = new ImageMessage(Role.User, binaryData);
  29. var textMessage = new TextMessage(Role.User, "what's in this image?");
  30. var reply = await ollamaAgent.SendAsync(chatHistory: [textMessage, imageMessage]);
  31. #endregion Send_Message
  32. #region Send_MultiModal_Message
  33. // You can also use MultiModalMessage to put text and image together in one message
  34. // In this case, all the messages in the multi-modal message will be put into single piece of message
  35. // where the text is the concatenation of all the text messages seperated by \n
  36. // and the images are all the images in the multi-modal message
  37. var multiModalMessage = new MultiModalMessage(Role.User, [textMessage, imageMessage]);
  38. reply = await ollamaAgent.SendAsync(chatHistory: [multiModalMessage]);
  39. #endregion Send_MultiModal_Message
  40. }
  41. }