mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
2f06fe557a
* Initial Commit for Olama Connector * Added Olama Sample * Add Sample & Fixed Open Telemetry * Fixed Spelling from Olama to Ollama * remove"opentelemetry-semantic-conventions-ai ~=0.4.13" since its handled in a different pr * Added Tool Calling * Finalizing test cases * Adjust samples to be more reliable * Update python/packages/ollama/agent_framework_ollama/_chat_client.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/packages/ollama/pyproject.toml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/packages/ollama/tests/test_ollama_chat_client.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/packages/ollama/agent_framework_ollama/_chat_client.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Improved Docstrings & Sample * Update python/packages/ollama/agent_framework_ollama/_chat_client.py Co-authored-by: Eduard van Valkenburg <eavanvalkenburg@users.noreply.github.com> * Integrate PR Feedback - Divided Streaming and Non-Streaming into independent Methods - Catch Ollama Validation Error - Add OTEL Provider Name - Checked Ollama Messages - Add Usage Statistics * Revert setting, so it can be none * Validate Message formatting between AF and Ollama * Catch Ollama Error and raise a ServiceResponse Error * Fix mypy error * remove .vscode comma * Add Reasoning support & adjust to new structure * Add Ollama Multimodality and Reasoning * Add test cases for reasoning * Add Tests for Error Handling in Ollama Client * Update python/samples/getting_started/multimodal_input/ollama_chat_multimodal.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Integrated Copilot Feedback * Implement first PR Feedback * Adjust Readme files for examples * Adjust argument passing via additional chat options * Implemented PR Feedback * Removing Ollama Package from Core and moving samples * Fix Link & Adding Samples to Main Sample Readme * Fixing Links in Readme * Moved Multimodal and Chat Example * Fixed Link in ChatClient to Ollama * Fix AgentFramework Links in Ollama Project * Fix observability breaking change --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Eduard van Valkenburg <eavanvalkenburg@users.noreply.github.com>
55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
import asyncio
|
|
|
|
from agent_framework import ChatMessage, DataContent, Role, TextContent
|
|
|
|
from agent_framework_ollama import OllamaChatClient
|
|
|
|
"""
|
|
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_CHAT_MODEL_ID 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 = ChatMessage(
|
|
role=Role.USER,
|
|
contents=[
|
|
TextContent(text="What's in this image?"),
|
|
DataContent(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())
|