| … | … | @@ -2,22 +2,6 @@ |
| 2 | 2 | |
| 3 | 3 | This document provides a summary of all the scripts created to help with the refactoring process for the OllamaTools project. |
| 4 | 4 | |
| 5 | ## Git Scripts | |
| 6 | ||
| 7 | ### `git_refactoring_commands.sh` | |
| 8 | ||
| 9 | Provides Git commands for different stages of the refactoring process. | |
| 10 | ||
| 11 | **Usage:** | |
| 12 | ```bash | |
| 13 | ./git_refactoring_commands.sh | |
| 14 | ``` | |
| 15 | ||
| 16 | **What it does:** | |
| 17 | - Provides Git commands for initial setup, refactoring process, testing, and finalization | |
| 18 | - Includes a Git commands cheat sheet for quick reference | |
| 19 | - Guides you through the Git workflow for the refactoring process | |
| 20 | ||
| 21 | 5 | ## Setup Scripts |
| 22 | 6 | |
| 23 | 7 | ### `setup_refactored_structure.sh` |
| … | … | @@ -158,14 +142,12 @@ Provides a step-by-step guide for the refactoring process. |
| 158 | 142 | |
| 159 | 143 | The typical workflow for using these scripts is: |
| 160 | 144 | |
| 161 | 1. Run `./git_refactoring_commands.sh` to understand the Git workflow for the refactoring process | |
| 162 | 2. Run `./setup_refactored_structure.sh` to create the new directory structure | |
| 163 | 3. Run `./generate_file_mapping.sh` to create the file mapping | |
| 164 | 4. Follow the steps in `./refactoring_guide.sh` to refactor the codebase | |
| 165 | 5. Use `./copy_refactor_file.sh` to copy and refactor files | |
| 166 | 6. Use `./update_mapping_status.sh` to track progress | |
| 167 | 7. Use `./test_refactored_code.sh` to test the refactored code | |
| 168 | 8. Run `./finalize_refactoring.sh` to finalize the refactoring process | |
| 169 | 9. Use Git commands from `./git_refactoring_commands.sh` to commit and push your changes | |
| 170 | ||
| 171 | This workflow ensures a systematic and organized approach to the refactoring process, with proper tracking, testing, and version control at each step. | |
| 145 | 1. Run `./setup_refactored_structure.sh` to create the new directory structure | |
| 146 | 2. Run `./generate_file_mapping.sh` to create the file mapping | |
| 147 | 3. Follow the steps in `./refactoring_guide.sh` to refactor the codebase | |
| 148 | 4. Use `./copy_refactor_file.sh` to copy and refactor files | |
| 149 | 5. Use `./update_mapping_status.sh` to track progress | |
| 150 | 6. Use `./test_refactored_code.sh` to test the refactored code | |
| 151 | 7. Run `./finalize_refactoring.sh` to finalize the refactoring process | |
| 152 | ||
| 153 | This workflow ensures a systematic and organized approach to the refactoring process, with proper tracking and testing at each step. |
| … | … | @@ -4,8 +4,8 @@ MATRIX: |
| 4 | 4 | PASSWORD: "chat7rn" |
| 5 | 5 | DEVICE_ID: "ollamatools-matrix" |
| 6 | 6 | ROOMS: |
| 7 | - "#general:prsm.space" | |
| 8 | - "#ai_bot_testing:prsm.space" | |
| 7 | # - "#general:prsm.space" | |
| 8 | - "#ai_testing:prsm.space" | |
| 9 | 9 | ADMIN_USERS: |
| 10 | 10 | - "@chat7rn:prsm.space" |
| 11 | 11 |
| … | … | @@ -4,7 +4,7 @@ MATRIX: |
| 4 | 4 | PASSWORD: "chat7rn" |
| 5 | 5 | DEVICE_ID: "ollamatools-matrix" |
| 6 | 6 | ROOMS: |
| 7 | - "#general:prsm.space" | |
| 7 | - "#ai_testing:prsm.space" | |
| 8 | 8 | OLLAMA: |
| 9 | 9 | HOST: "localhost:11434" |
| 10 | 10 | MODEL: "llama3.1:latest" |
| … | … | @@ -1,185 +0,0 @@ |
| 1 | #!/bin/bash | |
| 2 | ||
| 3 | # Script with Git commands to help with the refactoring process | |
| 4 | # This script provides Git commands for different stages of the refactoring process | |
| 5 | ||
| 6 | # Define colors for better readability | |
| 7 | RED='\033[0;31m' | |
| 8 | GREEN='\033[0;32m' | |
| 9 | YELLOW='\033[0;33m' | |
| 10 | BLUE='\033[0;34m' | |
| 11 | PURPLE='\033[0;35m' | |
| 12 | CYAN='\033[0;36m' | |
| 13 | NC='\033[0m' # No Color | |
| 14 | ||
| 15 | # Function to print section headers | |
| 16 | print_header() { | |
| 17 | echo -e "\n${BLUE}========== $1 ==========${NC}\n" | |
| 18 | } | |
| 19 | ||
| 20 | # Function to print steps | |
| 21 | print_step() { | |
| 22 | echo -e "${GREEN}Step $1:${NC} $2" | |
| 23 | } | |
| 24 | ||
| 25 | # Function to print commands | |
| 26 | print_command() { | |
| 27 | echo -e " ${YELLOW}$1${NC}" | |
| 28 | } | |
| 29 | ||
| 30 | # Function to print notes | |
| 31 | print_note() { | |
| 32 | echo -e " ${PURPLE}Note:${NC} $1" | |
| 33 | } | |
| 34 | ||
| 35 | # Function to print warnings | |
| 36 | print_warning() { | |
| 37 | echo -e " ${RED}Warning:${NC} $1" | |
| 38 | } | |
| 39 | ||
| 40 | # Clear the screen | |
| 41 | clear | |
| 42 | ||
| 43 | # Print the title | |
| 44 | echo -e "${CYAN}" | |
| 45 | echo "======================================================" | |
| 46 | echo " OllamaTools Git Refactoring Commands" | |
| 47 | echo "======================================================" | |
| 48 | echo -e "${NC}" | |
| 49 | echo "This script provides Git commands for different stages of the refactoring process." | |
| 50 | echo "Follow these commands to ensure proper version control during the refactoring." | |
| 51 | echo "" | |
| 52 | echo -e "${YELLOW}Note: This is a guide only. You will need to run the commands manually.${NC}" | |
| 53 | echo "" | |
| 54 | ||
| 55 | # Phase 1: Initial Setup | |
| 56 | print_header "Phase 1: Initial Setup" | |
| 57 | ||
| 58 | print_step "1" "Verify you're on the correct branch" | |
| 59 | print_command "git status" | |
| 60 | print_note "Ensure you're on the 'simplify' branch" | |
| 61 | ||
| 62 | print_step "2" "Create a new branch for the refactoring scripts (if needed)" | |
| 63 | print_command "git checkout -b refactoring-scripts" | |
| 64 | print_note "This creates a new branch for the refactoring scripts" | |
| 65 | print_warning "Skip this step if you want to keep working on the 'simplify' branch" | |
| 66 | ||
| 67 | print_step "3" "Add the refactoring scripts to Git" | |
| 68 | print_command "git add setup_refactored_structure.sh generate_file_mapping.sh update_mapping_status.sh copy_refactor_file.sh test_refactored_code.sh finalize_refactoring.sh refactoring_guide.sh git_refactoring_commands.sh" | |
| 69 | print_note "This adds all the refactoring scripts to Git" | |
| 70 | ||
| 71 | print_step "4" "Add the documentation files to Git" | |
| 72 | print_command "git add README_REFACTORING.md REFACTORING_SCRIPTS.md file_mapping.md" | |
| 73 | print_note "This adds all the documentation files to Git" | |
| 74 | ||
| 75 | print_step "5" "Commit the refactoring scripts and documentation" | |
| 76 | print_command "git commit -m 'Add refactoring scripts and documentation'" | |
| 77 | print_note "This commits all the refactoring scripts and documentation" | |
| 78 | ||
| 79 | # Phase 2: Refactoring Process | |
| 80 | print_header "Phase 2: Refactoring Process" | |
| 81 | ||
| 82 | print_step "1" "Create a new branch for the refactored code" | |
| 83 | print_command "git checkout -b refactored-code" | |
| 84 | print_note "This creates a new branch for the refactored code" | |
| 85 | print_warning "This should be done after running setup_refactored_structure.sh" | |
| 86 | ||
| 87 | print_step "2" "Add the new directory to .gitignore (optional)" | |
| 88 | print_command "echo '../ollamatools-new/' >> .gitignore" | |
| 89 | print_command "git add .gitignore" | |
| 90 | print_command "git commit -m 'Add ollamatools-new to .gitignore'" | |
| 91 | print_note "This prevents the new directory from being tracked by Git until it's ready" | |
| 92 | print_warning "Skip this step if you want to track the new directory with Git" | |
| 93 | ||
| 94 | print_step "3" "Commit changes after each phase of refactoring" | |
| 95 | print_command "git add ." | |
| 96 | print_command "git commit -m 'Complete Phase X: [Description]'" | |
| 97 | print_note "Replace X with the phase number and [Description] with a brief description" | |
| 98 | print_note "Commit after each major phase to maintain a clean history" | |
| 99 | ||
| 100 | # Phase 3: Testing | |
| 101 | print_header "Phase 3: Testing" | |
| 102 | ||
| 103 | print_step "1" "Create a branch for testing the refactored code" | |
| 104 | print_command "git checkout -b refactored-testing" | |
| 105 | print_note "This creates a new branch for testing the refactored code" | |
| 106 | print_warning "This should be done after completing the refactoring" | |
| 107 | ||
| 108 | print_step "2" "Commit test results and fixes" | |
| 109 | print_command "git add ." | |
| 110 | print_command "git commit -m 'Test results and fixes for [Component]'" | |
| 111 | print_note "Replace [Component] with the component being tested" | |
| 112 | print_note "Commit after testing each major component" | |
| 113 | ||
| 114 | # Phase 4: Finalization | |
| 115 | print_header "Phase 4: Finalization" | |
| 116 | ||
| 117 | print_step "1" "Merge the refactored code back to the main branch" | |
| 118 | print_command "git checkout simplify" | |
| 119 | print_command "git merge refactored-testing" | |
| 120 | print_note "This merges the refactored code back to the main branch" | |
| 121 | print_warning "Resolve any merge conflicts that may arise" | |
| 122 | ||
| 123 | print_step "2" "Tag the release" | |
| 124 | print_command "git tag -a v2.0.0 -m 'Refactored version 2.0.0'" | |
| 125 | print_note "This tags the release with a version number" | |
| 126 | print_note "Replace v2.0.0 with the appropriate version number" | |
| 127 | ||
| 128 | print_step "3" "Push the changes to the remote repository" | |
| 129 | print_command "git push origin simplify" | |
| 130 | print_command "git push origin v2.0.0" | |
| 131 | print_note "This pushes the changes and tag to the remote repository" | |
| 132 | ||
| 133 | # Current Status | |
| 134 | print_header "Current Status" | |
| 135 | ||
| 136 | print_step "1" "Add and commit the current refactoring scripts" | |
| 137 | print_command "git add setup_refactored_structure.sh generate_file_mapping.sh update_mapping_status.sh copy_refactor_file.sh test_refactored_code.sh finalize_refactoring.sh refactoring_guide.sh git_refactoring_commands.sh README_REFACTORING.md REFACTORING_SCRIPTS.md file_mapping.md" | |
| 138 | print_command "git commit -m 'Add refactoring scripts and documentation'" | |
| 139 | print_note "This adds and commits all the current refactoring scripts and documentation" | |
| 140 | ||
| 141 | print_step "2" "Push the changes to the remote repository" | |
| 142 | print_command "git push origin simplify" | |
| 143 | print_note "This pushes the changes to the remote repository" | |
| 144 | ||
| 145 | print_header "Git Commands Cheat Sheet" | |
| 146 | ||
| 147 | echo -e "${GREEN}Branching:${NC}" | |
| 148 | echo -e " ${YELLOW}git branch${NC} - List all branches" | |
| 149 | echo -e " ${YELLOW}git checkout <branch>${NC} - Switch to branch" | |
| 150 | echo -e " ${YELLOW}git checkout -b <new-branch>${NC} - Create and switch to new branch" | |
| 151 | ||
| 152 | echo -e "${GREEN}Status and Diff:${NC}" | |
| 153 | echo -e " ${YELLOW}git status${NC} - Show status of working directory" | |
| 154 | echo -e " ${YELLOW}git diff${NC} - Show changes in working directory" | |
| 155 | echo -e " ${YELLOW}git diff --staged${NC} - Show changes in staging area" | |
| 156 | ||
| 157 | echo -e "${GREEN}Staging and Committing:${NC}" | |
| 158 | echo -e " ${YELLOW}git add <file>${NC} - Add file to staging area" | |
| 159 | echo -e " ${YELLOW}git add .${NC} - Add all changes to staging area" | |
| 160 | echo -e " ${YELLOW}git commit -m 'message'${NC} - Commit staged changes" | |
| 161 | ||
| 162 | echo -e "${GREEN}History:${NC}" | |
| 163 | echo -e " ${YELLOW}git log${NC} - Show commit history" | |
| 164 | echo -e " ${YELLOW}git log --oneline${NC} - Show commit history (one line per commit)" | |
| 165 | echo -e " ${YELLOW}git blame <file>${NC} - Show who changed what in a file" | |
| 166 | ||
| 167 | echo -e "${GREEN}Remote Operations:${NC}" | |
| 168 | echo -e " ${YELLOW}git push origin <branch>${NC} - Push changes to remote repository" | |
| 169 | echo -e " ${YELLOW}git pull origin <branch>${NC} - Pull changes from remote repository" | |
| 170 | echo -e " ${YELLOW}git fetch${NC} - Fetch changes from remote repository" | |
| 171 | ||
| 172 | echo -e "${GREEN}Merging and Rebasing:${NC}" | |
| 173 | echo -e " ${YELLOW}git merge <branch>${NC} - Merge branch into current branch" | |
| 174 | echo -e " ${YELLOW}git rebase <branch>${NC} - Rebase current branch onto branch" | |
| 175 | echo -e " ${YELLOW}git cherry-pick <commit>${NC} - Apply changes from a specific commit" | |
| 176 | ||
| 177 | echo -e "${GREEN}Stashing:${NC}" | |
| 178 | echo -e " ${YELLOW}git stash${NC} - Stash changes in working directory" | |
| 179 | echo -e " ${YELLOW}git stash pop${NC} - Apply and remove the latest stash" | |
| 180 | echo -e " ${YELLOW}git stash list${NC} - List all stashes" | |
| 181 | ||
| 182 | echo -e "${GREEN}Tagging:${NC}" | |
| 183 | echo -e " ${YELLOW}git tag${NC} - List all tags" | |
| 184 | echo -e " ${YELLOW}git tag -a <tag> -m 'message'${NC} - Create annotated tag" | |
| 185 | echo -e " ${YELLOW}git push origin <tag>${NC} - Push tag to remote repository" |
| … | … | @@ -0,0 +1,47 @@ |
| 1 | # OllamaTools Simplified Refactoring Guide - Index | |
| 2 | ||
| 3 | This directory contains a simplified approach to refactoring the OllamaTools project. The original refactoring plan was found to be too complex, particularly because merging files together made them too large. This guide presents a more manageable approach that maintains the target directory structure but avoids merging files. | |
| 4 | ||
| 5 | ## Guide Structure | |
| 6 | ||
| 7 | The simplified refactoring guide is organized into the following documents: | |
| 8 | ||
| 9 | 1. **[00_INDEX.md](./00_INDEX.md)** - This index document | |
| 10 | 2. **[01_SIMPLIFIED_STRUCTURE.md](./01_SIMPLIFIED_STRUCTURE.md)** - The simplified file structure and file mapping strategy | |
| 11 | 3. **[02_IMPLEMENTATION_STEPS.md](./02_IMPLEMENTATION_STEPS.md)** - Detailed implementation steps for the simplified structure | |
| 12 | 4. **[03_FILE_MAPPING.md](./03_FILE_MAPPING.md)** - Complete file mapping table for reference | |
| 13 | ||
| 14 | ## Purpose | |
| 15 | ||
| 16 | This guide aims to provide a clear, step-by-step approach to refactoring the OllamaTools project in a way that: | |
| 17 | ||
| 18 | 1. Maintains the target directory structure from the original AI simplification guides | |
| 19 | 2. Avoids creating files that are too large to manage | |
| 20 | 3. Preserves existing functionality | |
| 21 | 4. Minimizes the risk of introducing bugs during refactoring | |
| 22 | ||
| 23 | ## How to Use This Guide | |
| 24 | ||
| 25 | This guide is designed to be followed sequentially: | |
| 26 | ||
| 27 | 1. Start by reviewing the simplified structure in [01_SIMPLIFIED_STRUCTURE.md](./01_SIMPLIFIED_STRUCTURE.md) | |
| 28 | 2. Follow the implementation steps in [02_IMPLEMENTATION_STEPS.md](./02_IMPLEMENTATION_STEPS.md) | |
| 29 | 3. Use the file mapping table in [03_FILE_MAPPING.md](./03_FILE_MAPPING.md) as a reference during implementation | |
| 30 | ||
| 31 | For developers: | |
| 32 | - Use this guide to understand the implementation plan | |
| 33 | - Follow the steps to create the new directory structure and move files | |
| 34 | - Update imports and references as described | |
| 35 | - Test the refactored code to ensure it works correctly | |
| 36 | ||
| 37 | ## Implementation Timeline | |
| 38 | ||
| 39 | The implementation can be broken down into manageable chunks: | |
| 40 | ||
| 41 | 1. **Week 1**: Create directory structure, copy files | |
| 42 | 2. **Week 2**: Update imports and references | |
| 43 | 3. **Week 3**: Implement new files | |
| 44 | 4. **Week 4**: Update package initialization, test code | |
| 45 | 5. **Week 5**: Documentation, migration guide, final steps | |
| 46 | ||
| 47 | By following this phased approach, we can implement the simplified structure in a controlled manner, ensuring that each step is properly tested before moving on to the next. |
| … | … | @@ -0,0 +1,172 @@ |
| 1 | # Simplified File Structure for OllamaTools Project | |
| 2 | ||
| 3 | This document outlines a simplified approach to refactoring the OllamaTools project. The original refactoring plan was found to be too complex, particularly because merging files together made them too large. This document presents a more manageable approach that maintains the target directory structure but avoids merging files. | |
| 4 | ||
| 5 | ## Current Large Files (>500 lines) | |
| 6 | ||
| 7 | Analysis of the current codebase reveals several files that are already quite large: | |
| 8 | ||
| 9 | - `ollamatools/tools/matrix_tools.py` (800 lines) | |
| 10 | - `ollamatools/agent/modular/agent.py` (702 lines) | |
| 11 | - `ollamatools/agent/modular/feedback.py` (586 lines) | |
| 12 | - `ollamatools/tools/web_tools.py` (484 lines) | |
| 13 | - `ollamatools/tools/enhanced_matrix_core.py` (466 lines) | |
| 14 | - `ollamatools/agent.py` (455 lines) | |
| 15 | ||
| 16 | Merging these already large files would create files that are too difficult to maintain. | |
| 17 | ||
| 18 | ## Revised Simplified Structure | |
| 19 | ||
| 20 | The target directory structure from the AI simplification guides provides a clear organization. Instead of merging files, we'll focus on organizing existing files into the appropriate directories while maintaining their individual functionality. | |
| 21 | ||
| 22 | ``` | |
| 23 | ollamatools/ | |
| 24 | ├── core/ # Core functionality | |
| 25 | │ ├── __init__.py | |
| 26 | │ ├── agent.py # Base agent implementation (from ollamatools/agent.py) | |
| 27 | │ ├── config.py # Configuration management (from ollamatools/config.py) | |
| 28 | │ ├── errors.py # Error definitions and handling (from ollamatools/errors.py) | |
| 29 | │ ├── security.py # Security utilities (from ollamatools/security.py) | |
| 30 | │ └── utils/ | |
| 31 | │ ├── __init__.py | |
| 32 | │ ├── logger.py # Logging utilities (from ollamatools/logger.py) | |
| 33 | │ ├── validators/ # Keep validators separate to avoid large files | |
| 34 | │ │ ├── __init__.py | |
| 35 | │ │ ├── command.py # Command validation (from ollamatools/command_validator.py) | |
| 36 | │ │ ├── path.py # Path validation (from ollamatools/path_validator.py) | |
| 37 | │ │ └── url.py # URL validation (from ollamatools/url_validator.py) | |
| 38 | │ └── formatting.py # Text formatting utilities (new file) | |
| 39 | │ | |
| 40 | ├── plugins/ # Plugin system and implementations | |
| 41 | │ ├── __init__.py | |
| 42 | │ ├── base.py # Base plugin interfaces (new file) | |
| 43 | │ ├── registry.py # Plugin discovery (from ollamatools/plugins/registry.py) | |
| 44 | │ ├── errors.py # Plugin-specific errors (from ollamatools/plugins/errors.py) | |
| 45 | │ ├── standard/ # Standard plugins | |
| 46 | │ │ ├── __init__.py | |
| 47 | │ │ ├── search.py # Search functionality (from ollamatools/agent/modular/search.py) | |
| 48 | │ │ ├── commands.py # Command management (from ollamatools/agent/modular/commands.py) | |
| 49 | │ │ ├── conversation/ | |
| 50 | │ │ │ ├── __init__.py | |
| 51 | │ │ │ ├── history.py # History tracking (from ollamatools/plugins/conversation_history.py) | |
| 52 | │ │ │ ├── context.py # Context management (from ollamatools/plugins/conversation_context.py) | |
| 53 | │ │ │ └── analysis.py # Topic analysis (new file) | |
| 54 | │ │ ├── feedback.py # Feedback collection (from ollamatools/agent/modular/feedback.py) | |
| 55 | │ │ ├── issues.py # Issue tracking (from ollamatools/agent/modular/issues.py) | |
| 56 | │ │ └── function_calling.py # Semantic function calling (new file) | |
| 57 | │ │ | |
| 58 | │ ├── tools/ # Tool plugins | |
| 59 | │ │ ├── __init__.py | |
| 60 | │ │ ├── system.py # System tools (from ollamatools/tools/system_tools.py) | |
| 61 | │ │ ├── web.py # Web tools (from ollamatools/tools/web_tools.py) | |
| 62 | │ │ └── doc.py # Documentation tools (from ollamatools/tools/doc_tools.py) | |
| 63 | │ │ | |
| 64 | │ └── integrations/ # Integration plugins | |
| 65 | │ ├── __init__.py | |
| 66 | │ ├── matrix/ # Keep Matrix files separate to avoid large files | |
| 67 | │ │ ├── __init__.py | |
| 68 | │ │ ├── client.py # Matrix client (from ollamatools/tools/matrix_tools.py) | |
| 69 | │ │ ├── commands.py # Matrix commands (from ollamatools/tools/enhanced_matrix_tools.py) | |
| 70 | │ │ ├── config.py # Matrix configuration (new file) | |
| 71 | │ │ ├── search.py # Matrix search (from ollamatools/tools/enhanced_matrix_search.py) | |
| 72 | │ │ ├── history.py # Matrix history (from ollamatools/tools/enhanced_matrix_history.py) | |
| 73 | │ │ └── rate_limit.py # Rate limiting (from ollamatools/tools/matrix_rate_limit_patch.py) | |
| 74 | │ └── opensearch/ | |
| 75 | │ ├── __init__.py | |
| 76 | │ ├── client.py # OpenSearch client (new file) | |
| 77 | │ └── tools.py # OpenSearch tools (from ollamatools/opensearch_web_tools.py) | |
| 78 | │ | |
| 79 | ├── agents/ # Agent implementations | |
| 80 | │ ├── __init__.py | |
| 81 | │ ├── basic.py # Basic agent (from ollamatools/agent/core.py) | |
| 82 | │ ├── modular.py # Modular agent (from ollamatools/agent/modular/agent.py) | |
| 83 | │ └── extended.py # Extended agent (from ollamatools/agent/extended/agent.py) | |
| 84 | │ | |
| 85 | ├── config/ # Configuration system | |
| 86 | │ ├── __init__.py | |
| 87 | │ ├── schemas.py # Configuration schemas (from ollamatools/config/schemas.py) | |
| 88 | │ ├── loader.py # Configuration loading (from ollamatools/config/core_config.py) | |
| 89 | │ └── defaults.py # Default configurations (from ollamatools/config/plugin_config.py) | |
| 90 | │ | |
| 91 | ├── cli/ # Command-line interface | |
| 92 | │ ├── __init__.py | |
| 93 | │ └── main.py # Command-line interface (new file) | |
| 94 | │ | |
| 95 | ├── __init__.py # Package initialization | |
| 96 | └── version.py # Version information | |
| 97 | ``` | |
| 98 | ||
| 99 | ## Key Differences from Original Plan | |
| 100 | ||
| 101 | 1. **Validators Directory**: Instead of merging all validators into a single file, keep them separate to avoid creating another large file. | |
| 102 | ||
| 103 | 2. **Matrix Integration**: Keep Matrix-related files separate rather than merging them, as the original matrix_tools.py is already 800 lines. | |
| 104 | ||
| 105 | 3. **No File Merging**: Focus on organizing files into the appropriate directories without merging them, which avoids creating files that are too large to manage. | |
| 106 | ||
| 107 | ## File Mapping Strategy | |
| 108 | ||
| 109 | ### Core Module | |
| 110 | - `ollamatools/agent.py` → `ollamatools/core/agent.py` | |
| 111 | - `ollamatools/errors.py` → `ollamatools/core/errors.py` | |
| 112 | - `ollamatools/config.py` → `ollamatools/core/config.py` | |
| 113 | - `ollamatools/security.py` → `ollamatools/core/security.py` | |
| 114 | - `ollamatools/logger.py` → `ollamatools/core/utils/logger.py` | |
| 115 | - `ollamatools/command_validator.py` → `ollamatools/core/utils/validators/command.py` | |
| 116 | - `ollamatools/path_validator.py` → `ollamatools/core/utils/validators/path.py` | |
| 117 | - `ollamatools/url_validator.py` → `ollamatools/core/utils/validators/url.py` | |
| 118 | ||
| 119 | ### Plugin System | |
| 120 | - `ollamatools/plugins/registry.py` → `ollamatools/plugins/registry.py` (same location) | |
| 121 | - `ollamatools/plugins/errors.py` → `ollamatools/plugins/errors.py` (same location) | |
| 122 | - Create new `ollamatools/plugins/base.py` from existing plugin interfaces | |
| 123 | ||
| 124 | ### Standard Plugins | |
| 125 | - `ollamatools/agent/modular/search.py` → `ollamatools/plugins/standard/search.py` | |
| 126 | - `ollamatools/agent/modular/commands.py` → `ollamatools/plugins/standard/commands.py` | |
| 127 | - `ollamatools/plugins/conversation_history.py` → `ollamatools/plugins/standard/conversation/history.py` | |
| 128 | - `ollamatools/plugins/conversation_context.py` → `ollamatools/plugins/standard/conversation/context.py` | |
| 129 | - `ollamatools/agent/modular/feedback.py` → `ollamatools/plugins/standard/feedback.py` | |
| 130 | - `ollamatools/agent/modular/issues.py` → `ollamatools/plugins/standard/issues.py` | |
| 131 | - Create new `ollamatools/plugins/standard/function_calling.py` | |
| 132 | ||
| 133 | ### Tool Plugins | |
| 134 | - `ollamatools/tools/system_tools.py` → `ollamatools/plugins/tools/system.py` | |
| 135 | - `ollamatools/tools/web_tools.py` → `ollamatools/plugins/tools/web.py` | |
| 136 | - `ollamatools/tools/doc_tools.py` → `ollamatools/plugins/tools/doc.py` | |
| 137 | ||
| 138 | ### Integration Plugins | |
| 139 | - `ollamatools/tools/matrix_tools.py` → `ollamatools/plugins/integrations/matrix/client.py` | |
| 140 | - `ollamatools/tools/enhanced_matrix_tools.py` → `ollamatools/plugins/integrations/matrix/commands.py` | |
| 141 | - `ollamatools/tools/enhanced_matrix_search.py` → `ollamatools/plugins/integrations/matrix/search.py` | |
| 142 | - `ollamatools/tools/enhanced_matrix_history.py` → `ollamatools/plugins/integrations/matrix/history.py` | |
| 143 | - `ollamatools/tools/matrix_rate_limit_patch.py` → `ollamatools/plugins/integrations/matrix/rate_limit.py` | |
| 144 | - `ollamatools/opensearch_web_tools.py` → `ollamatools/plugins/integrations/opensearch/tools.py` | |
| 145 | - Create new `ollamatools/plugins/integrations/matrix/config.py` | |
| 146 | - Create new `ollamatools/plugins/integrations/opensearch/client.py` | |
| 147 | ||
| 148 | ### Agent Implementations | |
| 149 | - `ollamatools/agent/core.py` → `ollamatools/agents/basic.py` | |
| 150 | - `ollamatools/agent/modular/agent.py` → `ollamatools/agents/modular.py` | |
| 151 | - `ollamatools/agent/extended/agent.py` → `ollamatools/agents/extended.py` | |
| 152 | ||
| 153 | ### Configuration System | |
| 154 | - `ollamatools/config/schemas.py` → `ollamatools/config/schemas.py` (same location) | |
| 155 | - `ollamatools/config/core_config.py` → `ollamatools/config/loader.py` | |
| 156 | - `ollamatools/config/plugin_config.py` → `ollamatools/config/defaults.py` | |
| 157 | ||
| 158 | ### CLI | |
| 159 | - Create new `ollamatools/cli/main.py` | |
| 160 | ||
| 161 | ## Benefits of This Approach | |
| 162 | ||
| 163 | 1. **Maintains file granularity**: Avoids creating files that are too large to manage | |
| 164 | 2. **Preserves existing functionality**: Each file maintains its original purpose | |
| 165 | 3. **Follows the target architecture**: Organizes code according to the simplified structure | |
| 166 | 4. **Easier to implement**: Simpler to move files than to merge and refactor them | |
| 167 | 5. **Reduced risk**: Less chance of introducing bugs during the refactoring process | |
| 168 | 6. **Easier to review**: Changes are more isolated and easier to understand | |
| 169 | ||
| 170 | ## Next Steps | |
| 171 | ||
| 172 | After understanding the simplified file structure and mapping strategy, proceed to the [Implementation Steps](./02_IMPLEMENTATION_STEPS.md) document to begin implementing the simplified structure. |
| … | … | @@ -0,0 +1,457 @@ |
| 1 | # Detailed Implementation Steps for the Simplified Structure | |
| 2 | ||
| 3 | This document provides a phased approach to implementing the simplified file structure for the OllamaTools project. By following these steps, you can refactor the codebase in a controlled manner, ensuring that each step is properly tested before moving on to the next. | |
| 4 | ||
| 5 | ## Phase 1: Create the Directory Structure | |
| 6 | ||
| 7 | 1. **Create all necessary directories**: | |
| 8 | ```bash | |
| 9 | # Core structure | |
| 10 | mkdir -p ollamatools-new/ollamatools/core/utils/validators | |
| 11 | mkdir -p ollamatools-new/ollamatools/plugins/standard/conversation | |
| 12 | mkdir -p ollamatools-new/ollamatools/plugins/tools | |
| 13 | mkdir -p ollamatools-new/ollamatools/plugins/integrations/matrix | |
| 14 | mkdir -p ollamatools-new/ollamatools/plugins/integrations/opensearch | |
| 15 | mkdir -p ollamatools-new/ollamatools/agents | |
| 16 | mkdir -p ollamatools-new/ollamatools/config | |
| 17 | mkdir -p ollamatools-new/ollamatools/cli | |
| 18 | ``` | |
| 19 | ||
| 20 | 2. **Create empty `__init__.py` files** in each directory to ensure proper Python package structure: | |
| 21 | ```bash | |
| 22 | find ollamatools-new -type d -exec touch {}/__init__.py \; | |
| 23 | ``` | |
| 24 | ||
| 25 | ## Phase 2: Copy Files to New Structure | |
| 26 | ||
| 27 | 1. **Create a file mapping document** that tracks the source and destination of each file: | |
| 28 | ``` | |
| 29 | # File Mapping Document (file_mapping.md) | |
| 30 | | Source File | Destination File | Status | | |
| 31 | |-------------|-----------------|--------| | |
| 32 | | ollamatools/agent.py | ollamatools-new/ollamatools/core/agent.py | Pending | | |
| 33 | | ollamatools/errors.py | ollamatools-new/ollamatools/core/errors.py | Pending | | |
| 34 | ... | |
| 35 | ``` | |
| 36 | ||
| 37 | 2. **Copy files** to their new locations without modifying content initially: | |
| 38 | ```bash | |
| 39 | # Core module | |
| 40 | cp ollamatools/agent.py ollamatools-new/ollamatools/core/agent.py | |
| 41 | cp ollamatools/errors.py ollamatools-new/ollamatools/core/errors.py | |
| 42 | cp ollamatools/config.py ollamatools-new/ollamatools/core/config.py | |
| 43 | cp ollamatools/security.py ollamatools-new/ollamatools/core/security.py | |
| 44 | cp ollamatools/logger.py ollamatools-new/ollamatools/core/utils/logger.py | |
| 45 | cp ollamatools/command_validator.py ollamatools-new/ollamatools/core/utils/validators/command.py | |
| 46 | cp ollamatools/path_validator.py ollamatools-new/ollamatools/core/utils/validators/path.py | |
| 47 | cp ollamatools/url_validator.py ollamatools-new/ollamatools/core/utils/validators/url.py | |
| 48 | ||
| 49 | # Plugin system | |
| 50 | cp ollamatools/plugins/registry.py ollamatools-new/ollamatools/plugins/registry.py | |
| 51 | cp ollamatools/plugins/errors.py ollamatools-new/ollamatools/plugins/errors.py | |
| 52 | ||
| 53 | # Standard plugins | |
| 54 | cp ollamatools/agent/modular/search.py ollamatools-new/ollamatools/plugins/standard/search.py | |
| 55 | cp ollamatools/agent/modular/commands.py ollamatools-new/ollamatools/plugins/standard/commands.py | |
| 56 | cp ollamatools/plugins/conversation_history.py ollamatools-new/ollamatools/plugins/standard/conversation/history.py | |
| 57 | cp ollamatools/plugins/conversation_context.py ollamatools-new/ollamatools/plugins/standard/conversation/context.py | |
| 58 | cp ollamatools/agent/modular/feedback.py ollamatools-new/ollamatools/plugins/standard/feedback.py | |
| 59 | cp ollamatools/agent/modular/issues.py ollamatools-new/ollamatools/plugins/standard/issues.py | |
| 60 | ||
| 61 | # Tool plugins | |
| 62 | cp ollamatools/tools/system_tools.py ollamatools-new/ollamatools/plugins/tools/system.py | |
| 63 | cp ollamatools/tools/web_tools.py ollamatools-new/ollamatools/plugins/tools/web.py | |
| 64 | cp ollamatools/tools/doc_tools.py ollamatools-new/ollamatools/plugins/tools/doc.py | |
| 65 | ||
| 66 | # Integration plugins | |
| 67 | cp ollamatools/tools/matrix_tools.py ollamatools-new/ollamatools/plugins/integrations/matrix/client.py | |
| 68 | cp ollamatools/tools/enhanced_matrix_tools.py ollamatools-new/ollamatools/plugins/integrations/matrix/commands.py | |
| 69 | cp ollamatools/tools/enhanced_matrix_search.py ollamatools-new/ollamatools/plugins/integrations/matrix/search.py | |
| 70 | cp ollamatools/tools/enhanced_matrix_history.py ollamatools-new/ollamatools/plugins/integrations/matrix/history.py | |
| 71 | cp ollamatools/tools/matrix_rate_limit_patch.py ollamatools-new/ollamatools/plugins/integrations/matrix/rate_limit.py | |
| 72 | cp ollamatools/opensearch_web_tools.py ollamatools-new/ollamatools/plugins/integrations/opensearch/tools.py | |
| 73 | ||
| 74 | # Agent implementations | |
| 75 | cp ollamatools/agent/core.py ollamatools-new/ollamatools/agents/basic.py | |
| 76 | cp ollamatools/agent/modular/agent.py ollamatools-new/ollamatools/agents/modular.py | |
| 77 | cp ollamatools/agent/extended/agent.py ollamatools-new/ollamatools/agents/extended.py | |
| 78 | ||
| 79 | # Configuration system | |
| 80 | cp ollamatools/config/schemas.py ollamatools-new/ollamatools/config/schemas.py | |
| 81 | cp ollamatools/config/core_config.py ollamatools-new/ollamatools/config/loader.py | |
| 82 | cp ollamatools/config/plugin_config.py ollamatools-new/ollamatools/config/defaults.py | |
| 83 | ``` | |
| 84 | ||
| 85 | 3. **Create new files** that don't exist in the current structure: | |
| 86 | ```bash | |
| 87 | # Create new files with placeholder content | |
| 88 | touch ollamatools-new/ollamatools/plugins/base.py | |
| 89 | touch ollamatools-new/ollamatools/plugins/standard/function_calling.py | |
| 90 | touch ollamatools-new/ollamatools/plugins/integrations/matrix/config.py | |
| 91 | touch ollamatools-new/ollamatools/plugins/integrations/opensearch/client.py | |
| 92 | touch ollamatools-new/ollamatools/core/utils/formatting.py | |
| 93 | touch ollamatools-new/ollamatools/plugins/standard/conversation/analysis.py | |
| 94 | touch ollamatools-new/ollamatools/cli/main.py | |
| 95 | touch ollamatools-new/ollamatools/version.py | |
| 96 | ``` | |
| 97 | ||
| 98 | ## Phase 3: Update Imports and References | |
| 99 | ||
| 100 | 1. **Create a script to update imports** in each file: | |
| 101 | ```python | |
| 102 | # update_imports.py | |
| 103 | import os | |
| 104 | import re | |
| 105 | ||
| 106 | def update_imports(file_path): | |
| 107 | with open(file_path, 'r') as f: | |
| 108 | content = f.read() | |
| 109 | ||
| 110 | # Update import patterns | |
| 111 | # from ollamatools.agent import X -> from ollamatools.core.agent import X | |
| 112 | content = re.sub(r'from ollamatools\.agent import', 'from ollamatools.core.agent import', content) | |
| 113 | # ... add more patterns based on the file mapping | |
| 114 | ||
| 115 | with open(file_path, 'w') as f: | |
| 116 | f.write(content) | |
| 117 | ||
| 118 | # Process all Python files in the new structure | |
| 119 | for root, dirs, files in os.walk('ollamatools-new'): | |
| 120 | for file in files: | |
| 121 | if file.endswith('.py'): | |
| 122 | update_imports(os.path.join(root, file)) | |
| 123 | ``` | |
| 124 | ||
| 125 | 2. **Manually review and fix imports** in each file: | |
| 126 | - Update relative imports to absolute imports | |
| 127 | - Fix circular dependencies | |
| 128 | - Ensure all imports reference the new file locations | |
| 129 | ||
| 130 | 3. **Update class and function references** to match the new structure: | |
| 131 | - Update any hardcoded paths or module references | |
| 132 | - Fix any references to module-level variables | |
| 133 | ||
| 134 | ## Phase 4: Implement New Files | |
| 135 | ||
| 136 | 1. **Implement `plugins/base.py`** with base plugin interfaces: | |
| 137 | ```python | |
| 138 | # ollamatools-new/ollamatools/plugins/base.py | |
| 139 | """Base plugin interfaces for the OllamaTools plugin system.""" | |
| 140 | ||
| 141 | from abc import ABC, abstractmethod | |
| 142 | from typing import Any, Dict, List, Optional | |
| 143 | ||
| 144 | class Plugin(ABC): | |
| 145 | """Base class for all plugins.""" | |
| 146 | ||
| 147 | @property | |
| 148 | @abstractmethod | |
| 149 | def name(self) -> str: | |
| 150 | """Return the name of the plugin.""" | |
| 151 | pass | |
| 152 | ||
| 153 | @property | |
| 154 | @abstractmethod | |
| 155 | def version(self) -> str: | |
| 156 | """Return the version of the plugin.""" | |
| 157 | pass | |
| 158 | ||
| 159 | @abstractmethod | |
| 160 | def initialize(self, config: Dict[str, Any]) -> None: | |
| 161 | """Initialize the plugin with the given configuration.""" | |
| 162 | pass | |
| 163 | ||
| 164 | @abstractmethod | |
| 165 | def shutdown(self) -> None: | |
| 166 | """Shutdown the plugin and release any resources.""" | |
| 167 | pass | |
| 168 | ||
| 169 | # Add more base classes for specific plugin types | |
| 170 | ``` | |
| 171 | ||
| 172 | 2. **Implement `plugins/standard/function_calling.py`** for semantic function calling: | |
| 173 | ```python | |
| 174 | # ollamatools-new/ollamatools/plugins/standard/function_calling.py | |
| 175 | """Plugin for semantic function calling.""" | |
| 176 | ||
| 177 | from typing import Any, Dict, List, Optional | |
| 178 | ||
| 179 | from ollamatools.plugins.base import Plugin | |
| 180 | ||
| 181 | class FunctionCallingPlugin(Plugin): | |
| 182 | """Plugin for semantic function calling.""" | |
| 183 | ||
| 184 | @property | |
| 185 | def name(self) -> str: | |
| 186 | return "function_calling" | |
| 187 | ||
| 188 | @property | |
| 189 | def version(self) -> str: | |
| 190 | return "0.1.0" | |
| 191 | ||
| 192 | def initialize(self, config: Dict[str, Any]) -> None: | |
| 193 | """Initialize the plugin with the given configuration.""" | |
| 194 | self.config = config | |
| 195 | ||
| 196 | def shutdown(self) -> None: | |
| 197 | """Shutdown the plugin and release any resources.""" | |
| 198 | pass | |
| 199 | ||
| 200 | # Add function calling implementation | |
| 201 | ``` | |
| 202 | ||
| 203 | 3. **Implement `plugins/integrations/matrix/config.py`** for Matrix configuration: | |
| 204 | ```python | |
| 205 | # ollamatools-new/ollamatools/plugins/integrations/matrix/config.py | |
| 206 | """Configuration for Matrix integration.""" | |
| 207 | ||
| 208 | from typing import Any, Dict, Optional | |
| 209 | ||
| 210 | def load_matrix_config(config_path: Optional[str] = None) -> Dict[str, Any]: | |
| 211 | """Load Matrix configuration from the given path.""" | |
| 212 | # Implementation | |
| 213 | return {} | |
| 214 | ||
| 215 | def validate_matrix_config(config: Dict[str, Any]) -> bool: | |
| 216 | """Validate Matrix configuration.""" | |
| 217 | # Implementation | |
| 218 | return True | |
| 219 | ``` | |
| 220 | ||
| 221 | 4. **Implement other new files** with appropriate content based on their purpose. | |
| 222 | ||
| 223 | ## Phase 5: Update Package Initialization | |
| 224 | ||
| 225 | 1. **Update `__init__.py` files** to expose the appropriate classes and functions: | |
| 226 | ```python | |
| 227 | # ollamatools-new/ollamatools/__init__.py | |
| 228 | """OllamaTools package.""" | |
| 229 | ||
| 230 | from ollamatools.version import __version__ | |
| 231 | ||
| 232 | # Expose core components | |
| 233 | from ollamatools.core.agent import Agent | |
| 234 | from ollamatools.core.config import Config | |
| 235 | ||
| 236 | # Expose agent implementations | |
| 237 | from ollamatools.agents.basic import BasicAgent | |
| 238 | from ollamatools.agents.modular import ModularAgent | |
| 239 | from ollamatools.agents.extended import ExtendedAgent | |
| 240 | ||
| 241 | # Expose plugin system | |
| 242 | from ollamatools.plugins.base import Plugin | |
| 243 | from ollamatools.plugins.registry import PluginRegistry | |
| 244 | ``` | |
| 245 | ||
| 246 | 2. **Create a version file** with version information: | |
| 247 | ```python | |
| 248 | # ollamatools-new/ollamatools/version.py | |
| 249 | """Version information for OllamaTools.""" | |
| 250 | ||
| 251 | __version__ = "0.1.0" | |
| 252 | ``` | |
| 253 | ||
| 254 | ## Phase 6: Test the Refactored Code | |
| 255 | ||
| 256 | 1. **Create a test script** to verify the refactored code: | |
| 257 | ```python | |
| 258 | # test_refactored_code.py | |
| 259 | """Test the refactored OllamaTools code.""" | |
| 260 | ||
| 261 | import sys | |
| 262 | sys.path.insert(0, 'ollamatools-new') | |
| 263 | ||
| 264 | # Import and test core components | |
| 265 | from ollamatools.core.agent import Agent | |
| 266 | print(f"Successfully imported Agent from core") | |
| 267 | ||
| 268 | # Import and test plugin system | |
| 269 | from ollamatools.plugins.registry import PluginRegistry | |
| 270 | print(f"Successfully imported PluginRegistry") | |
| 271 | ||
| 272 | # Import and test agent implementations | |
| 273 | from ollamatools.agents.basic import BasicAgent | |
| 274 | print(f"Successfully imported BasicAgent") | |
| 275 | ||
| 276 | # Add more tests for other components | |
| 277 | ``` | |
| 278 | ||
| 279 | 2. **Run existing tests** against the refactored code: | |
| 280 | ```bash | |
| 281 | # Run tests with the refactored code | |
| 282 | PYTHONPATH=ollamatools-new pytest tests/ | |
| 283 | ``` | |
| 284 | ||
| 285 | 3. **Fix any issues** discovered during testing: | |
| 286 | - Update imports that were missed | |
| 287 | - Fix any broken functionality | |
| 288 | - Address any compatibility issues | |
| 289 | ||
| 290 | ## Phase 7: Documentation and Migration Guide | |
| 291 | ||
| 292 | 1. **Update documentation** to reflect the new structure: | |
| 293 | - Update README.md with the new structure | |
| 294 | - Create a migration guide for users | |
| 295 | - Document the new plugin system | |
| 296 | ||
| 297 | 2. **Create a migration guide** for users: | |
| 298 | ```markdown | |
| 299 | # Migration Guide | |
| 300 | ||
| 301 | This guide helps you migrate from the old OllamaTools structure to the new simplified structure. | |
| 302 | ||
| 303 | ## Import Changes | |
| 304 | ||
| 305 | Old imports: | |
| 306 | ```python | |
| 307 | from ollamatools.agent import Agent | |
| 308 | ``` | |
| 309 | ||
| 310 | New imports: | |
| 311 | ```python | |
| 312 | from ollamatools.core.agent import Agent | |
| 313 | ``` | |
| 314 | ||
| 315 | ## Plugin System Changes | |
| 316 | ||
| 317 | Old plugin usage: | |
| 318 | ```python | |
| 319 | # Old code | |
| 320 | ``` | |
| 321 | ||
| 322 | New plugin usage: | |
| 323 | ```python | |
| 324 | # New code | |
| 325 | ``` | |
| 326 | ``` | |
| 327 | ||
| 328 | ## Phase 8: Final Steps | |
| 329 | ||
| 330 | 1. **Create a setup.py file** for the new package: | |
| 331 | ```python | |
| 332 | # ollamatools-new/setup.py | |
| 333 | from setuptools import setup, find_packages | |
| 334 | ||
| 335 | setup( | |
| 336 | name="ollamatools", | |
| 337 | version="0.1.0", | |
| 338 | packages=find_packages(), | |
| 339 | install_requires=[ | |
| 340 | # List dependencies | |
| 341 | ], | |
| 342 | author="Your Name", | |
| 343 | author_email="your.email@example.com", | |
| 344 | description="OllamaTools - A toolkit for working with Ollama", | |
| 345 | keywords="ollama, ai, tools", | |
| 346 | url="https://github.com/yourusername/ollamatools", | |
| 347 | ) | |
| 348 | ``` | |
| 349 | ||
| 350 | 2. **Create a deployment script** to install the new package: | |
| 351 | ```bash | |
| 352 | # deploy.sh | |
| 353 | #!/bin/bash | |
| 354 | ||
| 355 | # Build and install the new package | |
| 356 | cd ollamatools-new | |
| 357 | pip install -e . | |
| 358 | ``` | |
| 359 | ||
| 360 | 3. **Final verification**: | |
| 361 | - Run all tests | |
| 362 | - Verify all examples work | |
| 363 | - Check documentation | |
| 364 | ||
| 365 | ## Implementation Timeline | |
| 366 | ||
| 367 | This implementation can be broken down into manageable chunks: | |
| 368 | ||
| 369 | 1. **Week 1**: Phases 1-2 (Create directory structure, copy files) | |
| 370 | 2. **Week 2**: Phase 3 (Update imports and references) | |
| 371 | 3. **Week 3**: Phase 4 (Implement new files) | |
| 372 | 4. **Week 4**: Phases 5-6 (Update package initialization, test code) | |
| 373 | 5. **Week 5**: Phases 7-8 (Documentation, migration guide, final steps) | |
| 374 | ||
| 375 | By following this phased approach, we can implement the simplified structure in a controlled manner, ensuring that each step is properly tested before moving on to the next. | |
| 376 | ||
| 377 | ## Automation Scripts | |
| 378 | ||
| 379 | To facilitate the implementation, we can create several automation scripts: | |
| 380 | ||
| 381 | 1. **Directory Structure Creation Script**: | |
| 382 | ```bash | |
| 383 | #!/bin/bash | |
| 384 | # create_directory_structure.sh | |
| 385 | ||
| 386 | # Create the directory structure | |
| 387 | mkdir -p ollamatools-new/ollamatools/core/utils/validators | |
| 388 | mkdir -p ollamatools-new/ollamatools/plugins/standard/conversation | |
| 389 | mkdir -p ollamatools-new/ollamatools/plugins/tools | |
| 390 | mkdir -p ollamatools-new/ollamatools/plugins/integrations/matrix | |
| 391 | mkdir -p ollamatools-new/ollamatools/plugins/integrations/opensearch | |
| 392 | mkdir -p ollamatools-new/ollamatools/agents | |
| 393 | mkdir -p ollamatools-new/ollamatools/config | |
| 394 | mkdir -p ollamatools-new/ollamatools/cli | |
| 395 | ||
| 396 | # Create __init__.py files | |
| 397 | find ollamatools-new -type d -exec touch {}/__init__.py \; | |
| 398 | ||
| 399 | echo "Directory structure created successfully." | |
| 400 | ``` | |
| 401 | ||
| 402 | 2. **File Copy Script**: | |
| 403 | ```bash | |
| 404 | #!/bin/bash | |
| 405 | # copy_files.sh | |
| 406 | ||
| 407 | # Copy files to their new locations | |
| 408 | # Core module | |
| 409 | cp ollamatools/agent.py ollamatools-new/ollamatools/core/agent.py | |
| 410 | cp ollamatools/errors.py ollamatools-new/ollamatools/core/errors.py | |
| 411 | # ... add more copy commands | |
| 412 | ||
| 413 | echo "Files copied successfully." | |
| 414 | ``` | |
| 415 | ||
| 416 | 3. **Import Update Script**: | |
| 417 | ```python | |
| 418 | # update_imports.py | |
| 419 | ||
| 420 | import os | |
| 421 | import re | |
| 422 | ||
| 423 | def update_imports(file_path): | |
| 424 | with open(file_path, 'r') as f: | |
| 425 | content = f.read() | |
| 426 | ||
| 427 | # Update import patterns | |
| 428 | # ... add patterns | |
| 429 | ||
| 430 | with open(file_path, 'w') as f: | |
| 431 | f.write(content) | |
| 432 | ||
| 433 | # Process all Python files in the new structure | |
| 434 | for root, dirs, files in os.walk('ollamatools-new'): | |
| 435 | for file in files: | |
| 436 | if file.endswith('.py'): | |
| 437 | update_imports(os.path.join(root, file)) | |
| 438 | ||
| 439 | print("Imports updated successfully.") | |
| 440 | ``` | |
| 441 | ||
| 442 | 4. **Test Script**: | |
| 443 | ```bash | |
| 444 | #!/bin/bash | |
| 445 | # test_refactored_code.sh | |
| 446 | ||
| 447 | # Run tests with the refactored code | |
| 448 | PYTHONPATH=ollamatools-new pytest tests/ | |
| 449 | ||
| 450 | echo "Tests completed." | |
| 451 | ``` | |
| 452 | ||
| 453 | These scripts can be used to automate the implementation process and ensure consistency. | |
| 454 | ||
| 455 | ## Next Steps | |
| 456 | ||
| 457 | After implementing the simplified structure, proceed to the [File Mapping](./03_FILE_MAPPING.md) document for a complete reference of the file mapping. |
| … | … | @@ -0,0 +1,112 @@ |
| 1 | # Complete File Mapping for OllamaTools Refactoring | |
| 2 | ||
| 3 | This document provides a complete reference of the file mapping for the OllamaTools refactoring project. Use this table to track the status of each file during the implementation process. | |
| 4 | ||
| 5 | ## File Mapping Table | |
| 6 | ||
| 7 | | Source File | Destination File | Status | Notes | | |
| 8 | |-------------|-----------------|--------|-------| | |
| 9 | | **Core Module** | | | | | |
| 10 | | `ollamatools/agent.py` | `ollamatools/core/agent.py` | Pending | Base agent implementation | | |
| 11 | | `ollamatools/errors.py` | `ollamatools/core/errors.py` | Pending | Error definitions and handling | | |
| 12 | | `ollamatools/config.py` | `ollamatools/core/config.py` | Pending | Configuration management | | |
| 13 | | `ollamatools/security.py` | `ollamatools/core/security.py` | Pending | Security utilities | | |
| 14 | | `ollamatools/logger.py` | `ollamatools/core/utils/logger.py` | Pending | Logging utilities | | |
| 15 | | `ollamatools/command_validator.py` | `ollamatools/core/utils/validators/command.py` | Pending | Command validation | | |
| 16 | | `ollamatools/path_validator.py` | `ollamatools/core/utils/validators/path.py` | Pending | Path validation | | |
| 17 | | `ollamatools/url_validator.py` | `ollamatools/core/utils/validators/url.py` | Pending | URL validation | | |
| 18 | | N/A | `ollamatools/core/utils/formatting.py` | Pending | New file for text formatting utilities | | |
| 19 | | **Plugin System** | | | | | |
| 20 | | `ollamatools/plugins/registry.py` | `ollamatools/plugins/registry.py` | Pending | Plugin discovery and management | | |
| 21 | | `ollamatools/plugins/errors.py` | `ollamatools/plugins/errors.py` | Pending | Plugin-specific error handling | | |
| 22 | | N/A | `ollamatools/plugins/base.py` | Pending | New file for base plugin interfaces | | |
| 23 | | **Standard Plugins** | | | | | |
| 24 | | `ollamatools/agent/modular/search.py` | `ollamatools/plugins/standard/search.py` | Pending | Search functionality | | |
| 25 | | `ollamatools/agent/modular/commands.py` | `ollamatools/plugins/standard/commands.py` | Pending | Command management | | |
| 26 | | `ollamatools/plugins/conversation_history.py` | `ollamatools/plugins/standard/conversation/history.py` | Pending | Conversation history tracking | | |
| 27 | | `ollamatools/plugins/conversation_context.py` | `ollamatools/plugins/standard/conversation/context.py` | Pending | Conversation context management | | |
| 28 | | N/A | `ollamatools/plugins/standard/conversation/analysis.py` | Pending | New file for topic analysis | | |
| 29 | | `ollamatools/agent/modular/feedback.py` | `ollamatools/plugins/standard/feedback.py` | Pending | Feedback collection | | |
| 30 | | `ollamatools/agent/modular/issues.py` | `ollamatools/plugins/standard/issues.py` | Pending | Issue tracking | | |
| 31 | | N/A | `ollamatools/plugins/standard/function_calling.py` | Pending | New file for semantic function calling | | |
| 32 | | **Tool Plugins** | | | | | |
| 33 | | `ollamatools/tools/system_tools.py` | `ollamatools/plugins/tools/system.py` | Pending | System tools | | |
| 34 | | `ollamatools/tools/web_tools.py` | `ollamatools/plugins/tools/web.py` | Pending | Web tools | | |
| 35 | | `ollamatools/tools/doc_tools.py` | `ollamatools/plugins/tools/doc.py` | Pending | Documentation tools | | |
| 36 | | **Matrix Integration** | | | | | |
| 37 | | `ollamatools/tools/matrix_tools.py` | `ollamatools/plugins/integrations/matrix/client.py` | Pending | Matrix client core | | |
| 38 | | `ollamatools/tools/enhanced_matrix_tools.py` | `ollamatools/plugins/integrations/matrix/commands.py` | Pending | Matrix-specific commands | | |
| 39 | | `ollamatools/tools/enhanced_matrix_search.py` | `ollamatools/plugins/integrations/matrix/search.py` | Pending | Matrix search integration | | |
| 40 | | `ollamatools/tools/enhanced_matrix_history.py` | `ollamatools/plugins/integrations/matrix/history.py` | Pending | Matrix history tracking | | |
| 41 | | `ollamatools/tools/matrix_rate_limit_patch.py` | `ollamatools/plugins/integrations/matrix/rate_limit.py` | Pending | Rate limiting for Matrix | | |
| 42 | | N/A | `ollamatools/plugins/integrations/matrix/config.py` | Pending | New file for Matrix configuration | | |
| 43 | | **OpenSearch Integration** | | | | | |
| 44 | | `ollamatools/opensearch_web_tools.py` | `ollamatools/plugins/integrations/opensearch/tools.py` | Pending | OpenSearch web tools | | |
| 45 | | N/A | `ollamatools/plugins/integrations/opensearch/client.py` | Pending | New file for OpenSearch client | | |
| 46 | | **Agent Implementations** | | | | | |
| 47 | | `ollamatools/agent/core.py` | `ollamatools/agents/basic.py` | Pending | Basic agent implementation | | |
| 48 | | `ollamatools/agent/modular/agent.py` | `ollamatools/agents/modular.py` | Pending | Modular agent implementation | | |
| 49 | | `ollamatools/agent/extended/agent.py` | `ollamatools/agents/extended.py` | Pending | Extended agent implementation | | |
| 50 | | **Configuration System** | | | | | |
| 51 | | `ollamatools/config/schemas.py` | `ollamatools/config/schemas.py` | Pending | Configuration schemas | | |
| 52 | | `ollamatools/config/core_config.py` | `ollamatools/config/loader.py` | Pending | Configuration loading/validation | | |
| 53 | | `ollamatools/config/plugin_config.py` | `ollamatools/config/defaults.py` | Pending | Default configurations | | |
| 54 | | **Command-Line Interface** | | | | | |
| 55 | | N/A | `ollamatools/cli/main.py` | Pending | New file for command-line interface | | |
| 56 | | **Package Root** | | | | | |
| 57 | | `ollamatools/__init__.py` | `ollamatools/__init__.py` | Pending | Package initialization | | |
| 58 | | N/A | `ollamatools/version.py` | Pending | New file for version information | | |
| 59 | ||
| 60 | ## Status Definitions | |
| 61 | ||
| 62 | - **Pending**: File has not been copied or created yet | |
| 63 | - **Copied**: File has been copied to the new location but imports have not been updated | |
| 64 | - **Updated**: File has been copied and imports have been updated | |
| 65 | - **Tested**: File has been tested and is working correctly | |
| 66 | - **Completed**: File has been finalized and is ready for release | |
| 67 | ||
| 68 | ## Implementation Notes | |
| 69 | ||
| 70 | ### Large Files (>500 lines) | |
| 71 | ||
| 72 | Special attention should be given to these large files during the refactoring process: | |
| 73 | ||
| 74 | - `ollamatools/tools/matrix_tools.py` (800 lines) | |
| 75 | - `ollamatools/agent/modular/agent.py` (702 lines) | |
| 76 | - `ollamatools/agent/modular/feedback.py` (586 lines) | |
| 77 | - `ollamatools/tools/web_tools.py` (484 lines) | |
| 78 | - `ollamatools/tools/enhanced_matrix_core.py` (466 lines) | |
| 79 | - `ollamatools/agent.py` (455 lines) | |
| 80 | ||
| 81 | These files should be moved as-is without attempting to merge them with other files, as they are already quite large. | |
| 82 | ||
| 83 | ### New Files | |
| 84 | ||
| 85 | The following new files need to be created from scratch: | |
| 86 | ||
| 87 | - `ollamatools/core/utils/formatting.py` | |
| 88 | - `ollamatools/plugins/base.py` | |
| 89 | - `ollamatools/plugins/standard/conversation/analysis.py` | |
| 90 | - `ollamatools/plugins/standard/function_calling.py` | |
| 91 | - `ollamatools/plugins/integrations/matrix/config.py` | |
| 92 | - `ollamatools/plugins/integrations/opensearch/client.py` | |
| 93 | - `ollamatools/cli/main.py` | |
| 94 | - `ollamatools/version.py` | |
| 95 | ||
| 96 | ### Files to Keep in Same Location | |
| 97 | ||
| 98 | The following files will remain in the same location, but may need import updates: | |
| 99 | ||
| 100 | - `ollamatools/plugins/registry.py` | |
| 101 | - `ollamatools/plugins/errors.py` | |
| 102 | - `ollamatools/config/schemas.py` | |
| 103 | ||
| 104 | ## Tracking Progress | |
| 105 | ||
| 106 | Use this document to track the progress of the refactoring by updating the status of each file as you work through the implementation steps. This will help ensure that no files are missed and that the refactoring is completed systematically. | |
| 107 | ||
| 108 | To update the status of a file, simply change the "Pending" status to the appropriate status (Copied, Updated, Tested, or Completed) as you progress through the implementation. | |
| 109 | ||
| 110 | ## Next Steps | |
| 111 | ||
| 112 | After reviewing this file mapping, proceed to implement the refactoring according to the steps outlined in the [Implementation Steps](./02_IMPLEMENTATION_STEPS.md) document. |
| … | … | @@ -0,0 +1,363 @@ |
| 1 | # Migration Guide for OllamaTools Refactoring | |
| 2 | ||
| 3 | This guide helps you migrate your code from the old OllamaTools structure to the new simplified structure. It provides examples of how to update imports and adapt your code to work with the refactored codebase. | |
| 4 | ||
| 5 | ## Import Changes | |
| 6 | ||
| 7 | The most significant changes in the refactoring are the import paths. Here's how to update your imports: | |
| 8 | ||
| 9 | ### Core Module | |
| 10 | ||
| 11 | **Old imports:** | |
| 12 | ```python | |
| 13 | from ollamatools.agent import Agent | |
| 14 | from ollamatools import agent | |
| 15 | import ollamatools.agent | |
| 16 | ``` | |
| 17 | ||
| 18 | **New imports:** | |
| 19 | ```python | |
| 20 | from ollamatools.core.agent import Agent | |
| 21 | from ollamatools.core import agent | |
| 22 | import ollamatools.core.agent | |
| 23 | ``` | |
| 24 | ||
| 25 | ### Agent Implementations | |
| 26 | ||
| 27 | **Old imports:** | |
| 28 | ```python | |
| 29 | from ollamatools.agent.core import BasicAgent | |
| 30 | from ollamatools.agent.modular.agent import ModularAgent | |
| 31 | from ollamatools.agent.extended.agent import ExtendedAgent | |
| 32 | ``` | |
| 33 | ||
| 34 | **New imports:** | |
| 35 | ```python | |
| 36 | from ollamatools.agents.basic import BasicAgent | |
| 37 | from ollamatools.agents.modular import ModularAgent | |
| 38 | from ollamatools.agents.extended import ExtendedAgent | |
| 39 | ``` | |
| 40 | ||
| 41 | ### Standard Plugins | |
| 42 | ||
| 43 | **Old imports:** | |
| 44 | ```python | |
| 45 | from ollamatools.agent.modular.search import search_function | |
| 46 | from ollamatools.agent.modular.commands import execute_command | |
| 47 | from ollamatools.plugins.conversation_history import ConversationHistory | |
| 48 | from ollamatools.plugins.conversation_context import ConversationContext | |
| 49 | from ollamatools.agent.modular.feedback import collect_feedback | |
| 50 | from ollamatools.agent.modular.issues import track_issue | |
| 51 | ``` | |
| 52 | ||
| 53 | **New imports:** | |
| 54 | ```python | |
| 55 | from ollamatools.plugins.standard.search import search_function | |
| 56 | from ollamatools.plugins.standard.commands import execute_command | |
| 57 | from ollamatools.plugins.standard.conversation.history import ConversationHistory | |
| 58 | from ollamatools.plugins.standard.conversation.context import ConversationContext | |
| 59 | from ollamatools.plugins.standard.feedback import collect_feedback | |
| 60 | from ollamatools.plugins.standard.issues import track_issue | |
| 61 | ``` | |
| 62 | ||
| 63 | ### Tool Plugins | |
| 64 | ||
| 65 | **Old imports:** | |
| 66 | ```python | |
| 67 | from ollamatools.tools.system_tools import execute_system_command | |
| 68 | from ollamatools.tools.web_tools import make_web_request | |
| 69 | from ollamatools.tools.doc_tools import generate_documentation | |
| 70 | ``` | |
| 71 | ||
| 72 | **New imports:** | |
| 73 | ```python | |
| 74 | from ollamatools.plugins.tools.system import execute_system_command | |
| 75 | from ollamatools.plugins.tools.web import make_web_request | |
| 76 | from ollamatools.plugins.tools.doc import generate_documentation | |
| 77 | ``` | |
| 78 | ||
| 79 | ### Matrix Integration | |
| 80 | ||
| 81 | **Old imports:** | |
| 82 | ```python | |
| 83 | from ollamatools.tools.matrix_tools import MatrixClient | |
| 84 | from ollamatools.tools.enhanced_matrix_tools import EnhancedMatrixClient | |
| 85 | from ollamatools.tools.enhanced_matrix_search import MatrixSearch | |
| 86 | from ollamatools.tools.enhanced_matrix_history import MatrixHistory | |
| 87 | from ollamatools.tools.matrix_rate_limit_patch import apply_rate_limit_patch | |
| 88 | ``` | |
| 89 | ||
| 90 | **New imports:** | |
| 91 | ```python | |
| 92 | from ollamatools.plugins.integrations.matrix.client import MatrixClient | |
| 93 | from ollamatools.plugins.integrations.matrix.commands import EnhancedMatrixClient | |
| 94 | from ollamatools.plugins.integrations.matrix.search import MatrixSearch | |
| 95 | from ollamatools.plugins.integrations.matrix.history import MatrixHistory | |
| 96 | from ollamatools.plugins.integrations.matrix.rate_limit import apply_rate_limit_patch | |
| 97 | ``` | |
| 98 | ||
| 99 | ### OpenSearch Integration | |
| 100 | ||
| 101 | **Old imports:** | |
| 102 | ```python | |
| 103 | from ollamatools.opensearch_web_tools import OpenSearchWebTools | |
| 104 | ``` | |
| 105 | ||
| 106 | **New imports:** | |
| 107 | ```python | |
| 108 | from ollamatools.plugins.integrations.opensearch.tools import OpenSearchWebTools | |
| 109 | ``` | |
| 110 | ||
| 111 | ### Configuration System | |
| 112 | ||
| 113 | **Old imports:** | |
| 114 | ```python | |
| 115 | from ollamatools.config.core_config import load_config | |
| 116 | from ollamatools.config.plugin_config import get_plugin_config | |
| 117 | ``` | |
| 118 | ||
| 119 | **New imports:** | |
| 120 | ```python | |
| 121 | from ollamatools.config.loader import load_config | |
| 122 | from ollamatools.config.defaults import get_plugin_config | |
| 123 | ``` | |
| 124 | ||
| 125 | ## Creating Agents | |
| 126 | ||
| 127 | ### Basic Agent | |
| 128 | ||
| 129 | **Old code:** | |
| 130 | ```python | |
| 131 | from ollamatools.agent.core import BasicAgent | |
| 132 | ||
| 133 | agent = BasicAgent(model="llama2") | |
| 134 | response = agent.chat("Hello, world!") | |
| 135 | ``` | |
| 136 | ||
| 137 | **New code:** | |
| 138 | ```python | |
| 139 | from ollamatools.agents.basic import BasicAgent | |
| 140 | ||
| 141 | agent = BasicAgent(model="llama2") | |
| 142 | response = agent.chat("Hello, world!") | |
| 143 | ``` | |
| 144 | ||
| 145 | ### Modular Agent | |
| 146 | ||
| 147 | **Old code:** | |
| 148 | ```python | |
| 149 | from ollamatools.agent.modular.agent import ModularAgent | |
| 150 | from ollamatools.agent.modular.search import SearchModule | |
| 151 | from ollamatools.agent.modular.commands import CommandsModule | |
| 152 | ||
| 153 | agent = ModularAgent(model="llama2") | |
| 154 | agent.add_module(SearchModule()) | |
| 155 | agent.add_module(CommandsModule()) | |
| 156 | response = agent.chat("Search for information about Python") | |
| 157 | ``` | |
| 158 | ||
| 159 | **New code:** | |
| 160 | ```python | |
| 161 | from ollamatools.agents.modular import ModularAgent | |
| 162 | from ollamatools.plugins.standard.search import SearchPlugin | |
| 163 | from ollamatools.plugins.standard.commands import CommandsPlugin | |
| 164 | ||
| 165 | agent = ModularAgent(model="llama2") | |
| 166 | agent.add_plugin(SearchPlugin()) | |
| 167 | agent.add_plugin(CommandsPlugin()) | |
| 168 | response = agent.chat("Search for information about Python") | |
| 169 | ``` | |
| 170 | ||
| 171 | ### Extended Agent | |
| 172 | ||
| 173 | **Old code:** | |
| 174 | ```python | |
| 175 | from ollamatools.agent.extended.agent import ExtendedAgent | |
| 176 | ||
| 177 | agent = ExtendedAgent(model="llama2") | |
| 178 | response = agent.chat("Remember this information for later") | |
| 179 | ``` | |
| 180 | ||
| 181 | **New code:** | |
| 182 | ```python | |
| 183 | from ollamatools.agents.extended import ExtendedAgent | |
| 184 | ||
| 185 | agent = ExtendedAgent(model="llama2") | |
| 186 | response = agent.chat("Remember this information for later") | |
| 187 | ``` | |
| 188 | ||
| 189 | ## Using Plugins | |
| 190 | ||
| 191 | ### Search Plugin | |
| 192 | ||
| 193 | **Old code:** | |
| 194 | ```python | |
| 195 | from ollamatools.agent.modular.search import search_web | |
| 196 | ||
| 197 | results = search_web("Python programming") | |
| 198 | ``` | |
| 199 | ||
| 200 | **New code:** | |
| 201 | ```python | |
| 202 | from ollamatools.plugins.standard.search import search_web | |
| 203 | ||
| 204 | results = search_web("Python programming") | |
| 205 | ``` | |
| 206 | ||
| 207 | ### Commands Plugin | |
| 208 | ||
| 209 | **Old code:** | |
| 210 | ```python | |
| 211 | from ollamatools.agent.modular.commands import execute_command | |
| 212 | ||
| 213 | result = execute_command("ls -la") | |
| 214 | ``` | |
| 215 | ||
| 216 | **New code:** | |
| 217 | ```python | |
| 218 | from ollamatools.plugins.standard.commands import execute_command | |
| 219 | ||
| 220 | result = execute_command("ls -la") | |
| 221 | ``` | |
| 222 | ||
| 223 | ### Conversation History Plugin | |
| 224 | ||
| 225 | **Old code:** | |
| 226 | ```python | |
| 227 | from ollamatools.plugins.conversation_history import ConversationHistory | |
| 228 | ||
| 229 | history = ConversationHistory() | |
| 230 | history.add_message("user", "Hello") | |
| 231 | history.add_message("assistant", "Hi there!") | |
| 232 | ``` | |
| 233 | ||
| 234 | **New code:** | |
| 235 | ```python | |
| 236 | from ollamatools.plugins.standard.conversation.history import ConversationHistory | |
| 237 | ||
| 238 | history = ConversationHistory() | |
| 239 | history.add_message("user", "Hello") | |
| 240 | history.add_message("assistant", "Hi there!") | |
| 241 | ``` | |
| 242 | ||
| 243 | ## Using Tools | |
| 244 | ||
| 245 | ### System Tools | |
| 246 | ||
| 247 | **Old code:** | |
| 248 | ```python | |
| 249 | from ollamatools.tools.system_tools import execute_system_command, read_file | |
| 250 | ||
| 251 | result = execute_system_command("ls -la") | |
| 252 | content = read_file("example.txt") | |
| 253 | ``` | |
| 254 | ||
| 255 | **New code:** | |
| 256 | ```python | |
| 257 | from ollamatools.plugins.tools.system import execute_system_command, read_file | |
| 258 | ||
| 259 | result = execute_system_command("ls -la") | |
| 260 | content = read_file("example.txt") | |
| 261 | ``` | |
| 262 | ||
| 263 | ### Web Tools | |
| 264 | ||
| 265 | **Old code:** | |
| 266 | ```python | |
| 267 | from ollamatools.tools.web_tools import make_web_request | |
| 268 | ||
| 269 | response = make_web_request("https://example.com") | |
| 270 | ``` | |
| 271 | ||
| 272 | **New code:** | |
| 273 | ```python | |
| 274 | from ollamatools.plugins.tools.web import make_web_request | |
| 275 | ||
| 276 | response = make_web_request("https://example.com") | |
| 277 | ``` | |
| 278 | ||
| 279 | ## Using Integrations | |
| 280 | ||
| 281 | ### Matrix Integration | |
| 282 | ||
| 283 | **Old code:** | |
| 284 | ```python | |
| 285 | from ollamatools.tools.matrix_tools import MatrixClient | |
| 286 | ||
| 287 | client = MatrixClient(homeserver="https://matrix.org", token="your_token") | |
| 288 | client.send_message("!roomid:matrix.org", "Hello, Matrix!") | |
| 289 | ``` | |
| 290 | ||
| 291 | **New code:** | |
| 292 | ```python | |
| 293 | from ollamatools.plugins.integrations.matrix.client import MatrixClient | |
| 294 | ||
| 295 | client = MatrixClient(homeserver="https://matrix.org", token="your_token") | |
| 296 | client.send_message("!roomid:matrix.org", "Hello, Matrix!") | |
| 297 | ``` | |
| 298 | ||
| 299 | ### OpenSearch Integration | |
| 300 | ||
| 301 | **Old code:** | |
| 302 | ```python | |
| 303 | from ollamatools.opensearch_web_tools import OpenSearchWebTools | |
| 304 | ||
| 305 | opensearch = OpenSearchWebTools(host="localhost", port=9200) | |
| 306 | results = opensearch.search("example query") | |
| 307 | ``` | |
| 308 | ||
| 309 | **New code:** | |
| 310 | ```python | |
| 311 | from ollamatools.plugins.integrations.opensearch.tools import OpenSearchWebTools | |
| 312 | ||
| 313 | opensearch = OpenSearchWebTools(host="localhost", port=9200) | |
| 314 | results = opensearch.search("example query") | |
| 315 | ``` | |
| 316 | ||
| 317 | ## Configuration System | |
| 318 | ||
| 319 | **Old code:** | |
| 320 | ```python | |
| 321 | from ollamatools.config.core_config import load_config | |
| 322 | from ollamatools.config.plugin_config import get_plugin_config | |
| 323 | ||
| 324 | config = load_config("config.yaml") | |
| 325 | plugin_config = get_plugin_config("search") | |
| 326 | ``` | |
| 327 | ||
| 328 | **New code:** | |
| 329 | ```python | |
| 330 | from ollamatools.config.loader import load_config | |
| 331 | from ollamatools.config.defaults import get_plugin_config | |
| 332 | ||
| 333 | config = load_config("config.yaml") | |
| 334 | plugin_config = get_plugin_config("search") | |
| 335 | ``` | |
| 336 | ||
| 337 | ## Common Issues and Solutions | |
| 338 | ||
| 339 | ### Import Errors | |
| 340 | ||
| 341 | If you encounter import errors, make sure you're using the new import paths as described above. The most common issue is forgetting to update imports to the new structure. | |
| 342 | ||
| 343 | ### Plugin Registration | |
| 344 | ||
| 345 | In the new structure, plugins are registered using a more consistent API. If you were previously using modules with the modular agent, you'll need to update to use plugins instead. | |
| 346 | ||
| 347 | **Old code:** | |
| 348 | ```python | |
| 349 | agent.add_module(SearchModule()) | |
| 350 | ``` | |
| 351 | ||
| 352 | **New code:** | |
| 353 | ```python | |
| 354 | agent.add_plugin(SearchPlugin()) | |
| 355 | ``` | |
| 356 | ||
| 357 | ### Configuration Changes | |
| 358 | ||
| 359 | The configuration system has been simplified, but the API remains largely the same. If you're having issues with configuration, make sure you're using the correct import paths. | |
| 360 | ||
| 361 | ## Getting Help | |
| 362 | ||
| 363 | If you encounter any issues during migration, please refer to the documentation or open an issue on the GitHub repository. |
| … | … | @@ -0,0 +1,75 @@ |
| 1 | # OllamaTools Simplified Refactoring Guide | |
| 2 | ||
| 3 | This directory contains a simplified approach to refactoring the OllamaTools project. The original refactoring plan was found to be too complex, particularly because merging files together made them too large. This guide presents a more manageable approach that maintains the target directory structure but avoids merging files. | |
| 4 | ||
| 5 | ## Background | |
| 6 | ||
| 7 | The OllamaTools project has evolved through several phases, resulting in a complex architecture with multiple overlapping components. The original AI simplification guides proposed a comprehensive refactoring that involved merging related functionality into consolidated files. However, analysis of the current codebase revealed that several files are already quite large (over 500 lines of code), making further merging impractical. | |
| 8 | ||
| 9 | This simplified refactoring guide provides an alternative approach that: | |
| 10 | ||
| 11 | 1. Maintains the target directory structure from the original AI simplification guides | |
| 12 | 2. Avoids creating files that are too large to manage by keeping existing files separate | |
| 13 | 3. Preserves existing functionality | |
| 14 | 4. Minimizes the risk of introducing bugs during refactoring | |
| 15 | ||
| 16 | ## Guide Structure | |
| 17 | ||
| 18 | The simplified refactoring guide is organized into the following documents: | |
| 19 | ||
| 20 | 1. **[00_INDEX.md](./00_INDEX.md)** - Index document with an overview of the guide | |
| 21 | 2. **[01_SIMPLIFIED_STRUCTURE.md](./01_SIMPLIFIED_STRUCTURE.md)** - The simplified file structure and file mapping strategy | |
| 22 | 3. **[02_IMPLEMENTATION_STEPS.md](./02_IMPLEMENTATION_STEPS.md)** - Detailed implementation steps for the simplified structure | |
| 23 | 4. **[03_FILE_MAPPING.md](./03_FILE_MAPPING.md)** - Complete file mapping table for reference | |
| 24 | ||
| 25 | ## Key Differences from Original Plan | |
| 26 | ||
| 27 | 1. **Validators Directory**: Instead of merging all validators into a single file, keep them separate to avoid creating another large file. | |
| 28 | ||
| 29 | 2. **Matrix Integration**: Keep Matrix-related files separate rather than merging them, as the original matrix_tools.py is already 800 lines. | |
| 30 | ||
| 31 | 3. **No File Merging**: Focus on organizing files into the appropriate directories without merging them, which avoids creating files that are too large to manage. | |
| 32 | ||
| 33 | ## Implementation Approach | |
| 34 | ||
| 35 | The implementation is broken down into manageable phases: | |
| 36 | ||
| 37 | 1. **Phase 1**: Create the directory structure | |
| 38 | 2. **Phase 2**: Copy files to new structure | |
| 39 | 3. **Phase 3**: Update imports and references | |
| 40 | 4. **Phase 4**: Implement new files | |
| 41 | 5. **Phase 5**: Update package initialization | |
| 42 | 6. **Phase 6**: Test the refactored code | |
| 43 | 7. **Phase 7**: Documentation and migration guide | |
| 44 | 8. **Phase 8**: Final steps | |
| 45 | ||
| 46 | Each phase is detailed in the [Implementation Steps](./02_IMPLEMENTATION_STEPS.md) document. | |
| 47 | ||
| 48 | ## Benefits of This Approach | |
| 49 | ||
| 50 | 1. **Maintains file granularity**: Avoids creating files that are too large to manage | |
| 51 | 2. **Preserves existing functionality**: Each file maintains its original purpose | |
| 52 | 3. **Follows the target architecture**: Organizes code according to the simplified structure | |
| 53 | 4. **Easier to implement**: Simpler to move files than to merge and refactor them | |
| 54 | 5. **Reduced risk**: Less chance of introducing bugs during the refactoring process | |
| 55 | 6. **Easier to review**: Changes are more isolated and easier to understand | |
| 56 | ||
| 57 | ## Getting Started | |
| 58 | ||
| 59 | To get started with the refactoring, follow these steps: | |
| 60 | ||
| 61 | 1. Start by reviewing the simplified structure in [01_SIMPLIFIED_STRUCTURE.md](./01_SIMPLIFIED_STRUCTURE.md) | |
| 62 | 2. Follow the implementation steps in [02_IMPLEMENTATION_STEPS.md](./02_IMPLEMENTATION_STEPS.md) | |
| 63 | 3. Use the file mapping table in [03_FILE_MAPPING.md](./03_FILE_MAPPING.md) as a reference during implementation | |
| 64 | ||
| 65 | ## Implementation Timeline | |
| 66 | ||
| 67 | The implementation can be broken down into manageable chunks: | |
| 68 | ||
| 69 | 1. **Week 1**: Phases 1-2 (Create directory structure, copy files) | |
| 70 | 2. **Week 2**: Phase 3 (Update imports and references) | |
| 71 | 3. **Week 3**: Phase 4 (Implement new files) | |
| 72 | 4. **Week 4**: Phases 5-6 (Update package initialization, test code) | |
| 73 | 5. **Week 5**: Phases 7-8 (Documentation, migration guide, final steps) | |
| 74 | ||
| 75 | By following this phased approach, we can implement the simplified structure in a controlled manner, ensuring that each step is properly tested before moving on to the next. |
| … | … | @@ -0,0 +1,234 @@ |
| 1 | # OllamaTools | |
| 2 | ||
| 3 | OllamaTools is a toolkit for working with Ollama, providing a range of utilities and plugins for building AI-powered applications. | |
| 4 | ||
| 5 | ## Features | |
| 6 | ||
| 7 | - **Core Agent**: Base agent implementation with plugin support | |
| 8 | - **Plugin System**: Extensible plugin architecture for adding new functionality | |
| 9 | - **Standard Plugins**: Search, commands, conversation history, feedback, and more | |
| 10 | - **Tool Plugins**: System tools, web tools, documentation tools | |
| 11 | - **Integration Plugins**: Matrix chat integration, OpenSearch integration | |
| 12 | - **Agent Implementations**: Basic, modular, and extended agent implementations | |
| 13 | - **Configuration System**: Flexible configuration management | |
| 14 | - **Command-Line Interface**: Easy-to-use CLI for common tasks | |
| 15 | ||
| 16 | ## Installation | |
| 17 | ||
| 18 | You can install OllamaTools using pip: | |
| 19 | ||
| 20 | ```bash | |
| 21 | pip install ollamatools | |
| 22 | ``` | |
| 23 | ||
| 24 | For development: | |
| 25 | ||
| 26 | ```bash | |
| 27 | pip install -e ".[dev]" | |
| 28 | ``` | |
| 29 | ||
| 30 | For Matrix integration: | |
| 31 | ||
| 32 | ```bash | |
| 33 | pip install -e ".[matrix]" | |
| 34 | ``` | |
| 35 | ||
| 36 | For OpenSearch integration: | |
| 37 | ||
| 38 | ```bash | |
| 39 | pip install -e ".[opensearch]" | |
| 40 | ``` | |
| 41 | ||
| 42 | ## Quick Start | |
| 43 | ||
| 44 | ### Basic Agent | |
| 45 | ||
| 46 | ```python | |
| 47 | from ollamatools.agents.basic import BasicAgent | |
| 48 | ||
| 49 | agent = BasicAgent(model="llama2") | |
| 50 | response = agent.chat("Hello, world!") | |
| 51 | print(response) | |
| 52 | ``` | |
| 53 | ||
| 54 | ### Modular Agent with Plugins | |
| 55 | ||
| 56 | ```python | |
| 57 | from ollamatools.agents.modular import ModularAgent | |
| 58 | from ollamatools.plugins.standard.search import SearchPlugin | |
| 59 | from ollamatools.plugins.standard.commands import CommandsPlugin | |
| 60 | ||
| 61 | agent = ModularAgent(model="llama2") | |
| 62 | agent.add_plugin(SearchPlugin()) | |
| 63 | agent.add_plugin(CommandsPlugin()) | |
| 64 | response = agent.chat("Search for information about Python") | |
| 65 | print(response) | |
| 66 | ``` | |
| 67 | ||
| 68 | ### Extended Agent with Conversation History | |
| 69 | ||
| 70 | ```python | |
| 71 | from ollamatools.agents.extended import ExtendedAgent | |
| 72 | ||
| 73 | agent = ExtendedAgent(model="llama2") | |
| 74 | agent.chat("Remember this information for later") | |
| 75 | response = agent.chat("What did I ask you to remember?") | |
| 76 | print(response) | |
| 77 | ``` | |
| 78 | ||
| 79 | ## Using Plugins | |
| 80 | ||
| 81 | ### Search Plugin | |
| 82 | ||
| 83 | ```python | |
| 84 | from ollamatools.plugins.standard.search import search_web | |
| 85 | ||
| 86 | results = search_web("Python programming") | |
| 87 | print(results) | |
| 88 | ``` | |
| 89 | ||
| 90 | ### Commands Plugin | |
| 91 | ||
| 92 | ```python | |
| 93 | from ollamatools.plugins.standard.commands import execute_command | |
| 94 | ||
| 95 | result = execute_command("ls -la") | |
| 96 | print(result) | |
| 97 | ``` | |
| 98 | ||
| 99 | ### Conversation History Plugin | |
| 100 | ||
| 101 | ```python | |
| 102 | from ollamatools.plugins.standard.conversation.history import ConversationHistory | |
| 103 | ||
| 104 | history = ConversationHistory() | |
| 105 | history.add_message("user", "Hello") | |
| 106 | history.add_message("assistant", "Hi there!") | |
| 107 | print(history.get_messages()) | |
| 108 | ``` | |
| 109 | ||
| 110 | ## Using Tools | |
| 111 | ||
| 112 | ### System Tools | |
| 113 | ||
| 114 | ```python | |
| 115 | from ollamatools.plugins.tools.system import execute_system_command, read_file | |
| 116 | ||
| 117 | result = execute_system_command("ls -la") | |
| 118 | content = read_file("example.txt") | |
| 119 | print(result) | |
| 120 | print(content) | |
| 121 | ``` | |
| 122 | ||
| 123 | ### Web Tools | |
| 124 | ||
| 125 | ```python | |
| 126 | from ollamatools.plugins.tools.web import make_web_request | |
| 127 | ||
| 128 | response = make_web_request("https://example.com") | |
| 129 | print(response.text) | |
| 130 | ``` | |
| 131 | ||
| 132 | ## Using Integrations | |
| 133 | ||
| 134 | ### Matrix Integration | |
| 135 | ||
| 136 | ```python | |
| 137 | from ollamatools.plugins.integrations.matrix.client import MatrixClient | |
| 138 | ||
| 139 | client = MatrixClient(homeserver="https://matrix.org", token="your_token") | |
| 140 | client.send_message("!roomid:matrix.org", "Hello, Matrix!") | |
| 141 | ``` | |
| 142 | ||
| 143 | ### OpenSearch Integration | |
| 144 | ||
| 145 | ```python | |
| 146 | from ollamatools.plugins.integrations.opensearch.tools import OpenSearchWebTools | |
| 147 | ||
| 148 | opensearch = OpenSearchWebTools(host="localhost", port=9200) | |
| 149 | results = opensearch.search("example query") | |
| 150 | print(results) | |
| 151 | ``` | |
| 152 | ||
| 153 | ## Configuration | |
| 154 | ||
| 155 | OllamaTools uses a flexible configuration system that supports YAML files, environment variables, and programmatic configuration. | |
| 156 | ||
| 157 | ```python | |
| 158 | from ollamatools.config.loader import load_config | |
| 159 | ||
| 160 | config = load_config("config.yaml") | |
| 161 | print(config) | |
| 162 | ``` | |
| 163 | ||
| 164 | Example configuration file: | |
| 165 | ||
| 166 | ```yaml | |
| 167 | # config.yaml | |
| 168 | agent: | |
| 169 | model: llama2 | |
| 170 | temperature: 0.7 | |
| 171 | max_tokens: 1024 | |
| 172 | ||
| 173 | plugins: | |
| 174 | search: | |
| 175 | enabled: true | |
| 176 | engine: duckduckgo | |
| 177 | commands: | |
| 178 | enabled: true | |
| 179 | allow_system_commands: false | |
| 180 | ``` | |
| 181 | ||
| 182 | ## Command-Line Interface | |
| 183 | ||
| 184 | OllamaTools includes a command-line interface for common tasks: | |
| 185 | ||
| 186 | ```bash | |
| 187 | # Start a chat session | |
| 188 | ollamatools chat --model llama2 | |
| 189 | ||
| 190 | # Run a script or command | |
| 191 | ollamatools run "print('Hello, world!')" --model llama2 | |
| 192 | ||
| 193 | # Show version information | |
| 194 | ollamatools version | |
| 195 | ``` | |
| 196 | ||
| 197 | ## Development | |
| 198 | ||
| 199 | ### Setup | |
| 200 | ||
| 201 | ```bash | |
| 202 | # Clone the repository | |
| 203 | git clone https://github.com/yourusername/ollamatools.git | |
| 204 | cd ollamatools | |
| 205 | ||
| 206 | # Install development dependencies | |
| 207 | pip install -e ".[dev]" | |
| 208 | ||
| 209 | # Run tests | |
| 210 | pytest | |
| 211 | ``` | |
| 212 | ||
| 213 | ### Code Style | |
| 214 | ||
| 215 | OllamaTools uses Black for code formatting, isort for import sorting, and flake8 for linting: | |
| 216 | ||
| 217 | ```bash | |
| 218 | # Format code | |
| 219 | black ollamatools tests | |
| 220 | ||
| 221 | # Sort imports | |
| 222 | isort ollamatools tests | |
| 223 | ||
| 224 | # Lint code | |
| 225 | flake8 ollamatools tests | |
| 226 | ``` | |
| 227 | ||
| 228 | ## Contributing | |
| 229 | ||
| 230 | Contributions are welcome! Please feel free to submit a Pull Request. | |
| 231 | ||
| 232 | ## License | |
| 233 | ||
| 234 | This project is licensed under the MIT License - see the LICENSE file for details. |
| … | … | @@ -0,0 +1,413 @@ |
| 1 | #!/bin/bash | |
| 2 | # copy_files.sh | |
| 3 | # | |
| 4 | # This script copies files from the original OllamaTools structure to the new simplified structure | |
| 5 | # according to the file mapping defined in 03_FILE_MAPPING.md. | |
| 6 | ||
| 7 | # Set the base directory for the new structure | |
| 8 | BASE_DIR="ollamatools-new" | |
| 9 | ||
| 10 | # Check if the directory structure exists | |
| 11 | if [ ! -d "$BASE_DIR" ]; then | |
| 12 | echo "Error: Directory structure not found. Please run create_directory_structure.sh first." | |
| 13 | exit 1 | |
| 14 | fi | |
| 15 | ||
| 16 | echo "Copying files to new structure..." | |
| 17 | ||
| 18 | # Core Module | |
| 19 | echo "Copying Core Module files..." | |
| 20 | cp ollamatools/agent.py $BASE_DIR/ollamatools/core/agent.py | |
| 21 | cp ollamatools/errors.py $BASE_DIR/ollamatools/core/errors.py | |
| 22 | cp ollamatools/config.py $BASE_DIR/ollamatools/core/config.py | |
| 23 | cp ollamatools/security.py $BASE_DIR/ollamatools/core/security.py | |
| 24 | cp ollamatools/logger.py $BASE_DIR/ollamatools/core/utils/logger.py | |
| 25 | cp ollamatools/command_validator.py $BASE_DIR/ollamatools/core/utils/validators/command.py | |
| 26 | cp ollamatools/path_validator.py $BASE_DIR/ollamatools/core/utils/validators/path.py | |
| 27 | cp ollamatools/url_validator.py $BASE_DIR/ollamatools/core/utils/validators/url.py | |
| 28 | ||
| 29 | # Create new formatting.py file with placeholder content | |
| 30 | echo "Creating new formatting.py file..." | |
| 31 | cat > $BASE_DIR/ollamatools/core/utils/formatting.py << 'EOF' | |
| 32 | """Text formatting utilities for OllamaTools.""" | |
| 33 | ||
| 34 | def format_markdown(text): | |
| 35 | """Format text as markdown.""" | |
| 36 | return text | |
| 37 | ||
| 38 | def format_code(code, language="python"): | |
| 39 | """Format code with syntax highlighting.""" | |
| 40 | return f"```{language}\n{code}\n```" | |
| 41 | ||
| 42 | def format_table(headers, rows): | |
| 43 | """Format data as a markdown table.""" | |
| 44 | if not headers or not rows: | |
| 45 | return "" | |
| 46 | ||
| 47 | result = [] | |
| 48 | ||
| 49 | # Add headers | |
| 50 | result.append("| " + " | ".join(headers) + " |") | |
| 51 | ||
| 52 | # Add separator | |
| 53 | result.append("| " + " | ".join(["---"] * len(headers)) + " |") | |
| 54 | ||
| 55 | # Add rows | |
| 56 | for row in rows: | |
| 57 | result.append("| " + " | ".join(str(cell) for cell in row) + " |") | |
| 58 | ||
| 59 | return "\n".join(result) | |
| 60 | EOF | |
| 61 | ||
| 62 | # Plugin System | |
| 63 | echo "Copying Plugin System files..." | |
| 64 | cp ollamatools/plugins/registry.py $BASE_DIR/ollamatools/plugins/registry.py | |
| 65 | cp ollamatools/plugins/errors.py $BASE_DIR/ollamatools/plugins/errors.py | |
| 66 | ||
| 67 | # Create new base.py file with placeholder content | |
| 68 | echo "Creating new base.py file..." | |
| 69 | cat > $BASE_DIR/ollamatools/plugins/base.py << 'EOF' | |
| 70 | """Base plugin interfaces for the OllamaTools plugin system.""" | |
| 71 | ||
| 72 | from abc import ABC, abstractmethod | |
| 73 | from typing import Any, Dict, List, Optional | |
| 74 | ||
| 75 | class Plugin(ABC): | |
| 76 | """Base class for all plugins.""" | |
| 77 | ||
| 78 | @property | |
| 79 | @abstractmethod | |
| 80 | def name(self) -> str: | |
| 81 | """Return the name of the plugin.""" | |
| 82 | pass | |
| 83 | ||
| 84 | @property | |
| 85 | @abstractmethod | |
| 86 | def version(self) -> str: | |
| 87 | """Return the version of the plugin.""" | |
| 88 | pass | |
| 89 | ||
| 90 | @abstractmethod | |
| 91 | def initialize(self, config: Dict[str, Any]) -> None: | |
| 92 | """Initialize the plugin with the given configuration.""" | |
| 93 | pass | |
| 94 | ||
| 95 | @abstractmethod | |
| 96 | def shutdown(self) -> None: | |
| 97 | """Shutdown the plugin and release any resources.""" | |
| 98 | pass | |
| 99 | ||
| 100 | class ToolPlugin(Plugin): | |
| 101 | """Base class for tool plugins.""" | |
| 102 | ||
| 103 | @abstractmethod | |
| 104 | def get_tools(self) -> List[Dict[str, Any]]: | |
| 105 | """Return the list of tools provided by this plugin.""" | |
| 106 | pass | |
| 107 | ||
| 108 | class StandardPlugin(Plugin): | |
| 109 | """Base class for standard plugins.""" | |
| 110 | ||
| 111 | @abstractmethod | |
| 112 | def process_message(self, message: Dict[str, Any]) -> Dict[str, Any]: | |
| 113 | """Process a message and return the result.""" | |
| 114 | pass | |
| 115 | ||
| 116 | class IntegrationPlugin(Plugin): | |
| 117 | """Base class for integration plugins.""" | |
| 118 | ||
| 119 | @abstractmethod | |
| 120 | def connect(self) -> bool: | |
| 121 | """Connect to the external service.""" | |
| 122 | pass | |
| 123 | ||
| 124 | @abstractmethod | |
| 125 | def disconnect(self) -> None: | |
| 126 | """Disconnect from the external service.""" | |
| 127 | pass | |
| 128 | EOF | |
| 129 | ||
| 130 | # Standard Plugins | |
| 131 | echo "Copying Standard Plugins files..." | |
| 132 | cp ollamatools/agent/modular/search.py $BASE_DIR/ollamatools/plugins/standard/search.py | |
| 133 | cp ollamatools/agent/modular/commands.py $BASE_DIR/ollamatools/plugins/standard/commands.py | |
| 134 | cp ollamatools/plugins/conversation_history.py $BASE_DIR/ollamatools/plugins/standard/conversation/history.py | |
| 135 | cp ollamatools/plugins/conversation_context.py $BASE_DIR/ollamatools/plugins/standard/conversation/context.py | |
| 136 | cp ollamatools/agent/modular/feedback.py $BASE_DIR/ollamatools/plugins/standard/feedback.py | |
| 137 | cp ollamatools/agent/modular/issues.py $BASE_DIR/ollamatools/plugins/standard/issues.py | |
| 138 | ||
| 139 | # Create new conversation analysis file with placeholder content | |
| 140 | echo "Creating new conversation analysis file..." | |
| 141 | cat > $BASE_DIR/ollamatools/plugins/standard/conversation/analysis.py << 'EOF' | |
| 142 | """Conversation topic analysis and metrics.""" | |
| 143 | ||
| 144 | from typing import Any, Dict, List, Optional | |
| 145 | ||
| 146 | def analyze_topics(messages: List[Dict[str, Any]]) -> List[str]: | |
| 147 | """Analyze the topics in a conversation.""" | |
| 148 | # Implementation | |
| 149 | return ["topic1", "topic2"] | |
| 150 | ||
| 151 | def calculate_metrics(messages: List[Dict[str, Any]]) -> Dict[str, Any]: | |
| 152 | """Calculate metrics for a conversation.""" | |
| 153 | # Implementation | |
| 154 | return { | |
| 155 | "message_count": len(messages), | |
| 156 | "average_length": sum(len(m.get("content", "")) for m in messages) / max(1, len(messages)), | |
| 157 | "user_messages": sum(1 for m in messages if m.get("role") == "user"), | |
| 158 | "assistant_messages": sum(1 for m in messages if m.get("role") == "assistant"), | |
| 159 | } | |
| 160 | EOF | |
| 161 | ||
| 162 | # Create new function calling file with placeholder content | |
| 163 | echo "Creating new function calling file..." | |
| 164 | cat > $BASE_DIR/ollamatools/plugins/standard/function_calling.py << 'EOF' | |
| 165 | """Plugin for semantic function calling.""" | |
| 166 | ||
| 167 | from typing import Any, Dict, List, Optional | |
| 168 | ||
| 169 | from ollamatools.plugins.base import StandardPlugin | |
| 170 | ||
| 171 | class FunctionCallingPlugin(StandardPlugin): | |
| 172 | """Plugin for semantic function calling.""" | |
| 173 | ||
| 174 | @property | |
| 175 | def name(self) -> str: | |
| 176 | return "function_calling" | |
| 177 | ||
| 178 | @property | |
| 179 | def version(self) -> str: | |
| 180 | return "0.1.0" | |
| 181 | ||
| 182 | def initialize(self, config: Dict[str, Any]) -> None: | |
| 183 | """Initialize the plugin with the given configuration.""" | |
| 184 | self.config = config | |
| 185 | self.functions = {} | |
| 186 | ||
| 187 | def shutdown(self) -> None: | |
| 188 | """Shutdown the plugin and release any resources.""" | |
| 189 | pass | |
| 190 | ||
| 191 | def register_function(self, name: str, function: callable, description: str, parameters: Dict[str, Any]) -> None: | |
| 192 | """Register a function that can be called semantically.""" | |
| 193 | self.functions[name] = { | |
| 194 | "function": function, | |
| 195 | "description": description, | |
| 196 | "parameters": parameters, | |
| 197 | } | |
| 198 | ||
| 199 | def process_message(self, message: Dict[str, Any]) -> Dict[str, Any]: | |
| 200 | """Process a message and extract function calls.""" | |
| 201 | # Implementation | |
| 202 | return message | |
| 203 | EOF | |
| 204 | ||
| 205 | # Tool Plugins | |
| 206 | echo "Copying Tool Plugins files..." | |
| 207 | cp ollamatools/tools/system_tools.py $BASE_DIR/ollamatools/plugins/tools/system.py | |
| 208 | cp ollamatools/tools/web_tools.py $BASE_DIR/ollamatools/plugins/tools/web.py | |
| 209 | cp ollamatools/tools/doc_tools.py $BASE_DIR/ollamatools/plugins/tools/doc.py | |
| 210 | ||
| 211 | # Integration Plugins | |
| 212 | echo "Copying Integration Plugins files..." | |
| 213 | cp ollamatools/tools/matrix_tools.py $BASE_DIR/ollamatools/plugins/integrations/matrix/client.py | |
| 214 | cp ollamatools/tools/enhanced_matrix_tools.py $BASE_DIR/ollamatools/plugins/integrations/matrix/commands.py | |
| 215 | cp ollamatools/tools/enhanced_matrix_search.py $BASE_DIR/ollamatools/plugins/integrations/matrix/search.py | |
| 216 | cp ollamatools/tools/enhanced_matrix_history.py $BASE_DIR/ollamatools/plugins/integrations/matrix/history.py | |
| 217 | cp ollamatools/tools/matrix_rate_limit_patch.py $BASE_DIR/ollamatools/plugins/integrations/matrix/rate_limit.py | |
| 218 | cp ollamatools/opensearch_web_tools.py $BASE_DIR/ollamatools/plugins/integrations/opensearch/tools.py | |
| 219 | ||
| 220 | # Create new Matrix config file with placeholder content | |
| 221 | echo "Creating new Matrix config file..." | |
| 222 | cat > $BASE_DIR/ollamatools/plugins/integrations/matrix/config.py << 'EOF' | |
| 223 | """Configuration for Matrix integration.""" | |
| 224 | ||
| 225 | from typing import Any, Dict, Optional | |
| 226 | ||
| 227 | def load_matrix_config(config_path: Optional[str] = None) -> Dict[str, Any]: | |
| 228 | """Load Matrix configuration from the given path.""" | |
| 229 | # Implementation | |
| 230 | return {} | |
| 231 | ||
| 232 | def validate_matrix_config(config: Dict[str, Any]) -> bool: | |
| 233 | """Validate Matrix configuration.""" | |
| 234 | # Implementation | |
| 235 | return True | |
| 236 | ||
| 237 | def get_default_matrix_config() -> Dict[str, Any]: | |
| 238 | """Return the default Matrix configuration.""" | |
| 239 | return { | |
| 240 | "homeserver": "https://matrix.org", | |
| 241 | "user_id": "@ollamatools:matrix.org", | |
| 242 | "access_token": "", | |
| 243 | "device_id": "ollamatools", | |
| 244 | "room_ids": [], | |
| 245 | "rate_limit": { | |
| 246 | "max_requests": 5, | |
| 247 | "time_window": 1, | |
| 248 | "backoff_factor": 2, | |
| 249 | "max_retries": 5, | |
| 250 | }, | |
| 251 | } | |
| 252 | EOF | |
| 253 | ||
| 254 | # Create new OpenSearch client file with placeholder content | |
| 255 | echo "Creating new OpenSearch client file..." | |
| 256 | cat > $BASE_DIR/ollamatools/plugins/integrations/opensearch/client.py << 'EOF' | |
| 257 | """OpenSearch client for OllamaTools.""" | |
| 258 | ||
| 259 | from typing import Any, Dict, List, Optional | |
| 260 | ||
| 261 | class OpenSearchClient: | |
| 262 | """Client for interacting with OpenSearch.""" | |
| 263 | ||
| 264 | def __init__(self, host: str, port: int, username: Optional[str] = None, password: Optional[str] = None): | |
| 265 | """Initialize the OpenSearch client.""" | |
| 266 | self.host = host | |
| 267 | self.port = port | |
| 268 | self.username = username | |
| 269 | self.password = password | |
| 270 | self.connected = False | |
| 271 | ||
| 272 | def connect(self) -> bool: | |
| 273 | """Connect to the OpenSearch server.""" | |
| 274 | # Implementation | |
| 275 | self.connected = True | |
| 276 | return True | |
| 277 | ||
| 278 | def disconnect(self) -> None: | |
| 279 | """Disconnect from the OpenSearch server.""" | |
| 280 | # Implementation | |
| 281 | self.connected = False | |
| 282 | ||
| 283 | def search(self, index: str, query: Dict[str, Any]) -> List[Dict[str, Any]]: | |
| 284 | """Search for documents in the given index.""" | |
| 285 | # Implementation | |
| 286 | return [] | |
| 287 | ||
| 288 | def index_document(self, index: str, document: Dict[str, Any], id: Optional[str] = None) -> bool: | |
| 289 | """Index a document in the given index.""" | |
| 290 | # Implementation | |
| 291 | return True | |
| 292 | ||
| 293 | def delete_document(self, index: str, id: str) -> bool: | |
| 294 | """Delete a document from the given index.""" | |
| 295 | # Implementation | |
| 296 | return True | |
| 297 | EOF | |
| 298 | ||
| 299 | # Agent Implementations | |
| 300 | echo "Copying Agent Implementations files..." | |
| 301 | cp ollamatools/agent/core.py $BASE_DIR/ollamatools/agents/basic.py | |
| 302 | cp ollamatools/agent/modular/agent.py $BASE_DIR/ollamatools/agents/modular.py | |
| 303 | cp ollamatools/agent/extended/agent.py $BASE_DIR/ollamatools/agents/extended.py | |
| 304 | ||
| 305 | # Configuration System | |
| 306 | echo "Copying Configuration System files..." | |
| 307 | cp ollamatools/config/schemas.py $BASE_DIR/ollamatools/config/schemas.py | |
| 308 | cp ollamatools/config/core_config.py $BASE_DIR/ollamatools/config/loader.py | |
| 309 | cp ollamatools/config/plugin_config.py $BASE_DIR/ollamatools/config/defaults.py | |
| 310 | ||
| 311 | # Create new CLI main file with placeholder content | |
| 312 | echo "Creating new CLI main file..." | |
| 313 | cat > $BASE_DIR/ollamatools/cli/main.py << 'EOF' | |
| 314 | """Command-line interface for OllamaTools.""" | |
| 315 | ||
| 316 | import argparse | |
| 317 | import sys | |
| 318 | from typing import List, Optional | |
| 319 | ||
| 320 | def parse_args(args: Optional[List[str]] = None) -> argparse.Namespace: | |
| 321 | """Parse command-line arguments.""" | |
| 322 | parser = argparse.ArgumentParser(description="OllamaTools - A toolkit for working with Ollama") | |
| 323 | ||
| 324 | # Add subparsers for different commands | |
| 325 | subparsers = parser.add_subparsers(dest="command", help="Command to execute") | |
| 326 | ||
| 327 | # Chat command | |
| 328 | chat_parser = subparsers.add_parser("chat", help="Start a chat session") | |
| 329 | chat_parser.add_argument("--model", "-m", default="llama2", help="Model to use for chat") | |
| 330 | chat_parser.add_argument("--config", "-c", help="Path to configuration file") | |
| 331 | ||
| 332 | # Run command | |
| 333 | run_parser = subparsers.add_parser("run", help="Run a script or command") | |
| 334 | run_parser.add_argument("script", help="Script or command to run") | |
| 335 | run_parser.add_argument("--model", "-m", default="llama2", help="Model to use for execution") | |
| 336 | ||
| 337 | # Version command | |
| 338 | subparsers.add_parser("version", help="Show version information") | |
| 339 | ||
| 340 | return parser.parse_args(args) | |
| 341 | ||
| 342 | def main(args: Optional[List[str]] = None) -> int: | |
| 343 | """Main entry point for the CLI.""" | |
| 344 | parsed_args = parse_args(args) | |
| 345 | ||
| 346 | if parsed_args.command == "chat": | |
| 347 | # Start chat session | |
| 348 | print(f"Starting chat session with model {parsed_args.model}") | |
| 349 | # Implementation | |
| 350 | return 0 | |
| 351 | elif parsed_args.command == "run": | |
| 352 | # Run script or command | |
| 353 | print(f"Running {parsed_args.script} with model {parsed_args.model}") | |
| 354 | # Implementation | |
| 355 | return 0 | |
| 356 | elif parsed_args.command == "version": | |
| 357 | # Show version information | |
| 358 | from ollamatools.version import __version__ | |
| 359 | print(f"OllamaTools version {__version__}") | |
| 360 | return 0 | |
| 361 | else: | |
| 362 | # No command specified, show help | |
| 363 | parse_args(["--help"]) | |
| 364 | return 1 | |
| 365 | ||
| 366 | if __name__ == "__main__": | |
| 367 | sys.exit(main()) | |
| 368 | EOF | |
| 369 | ||
| 370 | # Create new version file with placeholder content | |
| 371 | echo "Creating new version file..." | |
| 372 | cat > $BASE_DIR/ollamatools/version.py << 'EOF' | |
| 373 | """Version information for OllamaTools.""" | |
| 374 | ||
| 375 | __version__ = "0.1.0" | |
| 376 | EOF | |
| 377 | ||
| 378 | # Update package initialization | |
| 379 | echo "Updating package initialization..." | |
| 380 | cat > $BASE_DIR/ollamatools/__init__.py << 'EOF' | |
| 381 | """OllamaTools package.""" | |
| 382 | ||
| 383 | from ollamatools.version import __version__ | |
| 384 | ||
| 385 | # Expose core components | |
| 386 | from ollamatools.core.agent import Agent | |
| 387 | from ollamatools.core.config import Config | |
| 388 | ||
| 389 | # Expose agent implementations | |
| 390 | from ollamatools.agents.basic import BasicAgent | |
| 391 | from ollamatools.agents.modular import ModularAgent | |
| 392 | from ollamatools.agents.extended import ExtendedAgent | |
| 393 | ||
| 394 | # Expose plugin system | |
| 395 | from ollamatools.plugins.base import Plugin | |
| 396 | from ollamatools.plugins.registry import PluginRegistry | |
| 397 | ||
| 398 | __all__ = [ | |
| 399 | "__version__", | |
| 400 | "Agent", | |
| 401 | "Config", | |
| 402 | "BasicAgent", | |
| 403 | "ModularAgent", | |
| 404 | "ExtendedAgent", | |
| 405 | "Plugin", | |
| 406 | "PluginRegistry", | |
| 407 | ] | |
| 408 | EOF | |
| 409 | ||
| 410 | echo "Files copied successfully." | |
| 411 | echo "Next steps:" | |
| 412 | echo "1. Update imports in the copied files" | |
| 413 | echo "2. Test the refactored code" |
| … | … | @@ -0,0 +1,29 @@ |
| 1 | #!/bin/bash | |
| 2 | # copy_readme.sh | |
| 3 | # | |
| 4 | # This script copies the README_REFACTORED.md file to the refactored project directory | |
| 5 | # as README.md. | |
| 6 | ||
| 7 | # Set the base directory for the new structure | |
| 8 | BASE_DIR="ollamatools-new" | |
| 9 | ||
| 10 | # Check if the directory structure exists | |
| 11 | if [ ! -d "$BASE_DIR" ]; then | |
| 12 | echo "Error: Directory structure not found. Please run create_directory_structure.sh first." | |
| 13 | exit 1 | |
| 14 | fi | |
| 15 | ||
| 16 | # Copy the README_REFACTORED.md file to the refactored project directory | |
| 17 | echo "Copying README_REFACTORED.md to $BASE_DIR/README.md..." | |
| 18 | cp simplified_guides/README_REFACTORED.md $BASE_DIR/README.md | |
| 19 | ||
| 20 | # Copy the setup.py file to the refactored project directory | |
| 21 | echo "Copying setup.py to $BASE_DIR/setup.py..." | |
| 22 | cp simplified_guides/setup.py $BASE_DIR/setup.py | |
| 23 | ||
| 24 | # Copy the MIGRATION_GUIDE.md file to the refactored project directory | |
| 25 | echo "Copying MIGRATION_GUIDE.md to $BASE_DIR/MIGRATION_GUIDE.md..." | |
| 26 | cp simplified_guides/MIGRATION_GUIDE.md $BASE_DIR/MIGRATION_GUIDE.md | |
| 27 | ||
| 28 | echo "Files copied successfully." | |
| 29 | echo "The refactored project now has a README.md, setup.py, and MIGRATION_GUIDE.md file." |
| … | … | @@ -0,0 +1,47 @@ |
| 1 | #!/bin/bash | |
| 2 | # create_directory_structure.sh | |
| 3 | # | |
| 4 | # This script creates the directory structure for the simplified OllamaTools refactoring. | |
| 5 | # It creates all necessary directories and initializes them with empty __init__.py files. | |
| 6 | ||
| 7 | # Set the base directory for the new structure | |
| 8 | BASE_DIR="ollamatools-new" | |
| 9 | ||
| 10 | # Create the base directory if it doesn't exist | |
| 11 | mkdir -p $BASE_DIR | |
| 12 | ||
| 13 | # Create the directory structure | |
| 14 | echo "Creating directory structure..." | |
| 15 | ||
| 16 | # Core module | |
| 17 | mkdir -p $BASE_DIR/ollamatools/core/utils/validators | |
| 18 | mkdir -p $BASE_DIR/ollamatools/core/utils | |
| 19 | ||
| 20 | # Plugin system | |
| 21 | mkdir -p $BASE_DIR/ollamatools/plugins/standard/conversation | |
| 22 | mkdir -p $BASE_DIR/ollamatools/plugins/tools | |
| 23 | mkdir -p $BASE_DIR/ollamatools/plugins/integrations/matrix | |
| 24 | mkdir -p $BASE_DIR/ollamatools/plugins/integrations/opensearch | |
| 25 | ||
| 26 | # Agent implementations | |
| 27 | mkdir -p $BASE_DIR/ollamatools/agents | |
| 28 | ||
| 29 | # Configuration system | |
| 30 | mkdir -p $BASE_DIR/ollamatools/config | |
| 31 | ||
| 32 | # Command-line interface | |
| 33 | mkdir -p $BASE_DIR/ollamatools/cli | |
| 34 | ||
| 35 | # Create __init__.py files in all directories | |
| 36 | echo "Creating __init__.py files..." | |
| 37 | find $BASE_DIR -type d -exec touch {}/__init__.py \; | |
| 38 | ||
| 39 | echo "Directory structure created successfully." | |
| 40 | echo "The following directories have been created:" | |
| 41 | find $BASE_DIR -type d | sort | |
| 42 | ||
| 43 | echo "Next steps:" | |
| 44 | echo "1. Copy files to their new locations using the file mapping in 03_FILE_MAPPING.md" | |
| 45 | echo "2. Update imports in the copied files" | |
| 46 | echo "3. Implement new files" | |
| 47 | echo "4. Test the refactored code" |
| … | … | @@ -0,0 +1,19 @@ |
| 1 | #!/bin/bash | |
| 2 | # make_scripts_executable.sh | |
| 3 | # | |
| 4 | # This script makes all shell scripts in the simplified_guides directory executable. | |
| 5 | ||
| 6 | # Make all shell scripts executable | |
| 7 | echo "Making shell scripts executable..." | |
| 8 | chmod +x simplified_guides/*.sh | |
| 9 | ||
| 10 | echo "Shell scripts are now executable." | |
| 11 | echo "You can now run the following scripts:" | |
| 12 | echo " - simplified_guides/create_directory_structure.sh" | |
| 13 | echo " - simplified_guides/copy_files.sh" | |
| 14 | echo " - simplified_guides/make_scripts_executable.sh" | |
| 15 | ||
| 16 | echo "To execute the scripts, run:" | |
| 17 | echo " ./simplified_guides/create_directory_structure.sh" | |
| 18 | echo " ./simplified_guides/copy_files.sh" | |
| 19 | echo " python simplified_guides/test_refactored_code.py" |
| … | … | @@ -0,0 +1,50 @@ |
| 1 | #!/bin/bash | |
| 2 | # run_all_steps.sh | |
| 3 | # | |
| 4 | # This script runs all the steps in the simplified refactoring process in sequence. | |
| 5 | # It creates the directory structure, copies files, updates imports, and tests the refactored code. | |
| 6 | ||
| 7 | # Set the base directory for the new structure | |
| 8 | BASE_DIR="ollamatools-new" | |
| 9 | ||
| 10 | # Function to check if a command succeeded | |
| 11 | check_status() { | |
| 12 | if [ $? -ne 0 ]; then | |
| 13 | echo "Error: $1 failed. Exiting." | |
| 14 | exit 1 | |
| 15 | fi | |
| 16 | } | |
| 17 | ||
| 18 | # Make all scripts executable | |
| 19 | echo "Making scripts executable..." | |
| 20 | chmod +x simplified_guides/*.sh | |
| 21 | check_status "Making scripts executable" | |
| 22 | ||
| 23 | # Step 1: Create the directory structure | |
| 24 | echo -e "\n=== Step 1: Creating Directory Structure ===\n" | |
| 25 | ./simplified_guides/create_directory_structure.sh | |
| 26 | check_status "Creating directory structure" | |
| 27 | ||
| 28 | # Step 2: Copy files to new structure | |
| 29 | echo -e "\n=== Step 2: Copying Files ===\n" | |
| 30 | ./simplified_guides/copy_files.sh | |
| 31 | check_status "Copying files" | |
| 32 | ||
| 33 | # Step 3: Update imports | |
| 34 | echo -e "\n=== Step 3: Updating Imports ===\n" | |
| 35 | python simplified_guides/update_imports.py | |
| 36 | check_status "Updating imports" | |
| 37 | ||
| 38 | # Step 4: Test the refactored code | |
| 39 | echo -e "\n=== Step 4: Testing Refactored Code ===\n" | |
| 40 | python simplified_guides/test_refactored_code.py | |
| 41 | check_status "Testing refactored code" | |
| 42 | ||
| 43 | # Step 5: Copy README and other files | |
| 44 | echo -e "\n=== Step 5: Copying README and Other Files ===\n" | |
| 45 | ./simplified_guides/copy_readme.sh | |
| 46 | check_status "Copying README and other files" | |
| 47 | ||
| 48 | echo -e "\n=== All Steps Completed Successfully ===\n" | |
| 49 | echo "The refactored code is now available in the '$BASE_DIR' directory." | |
| 50 | echo "You can now proceed with further testing and integration." |
| … | … | @@ -0,0 +1,69 @@ |
| 1 | #!/usr/bin/env python3 | |
| 2 | """ | |
| 3 | Setup script for the refactored OllamaTools package. | |
| 4 | ||
| 5 | This script installs the refactored OllamaTools package and its dependencies. | |
| 6 | It should be placed in the root directory of the refactored project. | |
| 7 | """ | |
| 8 | ||
| 9 | from setuptools import setup, find_packages | |
| 10 | ||
| 11 | with open("README.md", "r", encoding="utf-8") as fh: | |
| 12 | long_description = fh.read() | |
| 13 | ||
| 14 | setup( | |
| 15 | name="ollamatools", | |
| 16 | version="0.1.0", | |
| 17 | author="OllamaTools Team", | |
| 18 | author_email="info@example.com", | |
| 19 | description="A toolkit for working with Ollama", | |
| 20 | long_description=long_description, | |
| 21 | long_description_content_type="text/markdown", | |
| 22 | url="https://github.com/yourusername/ollamatools", | |
| 23 | packages=find_packages(), | |
| 24 | classifiers=[ | |
| 25 | "Programming Language :: Python :: 3", | |
| 26 | "License :: OSI Approved :: MIT License", | |
| 27 | "Operating System :: OS Independent", | |
| 28 | ], | |
| 29 | python_requires=">=3.8", | |
| 30 | install_requires=[ | |
| 31 | "requests>=2.25.0", | |
| 32 | "pyyaml>=5.4.0", | |
| 33 | "typing-extensions>=4.0.0", | |
| 34 | "aiohttp>=3.7.4", | |
| 35 | "websockets>=10.0", | |
| 36 | "pydantic>=1.8.0", | |
| 37 | "numpy>=1.20.0", | |
| 38 | "pandas>=1.3.0", | |
| 39 | "matplotlib>=3.4.0", | |
| 40 | "pytest>=6.2.0", | |
| 41 | "pytest-cov>=2.12.0", | |
| 42 | "black>=21.5b2", | |
| 43 | "isort>=5.9.0", | |
| 44 | "flake8>=3.9.0", | |
| 45 | ], | |
| 46 | extras_require={ | |
| 47 | "dev": [ | |
| 48 | "pytest>=6.2.0", | |
| 49 | "pytest-cov>=2.12.0", | |
| 50 | "black>=21.5b2", | |
| 51 | "isort>=5.9.0", | |
| 52 | "flake8>=3.9.0", | |
| 53 | "mypy>=0.812", | |
| 54 | "sphinx>=4.0.0", | |
| 55 | "sphinx-rtd-theme>=0.5.2", | |
| 56 | ], | |
| 57 | "matrix": [ | |
| 58 | "matrix-nio>=0.19.0", | |
| 59 | ], | |
| 60 | "opensearch": [ | |
| 61 | "opensearch-py>=1.0.0", | |
| 62 | ], | |
| 63 | }, | |
| 64 | entry_points={ | |
| 65 | "console_scripts": [ | |
| 66 | "ollamatools=ollamatools.cli.main:main", | |
| 67 | ], | |
| 68 | }, | |
| 69 | ) |
| … | … | @@ -0,0 +1,200 @@ |
| 1 | #!/usr/bin/env python3 | |
| 2 | """ | |
| 3 | Test script for the refactored OllamaTools code. | |
| 4 | ||
| 5 | This script tests the basic functionality of the refactored OllamaTools code | |
| 6 | by importing key components and verifying that they can be instantiated. | |
| 7 | ||
| 8 | Usage: | |
| 9 | python test_refactored_code.py | |
| 10 | ||
| 11 | Note: | |
| 12 | This script assumes that the refactored code is in the 'ollamatools-new' directory. | |
| 13 | Make sure to run create_directory_structure.sh and copy_files.sh before running this script. | |
| 14 | """ | |
| 15 | ||
| 16 | import os | |
| 17 | import sys | |
| 18 | import importlib | |
| 19 | import traceback | |
| 20 | ||
| 21 | # Add the refactored code to the Python path | |
| 22 | REFACTORED_DIR = "ollamatools-new" | |
| 23 | sys.path.insert(0, REFACTORED_DIR) | |
| 24 | ||
| 25 | def test_import(module_name, class_name=None): | |
| 26 | """Test importing a module and optionally a class from that module.""" | |
| 27 | try: | |
| 28 | module = importlib.import_module(module_name) | |
| 29 | print(f"✅ Successfully imported {module_name}") | |
| 30 | ||
| 31 | if class_name: | |
| 32 | cls = getattr(module, class_name) | |
| 33 | print(f"✅ Successfully imported {class_name} from {module_name}") | |
| 34 | return cls | |
| 35 | return module | |
| 36 | except Exception as e: | |
| 37 | print(f"❌ Failed to import {module_name}{' - ' + class_name if class_name else ''}") | |
| 38 | print(f" Error: {str(e)}") | |
| 39 | traceback.print_exc() | |
| 40 | return None | |
| 41 | ||
| 42 | def test_core_components(): | |
| 43 | """Test core components.""" | |
| 44 | print("\n=== Testing Core Components ===") | |
| 45 | ||
| 46 | # Test core agent | |
| 47 | Agent = test_import("ollamatools.core.agent", "Agent") | |
| 48 | ||
| 49 | # Test core config | |
| 50 | Config = test_import("ollamatools.core.config", "Config") | |
| 51 | ||
| 52 | # Test core errors | |
| 53 | test_import("ollamatools.core.errors") | |
| 54 | ||
| 55 | # Test core security | |
| 56 | test_import("ollamatools.core.security") | |
| 57 | ||
| 58 | # Test core utils | |
| 59 | test_import("ollamatools.core.utils.logger") | |
| 60 | test_import("ollamatools.core.utils.validators.command") | |
| 61 | test_import("ollamatools.core.utils.validators.path") | |
| 62 | test_import("ollamatools.core.utils.validators.url") | |
| 63 | test_import("ollamatools.core.utils.formatting") | |
| 64 | ||
| 65 | def test_plugin_system(): | |
| 66 | """Test plugin system.""" | |
| 67 | print("\n=== Testing Plugin System ===") | |
| 68 | ||
| 69 | # Test plugin base | |
| 70 | Plugin = test_import("ollamatools.plugins.base", "Plugin") | |
| 71 | ||
| 72 | # Test plugin registry | |
| 73 | PluginRegistry = test_import("ollamatools.plugins.registry", "PluginRegistry") | |
| 74 | ||
| 75 | # Test plugin errors | |
| 76 | test_import("ollamatools.plugins.errors") | |
| 77 | ||
| 78 | def test_standard_plugins(): | |
| 79 | """Test standard plugins.""" | |
| 80 | print("\n=== Testing Standard Plugins ===") | |
| 81 | ||
| 82 | # Test search plugin | |
| 83 | test_import("ollamatools.plugins.standard.search") | |
| 84 | ||
| 85 | # Test commands plugin | |
| 86 | test_import("ollamatools.plugins.standard.commands") | |
| 87 | ||
| 88 | # Test conversation plugins | |
| 89 | test_import("ollamatools.plugins.standard.conversation.history") | |
| 90 | test_import("ollamatools.plugins.standard.conversation.context") | |
| 91 | test_import("ollamatools.plugins.standard.conversation.analysis") | |
| 92 | ||
| 93 | # Test feedback plugin | |
| 94 | test_import("ollamatools.plugins.standard.feedback") | |
| 95 | ||
| 96 | # Test issues plugin | |
| 97 | test_import("ollamatools.plugins.standard.issues") | |
| 98 | ||
| 99 | # Test function calling plugin | |
| 100 | test_import("ollamatools.plugins.standard.function_calling") | |
| 101 | ||
| 102 | def test_tool_plugins(): | |
| 103 | """Test tool plugins.""" | |
| 104 | print("\n=== Testing Tool Plugins ===") | |
| 105 | ||
| 106 | # Test system tools | |
| 107 | test_import("ollamatools.plugins.tools.system") | |
| 108 | ||
| 109 | # Test web tools | |
| 110 | test_import("ollamatools.plugins.tools.web") | |
| 111 | ||
| 112 | # Test doc tools | |
| 113 | test_import("ollamatools.plugins.tools.doc") | |
| 114 | ||
| 115 | def test_integration_plugins(): | |
| 116 | """Test integration plugins.""" | |
| 117 | print("\n=== Testing Integration Plugins ===") | |
| 118 | ||
| 119 | # Test Matrix integration | |
| 120 | test_import("ollamatools.plugins.integrations.matrix.client") | |
| 121 | test_import("ollamatools.plugins.integrations.matrix.commands") | |
| 122 | test_import("ollamatools.plugins.integrations.matrix.search") | |
| 123 | test_import("ollamatools.plugins.integrations.matrix.history") | |
| 124 | test_import("ollamatools.plugins.integrations.matrix.rate_limit") | |
| 125 | test_import("ollamatools.plugins.integrations.matrix.config") | |
| 126 | ||
| 127 | # Test OpenSearch integration | |
| 128 | test_import("ollamatools.plugins.integrations.opensearch.tools") | |
| 129 | test_import("ollamatools.plugins.integrations.opensearch.client") | |
| 130 | ||
| 131 | def test_agent_implementations(): | |
| 132 | """Test agent implementations.""" | |
| 133 | print("\n=== Testing Agent Implementations ===") | |
| 134 | ||
| 135 | # Test basic agent | |
| 136 | test_import("ollamatools.agents.basic", "BasicAgent") | |
| 137 | ||
| 138 | # Test modular agent | |
| 139 | test_import("ollamatools.agents.modular", "ModularAgent") | |
| 140 | ||
| 141 | # Test extended agent | |
| 142 | test_import("ollamatools.agents.extended", "ExtendedAgent") | |
| 143 | ||
| 144 | def test_configuration_system(): | |
| 145 | """Test configuration system.""" | |
| 146 | print("\n=== Testing Configuration System ===") | |
| 147 | ||
| 148 | # Test schemas | |
| 149 | test_import("ollamatools.config.schemas") | |
| 150 | ||
| 151 | # Test loader | |
| 152 | test_import("ollamatools.config.loader") | |
| 153 | ||
| 154 | # Test defaults | |
| 155 | test_import("ollamatools.config.defaults") | |
| 156 | ||
| 157 | def test_cli(): | |
| 158 | """Test command-line interface.""" | |
| 159 | print("\n=== Testing Command-Line Interface ===") | |
| 160 | ||
| 161 | # Test CLI main | |
| 162 | test_import("ollamatools.cli.main") | |
| 163 | ||
| 164 | def test_package_root(): | |
| 165 | """Test package root.""" | |
| 166 | print("\n=== Testing Package Root ===") | |
| 167 | ||
| 168 | # Test package initialization | |
| 169 | test_import("ollamatools") | |
| 170 | ||
| 171 | # Test version | |
| 172 | test_import("ollamatools.version") | |
| 173 | ||
| 174 | def main(): | |
| 175 | """Main entry point.""" | |
| 176 | if not os.path.exists(REFACTORED_DIR): | |
| 177 | print(f"Error: Directory '{REFACTORED_DIR}' not found.") | |
| 178 | print("Please run create_directory_structure.sh and copy_files.sh first.") | |
| 179 | return 1 | |
| 180 | ||
| 181 | print(f"Testing refactored code in '{REFACTORED_DIR}'...") | |
| 182 | ||
| 183 | # Test all components | |
| 184 | test_core_components() | |
| 185 | test_plugin_system() | |
| 186 | test_standard_plugins() | |
| 187 | test_tool_plugins() | |
| 188 | test_integration_plugins() | |
| 189 | test_agent_implementations() | |
| 190 | test_configuration_system() | |
| 191 | test_cli() | |
| 192 | test_package_root() | |
| 193 | ||
| 194 | print("\n=== Test Summary ===") | |
| 195 | print("All tests completed. Check the output above for any failures.") | |
| 196 | ||
| 197 | return 0 | |
| 198 | ||
| 199 | if __name__ == "__main__": | |
| 200 | sys.exit(main()) |
| … | … | @@ -0,0 +1,182 @@ |
| 1 | #!/usr/bin/env python3 | |
| 2 | """ | |
| 3 | Script to update imports in the refactored OllamaTools code. | |
| 4 | ||
| 5 | This script updates import statements in the refactored OllamaTools code to reflect | |
| 6 | the new directory structure. It replaces old import paths with new ones based on | |
| 7 | the file mapping defined in the simplified refactoring guide. | |
| 8 | ||
| 9 | Usage: | |
| 10 | python update_imports.py | |
| 11 | ||
| 12 | Note: | |
| 13 | This script assumes that the refactored code is in the 'ollamatools-new' directory. | |
| 14 | Make sure to run create_directory_structure.sh and copy_files.sh before running this script. | |
| 15 | """ | |
| 16 | ||
| 17 | import os | |
| 18 | import re | |
| 19 | import sys | |
| 20 | ||
| 21 | # Set the base directory for the new structure | |
| 22 | BASE_DIR = "ollamatools-new" | |
| 23 | ||
| 24 | # Define import mappings (old import -> new import) | |
| 25 | IMPORT_MAPPINGS = [ | |
| 26 | # Core module | |
| 27 | (r'from ollamatools\.agent import', 'from ollamatools.core.agent import'), | |
| 28 | (r'from ollamatools import agent', 'from ollamatools.core import agent'), | |
| 29 | (r'import ollamatools\.agent', 'import ollamatools.core.agent'), | |
| 30 | ||
| 31 | (r'from ollamatools\.errors import', 'from ollamatools.core.errors import'), | |
| 32 | (r'from ollamatools import errors', 'from ollamatools.core import errors'), | |
| 33 | (r'import ollamatools\.errors', 'import ollamatools.core.errors'), | |
| 34 | ||
| 35 | (r'from ollamatools\.config import', 'from ollamatools.core.config import'), | |
| 36 | (r'from ollamatools import config', 'from ollamatools.core import config'), | |
| 37 | (r'import ollamatools\.config', 'import ollamatools.core.config'), | |
| 38 | ||
| 39 | (r'from ollamatools\.security import', 'from ollamatools.core.security import'), | |
| 40 | (r'from ollamatools import security', 'from ollamatools.core import security'), | |
| 41 | (r'import ollamatools\.security', 'import ollamatools.core.security'), | |
| 42 | ||
| 43 | (r'from ollamatools\.logger import', 'from ollamatools.core.utils.logger import'), | |
| 44 | (r'from ollamatools import logger', 'from ollamatools.core.utils import logger'), | |
| 45 | (r'import ollamatools\.logger', 'import ollamatools.core.utils.logger'), | |
| 46 | ||
| 47 | (r'from ollamatools\.command_validator import', 'from ollamatools.core.utils.validators.command import'), | |
| 48 | (r'from ollamatools import command_validator', 'from ollamatools.core.utils.validators import command'), | |
| 49 | (r'import ollamatools\.command_validator', 'import ollamatools.core.utils.validators.command'), | |
| 50 | ||
| 51 | (r'from ollamatools\.path_validator import', 'from ollamatools.core.utils.validators.path import'), | |
| 52 | (r'from ollamatools import path_validator', 'from ollamatools.core.utils.validators import path'), | |
| 53 | (r'import ollamatools\.path_validator', 'import ollamatools.core.utils.validators.path'), | |
| 54 | ||
| 55 | (r'from ollamatools\.url_validator import', 'from ollamatools.core.utils.validators.url import'), | |
| 56 | (r'from ollamatools import url_validator', 'from ollamatools.core.utils.validators import url'), | |
| 57 | (r'import ollamatools\.url_validator', 'import ollamatools.core.utils.validators.url'), | |
| 58 | ||
| 59 | # Agent implementations | |
| 60 | (r'from ollamatools\.agent\.core import', 'from ollamatools.agents.basic import'), | |
| 61 | (r'from ollamatools\.agent import core', 'from ollamatools.agents import basic'), | |
| 62 | (r'import ollamatools\.agent\.core', 'import ollamatools.agents.basic'), | |
| 63 | ||
| 64 | (r'from ollamatools\.agent\.modular\.agent import', 'from ollamatools.agents.modular import'), | |
| 65 | (r'from ollamatools\.agent\.modular import agent', 'from ollamatools.agents import modular'), | |
| 66 | (r'import ollamatools\.agent\.modular\.agent', 'import ollamatools.agents.modular'), | |
| 67 | ||
| 68 | (r'from ollamatools\.agent\.extended\.agent import', 'from ollamatools.agents.extended import'), | |
| 69 | (r'from ollamatools\.agent\.extended import agent', 'from ollamatools.agents import extended'), | |
| 70 | (r'import ollamatools\.agent\.extended\.agent', 'import ollamatools.agents.extended'), | |
| 71 | ||
| 72 | # Standard plugins | |
| 73 | (r'from ollamatools\.agent\.modular\.search import', 'from ollamatools.plugins.standard.search import'), | |
| 74 | (r'from ollamatools\.agent\.modular import search', 'from ollamatools.plugins.standard import search'), | |
| 75 | (r'import ollamatools\.agent\.modular\.search', 'import ollamatools.plugins.standard.search'), | |
| 76 | ||
| 77 | (r'from ollamatools\.agent\.modular\.commands import', 'from ollamatools.plugins.standard.commands import'), | |
| 78 | (r'from ollamatools\.agent\.modular import commands', 'from ollamatools.plugins.standard import commands'), | |
| 79 | (r'import ollamatools\.agent\.modular\.commands', 'import ollamatools.plugins.standard.commands'), | |
| 80 | ||
| 81 | (r'from ollamatools\.plugins\.conversation_history import', 'from ollamatools.plugins.standard.conversation.history import'), | |
| 82 | (r'from ollamatools\.plugins import conversation_history', 'from ollamatools.plugins.standard.conversation import history'), | |
| 83 | (r'import ollamatools\.plugins\.conversation_history', 'import ollamatools.plugins.standard.conversation.history'), | |
| 84 | ||
| 85 | (r'from ollamatools\.plugins\.conversation_context import', 'from ollamatools.plugins.standard.conversation.context import'), | |
| 86 | (r'from ollamatools\.plugins import conversation_context', 'from ollamatools.plugins.standard.conversation import context'), | |
| 87 | (r'import ollamatools\.plugins\.conversation_context', 'import ollamatools.plugins.standard.conversation.context'), | |
| 88 | ||
| 89 | (r'from ollamatools\.agent\.modular\.feedback import', 'from ollamatools.plugins.standard.feedback import'), | |
| 90 | (r'from ollamatools\.agent\.modular import feedback', 'from ollamatools.plugins.standard import feedback'), | |
| 91 | (r'import ollamatools\.agent\.modular\.feedback', 'import ollamatools.plugins.standard.feedback'), | |
| 92 | ||
| 93 | (r'from ollamatools\.agent\.modular\.issues import', 'from ollamatools.plugins.standard.issues import'), | |
| 94 | (r'from ollamatools\.agent\.modular import issues', 'from ollamatools.plugins.standard import issues'), | |
| 95 | (r'import ollamatools\.agent\.modular\.issues', 'import ollamatools.plugins.standard.issues'), | |
| 96 | ||
| 97 | # Tool plugins | |
| 98 | (r'from ollamatools\.tools\.system_tools import', 'from ollamatools.plugins.tools.system import'), | |
| 99 | (r'from ollamatools\.tools import system_tools', 'from ollamatools.plugins.tools import system'), | |
| 100 | (r'import ollamatools\.tools\.system_tools', 'import ollamatools.plugins.tools.system'), | |
| 101 | ||
| 102 | (r'from ollamatools\.tools\.web_tools import', 'from ollamatools.plugins.tools.web import'), | |
| 103 | (r'from ollamatools\.tools import web_tools', 'from ollamatools.plugins.tools import web'), | |
| 104 | (r'import ollamatools\.tools\.web_tools', 'import ollamatools.plugins.tools.web'), | |
| 105 | ||
| 106 | (r'from ollamatools\.tools\.doc_tools import', 'from ollamatools.plugins.tools.doc import'), | |
| 107 | (r'from ollamatools\.tools import doc_tools', 'from ollamatools.plugins.tools import doc'), | |
| 108 | (r'import ollamatools\.tools\.doc_tools', 'import ollamatools.plugins.tools.doc'), | |
| 109 | ||
| 110 | # Matrix integration | |
| 111 | (r'from ollamatools\.tools\.matrix_tools import', 'from ollamatools.plugins.integrations.matrix.client import'), | |
| 112 | (r'from ollamatools\.tools import matrix_tools', 'from ollamatools.plugins.integrations.matrix import client'), | |
| 113 | (r'import ollamatools\.tools\.matrix_tools', 'import ollamatools.plugins.integrations.matrix.client'), | |
| 114 | ||
| 115 | (r'from ollamatools\.tools\.enhanced_matrix_tools import', 'from ollamatools.plugins.integrations.matrix.commands import'), | |
| 116 | (r'from ollamatools\.tools import enhanced_matrix_tools', 'from ollamatools.plugins.integrations.matrix import commands'), | |
| 117 | (r'import ollamatools\.tools\.enhanced_matrix_tools', 'import ollamatools.plugins.integrations.matrix.commands'), | |
| 118 | ||
| 119 | (r'from ollamatools\.tools\.enhanced_matrix_search import', 'from ollamatools.plugins.integrations.matrix.search import'), | |
| 120 | (r'from ollamatools\.tools import enhanced_matrix_search', 'from ollamatools.plugins.integrations.matrix import search'), | |
| 121 | (r'import ollamatools\.tools\.enhanced_matrix_search', 'import ollamatools.plugins.integrations.matrix.search'), | |
| 122 | ||
| 123 | (r'from ollamatools\.tools\.enhanced_matrix_history import', 'from ollamatools.plugins.integrations.matrix.history import'), | |
| 124 | (r'from ollamatools\.tools import enhanced_matrix_history', 'from ollamatools.plugins.integrations.matrix import history'), | |
| 125 | (r'import ollamatools\.tools\.enhanced_matrix_history', 'import ollamatools.plugins.integrations.matrix.history'), | |
| 126 | ||
| 127 | (r'from ollamatools\.tools\.matrix_rate_limit_patch import', 'from ollamatools.plugins.integrations.matrix.rate_limit import'), | |
| 128 | (r'from ollamatools\.tools import matrix_rate_limit_patch', 'from ollamatools.plugins.integrations.matrix import rate_limit'), | |
| 129 | (r'import ollamatools\.tools\.matrix_rate_limit_patch', 'import ollamatools.plugins.integrations.matrix.rate_limit'), | |
| 130 | ||
| 131 | # OpenSearch integration | |
| 132 | (r'from ollamatools\.opensearch_web_tools import', 'from ollamatools.plugins.integrations.opensearch.tools import'), | |
| 133 | (r'from ollamatools import opensearch_web_tools', 'from ollamatools.plugins.integrations.opensearch import tools'), | |
| 134 | (r'import ollamatools\.opensearch_web_tools', 'import ollamatools.plugins.integrations.opensearch.tools'), | |
| 135 | ||
| 136 | # Configuration system | |
| 137 | (r'from ollamatools\.config\.core_config import', 'from ollamatools.config.loader import'), | |
| 138 | (r'from ollamatools\.config import core_config', 'from ollamatools.config import loader'), | |
| 139 | (r'import ollamatools\.config\.core_config', 'import ollamatools.config.loader'), | |
| 140 | ||
| 141 | (r'from ollamatools\.config\.plugin_config import', 'from ollamatools.config.defaults import'), | |
| 142 | (r'from ollamatools\.config import plugin_config', 'from ollamatools.config import defaults'), | |
| 143 | (r'import ollamatools\.config\.plugin_config', 'import ollamatools.config.defaults'), | |
| 144 | ] | |
| 145 | ||
| 146 | def update_imports(file_path): | |
| 147 | """Update import statements in a file.""" | |
| 148 | with open(file_path, 'r') as f: | |
| 149 | content = f.read() | |
| 150 | ||
| 151 | # Apply import mappings | |
| 152 | for old_import, new_import in IMPORT_MAPPINGS: | |
| 153 | content = re.sub(old_import, new_import, content) | |
| 154 | ||
| 155 | with open(file_path, 'w') as f: | |
| 156 | f.write(content) | |
| 157 | ||
| 158 | def main(): | |
| 159 | """Main entry point.""" | |
| 160 | if not os.path.exists(BASE_DIR): | |
| 161 | print(f"Error: Directory '{BASE_DIR}' not found.") | |
| 162 | print("Please run create_directory_structure.sh and copy_files.sh first.") | |
| 163 | return 1 | |
| 164 | ||
| 165 | print(f"Updating imports in '{BASE_DIR}'...") | |
| 166 | ||
| 167 | # Process all Python files in the new structure | |
| 168 | for root, dirs, files in os.walk(BASE_DIR): | |
| 169 | for file in files: | |
| 170 | if file.endswith('.py'): | |
| 171 | file_path = os.path.join(root, file) | |
| 172 | print(f"Updating imports in {file_path}") | |
| 173 | update_imports(file_path) | |
| 174 | ||
| 175 | print("Imports updated successfully.") | |
| 176 | print("Next steps:") | |
| 177 | print("1. Test the refactored code with: python simplified_guides/test_refactored_code.py") | |
| 178 | ||
| 179 | return 0 | |
| 180 | ||
| 181 | if __name__ == "__main__": | |
| 182 | sys.exit(main()) |
| … | … | @@ -49,22 +49,16 @@ if ! grep -q "\`$ORIGINAL_FILE\`" "$MAPPING_FILE"; then |
| 49 | 49 | exit 1 |
| 50 | 50 | fi |
| 51 | 51 | |
| 52 | # Get the new file path from the mapping file | |
| 53 | NEW_FILE=$(grep "\`$ORIGINAL_FILE\`" "$MAPPING_FILE" | sed -E 's/.*\| `[^`]+` \| `([^`]+)`.*/\1/') | |
| 54 | ||
| 55 | # Escape special characters in the new file path for use in sed | |
| 56 | ESCAPED_NEW_FILE=$(echo "$NEW_FILE" | sed 's/\//\\\//g') | |
| 57 | ||
| 58 | 52 | # If notes are provided, update both status and notes |
| 59 | 53 | if [ -n "$NEW_NOTES" ]; then |
| 60 | 54 | # Escape special characters in the notes for use in sed |
| 61 | 55 | ESCAPED_NOTES=$(echo "$NEW_NOTES" | sed 's/\//\\\//g') |
| 62 | 56 | |
| 63 | 57 | # Update the status and notes |
| 64 | sed -i "s/| \`$ESCAPED_FILE\` | \`[^']*\` | [^|]* | [^|]* |/| \`$ESCAPED_FILE\` | \`$ESCAPED_NEW_FILE\` | $NEW_STATUS | $ESCAPED_NOTES |/" "$MAPPING_FILE" | |
| 58 | sed -i "s/| \`$ESCAPED_FILE\` | \`[^']*\` | [^|]* | [^|]* |/| \`$ESCAPED_FILE\` | \`&\` | $NEW_STATUS | $ESCAPED_NOTES |/" "$MAPPING_FILE" | |
| 65 | 59 | else |
| 66 | 60 | # Update only the status |
| 67 | sed -i "s/| \`$ESCAPED_FILE\` | \`[^']*\` | [^|]* |/| \`$ESCAPED_FILE\` | \`$ESCAPED_NEW_FILE\` | $NEW_STATUS |/" "$MAPPING_FILE" | |
| 61 | sed -i "s/| \`$ESCAPED_FILE\` | \`[^']*\` | [^|]* |/| \`$ESCAPED_FILE\` | \`&\` | $NEW_STATUS |/" "$MAPPING_FILE" | |
| 68 | 62 | fi |
| 69 | 63 | |
| 70 | 64 | echo "Updated status of $ORIGINAL_FILE to '$NEW_STATUS'." |