Created
October 23, 2025 15:48
-
-
Save tsoe77/db40b6cd1ddce7102ca9b48d8dfb2371 to your computer and use it in GitHub Desktop.
agentic calculator π
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pydantic import BaseModel | |
| from pydantic_ai import Agent | |
| from pydantic_ai.models.openai import OpenAIChatModel | |
| from pydantic_ai.providers.ollama import OllamaProvider | |
| ollama_model = OpenAIChatModel( | |
| model_name='llama3.2:latest', | |
| provider=OllamaProvider(base_url='http://localhost:11434/v1'), | |
| ) | |
| class SumModel(BaseModel): | |
| a: int | |
| b: int | |
| class SumResultModel(BaseModel): | |
| result: int | |
| def compute_sum(input=BaseModel): | |
| a = input.a | |
| b = input.b | |
| agent = Agent(ollama_model, output_type=SumResultModel) | |
| result = agent.run_sync(f"Sum of {a} + {b}") | |
| return result.output.result | |
| def test_sum(): | |
| a, b = 3, 4 | |
| assert compute_sum(SumModel(a=a, b=b)) == a + b | |
| if __name__ == "__main__": | |
| import pytest | |
| pytest.main([__file__, "--disable-warnings"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment