Cover image
Try Now
2025-04-07

使用MCP服务器集成的本地Ollama模型为Pydantic Agent创建了样本项目。

3 years

Works with Finder

1

Github Watches

0

Github Forks

0

Github Stars

Ollama Pydantic Project

This project demonstrates how to use a local Ollama model with the Pydantic agent framework to create an intelligent agent. The agent is connected to an MCP server to utilize tools and provides a user-friendly interface using Streamlit.

Overview

The main goal of this project is to showcase:

  • Local Ollama Model Integration: Using a locally hosted Ollama model for generating responses.
  • Pydantic Agent Framework: Creating an agent with Pydantic for data validation and interaction.
  • MCP Server Connection: Enabling the agent to use tools via an MCP server.
  • Streamlit UI: Providing a web-based chatbot interface for user interaction.

Prerequisites

Before setting up the project, ensure the following:

  1. Python: Install Python 3.8 or higher. You can download it from python.org.
  2. Ollama Model: Install and run the Ollama server locally:
    • Download the Ollama CLI from Ollama's official website.
    • Install the CLI by following the instructions provided on their website.
    • Start the Ollama server:
      ollama serve
      
    • Ensure the server is running on http://localhost:11434/v1.
  3. MCP Server: Set up an MCP server to enable agent tools. For more details, refer to MCP Server Sample.

Setup Instructions

Follow these steps to set up the project:

  1. Clone the Repository:

    git clone <repository-url>
    cd ollama-pydantic-project
    
  2. Create a Virtual Environment:

    python3 -m venv venv
    
  3. Activate the Virtual Environment:

    • On macOS/Linux:
      source venv/bin/activate
      
    • On Windows:
      venv\Scripts\activate
      
  4. Install Dependencies:

    pip install -r requirements.txt
    
  5. Ensure the Ollama Server is Running: Start the Ollama server as described in the prerequisites.

  6. Run the Application: Start the Streamlit application:

    streamlit run src/streamlit_app.py
    

Usage

Once the application is running, open the provided URL in your browser (usually http://localhost:8501). You can interact with the chatbot by typing your queries in the input box. The agent will process your queries using the Ollama model and tools provided by the MCP server.

Example Interaction

Below is an example of how the chatbot interface looks when interacting with the agent:

Chatbot Example

Project Structure

The project is organized as follows:

ollama-pydantic-project/
├── src/
│   ├── streamlit_app.py        # Main Streamlit application
│   ├── agents/
│   │   ├── base_agent.py       # Abstract base class for agents
│   │   ├── ollama_agent.py     # Implementation of the Ollama agent
│   ├── utils/
│       ├── config.py           # Configuration settings
│       ├── logger.py           # Logger utility
├── requirements.txt            # Python dependencies
├── README.md                   # Project documentation
├── assets/
│   ├── ollama_agent_mcp_example.png  # Example interaction image
├── .gitignore                  # Git ignore file

Features

  • Streamlit Chatbot: A user-friendly chatbot interface.
  • Ollama Model Integration: Uses a local Ollama model for generating responses.
  • MCP Server Tools: Connects to an MCP server to enhance agent capabilities.
  • Pydantic Framework: Ensures data validation and type safety.

Troubleshooting

  • If you encounter issues with the Ollama server, ensure it is running on http://localhost:11434/v1.
  • If dependencies fail to install, ensure you are using Python 3.8 or higher and that your virtual environment is activated.
  • For MCP server-related issues, refer to the MCP Server Sample.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

  • JackKuo666
  • 🔍使AI助手可以通过简单的MCP接口搜索和访问PYPI软件包信息。

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • appcypher
  • 很棒的MCP服务器 - 模型上下文协议服务器的策划列表

    Reviews

    4 (1)
    Avatar
    user_X7TfBaTz
    2025-04-17

    I've been using the ollama-pydantic-project for a few weeks now, and I'm thoroughly impressed. The implementation is seamless and integrates perfectly with my existing workflow. Kudos to jageenshukla for creating such a well-thought-out project. If you're working with Pydantic, this is a must-try! Highly recommended. Check it out at the GitHub link provided.