OverviewFilesCommitsIssuesDocsReleasesPeers

ollama_semantic_function_calling commits / 1816c15

matrix-cmd working ?
1816c15c98af5ed7dd86110b2dbea6b60a061b4c
by fleeky.ashatron <fleeky@7rnx.net> · 2025-04-19T23:01:53.000Z

Changed files (20) +2483 -223

ollamatools-project/REFACTORING_SCRIPTS.md +9 -27
……@@ -2,22 +2,6 @@
22
33This document provides a summary of all the scripts created to help with the refactoring process for the OllamaTools project.
44
5## Git Scripts
6
7### `git_refactoring_commands.sh`
8
9Provides 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
215## Setup Scripts
226
237### `setup_refactored_structure.sh`
……@@ -158,14 +142,12 @@ Provides a step-by-step guide for the refactoring process.
158142
159143The typical workflow for using these scripts is:
160144
1611. Run `./git_refactoring_commands.sh` to understand the Git workflow for the refactoring process
1622. Run `./setup_refactored_structure.sh` to create the new directory structure
1633. Run `./generate_file_mapping.sh` to create the file mapping
1644. Follow the steps in `./refactoring_guide.sh` to refactor the codebase
1655. Use `./copy_refactor_file.sh` to copy and refactor files
1666. Use `./update_mapping_status.sh` to track progress
1677. Use `./test_refactored_code.sh` to test the refactored code
1688. Run `./finalize_refactoring.sh` to finalize the refactoring process
1699. Use Git commands from `./git_refactoring_commands.sh` to commit and push your changes
170
171This workflow ensures a systematic and organized approach to the refactoring process, with proper tracking, testing, and version control at each step.
1451. Run `./setup_refactored_structure.sh` to create the new directory structure
1462. Run `./generate_file_mapping.sh` to create the file mapping
1473. Follow the steps in `./refactoring_guide.sh` to refactor the codebase
1484. Use `./copy_refactor_file.sh` to copy and refactor files
1495. Use `./update_mapping_status.sh` to track progress
1506. Use `./test_refactored_code.sh` to test the refactored code
1517. Run `./finalize_refactoring.sh` to finalize the refactoring process
152
153This workflow ensures a systematic and organized approach to the refactoring process, with proper tracking and testing at each step.
ollamatools-project/examples/config/enhanced_matrix_config.yaml +2 -2
……@@ -4,8 +4,8 @@ MATRIX:
44 PASSWORD: "chat7rn"
55 DEVICE_ID: "ollamatools-matrix"
66 ROOMS:
7 - "#general:prsm.space"
8 - "#ai_bot_testing:prsm.space"
7 # - "#general:prsm.space"
8 - "#ai_testing:prsm.space"
99 ADMIN_USERS:
1010 - "@chat7rn:prsm.space"
1111
ollamatools-project/examples/config/matrix_config.yaml +1 -1
……@@ -4,7 +4,7 @@ MATRIX:
44 PASSWORD: "chat7rn"
55 DEVICE_ID: "ollamatools-matrix"
66 ROOMS:
7 - "#general:prsm.space"
7 - "#ai_testing:prsm.space"
88OLLAMA:
99 HOST: "localhost:11434"
1010 MODEL: "llama3.1:latest"
ollamatools-project/git_refactoring_commands.sh +0 -185
……@@ -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
7RED='\033[0;31m'
8GREEN='\033[0;32m'
9YELLOW='\033[0;33m'
10BLUE='\033[0;34m'
11PURPLE='\033[0;35m'
12CYAN='\033[0;36m'
13NC='\033[0m' # No Color
14
15# Function to print section headers
16print_header() {
17 echo -e "\n${BLUE}========== $1 ==========${NC}\n"
18}
19
20# Function to print steps
21print_step() {
22 echo -e "${GREEN}Step $1:${NC} $2"
23}
24
25# Function to print commands
26print_command() {
27 echo -e " ${YELLOW}$1${NC}"
28}
29
30# Function to print notes
31print_note() {
32 echo -e " ${PURPLE}Note:${NC} $1"
33}
34
35# Function to print warnings
36print_warning() {
37 echo -e " ${RED}Warning:${NC} $1"
38}
39
40# Clear the screen
41clear
42
43# Print the title
44echo -e "${CYAN}"
45echo "======================================================"
46echo " OllamaTools Git Refactoring Commands"
47echo "======================================================"
48echo -e "${NC}"
49echo "This script provides Git commands for different stages of the refactoring process."
50echo "Follow these commands to ensure proper version control during the refactoring."
51echo ""
52echo -e "${YELLOW}Note: This is a guide only. You will need to run the commands manually.${NC}"
53echo ""
54
55# Phase 1: Initial Setup
56print_header "Phase 1: Initial Setup"
57
58print_step "1" "Verify you're on the correct branch"
59print_command "git status"
60print_note "Ensure you're on the 'simplify' branch"
61
62print_step "2" "Create a new branch for the refactoring scripts (if needed)"
63print_command "git checkout -b refactoring-scripts"
64print_note "This creates a new branch for the refactoring scripts"
65print_warning "Skip this step if you want to keep working on the 'simplify' branch"
66
67print_step "3" "Add the refactoring scripts to Git"
68print_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"
69print_note "This adds all the refactoring scripts to Git"
70
71print_step "4" "Add the documentation files to Git"
72print_command "git add README_REFACTORING.md REFACTORING_SCRIPTS.md file_mapping.md"
73print_note "This adds all the documentation files to Git"
74
75print_step "5" "Commit the refactoring scripts and documentation"
76print_command "git commit -m 'Add refactoring scripts and documentation'"
77print_note "This commits all the refactoring scripts and documentation"
78
79# Phase 2: Refactoring Process
80print_header "Phase 2: Refactoring Process"
81
82print_step "1" "Create a new branch for the refactored code"
83print_command "git checkout -b refactored-code"
84print_note "This creates a new branch for the refactored code"
85print_warning "This should be done after running setup_refactored_structure.sh"
86
87print_step "2" "Add the new directory to .gitignore (optional)"
88print_command "echo '../ollamatools-new/' >> .gitignore"
89print_command "git add .gitignore"
90print_command "git commit -m 'Add ollamatools-new to .gitignore'"
91print_note "This prevents the new directory from being tracked by Git until it's ready"
92print_warning "Skip this step if you want to track the new directory with Git"
93
94print_step "3" "Commit changes after each phase of refactoring"
95print_command "git add ."
96print_command "git commit -m 'Complete Phase X: [Description]'"
97print_note "Replace X with the phase number and [Description] with a brief description"
98print_note "Commit after each major phase to maintain a clean history"
99
100# Phase 3: Testing
101print_header "Phase 3: Testing"
102
103print_step "1" "Create a branch for testing the refactored code"
104print_command "git checkout -b refactored-testing"
105print_note "This creates a new branch for testing the refactored code"
106print_warning "This should be done after completing the refactoring"
107
108print_step "2" "Commit test results and fixes"
109print_command "git add ."
110print_command "git commit -m 'Test results and fixes for [Component]'"
111print_note "Replace [Component] with the component being tested"
112print_note "Commit after testing each major component"
113
114# Phase 4: Finalization
115print_header "Phase 4: Finalization"
116
117print_step "1" "Merge the refactored code back to the main branch"
118print_command "git checkout simplify"
119print_command "git merge refactored-testing"
120print_note "This merges the refactored code back to the main branch"
121print_warning "Resolve any merge conflicts that may arise"
122
123print_step "2" "Tag the release"
124print_command "git tag -a v2.0.0 -m 'Refactored version 2.0.0'"
125print_note "This tags the release with a version number"
126print_note "Replace v2.0.0 with the appropriate version number"
127
128print_step "3" "Push the changes to the remote repository"
129print_command "git push origin simplify"
130print_command "git push origin v2.0.0"
131print_note "This pushes the changes and tag to the remote repository"
132
133# Current Status
134print_header "Current Status"
135
136print_step "1" "Add and commit the current refactoring scripts"
137print_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"
138print_command "git commit -m 'Add refactoring scripts and documentation'"
139print_note "This adds and commits all the current refactoring scripts and documentation"
140
141print_step "2" "Push the changes to the remote repository"
142print_command "git push origin simplify"
143print_note "This pushes the changes to the remote repository"
144
145print_header "Git Commands Cheat Sheet"
146
147echo -e "${GREEN}Branching:${NC}"
148echo -e " ${YELLOW}git branch${NC} - List all branches"
149echo -e " ${YELLOW}git checkout <branch>${NC} - Switch to branch"
150echo -e " ${YELLOW}git checkout -b <new-branch>${NC} - Create and switch to new branch"
151
152echo -e "${GREEN}Status and Diff:${NC}"
153echo -e " ${YELLOW}git status${NC} - Show status of working directory"
154echo -e " ${YELLOW}git diff${NC} - Show changes in working directory"
155echo -e " ${YELLOW}git diff --staged${NC} - Show changes in staging area"
156
157echo -e "${GREEN}Staging and Committing:${NC}"
158echo -e " ${YELLOW}git add <file>${NC} - Add file to staging area"
159echo -e " ${YELLOW}git add .${NC} - Add all changes to staging area"
160echo -e " ${YELLOW}git commit -m 'message'${NC} - Commit staged changes"
161
162echo -e "${GREEN}History:${NC}"
163echo -e " ${YELLOW}git log${NC} - Show commit history"
164echo -e " ${YELLOW}git log --oneline${NC} - Show commit history (one line per commit)"
165echo -e " ${YELLOW}git blame <file>${NC} - Show who changed what in a file"
166
167echo -e "${GREEN}Remote Operations:${NC}"
168echo -e " ${YELLOW}git push origin <branch>${NC} - Push changes to remote repository"
169echo -e " ${YELLOW}git pull origin <branch>${NC} - Pull changes from remote repository"
170echo -e " ${YELLOW}git fetch${NC} - Fetch changes from remote repository"
171
172echo -e "${GREEN}Merging and Rebasing:${NC}"
173echo -e " ${YELLOW}git merge <branch>${NC} - Merge branch into current branch"
174echo -e " ${YELLOW}git rebase <branch>${NC} - Rebase current branch onto branch"
175echo -e " ${YELLOW}git cherry-pick <commit>${NC} - Apply changes from a specific commit"
176
177echo -e "${GREEN}Stashing:${NC}"
178echo -e " ${YELLOW}git stash${NC} - Stash changes in working directory"
179echo -e " ${YELLOW}git stash pop${NC} - Apply and remove the latest stash"
180echo -e " ${YELLOW}git stash list${NC} - List all stashes"
181
182echo -e "${GREEN}Tagging:${NC}"
183echo -e " ${YELLOW}git tag${NC} - List all tags"
184echo -e " ${YELLOW}git tag -a <tag> -m 'message'${NC} - Create annotated tag"
185echo -e " ${YELLOW}git push origin <tag>${NC} - Push tag to remote repository"
ollamatools-project/simplified_guides/00_INDEX.md +47 -0
……@@ -0,0 +1,47 @@
1# OllamaTools Simplified Refactoring Guide - Index
2
3This 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
7The simplified refactoring guide is organized into the following documents:
8
91. **[00_INDEX.md](./00_INDEX.md)** - This index document
102. **[01_SIMPLIFIED_STRUCTURE.md](./01_SIMPLIFIED_STRUCTURE.md)** - The simplified file structure and file mapping strategy
113. **[02_IMPLEMENTATION_STEPS.md](./02_IMPLEMENTATION_STEPS.md)** - Detailed implementation steps for the simplified structure
124. **[03_FILE_MAPPING.md](./03_FILE_MAPPING.md)** - Complete file mapping table for reference
13
14## Purpose
15
16This guide aims to provide a clear, step-by-step approach to refactoring the OllamaTools project in a way that:
17
181. Maintains the target directory structure from the original AI simplification guides
192. Avoids creating files that are too large to manage
203. Preserves existing functionality
214. Minimizes the risk of introducing bugs during refactoring
22
23## How to Use This Guide
24
25This guide is designed to be followed sequentially:
26
271. Start by reviewing the simplified structure in [01_SIMPLIFIED_STRUCTURE.md](./01_SIMPLIFIED_STRUCTURE.md)
282. Follow the implementation steps in [02_IMPLEMENTATION_STEPS.md](./02_IMPLEMENTATION_STEPS.md)
293. Use the file mapping table in [03_FILE_MAPPING.md](./03_FILE_MAPPING.md) as a reference during implementation
30
31For 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
39The implementation can be broken down into manageable chunks:
40
411. **Week 1**: Create directory structure, copy files
422. **Week 2**: Update imports and references
433. **Week 3**: Implement new files
444. **Week 4**: Update package initialization, test code
455. **Week 5**: Documentation, migration guide, final steps
46
47By 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.
ollamatools-project/simplified_guides/01_SIMPLIFIED_STRUCTURE.md +172 -0
……@@ -0,0 +1,172 @@
1# Simplified File Structure for OllamaTools Project
2
3This 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
7Analysis 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
16Merging these already large files would create files that are too difficult to maintain.
17
18## Revised Simplified Structure
19
20The 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```
23ollamatools/
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
1011. **Validators Directory**: Instead of merging all validators into a single file, keep them separate to avoid creating another large file.
102
1032. **Matrix Integration**: Keep Matrix-related files separate rather than merging them, as the original matrix_tools.py is already 800 lines.
104
1053. **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
1631. **Maintains file granularity**: Avoids creating files that are too large to manage
1642. **Preserves existing functionality**: Each file maintains its original purpose
1653. **Follows the target architecture**: Organizes code according to the simplified structure
1664. **Easier to implement**: Simpler to move files than to merge and refactor them
1675. **Reduced risk**: Less chance of introducing bugs during the refactoring process
1686. **Easier to review**: Changes are more isolated and easier to understand
169
170## Next Steps
171
172After understanding the simplified file structure and mapping strategy, proceed to the [Implementation Steps](./02_IMPLEMENTATION_STEPS.md) document to begin implementing the simplified structure.
ollamatools-project/simplified_guides/02_IMPLEMENTATION_STEPS.md +457 -0
……@@ -0,0 +1,457 @@
1# Detailed Implementation Steps for the Simplified Structure
2
3This 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
71. **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
202. **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
271. **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
372. **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
853. **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
1001. **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
1252. **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
1303. **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
1361. **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
1722. **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
2033. **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
2214. **Implement other new files** with appropriate content based on their purpose.
222
223## Phase 5: Update Package Initialization
224
2251. **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
2462. **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
2561. **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
2792. **Run existing tests** against the refactored code:
280 ```bash
281 # Run tests with the refactored code
282 PYTHONPATH=ollamatools-new pytest tests/
283 ```
284
2853. **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
2921. **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
2972. **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
3301. **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
3502. **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
3603. **Final verification**:
361 - Run all tests
362 - Verify all examples work
363 - Check documentation
364
365## Implementation Timeline
366
367This implementation can be broken down into manageable chunks:
368
3691. **Week 1**: Phases 1-2 (Create directory structure, copy files)
3702. **Week 2**: Phase 3 (Update imports and references)
3713. **Week 3**: Phase 4 (Implement new files)
3724. **Week 4**: Phases 5-6 (Update package initialization, test code)
3735. **Week 5**: Phases 7-8 (Documentation, migration guide, final steps)
374
375By 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
379To facilitate the implementation, we can create several automation scripts:
380
3811. **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
4022. **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
4163. **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
4424. **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
453These scripts can be used to automate the implementation process and ensure consistency.
454
455## Next Steps
456
457After implementing the simplified structure, proceed to the [File Mapping](./03_FILE_MAPPING.md) document for a complete reference of the file mapping.
ollamatools-project/simplified_guides/03_FILE_MAPPING.md +112 -0
……@@ -0,0 +1,112 @@
1# Complete File Mapping for OllamaTools Refactoring
2
3This 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
72Special 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
81These 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
85The 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
98The 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
106Use 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
108To 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
112After reviewing this file mapping, proceed to implement the refactoring according to the steps outlined in the [Implementation Steps](./02_IMPLEMENTATION_STEPS.md) document.
ollamatools-project/simplified_guides/MIGRATION_GUIDE.md +363 -0
……@@ -0,0 +1,363 @@
1# Migration Guide for OllamaTools Refactoring
2
3This 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
7The 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
13from ollamatools.agent import Agent
14from ollamatools import agent
15import ollamatools.agent
16```
17
18**New imports:**
19```python
20from ollamatools.core.agent import Agent
21from ollamatools.core import agent
22import ollamatools.core.agent
23```
24
25### Agent Implementations
26
27**Old imports:**
28```python
29from ollamatools.agent.core import BasicAgent
30from ollamatools.agent.modular.agent import ModularAgent
31from ollamatools.agent.extended.agent import ExtendedAgent
32```
33
34**New imports:**
35```python
36from ollamatools.agents.basic import BasicAgent
37from ollamatools.agents.modular import ModularAgent
38from ollamatools.agents.extended import ExtendedAgent
39```
40
41### Standard Plugins
42
43**Old imports:**
44```python
45from ollamatools.agent.modular.search import search_function
46from ollamatools.agent.modular.commands import execute_command
47from ollamatools.plugins.conversation_history import ConversationHistory
48from ollamatools.plugins.conversation_context import ConversationContext
49from ollamatools.agent.modular.feedback import collect_feedback
50from ollamatools.agent.modular.issues import track_issue
51```
52
53**New imports:**
54```python
55from ollamatools.plugins.standard.search import search_function
56from ollamatools.plugins.standard.commands import execute_command
57from ollamatools.plugins.standard.conversation.history import ConversationHistory
58from ollamatools.plugins.standard.conversation.context import ConversationContext
59from ollamatools.plugins.standard.feedback import collect_feedback
60from ollamatools.plugins.standard.issues import track_issue
61```
62
63### Tool Plugins
64
65**Old imports:**
66```python
67from ollamatools.tools.system_tools import execute_system_command
68from ollamatools.tools.web_tools import make_web_request
69from ollamatools.tools.doc_tools import generate_documentation
70```
71
72**New imports:**
73```python
74from ollamatools.plugins.tools.system import execute_system_command
75from ollamatools.plugins.tools.web import make_web_request
76from ollamatools.plugins.tools.doc import generate_documentation
77```
78
79### Matrix Integration
80
81**Old imports:**
82```python
83from ollamatools.tools.matrix_tools import MatrixClient
84from ollamatools.tools.enhanced_matrix_tools import EnhancedMatrixClient
85from ollamatools.tools.enhanced_matrix_search import MatrixSearch
86from ollamatools.tools.enhanced_matrix_history import MatrixHistory
87from ollamatools.tools.matrix_rate_limit_patch import apply_rate_limit_patch
88```
89
90**New imports:**
91```python
92from ollamatools.plugins.integrations.matrix.client import MatrixClient
93from ollamatools.plugins.integrations.matrix.commands import EnhancedMatrixClient
94from ollamatools.plugins.integrations.matrix.search import MatrixSearch
95from ollamatools.plugins.integrations.matrix.history import MatrixHistory
96from ollamatools.plugins.integrations.matrix.rate_limit import apply_rate_limit_patch
97```
98
99### OpenSearch Integration
100
101**Old imports:**
102```python
103from ollamatools.opensearch_web_tools import OpenSearchWebTools
104```
105
106**New imports:**
107```python
108from ollamatools.plugins.integrations.opensearch.tools import OpenSearchWebTools
109```
110
111### Configuration System
112
113**Old imports:**
114```python
115from ollamatools.config.core_config import load_config
116from ollamatools.config.plugin_config import get_plugin_config
117```
118
119**New imports:**
120```python
121from ollamatools.config.loader import load_config
122from ollamatools.config.defaults import get_plugin_config
123```
124
125## Creating Agents
126
127### Basic Agent
128
129**Old code:**
130```python
131from ollamatools.agent.core import BasicAgent
132
133agent = BasicAgent(model="llama2")
134response = agent.chat("Hello, world!")
135```
136
137**New code:**
138```python
139from ollamatools.agents.basic import BasicAgent
140
141agent = BasicAgent(model="llama2")
142response = agent.chat("Hello, world!")
143```
144
145### Modular Agent
146
147**Old code:**
148```python
149from ollamatools.agent.modular.agent import ModularAgent
150from ollamatools.agent.modular.search import SearchModule
151from ollamatools.agent.modular.commands import CommandsModule
152
153agent = ModularAgent(model="llama2")
154agent.add_module(SearchModule())
155agent.add_module(CommandsModule())
156response = agent.chat("Search for information about Python")
157```
158
159**New code:**
160```python
161from ollamatools.agents.modular import ModularAgent
162from ollamatools.plugins.standard.search import SearchPlugin
163from ollamatools.plugins.standard.commands import CommandsPlugin
164
165agent = ModularAgent(model="llama2")
166agent.add_plugin(SearchPlugin())
167agent.add_plugin(CommandsPlugin())
168response = agent.chat("Search for information about Python")
169```
170
171### Extended Agent
172
173**Old code:**
174```python
175from ollamatools.agent.extended.agent import ExtendedAgent
176
177agent = ExtendedAgent(model="llama2")
178response = agent.chat("Remember this information for later")
179```
180
181**New code:**
182```python
183from ollamatools.agents.extended import ExtendedAgent
184
185agent = ExtendedAgent(model="llama2")
186response = agent.chat("Remember this information for later")
187```
188
189## Using Plugins
190
191### Search Plugin
192
193**Old code:**
194```python
195from ollamatools.agent.modular.search import search_web
196
197results = search_web("Python programming")
198```
199
200**New code:**
201```python
202from ollamatools.plugins.standard.search import search_web
203
204results = search_web("Python programming")
205```
206
207### Commands Plugin
208
209**Old code:**
210```python
211from ollamatools.agent.modular.commands import execute_command
212
213result = execute_command("ls -la")
214```
215
216**New code:**
217```python
218from ollamatools.plugins.standard.commands import execute_command
219
220result = execute_command("ls -la")
221```
222
223### Conversation History Plugin
224
225**Old code:**
226```python
227from ollamatools.plugins.conversation_history import ConversationHistory
228
229history = ConversationHistory()
230history.add_message("user", "Hello")
231history.add_message("assistant", "Hi there!")
232```
233
234**New code:**
235```python
236from ollamatools.plugins.standard.conversation.history import ConversationHistory
237
238history = ConversationHistory()
239history.add_message("user", "Hello")
240history.add_message("assistant", "Hi there!")
241```
242
243## Using Tools
244
245### System Tools
246
247**Old code:**
248```python
249from ollamatools.tools.system_tools import execute_system_command, read_file
250
251result = execute_system_command("ls -la")
252content = read_file("example.txt")
253```
254
255**New code:**
256```python
257from ollamatools.plugins.tools.system import execute_system_command, read_file
258
259result = execute_system_command("ls -la")
260content = read_file("example.txt")
261```
262
263### Web Tools
264
265**Old code:**
266```python
267from ollamatools.tools.web_tools import make_web_request
268
269response = make_web_request("https://example.com")
270```
271
272**New code:**
273```python
274from ollamatools.plugins.tools.web import make_web_request
275
276response = make_web_request("https://example.com")
277```
278
279## Using Integrations
280
281### Matrix Integration
282
283**Old code:**
284```python
285from ollamatools.tools.matrix_tools import MatrixClient
286
287client = MatrixClient(homeserver="https://matrix.org", token="your_token")
288client.send_message("!roomid:matrix.org", "Hello, Matrix!")
289```
290
291**New code:**
292```python
293from ollamatools.plugins.integrations.matrix.client import MatrixClient
294
295client = MatrixClient(homeserver="https://matrix.org", token="your_token")
296client.send_message("!roomid:matrix.org", "Hello, Matrix!")
297```
298
299### OpenSearch Integration
300
301**Old code:**
302```python
303from ollamatools.opensearch_web_tools import OpenSearchWebTools
304
305opensearch = OpenSearchWebTools(host="localhost", port=9200)
306results = opensearch.search("example query")
307```
308
309**New code:**
310```python
311from ollamatools.plugins.integrations.opensearch.tools import OpenSearchWebTools
312
313opensearch = OpenSearchWebTools(host="localhost", port=9200)
314results = opensearch.search("example query")
315```
316
317## Configuration System
318
319**Old code:**
320```python
321from ollamatools.config.core_config import load_config
322from ollamatools.config.plugin_config import get_plugin_config
323
324config = load_config("config.yaml")
325plugin_config = get_plugin_config("search")
326```
327
328**New code:**
329```python
330from ollamatools.config.loader import load_config
331from ollamatools.config.defaults import get_plugin_config
332
333config = load_config("config.yaml")
334plugin_config = get_plugin_config("search")
335```
336
337## Common Issues and Solutions
338
339### Import Errors
340
341If 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
345In 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
349agent.add_module(SearchModule())
350```
351
352**New code:**
353```python
354agent.add_plugin(SearchPlugin())
355```
356
357### Configuration Changes
358
359The 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
363If you encounter any issues during migration, please refer to the documentation or open an issue on the GitHub repository.
ollamatools-project/simplified_guides/README.md +75 -0
……@@ -0,0 +1,75 @@
1# OllamaTools Simplified Refactoring Guide
2
3This 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
7The 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
9This simplified refactoring guide provides an alternative approach that:
10
111. Maintains the target directory structure from the original AI simplification guides
122. Avoids creating files that are too large to manage by keeping existing files separate
133. Preserves existing functionality
144. Minimizes the risk of introducing bugs during refactoring
15
16## Guide Structure
17
18The simplified refactoring guide is organized into the following documents:
19
201. **[00_INDEX.md](./00_INDEX.md)** - Index document with an overview of the guide
212. **[01_SIMPLIFIED_STRUCTURE.md](./01_SIMPLIFIED_STRUCTURE.md)** - The simplified file structure and file mapping strategy
223. **[02_IMPLEMENTATION_STEPS.md](./02_IMPLEMENTATION_STEPS.md)** - Detailed implementation steps for the simplified structure
234. **[03_FILE_MAPPING.md](./03_FILE_MAPPING.md)** - Complete file mapping table for reference
24
25## Key Differences from Original Plan
26
271. **Validators Directory**: Instead of merging all validators into a single file, keep them separate to avoid creating another large file.
28
292. **Matrix Integration**: Keep Matrix-related files separate rather than merging them, as the original matrix_tools.py is already 800 lines.
30
313. **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
35The implementation is broken down into manageable phases:
36
371. **Phase 1**: Create the directory structure
382. **Phase 2**: Copy files to new structure
393. **Phase 3**: Update imports and references
404. **Phase 4**: Implement new files
415. **Phase 5**: Update package initialization
426. **Phase 6**: Test the refactored code
437. **Phase 7**: Documentation and migration guide
448. **Phase 8**: Final steps
45
46Each phase is detailed in the [Implementation Steps](./02_IMPLEMENTATION_STEPS.md) document.
47
48## Benefits of This Approach
49
501. **Maintains file granularity**: Avoids creating files that are too large to manage
512. **Preserves existing functionality**: Each file maintains its original purpose
523. **Follows the target architecture**: Organizes code according to the simplified structure
534. **Easier to implement**: Simpler to move files than to merge and refactor them
545. **Reduced risk**: Less chance of introducing bugs during the refactoring process
556. **Easier to review**: Changes are more isolated and easier to understand
56
57## Getting Started
58
59To get started with the refactoring, follow these steps:
60
611. Start by reviewing the simplified structure in [01_SIMPLIFIED_STRUCTURE.md](./01_SIMPLIFIED_STRUCTURE.md)
622. Follow the implementation steps in [02_IMPLEMENTATION_STEPS.md](./02_IMPLEMENTATION_STEPS.md)
633. Use the file mapping table in [03_FILE_MAPPING.md](./03_FILE_MAPPING.md) as a reference during implementation
64
65## Implementation Timeline
66
67The implementation can be broken down into manageable chunks:
68
691. **Week 1**: Phases 1-2 (Create directory structure, copy files)
702. **Week 2**: Phase 3 (Update imports and references)
713. **Week 3**: Phase 4 (Implement new files)
724. **Week 4**: Phases 5-6 (Update package initialization, test code)
735. **Week 5**: Phases 7-8 (Documentation, migration guide, final steps)
74
75By 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.
ollamatools-project/simplified_guides/README_REFACTORED.md +234 -0
……@@ -0,0 +1,234 @@
1# OllamaTools
2
3OllamaTools 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
18You can install OllamaTools using pip:
19
20```bash
21pip install ollamatools
22```
23
24For development:
25
26```bash
27pip install -e ".[dev]"
28```
29
30For Matrix integration:
31
32```bash
33pip install -e ".[matrix]"
34```
35
36For OpenSearch integration:
37
38```bash
39pip install -e ".[opensearch]"
40```
41
42## Quick Start
43
44### Basic Agent
45
46```python
47from ollamatools.agents.basic import BasicAgent
48
49agent = BasicAgent(model="llama2")
50response = agent.chat("Hello, world!")
51print(response)
52```
53
54### Modular Agent with Plugins
55
56```python
57from ollamatools.agents.modular import ModularAgent
58from ollamatools.plugins.standard.search import SearchPlugin
59from ollamatools.plugins.standard.commands import CommandsPlugin
60
61agent = ModularAgent(model="llama2")
62agent.add_plugin(SearchPlugin())
63agent.add_plugin(CommandsPlugin())
64response = agent.chat("Search for information about Python")
65print(response)
66```
67
68### Extended Agent with Conversation History
69
70```python
71from ollamatools.agents.extended import ExtendedAgent
72
73agent = ExtendedAgent(model="llama2")
74agent.chat("Remember this information for later")
75response = agent.chat("What did I ask you to remember?")
76print(response)
77```
78
79## Using Plugins
80
81### Search Plugin
82
83```python
84from ollamatools.plugins.standard.search import search_web
85
86results = search_web("Python programming")
87print(results)
88```
89
90### Commands Plugin
91
92```python
93from ollamatools.plugins.standard.commands import execute_command
94
95result = execute_command("ls -la")
96print(result)
97```
98
99### Conversation History Plugin
100
101```python
102from ollamatools.plugins.standard.conversation.history import ConversationHistory
103
104history = ConversationHistory()
105history.add_message("user", "Hello")
106history.add_message("assistant", "Hi there!")
107print(history.get_messages())
108```
109
110## Using Tools
111
112### System Tools
113
114```python
115from ollamatools.plugins.tools.system import execute_system_command, read_file
116
117result = execute_system_command("ls -la")
118content = read_file("example.txt")
119print(result)
120print(content)
121```
122
123### Web Tools
124
125```python
126from ollamatools.plugins.tools.web import make_web_request
127
128response = make_web_request("https://example.com")
129print(response.text)
130```
131
132## Using Integrations
133
134### Matrix Integration
135
136```python
137from ollamatools.plugins.integrations.matrix.client import MatrixClient
138
139client = MatrixClient(homeserver="https://matrix.org", token="your_token")
140client.send_message("!roomid:matrix.org", "Hello, Matrix!")
141```
142
143### OpenSearch Integration
144
145```python
146from ollamatools.plugins.integrations.opensearch.tools import OpenSearchWebTools
147
148opensearch = OpenSearchWebTools(host="localhost", port=9200)
149results = opensearch.search("example query")
150print(results)
151```
152
153## Configuration
154
155OllamaTools uses a flexible configuration system that supports YAML files, environment variables, and programmatic configuration.
156
157```python
158from ollamatools.config.loader import load_config
159
160config = load_config("config.yaml")
161print(config)
162```
163
164Example configuration file:
165
166```yaml
167# config.yaml
168agent:
169 model: llama2
170 temperature: 0.7
171 max_tokens: 1024
172
173plugins:
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
184OllamaTools includes a command-line interface for common tasks:
185
186```bash
187# Start a chat session
188ollamatools chat --model llama2
189
190# Run a script or command
191ollamatools run "print('Hello, world!')" --model llama2
192
193# Show version information
194ollamatools version
195```
196
197## Development
198
199### Setup
200
201```bash
202# Clone the repository
203git clone https://github.com/yourusername/ollamatools.git
204cd ollamatools
205
206# Install development dependencies
207pip install -e ".[dev]"
208
209# Run tests
210pytest
211```
212
213### Code Style
214
215OllamaTools uses Black for code formatting, isort for import sorting, and flake8 for linting:
216
217```bash
218# Format code
219black ollamatools tests
220
221# Sort imports
222isort ollamatools tests
223
224# Lint code
225flake8 ollamatools tests
226```
227
228## Contributing
229
230Contributions are welcome! Please feel free to submit a Pull Request.
231
232## License
233
234This project is licensed under the MIT License - see the LICENSE file for details.
ollamatools-project/simplified_guides/copy_files.sh +413 -0
……@@ -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
8BASE_DIR="ollamatools-new"
9
10# Check if the directory structure exists
11if [ ! -d "$BASE_DIR" ]; then
12 echo "Error: Directory structure not found. Please run create_directory_structure.sh first."
13 exit 1
14fi
15
16echo "Copying files to new structure..."
17
18# Core Module
19echo "Copying Core Module files..."
20cp ollamatools/agent.py $BASE_DIR/ollamatools/core/agent.py
21cp ollamatools/errors.py $BASE_DIR/ollamatools/core/errors.py
22cp ollamatools/config.py $BASE_DIR/ollamatools/core/config.py
23cp ollamatools/security.py $BASE_DIR/ollamatools/core/security.py
24cp ollamatools/logger.py $BASE_DIR/ollamatools/core/utils/logger.py
25cp ollamatools/command_validator.py $BASE_DIR/ollamatools/core/utils/validators/command.py
26cp ollamatools/path_validator.py $BASE_DIR/ollamatools/core/utils/validators/path.py
27cp ollamatools/url_validator.py $BASE_DIR/ollamatools/core/utils/validators/url.py
28
29# Create new formatting.py file with placeholder content
30echo "Creating new formatting.py file..."
31cat > $BASE_DIR/ollamatools/core/utils/formatting.py << 'EOF'
32"""Text formatting utilities for OllamaTools."""
33
34def format_markdown(text):
35 """Format text as markdown."""
36 return text
37
38def format_code(code, language="python"):
39 """Format code with syntax highlighting."""
40 return f"```{language}\n{code}\n```"
41
42def 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)
60EOF
61
62# Plugin System
63echo "Copying Plugin System files..."
64cp ollamatools/plugins/registry.py $BASE_DIR/ollamatools/plugins/registry.py
65cp ollamatools/plugins/errors.py $BASE_DIR/ollamatools/plugins/errors.py
66
67# Create new base.py file with placeholder content
68echo "Creating new base.py file..."
69cat > $BASE_DIR/ollamatools/plugins/base.py << 'EOF'
70"""Base plugin interfaces for the OllamaTools plugin system."""
71
72from abc import ABC, abstractmethod
73from typing import Any, Dict, List, Optional
74
75class 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
100class 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
108class 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
116class 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
128EOF
129
130# Standard Plugins
131echo "Copying Standard Plugins files..."
132cp ollamatools/agent/modular/search.py $BASE_DIR/ollamatools/plugins/standard/search.py
133cp ollamatools/agent/modular/commands.py $BASE_DIR/ollamatools/plugins/standard/commands.py
134cp ollamatools/plugins/conversation_history.py $BASE_DIR/ollamatools/plugins/standard/conversation/history.py
135cp ollamatools/plugins/conversation_context.py $BASE_DIR/ollamatools/plugins/standard/conversation/context.py
136cp ollamatools/agent/modular/feedback.py $BASE_DIR/ollamatools/plugins/standard/feedback.py
137cp ollamatools/agent/modular/issues.py $BASE_DIR/ollamatools/plugins/standard/issues.py
138
139# Create new conversation analysis file with placeholder content
140echo "Creating new conversation analysis file..."
141cat > $BASE_DIR/ollamatools/plugins/standard/conversation/analysis.py << 'EOF'
142"""Conversation topic analysis and metrics."""
143
144from typing import Any, Dict, List, Optional
145
146def analyze_topics(messages: List[Dict[str, Any]]) -> List[str]:
147 """Analyze the topics in a conversation."""
148 # Implementation
149 return ["topic1", "topic2"]
150
151def 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 }
160EOF
161
162# Create new function calling file with placeholder content
163echo "Creating new function calling file..."
164cat > $BASE_DIR/ollamatools/plugins/standard/function_calling.py << 'EOF'
165"""Plugin for semantic function calling."""
166
167from typing import Any, Dict, List, Optional
168
169from ollamatools.plugins.base import StandardPlugin
170
171class 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
203EOF
204
205# Tool Plugins
206echo "Copying Tool Plugins files..."
207cp ollamatools/tools/system_tools.py $BASE_DIR/ollamatools/plugins/tools/system.py
208cp ollamatools/tools/web_tools.py $BASE_DIR/ollamatools/plugins/tools/web.py
209cp ollamatools/tools/doc_tools.py $BASE_DIR/ollamatools/plugins/tools/doc.py
210
211# Integration Plugins
212echo "Copying Integration Plugins files..."
213cp ollamatools/tools/matrix_tools.py $BASE_DIR/ollamatools/plugins/integrations/matrix/client.py
214cp ollamatools/tools/enhanced_matrix_tools.py $BASE_DIR/ollamatools/plugins/integrations/matrix/commands.py
215cp ollamatools/tools/enhanced_matrix_search.py $BASE_DIR/ollamatools/plugins/integrations/matrix/search.py
216cp ollamatools/tools/enhanced_matrix_history.py $BASE_DIR/ollamatools/plugins/integrations/matrix/history.py
217cp ollamatools/tools/matrix_rate_limit_patch.py $BASE_DIR/ollamatools/plugins/integrations/matrix/rate_limit.py
218cp ollamatools/opensearch_web_tools.py $BASE_DIR/ollamatools/plugins/integrations/opensearch/tools.py
219
220# Create new Matrix config file with placeholder content
221echo "Creating new Matrix config file..."
222cat > $BASE_DIR/ollamatools/plugins/integrations/matrix/config.py << 'EOF'
223"""Configuration for Matrix integration."""
224
225from typing import Any, Dict, Optional
226
227def load_matrix_config(config_path: Optional[str] = None) -> Dict[str, Any]:
228 """Load Matrix configuration from the given path."""
229 # Implementation
230 return {}
231
232def validate_matrix_config(config: Dict[str, Any]) -> bool:
233 """Validate Matrix configuration."""
234 # Implementation
235 return True
236
237def 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 }
252EOF
253
254# Create new OpenSearch client file with placeholder content
255echo "Creating new OpenSearch client file..."
256cat > $BASE_DIR/ollamatools/plugins/integrations/opensearch/client.py << 'EOF'
257"""OpenSearch client for OllamaTools."""
258
259from typing import Any, Dict, List, Optional
260
261class 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
297EOF
298
299# Agent Implementations
300echo "Copying Agent Implementations files..."
301cp ollamatools/agent/core.py $BASE_DIR/ollamatools/agents/basic.py
302cp ollamatools/agent/modular/agent.py $BASE_DIR/ollamatools/agents/modular.py
303cp ollamatools/agent/extended/agent.py $BASE_DIR/ollamatools/agents/extended.py
304
305# Configuration System
306echo "Copying Configuration System files..."
307cp ollamatools/config/schemas.py $BASE_DIR/ollamatools/config/schemas.py
308cp ollamatools/config/core_config.py $BASE_DIR/ollamatools/config/loader.py
309cp ollamatools/config/plugin_config.py $BASE_DIR/ollamatools/config/defaults.py
310
311# Create new CLI main file with placeholder content
312echo "Creating new CLI main file..."
313cat > $BASE_DIR/ollamatools/cli/main.py << 'EOF'
314"""Command-line interface for OllamaTools."""
315
316import argparse
317import sys
318from typing import List, Optional
319
320def 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
342def 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
366if __name__ == "__main__":
367 sys.exit(main())
368EOF
369
370# Create new version file with placeholder content
371echo "Creating new version file..."
372cat > $BASE_DIR/ollamatools/version.py << 'EOF'
373"""Version information for OllamaTools."""
374
375__version__ = "0.1.0"
376EOF
377
378# Update package initialization
379echo "Updating package initialization..."
380cat > $BASE_DIR/ollamatools/__init__.py << 'EOF'
381"""OllamaTools package."""
382
383from ollamatools.version import __version__
384
385# Expose core components
386from ollamatools.core.agent import Agent
387from ollamatools.core.config import Config
388
389# Expose agent implementations
390from ollamatools.agents.basic import BasicAgent
391from ollamatools.agents.modular import ModularAgent
392from ollamatools.agents.extended import ExtendedAgent
393
394# Expose plugin system
395from ollamatools.plugins.base import Plugin
396from 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]
408EOF
409
410echo "Files copied successfully."
411echo "Next steps:"
412echo "1. Update imports in the copied files"
413echo "2. Test the refactored code"
ollamatools-project/simplified_guides/copy_readme.sh +29 -0
……@@ -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
8BASE_DIR="ollamatools-new"
9
10# Check if the directory structure exists
11if [ ! -d "$BASE_DIR" ]; then
12 echo "Error: Directory structure not found. Please run create_directory_structure.sh first."
13 exit 1
14fi
15
16# Copy the README_REFACTORED.md file to the refactored project directory
17echo "Copying README_REFACTORED.md to $BASE_DIR/README.md..."
18cp simplified_guides/README_REFACTORED.md $BASE_DIR/README.md
19
20# Copy the setup.py file to the refactored project directory
21echo "Copying setup.py to $BASE_DIR/setup.py..."
22cp simplified_guides/setup.py $BASE_DIR/setup.py
23
24# Copy the MIGRATION_GUIDE.md file to the refactored project directory
25echo "Copying MIGRATION_GUIDE.md to $BASE_DIR/MIGRATION_GUIDE.md..."
26cp simplified_guides/MIGRATION_GUIDE.md $BASE_DIR/MIGRATION_GUIDE.md
27
28echo "Files copied successfully."
29echo "The refactored project now has a README.md, setup.py, and MIGRATION_GUIDE.md file."
ollamatools-project/simplified_guides/create_directory_structure.sh +47 -0
……@@ -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
8BASE_DIR="ollamatools-new"
9
10# Create the base directory if it doesn't exist
11mkdir -p $BASE_DIR
12
13# Create the directory structure
14echo "Creating directory structure..."
15
16# Core module
17mkdir -p $BASE_DIR/ollamatools/core/utils/validators
18mkdir -p $BASE_DIR/ollamatools/core/utils
19
20# Plugin system
21mkdir -p $BASE_DIR/ollamatools/plugins/standard/conversation
22mkdir -p $BASE_DIR/ollamatools/plugins/tools
23mkdir -p $BASE_DIR/ollamatools/plugins/integrations/matrix
24mkdir -p $BASE_DIR/ollamatools/plugins/integrations/opensearch
25
26# Agent implementations
27mkdir -p $BASE_DIR/ollamatools/agents
28
29# Configuration system
30mkdir -p $BASE_DIR/ollamatools/config
31
32# Command-line interface
33mkdir -p $BASE_DIR/ollamatools/cli
34
35# Create __init__.py files in all directories
36echo "Creating __init__.py files..."
37find $BASE_DIR -type d -exec touch {}/__init__.py \;
38
39echo "Directory structure created successfully."
40echo "The following directories have been created:"
41find $BASE_DIR -type d | sort
42
43echo "Next steps:"
44echo "1. Copy files to their new locations using the file mapping in 03_FILE_MAPPING.md"
45echo "2. Update imports in the copied files"
46echo "3. Implement new files"
47echo "4. Test the refactored code"
ollamatools-project/simplified_guides/make_scripts_executable.sh +19 -0
……@@ -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
7echo "Making shell scripts executable..."
8chmod +x simplified_guides/*.sh
9
10echo "Shell scripts are now executable."
11echo "You can now run the following scripts:"
12echo " - simplified_guides/create_directory_structure.sh"
13echo " - simplified_guides/copy_files.sh"
14echo " - simplified_guides/make_scripts_executable.sh"
15
16echo "To execute the scripts, run:"
17echo " ./simplified_guides/create_directory_structure.sh"
18echo " ./simplified_guides/copy_files.sh"
19echo " python simplified_guides/test_refactored_code.py"
ollamatools-project/simplified_guides/run_all_steps.sh +50 -0
……@@ -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
8BASE_DIR="ollamatools-new"
9
10# Function to check if a command succeeded
11check_status() {
12 if [ $? -ne 0 ]; then
13 echo "Error: $1 failed. Exiting."
14 exit 1
15 fi
16}
17
18# Make all scripts executable
19echo "Making scripts executable..."
20chmod +x simplified_guides/*.sh
21check_status "Making scripts executable"
22
23# Step 1: Create the directory structure
24echo -e "\n=== Step 1: Creating Directory Structure ===\n"
25./simplified_guides/create_directory_structure.sh
26check_status "Creating directory structure"
27
28# Step 2: Copy files to new structure
29echo -e "\n=== Step 2: Copying Files ===\n"
30./simplified_guides/copy_files.sh
31check_status "Copying files"
32
33# Step 3: Update imports
34echo -e "\n=== Step 3: Updating Imports ===\n"
35python simplified_guides/update_imports.py
36check_status "Updating imports"
37
38# Step 4: Test the refactored code
39echo -e "\n=== Step 4: Testing Refactored Code ===\n"
40python simplified_guides/test_refactored_code.py
41check_status "Testing refactored code"
42
43# Step 5: Copy README and other files
44echo -e "\n=== Step 5: Copying README and Other Files ===\n"
45./simplified_guides/copy_readme.sh
46check_status "Copying README and other files"
47
48echo -e "\n=== All Steps Completed Successfully ===\n"
49echo "The refactored code is now available in the '$BASE_DIR' directory."
50echo "You can now proceed with further testing and integration."
ollamatools-project/simplified_guides/setup.py +69 -0
……@@ -0,0 +1,69 @@
1#!/usr/bin/env python3
2"""
3Setup script for the refactored OllamaTools package.
4
5This script installs the refactored OllamaTools package and its dependencies.
6It should be placed in the root directory of the refactored project.
7"""
8
9from setuptools import setup, find_packages
10
11with open("README.md", "r", encoding="utf-8") as fh:
12 long_description = fh.read()
13
14setup(
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)
ollamatools-project/simplified_guides/test_refactored_code.py +200 -0
……@@ -0,0 +1,200 @@
1#!/usr/bin/env python3
2"""
3Test script for the refactored OllamaTools code.
4
5This script tests the basic functionality of the refactored OllamaTools code
6by importing key components and verifying that they can be instantiated.
7
8Usage:
9 python test_refactored_code.py
10
11Note:
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
16import os
17import sys
18import importlib
19import traceback
20
21# Add the refactored code to the Python path
22REFACTORED_DIR = "ollamatools-new"
23sys.path.insert(0, REFACTORED_DIR)
24
25def 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
42def 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
65def 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
78def 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
102def 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
115def 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
131def 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
144def 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
157def 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
164def 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
174def 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
199if __name__ == "__main__":
200 sys.exit(main())
ollamatools-project/simplified_guides/update_imports.py +182 -0
……@@ -0,0 +1,182 @@
1#!/usr/bin/env python3
2"""
3Script to update imports in the refactored OllamaTools code.
4
5This script updates import statements in the refactored OllamaTools code to reflect
6the new directory structure. It replaces old import paths with new ones based on
7the file mapping defined in the simplified refactoring guide.
8
9Usage:
10 python update_imports.py
11
12Note:
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
17import os
18import re
19import sys
20
21# Set the base directory for the new structure
22BASE_DIR = "ollamatools-new"
23
24# Define import mappings (old import -> new import)
25IMPORT_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
146def 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
158def 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
181if __name__ == "__main__":
182 sys.exit(main())
ollamatools-project/update_mapping_status.sh +2 -8
……@@ -49,22 +49,16 @@ if ! grep -q "\`$ORIGINAL_FILE\`" "$MAPPING_FILE"; then
4949 exit 1
5050fi
5151
52# Get the new file path from the mapping file
53NEW_FILE=$(grep "\`$ORIGINAL_FILE\`" "$MAPPING_FILE" | sed -E 's/.*\| `[^`]+` \| `([^`]+)`.*/\1/')
54
55# Escape special characters in the new file path for use in sed
56ESCAPED_NEW_FILE=$(echo "$NEW_FILE" | sed 's/\//\\\//g')
57
5852# If notes are provided, update both status and notes
5953if [ -n "$NEW_NOTES" ]; then
6054 # Escape special characters in the notes for use in sed
6155 ESCAPED_NOTES=$(echo "$NEW_NOTES" | sed 's/\//\\\//g')
6256
6357 # 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"
6559else
6660 # 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"
6862fi
6963
7064echo "Updated status of $ORIGINAL_FILE to '$NEW_STATUS'."