db620d33df
CodeQL / Analyze (csharp) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
dotnet-build-and-test / dotnet-test-functions (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-foundry-hosted-it (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
dotnet-build-and-test / Integration Test Report (push) Has been cancelled
58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
import asyncio
|
|
|
|
from agent_framework import Content, Message
|
|
from agent_framework.ollama import OllamaChatClient
|
|
from dotenv import load_dotenv
|
|
|
|
# Load environment variables from .env file
|
|
load_dotenv()
|
|
|
|
"""
|
|
Ollama Agent Multimodal Example
|
|
|
|
This sample demonstrates implementing a Ollama agent with multimodal input capabilities.
|
|
|
|
Ensure to install Ollama and have a model running locally before running the sample
|
|
Not all Models support multimodal input, to test multimodal input try gemma3:4b
|
|
Set the model to use via the OLLAMA_MODEL environment variable or modify the code below.
|
|
https://ollama.com/
|
|
|
|
"""
|
|
|
|
|
|
def create_sample_image() -> str:
|
|
"""Create a simple 1x1 pixel PNG image for testing."""
|
|
# This is a tiny red pixel in PNG format
|
|
png_data = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=="
|
|
return f"data:image/png;base64,{png_data}"
|
|
|
|
|
|
async def test_image() -> None:
|
|
"""Test image analysis with Ollama."""
|
|
|
|
client = OllamaChatClient()
|
|
|
|
image_uri = create_sample_image()
|
|
|
|
message = Message(
|
|
role="user",
|
|
contents=[
|
|
Content.from_text(text="What's in this image?"),
|
|
Content.from_uri(uri=image_uri, media_type="image/png"),
|
|
],
|
|
)
|
|
|
|
response = await client.get_response([message])
|
|
print(f"Image Response: {response}")
|
|
|
|
|
|
async def main() -> None:
|
|
print("=== Testing Ollama Multimodal ===")
|
|
await test_image()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|