A powerful, minimal AI researcher leveraging strict Pydantic V2 typing, DuckDuckGo Search, and Local Ollama Models.
This project demonstrates the sheer power of Pydantic V2 combined with an agentic web search workflow. By enforcing strict JSON schemas on the local granite4.1:3b model, we guarantee that the synthesized research reports are robust, perfectly structured, and ready to be downloaded via a stunning Streamlit UI.
- Pydantic V2: Strict schema definition, validation, and JSON generation.
- Streamlit: Beautiful, rapid web interface.
- Ollama: Local AI inference using
granite4.1:3b(zero-cost, fast). - DuckDuckGo Search: Real-time web context gathering.
app.py: The main Streamlit web application. It handles the UI, invokes DuckDuckGo for web searches, formats the prompt for Ollama, and displays the final Markdown report.models.py: Contains theResearchReportPydantic V2 schema. It enforces strict type validation and utilizes@field_validatorto automatically clean up the LLM's text output.requirements.txt: Python package dependencies.output.md/ideal_outputs.md: Sample generated markdown reports produced by the tool.
Copy and paste these commands into your Windows AntiGravity PowerShell:
Ensure you have Ollama installed on your system. Run the following command to download the model and ensure the server is running:
ollama run granite4.1:3b(You can exit the interactive prompt once it downloads by typing /bye. Ollama will continue running in the background).
pip install -r requirements.txtstreamlit run app.pyTo quickly test the Pydantic generation pipeline without the UI:
python -c "from app import generate_report; print(generate_report('AI Agents', 'AI Agents are autonomous entities.').model_dump_json(indent=2))"- Automated Market Research: Instantly generate well-structured reports on competitors by typing their names.
- Academic Synthesis: Summarize the latest breakthroughs on highly specific topics in seconds.
- News Aggregation: Get the top 3 key findings of current world events strongly validated by Pydantic.
- Offline-First AI Tools: Completely local analysis (aside from the search ping) ensuring zero data leakage to cloud LLM providers.
- Data Pipeline Prototyping: Serve as a visual frontend before adapting the robust
models.pyfor a backend production pipeline.
- Multi-Step Agents: Add a planning step where the LLM decides what to search before searching.
- Dynamic Model Switching: A sidebar dropdown to switch between installed Ollama models dynamically.
- PDF Export: Convert the generated markdown into a beautiful PDF file alongside the Markdown download.
- Pydantic TypeAdapter: Implement
TypeAdapterfor batch validation of multiple concurrent research reports. - Streaming Responses: Stream the generated report chunks directly into the UI for a faster perceived experience.
- Pydantic V2 Get Started: Official documentation to jump right into Pydantic V2 core concepts.
- Migration Code Transformation Tool: A helpful guide and tool (
bump-pydantic) for migrating your Pydantic V1 code to V2 seamlessly. - Pydantic V2 Article: An in-depth article discussing the vision, performance enhancements, and architectural shifts in Pydantic V2.
Pydantic V2, AI Agents, Local Ollama, Granite Model, Streamlit UI, DuckDuckGo Search, Python, AI Workflow.