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.md 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. This tutorial shows how to perform image chat with an agent using the @AutoGen.OpenAI.OpenAIChatAgent as an example.
  2. > [!NOTE]
  3. > To chat image with an agent, the model behind the agent needs to support image input. Here is a partial list of models that support image input:
  4. > - gpt-4o
  5. > - gemini-1.5
  6. > - llava
  7. > - claude-3
  8. > - ...
  9. >
  10. > In this example, we are using the gpt-4o model as the backend model for the agent.
  11. > [!NOTE]
  12. > The complete code example can be found in [Image_Chat_With_Agent.cs](https://github.com/microsoft/autogen/blob/main/dotnet/sample/AutoGen.BasicSamples/GettingStart/Image_Chat_With_Agent.cs)
  13. ## Step 1: Install AutoGen
  14. First, install the AutoGen package using the following command:
  15. ```bash
  16. dotnet add package AutoGen
  17. ```
  18. ## Step 2: Add Using Statements
  19. [!code-csharp[Using Statements](../../sample/AutoGen.BasicSamples/GettingStart/Image_Chat_With_Agent.cs?name=Using)]
  20. ## Step 3: Create an @AutoGen.OpenAI.OpenAIChatAgent
  21. [!code-csharp[Create an OpenAIChatAgent](../../sample/AutoGen.BasicSamples/GettingStart/Image_Chat_With_Agent.cs?name=Create_Agent)]
  22. ## Step 4: Prepare Image Message
  23. In AutoGen, you can create an image message using either @AutoGen.Core.ImageMessage or @AutoGen.Core.MultiModalMessage. The @AutoGen.Core.ImageMessage takes a single image as input, whereas the @AutoGen.Core.MultiModalMessage allows you to pass multiple modalities like text or image.
  24. Here is how to create an image message using @AutoGen.Core.ImageMessage:
  25. [!code-csharp[Create Image Message](../../sample/AutoGen.BasicSamples/GettingStart/Image_Chat_With_Agent.cs?name=Prepare_Image_Input)]
  26. Here is how to create a multimodal message using @AutoGen.Core.MultiModalMessage:
  27. [!code-csharp[Create MultiModal Message](../../sample/AutoGen.BasicSamples/GettingStart/Image_Chat_With_Agent.cs?name=Prepare_Multimodal_Input)]
  28. ## Step 5: Generate Response
  29. To generate response, you can use one of the overloaded methods of @AutoGen.Core.AgentExtension.SendAsync* method. The following code shows how to generate response with an image message:
  30. [!code-csharp[Generate Response](../../sample/AutoGen.BasicSamples/GettingStart/Image_Chat_With_Agent.cs?name=Chat_With_Agent)]
  31. ## Further Reading
  32. - [Image chat with gemini](../articles/AutoGen.Gemini/Image-chat-with-gemini.md)
  33. - [Image chat with llava](../articles/AutoGen.Ollama/Chat-with-llava.md)