| … | … | @@ -0,0 +1,153 @@ |
| 1 | # OllamaTools: Function Library for Ollama LLMs |
| 2 | |
| 3 | OllamaTools is a Python library that extends Ollama with semantic function calling capabilities, enabling automatic invocation of system commands, web requests, and documentation utilities based on conversational context. |
| 4 | |
| 5 | ## Project Overview |
| 6 | |
| 7 | **Primary Goal:** Allow Ollama LLMs to execute external functions based on semantic understanding of user queries without requiring explicit enabling/disabling of tools. |
| 8 | |
| 9 | ### Key Features |
| 10 | |
| 11 | - **Semantic Function Detection:** Automatically detect when a function should be called based on conversation |
| 12 | - **Secure Permission System:** Interactive prompt-based security for sensitive operations |
| 13 | - **System Tools:** Execute commands and file operations seamlessly |
| 14 | - **Web Tools:** Make web requests and process responses |
| 15 | - **Documentation Tools:** Generate and process documentation |
| 16 | |
| 17 | ## Current Implementation Status |
| 18 | |
| 19 | - ✅ Project Structure and Configuration |
| 20 | - ✅ Configuration Management |
| 21 | - ✅ Logging Utilities |
| 22 | - ✅ Basic Permission Manager |
| 23 | - ✅ Interactive Permission Prompts |
| 24 | - 🔄 Command Execution (In Progress) |
| 25 | - ⏳ File Operations (Planned) |
| 26 | - ⏳ Web Tools (Planned) |
| 27 | - ⏳ Documentation Tools (Planned) |
| 28 | - ⏳ Core Agent (Planned) |
| 29 | |
| 30 | ## Installation |
| 31 | |
| 32 | ```bash |
| 33 | # Clone the repository |
| 34 | git clone https://github.com/yourusername/ollamatools.git |
| 35 | cd ollamatools |
| 36 | |
| 37 | # Install in development mode |
| 38 | pip install -e . |
| 39 | ``` |
| 40 | |
| 41 | ## Requirements |
| 42 | |
| 43 | - Python 3.8+ |
| 44 | - Ollama 0.4.0+ with function calling support |
| 45 | - Linux-based operating system (primary target) |
| 46 | |
| 47 | ### Dependencies |
| 48 | |
| 49 | - ollama-python >= 0.4.0 |
| 50 | - requests >= 2.28.0 |
| 51 | - beautifulsoup4 >= 4.11.0 |
| 52 | - pydantic >= 1.10.0 |
| 53 | - markdown >= 3.4.0 |
| 54 | - typing-extensions >= 4.4.0 |
| 55 | - pytest >= 7.0.0 (for testing) |
| 56 | |
| 57 | ## Usage Examples |
| 58 | |
| 59 | ### Basic Permission System |
| 60 | |
| 61 | ```python |
| 62 | from ollamatools.security import PermissionManager |
| 63 | |
| 64 | # Create a permission manager with default settings |
| 65 | pm = PermissionManager() |
| 66 | |
| 67 | # Request permission for an operation |
| 68 | if pm.request_permission("read_file", {"path": "/etc/hosts"}): |
| 69 | # Operation was approved |
| 70 | print("Permission granted!") |
| 71 | else: |
| 72 | # Operation was denied |
| 73 | print("Permission denied.") |
| 74 | |
| 75 | # Request permission for a sudo operation |
| 76 | if pm.request_permission("execute_command", {"command": "sudo apt update"}, is_sudo=True): |
| 77 | # Sudo operation was approved |
| 78 | print("Sudo operation approved!") |
| 79 | else: |
| 80 | # Sudo operation was denied |
| 81 | print("Sudo operation denied.") |
| 82 | ``` |
| 83 | |
| 84 | ### Response Options |
| 85 | |
| 86 | When prompted for permission, you can: |
| 87 | |
| 88 | - **[A] Allow:** Grant permission for this operation only |
| 89 | - **[S] Allow for Session:** Grant permission for similar operations in this session |
| 90 | - **[M] Modify:** Modify the operation before execution |
| 91 | - **[D] Deny:** Reject the operation |
| 92 | |
| 93 | ## Security Features |
| 94 | |
| 95 | OllamaTools is designed with security as a primary concern: |
| 96 | |
| 97 | - **Prompt-Based Permissions:** Clear, informative prompts explain operations and potential risks |
| 98 | - **Special Handling for Sudo:** Sudo commands always require permission by default |
| 99 | - **Session Permissions:** Reduce prompt fatigue while maintaining security |
| 100 | - **Command Modification:** Modify operations before execution for fine-grained control |
| 101 | |
| 102 | ## Development |
| 103 | |
| 104 | ### Running Tests |
| 105 | |
| 106 | ```bash |
| 107 | # Run all tests |
| 108 | pytest |
| 109 | |
| 110 | # Run specific test file |
| 111 | pytest tests/test_security.py |
| 112 | ``` |
| 113 | |
| 114 | ### Project Structure |
| 115 | |
| 116 | ``` |
| 117 | OllamaTools/ |
| 118 | ├── ollamatools/ |
| 119 | │ ├── __init__.py |
| 120 | │ ├── agent.py # Main agent interface |
| 121 | │ ├── security.py # Permission management |
| 122 | │ ├── config.py # Configuration management |
| 123 | │ ├── tools/ # Function groups |
| 124 | │ │ ├── __init__.py |
| 125 | │ │ ├── system_tools.py # Linux command execution |
| 126 | │ │ ├── web_tools.py # Web requests |
| 127 | │ │ └── doc_tools.py # Documentation utilities |
| 128 | │ └── utils/ |
| 129 | │ ├── __init__.py |
| 130 | │ └── logger.py # Logging utilities |
| 131 | ├── tests/ # Unit and integration tests |
| 132 | ├── examples/ # Example scripts |
| 133 | ├── README.md |
| 134 | ├── LICENSE |
| 135 | ├── setup.py |
| 136 | └── requirements.txt |
| 137 | ``` |
| 138 | |
| 139 | ## Future Development |
| 140 | |
| 141 | - Full implementation of system tools |
| 142 | - Web requests and API integrations |
| 143 | - Documentation generation utilities |
| 144 | - Core agent with Ollama integration |
| 145 | - Comprehensive testing and documentation |
| 146 | |
| 147 | ## Contributing |
| 148 | |
| 149 | Contributions are welcome! Please feel free to submit a Pull Request. |
| 150 | |
| 151 | ## License |
| 152 | |
| 153 | This project is licensed under the [MIT License](LICENSE). |