naive-knowledge-base 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agents/__init__.py +7 -0
- agents/common/__init__.py +28 -0
- agents/common/base.py +187 -0
- agents/common/exceptions.py +62 -0
- agents/common/logging.py +60 -0
- agents/common/schema_converter.py +112 -0
- agents/common/tools.py +195 -0
- agents/common/utils.py +161 -0
- agents/dependency_graph/__init__.py +7 -0
- agents/dependency_graph/agent.py +205 -0
- agents/dependency_graph/model.py +38 -0
- api_models/__init__.py +3 -0
- api_models/flow_api_model.py +390 -0
- cli.py +203 -0
- main.py +68 -0
- naive_knowledge_base-0.1.0.dist-info/METADATA +215 -0
- naive_knowledge_base-0.1.0.dist-info/RECORD +24 -0
- naive_knowledge_base-0.1.0.dist-info/WHEEL +5 -0
- naive_knowledge_base-0.1.0.dist-info/entry_points.txt +2 -0
- naive_knowledge_base-0.1.0.dist-info/licenses/LICENSE +21 -0
- naive_knowledge_base-0.1.0.dist-info/top_level.txt +5 -0
- tools/__init__.py +11 -0
- tools/io.py +59 -0
- tools/tree.py +42 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: naive-knowledge-base
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A dependency graph analyzer using smolagents
|
|
5
|
+
Home-page: https://github.com/yourusername/naive-knowledge-base
|
|
6
|
+
Author: Your Name
|
|
7
|
+
Author-email: Your Name <your.email@example.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/yourusername/naive-knowledge-base
|
|
10
|
+
Project-URL: Documentation, https://github.com/yourusername/naive-knowledge-base#readme
|
|
11
|
+
Project-URL: Repository, https://github.com/yourusername/naive-knowledge-base
|
|
12
|
+
Project-URL: Issues, https://github.com/yourusername/naive-knowledge-base/issues
|
|
13
|
+
Keywords: dependency-graph,code-analysis,smolagents,ai-agents
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Requires-Python: >=3.8
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Dynamic: author
|
|
28
|
+
Dynamic: home-page
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
Dynamic: requires-python
|
|
31
|
+
|
|
32
|
+
# Naive Knowledge Base
|
|
33
|
+
|
|
34
|
+
A dependency graph analyzer using smolagents for building and analyzing code dependencies.
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
- 🔍 **Dependency Graph Generation**: Automatically generate dependency graphs from source code
|
|
39
|
+
- 🤖 **AI-Powered Analysis**: Uses smolagents for intelligent code analysis
|
|
40
|
+
- 📊 **Multiple Language Support**: Support for Java and other languages
|
|
41
|
+
- 🌳 **Directory Tree Visualization**: Generate visual representations of project structure
|
|
42
|
+
- 📝 **File Operations**: Read, write, and manage files programmatically
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
### From Source
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
git clone https://github.com/yourusername/naive-knowledge-base.git
|
|
50
|
+
cd naive-knowledge-base
|
|
51
|
+
pip install -e .
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### From PyPI (when published)
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install naive-knowledge-base
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Requirements
|
|
61
|
+
|
|
62
|
+
- Python 3.8+
|
|
63
|
+
- OpenAI API key (or compatible API)
|
|
64
|
+
|
|
65
|
+
## Configuration
|
|
66
|
+
|
|
67
|
+
Create a `.env` file in your project directory with the following:
|
|
68
|
+
|
|
69
|
+
```env
|
|
70
|
+
OPENAI_API_KEY=your_api_key_here
|
|
71
|
+
# Or configure your API endpoint
|
|
72
|
+
API_BASE_URL=your_api_base_url
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Usage
|
|
76
|
+
|
|
77
|
+
### Command Line Interface
|
|
78
|
+
|
|
79
|
+
After installation, you can use the `naive-kb` command:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Basic usage
|
|
83
|
+
naive-kb /path/to/source/directory
|
|
84
|
+
|
|
85
|
+
# Specify file extensions
|
|
86
|
+
naive-kb /path/to/source/directory java
|
|
87
|
+
|
|
88
|
+
# Specify directories to ignore
|
|
89
|
+
naive-kb /path/to/source/directory java "target,.git,test,node_modules"
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Python API
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from naive_knowledge_base import run_analysis
|
|
96
|
+
|
|
97
|
+
# Run dependency graph analysis
|
|
98
|
+
result = run_analysis(
|
|
99
|
+
source_directory="/path/to/source",
|
|
100
|
+
file_extensions="java",
|
|
101
|
+
ignore_dirs="target,.git,test"
|
|
102
|
+
)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Advanced Usage
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from smolagents import CodeAgent, ToolCallingAgent
|
|
109
|
+
from naive_knowledge_base.api_models import FlowApiModel
|
|
110
|
+
from naive_knowledge_base.tools import (
|
|
111
|
+
save_content_to_file,
|
|
112
|
+
read_file_content,
|
|
113
|
+
delete_folder_or_file,
|
|
114
|
+
generate_folder_tree
|
|
115
|
+
)
|
|
116
|
+
from naive_knowledge_base.agents.dependency_graph import generate_dependency_graph
|
|
117
|
+
|
|
118
|
+
# Create custom agents
|
|
119
|
+
model = FlowApiModel(model_id="gpt-4.1", temperature=0.5)
|
|
120
|
+
|
|
121
|
+
dependency_agent = ToolCallingAgent(
|
|
122
|
+
tools=[generate_dependency_graph],
|
|
123
|
+
model=model,
|
|
124
|
+
max_steps=7,
|
|
125
|
+
name="dependency_graph_agent"
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
manager_agent = CodeAgent(
|
|
129
|
+
managed_agents=[dependency_agent],
|
|
130
|
+
model=model,
|
|
131
|
+
tools=[read_file_content, save_content_to_file],
|
|
132
|
+
max_steps=30,
|
|
133
|
+
name="tech_lead_agent"
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# Run analysis
|
|
137
|
+
result = manager_agent.run("Analyze dependencies in /path/to/source")
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Package Structure
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
naive_knowledge_base/
|
|
144
|
+
├── agents/
|
|
145
|
+
│ ├── common/ # Common agent utilities
|
|
146
|
+
│ │ ├── base.py
|
|
147
|
+
│ │ ├── exceptions.py
|
|
148
|
+
│ │ ├── logging.py
|
|
149
|
+
│ │ └── utils.py
|
|
150
|
+
│ └── dependency_graph/ # Dependency graph analysis
|
|
151
|
+
│ ├── agent.py
|
|
152
|
+
│ └── model.py
|
|
153
|
+
├── api_models/ # API model integrations
|
|
154
|
+
│ └── flow_api_model.py
|
|
155
|
+
└── tools/ # Agent tools
|
|
156
|
+
├── io.py # File I/O operations
|
|
157
|
+
└── tree.py # Directory tree generation
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Development
|
|
161
|
+
|
|
162
|
+
### Setup Development Environment
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
# Clone the repository
|
|
166
|
+
git clone https://github.com/yourusername/naive-knowledge-base.git
|
|
167
|
+
cd naive-knowledge-base
|
|
168
|
+
|
|
169
|
+
# Create virtual environment
|
|
170
|
+
python -m venv venv
|
|
171
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
172
|
+
|
|
173
|
+
# Install in editable mode with dev dependencies
|
|
174
|
+
pip install -e ".[dev]"
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Running Tests
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
pytest tests/
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Code Formatting
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
# Format code
|
|
187
|
+
black .
|
|
188
|
+
isort .
|
|
189
|
+
|
|
190
|
+
# Check code quality
|
|
191
|
+
pylint naive_knowledge_base/
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Contributing
|
|
195
|
+
|
|
196
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
197
|
+
|
|
198
|
+
1. Fork the repository
|
|
199
|
+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
|
200
|
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
|
201
|
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
|
202
|
+
5. Open a Pull Request
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
207
|
+
|
|
208
|
+
## Acknowledgments
|
|
209
|
+
|
|
210
|
+
- Built with [smolagents](https://github.com/huggingface/smolagents)
|
|
211
|
+
- Uses OpenAI API for AI-powered analysis
|
|
212
|
+
|
|
213
|
+
## Support
|
|
214
|
+
|
|
215
|
+
For issues and questions, please file an issue on the [GitHub repository](https://github.com/yourusername/naive-knowledge-base/issues).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
cli.py,sha256=ZqBfGleriD2imzWhbV7noEz2IBClE2sRzRDG9hmygXk,5782
|
|
2
|
+
main.py,sha256=AjFqJ-BAXUxeK31kuQOL_tkGW1w7WhgsS_HS5eqheXk,2219
|
|
3
|
+
agents/__init__.py,sha256=5M5g7jPBn9PeMJ9TwH2Yggq0SqWY95rSnD8NWZm0cXY,151
|
|
4
|
+
agents/common/__init__.py,sha256=9iwI7BZR8GqRlRD-Fvq42fW52SAZt3oUM2e0hR1bXW4,563
|
|
5
|
+
agents/common/base.py,sha256=m8o2HQ6Q0sTpbjxIoNV9amuXE3wPzgN2QHqKflOBmNk,5083
|
|
6
|
+
agents/common/exceptions.py,sha256=QilIzsJHLShZ8i1ZDRpWT6KRhSG5CJVSwynbHTO3-6I,2130
|
|
7
|
+
agents/common/logging.py,sha256=ZinsduEU6PUwPwy8yzITCn-4EZE5j7_6b206sV90fHk,1868
|
|
8
|
+
agents/common/schema_converter.py,sha256=sFGFngQpFwPAAbjcVbqFfGifXKXN4iZZiun4oz9fFgs,4401
|
|
9
|
+
agents/common/tools.py,sha256=zsHPqDkuHQJjO8rmqo0XRCFP4OCeyXWDnUPExMAhY7U,5358
|
|
10
|
+
agents/common/utils.py,sha256=gcjfYERYWc8cRNm3BYcaOsxsrGXb4mZQiwGIuO20u1g,4628
|
|
11
|
+
agents/dependency_graph/__init__.py,sha256=an4MdRnl5JJUhw4FCfvRvjHyozxy8DowVetOlrhZ5qw,149
|
|
12
|
+
agents/dependency_graph/agent.py,sha256=RyOgA7VqcYKIV_2OKGVajhcQnbc51shumrHYs62UkyM,7292
|
|
13
|
+
agents/dependency_graph/model.py,sha256=fMA4iXphVZQ41UcrgWHpp_hdUFaLY4_8-6QVaTU4o44,1098
|
|
14
|
+
api_models/__init__.py,sha256=iPxcX-RpouvXZFmwbH-SeUWhW4UQBe8a-l2DmC2csrM,96
|
|
15
|
+
api_models/flow_api_model.py,sha256=aSmsY0TRHB8Ylisbk8-CzB4CBo8QwAZJRLmiIa6nx6s,15184
|
|
16
|
+
naive_knowledge_base-0.1.0.dist-info/licenses/LICENSE,sha256=OphKV48tcMv6ep-7j-8T6nycykPT0g8ZlMJ9zbGvdPs,1066
|
|
17
|
+
tools/__init__.py,sha256=RUzn2bV-Q7GJrx6jy-Vo3j_5kBlJH9GTv9ZK3Z-hKGE,271
|
|
18
|
+
tools/io.py,sha256=MfRJMbIjYx54iNq4nit5jVjXZqjPktg9m7RI_gCxHWo,1612
|
|
19
|
+
tools/tree.py,sha256=rUv5Qm4PZW7-zxD3S8e_PFj5PliAA5XdTJyqF8L42nk,1666
|
|
20
|
+
naive_knowledge_base-0.1.0.dist-info/METADATA,sha256=AP65NDms9-h53diiSEdhnFLMOQfrNgA4rZUPZtCP0t4,5676
|
|
21
|
+
naive_knowledge_base-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
22
|
+
naive_knowledge_base-0.1.0.dist-info/entry_points.txt,sha256=UgKAmqSs86uLJ3P81eLHEauN-RWaGFT0uhZ54mTzvqo,38
|
|
23
|
+
naive_knowledge_base-0.1.0.dist-info/top_level.txt,sha256=QLdDlcaSJKlVrg-wXEyzw4dfOnxkVaXP02og9vzF5aU,33
|
|
24
|
+
naive_knowledge_base-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Your Name
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
tools/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from .io import save_content_to_file
|
|
2
|
+
from .io import delete_folder_or_file
|
|
3
|
+
from .io import read_file_content
|
|
4
|
+
from .tree import generate_folder_tree
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"save_content_to_file",
|
|
8
|
+
"delete_folder_or_file",
|
|
9
|
+
"read_file_content",
|
|
10
|
+
"generate_folder_tree"
|
|
11
|
+
]
|
tools/io.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from smolagents.tools import tool
|
|
2
|
+
import os
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import shutil
|
|
5
|
+
|
|
6
|
+
@tool
|
|
7
|
+
def delete_folder_or_file(absolute_path: str) -> bool:
|
|
8
|
+
"""
|
|
9
|
+
Deletes a folder or file.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
absolute_path (str): The path to the folder or file to delete.
|
|
13
|
+
Returns:
|
|
14
|
+
bool: True if the deletion was successful, False otherwise.
|
|
15
|
+
"""
|
|
16
|
+
path = Path(absolute_path).resolve()
|
|
17
|
+
|
|
18
|
+
if path.is_dir():
|
|
19
|
+
shutil.rmtree(path)
|
|
20
|
+
elif path.is_file():
|
|
21
|
+
os.remove(path)
|
|
22
|
+
else:
|
|
23
|
+
return False
|
|
24
|
+
|
|
25
|
+
return True
|
|
26
|
+
|
|
27
|
+
@tool
|
|
28
|
+
def save_content_to_file(content: str, source_directory: str, file_name: str) -> str:
|
|
29
|
+
"""
|
|
30
|
+
Saves the given content to a file.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
content (str): The content to be saved.
|
|
34
|
+
source_directory (str): The directory where the file will be saved.
|
|
35
|
+
file_name (str): The name of the file where the content will be saved.
|
|
36
|
+
Returns:
|
|
37
|
+
str: The full path of the saved file.
|
|
38
|
+
"""
|
|
39
|
+
knolwledge_base_dir = f"{source_directory}/knowledge_base/{file_name}"
|
|
40
|
+
file_path_obj = Path(knolwledge_base_dir).resolve()
|
|
41
|
+
file_path_obj.parent.mkdir(parents=True, exist_ok=True)
|
|
42
|
+
with open(file_path_obj, "w") as file:
|
|
43
|
+
file.write(content)
|
|
44
|
+
|
|
45
|
+
return str(file_path_obj)
|
|
46
|
+
|
|
47
|
+
@tool
|
|
48
|
+
def read_file_content(absolute_file_path: str) -> str:
|
|
49
|
+
"""
|
|
50
|
+
Reads the content of a dependency.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
absolute_file_path (str): The path to the file to read.
|
|
54
|
+
Returns:
|
|
55
|
+
str: The content of the file.
|
|
56
|
+
"""
|
|
57
|
+
file_path = Path(absolute_file_path).resolve()
|
|
58
|
+
|
|
59
|
+
return file_path.read_text(encoding="utf-8")
|
tools/tree.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from smolagents import tool
|
|
2
|
+
import os
|
|
3
|
+
from tools import save_content_to_file, delete_folder_or_file
|
|
4
|
+
from directory_tree import DisplayTree
|
|
5
|
+
|
|
6
|
+
@tool
|
|
7
|
+
def generate_folder_tree(source_directory: str, ignore_directories_containing: list[str]) -> str:
|
|
8
|
+
"""
|
|
9
|
+
Generates a folder tree for the given source directory.
|
|
10
|
+
Args:
|
|
11
|
+
source_directory: The source directory to analyze.
|
|
12
|
+
permit_file_extensions: The file extensions to permit in the analysis.
|
|
13
|
+
ignore_directories_containing: The directories to ignore in the analysis.
|
|
14
|
+
Returns:
|
|
15
|
+
str: The folder tree file path.
|
|
16
|
+
Raises:
|
|
17
|
+
ValueError: If the source directory does not exist or is not a directory.
|
|
18
|
+
"""
|
|
19
|
+
# Check if the source directory exists
|
|
20
|
+
if not os.path.exists(source_directory):
|
|
21
|
+
raise ValueError(f"Source directory does not exist: {source_directory}")
|
|
22
|
+
|
|
23
|
+
# Check if the source directory is a directory
|
|
24
|
+
if not os.path.isdir(source_directory):
|
|
25
|
+
raise ValueError(f"Source path is not a directory: {source_directory}")
|
|
26
|
+
|
|
27
|
+
# Generate the folder tree
|
|
28
|
+
tree = DisplayTree(
|
|
29
|
+
dirPath=source_directory,
|
|
30
|
+
stringRep=True,
|
|
31
|
+
ignoreList=ignore_directories_containing if 'ignore_directories_containing' in locals() else None
|
|
32
|
+
)
|
|
33
|
+
folder_tree_str = f"# Folder Structure:\n\n```\n{tree}\n```\n\n## Dependency Graph\n\nFor detailed component and module dependencies, see [dependency_graph.toon](dependency_graph.toon)"
|
|
34
|
+
|
|
35
|
+
# Save the folder tree to a file
|
|
36
|
+
file_path = save_content_to_file(
|
|
37
|
+
content=folder_tree_str,
|
|
38
|
+
source_directory=source_directory,
|
|
39
|
+
file_name="brief.md"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
return file_path
|