jarvis-ai-assistant 0.1.12__tar.gz → 0.1.14__tar.gz
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.
Potentially problematic release.
This version of jarvis-ai-assistant might be problematic. Click here for more details.
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/PKG-INFO +69 -7
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/README.md +67 -6
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/pyproject.toml +2 -1
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/setup.py +2 -1
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/__init__.py +1 -1
- jarvis_ai_assistant-0.1.14/src/jarvis/__pycache__/__init__.cpython-313.pyc +0 -0
- jarvis_ai_assistant-0.1.14/src/jarvis/__pycache__/main.cpython-313.pyc +0 -0
- jarvis_ai_assistant-0.1.14/src/jarvis/__pycache__/utils.cpython-313.pyc +0 -0
- jarvis_ai_assistant-0.1.14/src/jarvis/main.py +155 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/utils.py +40 -22
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis_ai_assistant.egg-info/PKG-INFO +69 -7
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis_ai_assistant.egg-info/requires.txt +1 -0
- jarvis_ai_assistant-0.1.12/src/jarvis/__pycache__/__init__.cpython-313.pyc +0 -0
- jarvis_ai_assistant-0.1.12/src/jarvis/__pycache__/main.cpython-313.pyc +0 -0
- jarvis_ai_assistant-0.1.12/src/jarvis/__pycache__/utils.cpython-313.pyc +0 -0
- jarvis_ai_assistant-0.1.12/src/jarvis/main.py +0 -122
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/MANIFEST.in +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/setup.cfg +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/__pycache__/agent.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/__pycache__/models.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/__pycache__/tools.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/__pycache__/zte_llm.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/agent.py +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/models/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/models/__pycache__/__init__.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/models/__pycache__/base.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/models/__pycache__/kimi.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/models/base.py +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/models/kimi.py +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/__pycache__/__init__.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/__pycache__/base.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/__pycache__/bing_search.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/__pycache__/file_ops.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/__pycache__/python_script.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/__pycache__/rag.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/__pycache__/search.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/__pycache__/shell.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/__pycache__/sub_agent.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/__pycache__/user_confirmation.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/__pycache__/user_input.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/__pycache__/user_interaction.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/__pycache__/webpage.cpython-313.pyc +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/base.py +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/file_ops.py +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis/tools/shell.py +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis_ai_assistant.egg-info/SOURCES.txt +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis_ai_assistant.egg-info/dependency_links.txt +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis_ai_assistant.egg-info/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis_ai_assistant.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: jarvis-ai-assistant
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.14
|
|
4
4
|
Summary: Jarvis: An AI assistant that uses tools to interact with the system
|
|
5
5
|
Home-page: https://github.com/skyfireitdiy/Jarvis
|
|
6
6
|
Author: skyfire
|
|
@@ -19,6 +19,7 @@ Description-Content-Type: text/markdown
|
|
|
19
19
|
Requires-Dist: requests>=2.25.1
|
|
20
20
|
Requires-Dist: pyyaml>=5.1
|
|
21
21
|
Requires-Dist: colorama>=0.4.6
|
|
22
|
+
Requires-Dist: prompt_toolkit>=3.0.0
|
|
22
23
|
Provides-Extra: dev
|
|
23
24
|
Requires-Dist: pytest; extra == "dev"
|
|
24
25
|
Requires-Dist: black; extra == "dev"
|
|
@@ -72,6 +73,42 @@ Dynamic: requires-python
|
|
|
72
73
|
- Multi-line input support
|
|
73
74
|
- Colored output with progress indicators
|
|
74
75
|
|
|
76
|
+
|
|
77
|
+
## ⚙️ Environment Setup
|
|
78
|
+
|
|
79
|
+
Before using Jarvis, you need to set up your environment:
|
|
80
|
+
|
|
81
|
+
1. **API Key Configuration**
|
|
82
|
+
|
|
83
|
+
Create a `.jarvis_env` file in your home directory (`~/.jarvis_env`):
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
KIMI_API_KEY=your_kimi_api_key_here
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
To get your Kimi API key:
|
|
90
|
+
1. Visit [Kimi AI Platform](https://kimi.moonshot.cn) in your browser
|
|
91
|
+
2. Login to your account
|
|
92
|
+
3. Open browser Developer Tools (F12 or right-click -> Inspect)
|
|
93
|
+
4. Go to Network tab
|
|
94
|
+
5. Make any request (e.g., send a message)
|
|
95
|
+
6. Find a request to the Kimi API
|
|
96
|
+
7. Look for the `Authorization` header in the request headers
|
|
97
|
+
8. Copy the token value (remove the "Bearer " prefix)
|
|
98
|
+
9. Use this token as your `KIMI_API_KEY` in the `.jarvis_env` file
|
|
99
|
+
|
|
100
|
+
2. **Task Configuration (Optional)**
|
|
101
|
+
|
|
102
|
+
Create a `.jarvis` file in your working directory to define predefined tasks:
|
|
103
|
+
|
|
104
|
+
```yaml
|
|
105
|
+
# .jarvis
|
|
106
|
+
analyze_code: Analyze the code structure and quality in the current directory
|
|
107
|
+
fix_bugs: Help me find and fix potential bugs in the code
|
|
108
|
+
optimize: Suggest optimizations for the code
|
|
109
|
+
document: Generate documentation for the code
|
|
110
|
+
```
|
|
111
|
+
|
|
75
112
|
## 🚀 Installation
|
|
76
113
|
|
|
77
114
|
```bash
|
|
@@ -80,19 +117,44 @@ pip install jarvis-ai-assistant
|
|
|
80
117
|
|
|
81
118
|
## 💡 Usage
|
|
82
119
|
|
|
120
|
+
1. **Basic Usage**
|
|
83
121
|
```bash
|
|
84
|
-
#
|
|
122
|
+
# Start Jarvis
|
|
85
123
|
jarvis
|
|
86
124
|
|
|
87
|
-
# Process files
|
|
125
|
+
# Process specific files
|
|
88
126
|
jarvis -f file1.txt file2.py
|
|
127
|
+
```
|
|
89
128
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
129
|
+
2. **Using Predefined Tasks**
|
|
130
|
+
|
|
131
|
+
If you have a `.jarvis` file in your working directory:
|
|
132
|
+
```bash
|
|
133
|
+
# Jarvis will show available tasks on startup
|
|
134
|
+
# Select a task number or start a new conversation
|
|
94
135
|
```
|
|
95
136
|
|
|
137
|
+
3. **Interactive Features**
|
|
138
|
+
- Multi-line input support (press Enter twice to submit)
|
|
139
|
+
- File understanding and analysis
|
|
140
|
+
- Context-aware conversations
|
|
141
|
+
- Tool integration for system operations
|
|
142
|
+
|
|
143
|
+
4. **Environment Variables**
|
|
144
|
+
- `KIMI_API_KEY`: Your Kimi AI API key (required)
|
|
145
|
+
- Location: `~/.jarvis_env`
|
|
146
|
+
- Format: `KEY=value` (one per line)
|
|
147
|
+
|
|
148
|
+
5. **Task Configuration**
|
|
149
|
+
- File: `.jarvis` in working directory
|
|
150
|
+
- Format: `task_name: task_description`
|
|
151
|
+
- Purpose: Define commonly used tasks for quick access
|
|
152
|
+
- Example tasks:
|
|
153
|
+
- Code analysis
|
|
154
|
+
- Bug finding
|
|
155
|
+
- Documentation generation
|
|
156
|
+
- Performance optimization
|
|
157
|
+
|
|
96
158
|
## 🧰 Tools
|
|
97
159
|
|
|
98
160
|
| Tool | Description | Example |
|
|
@@ -42,6 +42,42 @@
|
|
|
42
42
|
- Multi-line input support
|
|
43
43
|
- Colored output with progress indicators
|
|
44
44
|
|
|
45
|
+
|
|
46
|
+
## ⚙️ Environment Setup
|
|
47
|
+
|
|
48
|
+
Before using Jarvis, you need to set up your environment:
|
|
49
|
+
|
|
50
|
+
1. **API Key Configuration**
|
|
51
|
+
|
|
52
|
+
Create a `.jarvis_env` file in your home directory (`~/.jarvis_env`):
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
KIMI_API_KEY=your_kimi_api_key_here
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
To get your Kimi API key:
|
|
59
|
+
1. Visit [Kimi AI Platform](https://kimi.moonshot.cn) in your browser
|
|
60
|
+
2. Login to your account
|
|
61
|
+
3. Open browser Developer Tools (F12 or right-click -> Inspect)
|
|
62
|
+
4. Go to Network tab
|
|
63
|
+
5. Make any request (e.g., send a message)
|
|
64
|
+
6. Find a request to the Kimi API
|
|
65
|
+
7. Look for the `Authorization` header in the request headers
|
|
66
|
+
8. Copy the token value (remove the "Bearer " prefix)
|
|
67
|
+
9. Use this token as your `KIMI_API_KEY` in the `.jarvis_env` file
|
|
68
|
+
|
|
69
|
+
2. **Task Configuration (Optional)**
|
|
70
|
+
|
|
71
|
+
Create a `.jarvis` file in your working directory to define predefined tasks:
|
|
72
|
+
|
|
73
|
+
```yaml
|
|
74
|
+
# .jarvis
|
|
75
|
+
analyze_code: Analyze the code structure and quality in the current directory
|
|
76
|
+
fix_bugs: Help me find and fix potential bugs in the code
|
|
77
|
+
optimize: Suggest optimizations for the code
|
|
78
|
+
document: Generate documentation for the code
|
|
79
|
+
```
|
|
80
|
+
|
|
45
81
|
## 🚀 Installation
|
|
46
82
|
|
|
47
83
|
```bash
|
|
@@ -50,19 +86,44 @@ pip install jarvis-ai-assistant
|
|
|
50
86
|
|
|
51
87
|
## 💡 Usage
|
|
52
88
|
|
|
89
|
+
1. **Basic Usage**
|
|
53
90
|
```bash
|
|
54
|
-
#
|
|
91
|
+
# Start Jarvis
|
|
55
92
|
jarvis
|
|
56
93
|
|
|
57
|
-
# Process files
|
|
94
|
+
# Process specific files
|
|
58
95
|
jarvis -f file1.txt file2.py
|
|
96
|
+
```
|
|
59
97
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
98
|
+
2. **Using Predefined Tasks**
|
|
99
|
+
|
|
100
|
+
If you have a `.jarvis` file in your working directory:
|
|
101
|
+
```bash
|
|
102
|
+
# Jarvis will show available tasks on startup
|
|
103
|
+
# Select a task number or start a new conversation
|
|
64
104
|
```
|
|
65
105
|
|
|
106
|
+
3. **Interactive Features**
|
|
107
|
+
- Multi-line input support (press Enter twice to submit)
|
|
108
|
+
- File understanding and analysis
|
|
109
|
+
- Context-aware conversations
|
|
110
|
+
- Tool integration for system operations
|
|
111
|
+
|
|
112
|
+
4. **Environment Variables**
|
|
113
|
+
- `KIMI_API_KEY`: Your Kimi AI API key (required)
|
|
114
|
+
- Location: `~/.jarvis_env`
|
|
115
|
+
- Format: `KEY=value` (one per line)
|
|
116
|
+
|
|
117
|
+
5. **Task Configuration**
|
|
118
|
+
- File: `.jarvis` in working directory
|
|
119
|
+
- Format: `task_name: task_description`
|
|
120
|
+
- Purpose: Define commonly used tasks for quick access
|
|
121
|
+
- Example tasks:
|
|
122
|
+
- Code analysis
|
|
123
|
+
- Bug finding
|
|
124
|
+
- Documentation generation
|
|
125
|
+
- Performance optimization
|
|
126
|
+
|
|
66
127
|
## 🧰 Tools
|
|
67
128
|
|
|
68
129
|
| Tool | Description | Example |
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "jarvis-ai-assistant"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.14"
|
|
8
8
|
description = "Jarvis: An AI assistant that uses tools to interact with the system"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [{ name = "Your Name", email = "your.email@example.com" }]
|
|
@@ -23,6 +23,7 @@ dependencies = [
|
|
|
23
23
|
"requests>=2.25.1",
|
|
24
24
|
"pyyaml>=5.1",
|
|
25
25
|
"colorama>=0.4.6",
|
|
26
|
+
"prompt_toolkit>=3.0.0",
|
|
26
27
|
]
|
|
27
28
|
requires-python = ">=3.8"
|
|
28
29
|
|
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name="jarvis-ai-assistant",
|
|
5
|
-
version="0.1.
|
|
5
|
+
version="0.1.14",
|
|
6
6
|
author="skyfire",
|
|
7
7
|
author_email="skyfireitdiy@hotmail.com",
|
|
8
8
|
description="An AI assistant that uses various tools to interact with the system",
|
|
@@ -16,6 +16,7 @@ setup(
|
|
|
16
16
|
"requests>=2.25.1",
|
|
17
17
|
"pyyaml>=5.1",
|
|
18
18
|
"colorama>=0.4.6",
|
|
19
|
+
"prompt_toolkit>=3.0.0",
|
|
19
20
|
],
|
|
20
21
|
entry_points={
|
|
21
22
|
"console_scripts": [
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Command line interface for Jarvis."""
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import yaml
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
# 添加父目录到Python路径以支持导入
|
|
11
|
+
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
12
|
+
|
|
13
|
+
from jarvis.agent import Agent
|
|
14
|
+
from jarvis.tools import ToolRegistry
|
|
15
|
+
from jarvis.models import KimiModel
|
|
16
|
+
from jarvis.utils import PrettyOutput, OutputType, get_multiline_input, load_env_from_file
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def load_tasks() -> dict:
|
|
20
|
+
"""Load tasks from .jarvis files in user home and current directory."""
|
|
21
|
+
tasks = {}
|
|
22
|
+
|
|
23
|
+
# 检查用户目录下的 .jarvis
|
|
24
|
+
user_jarvis = os.path.expanduser("~/.jarvis")
|
|
25
|
+
if os.path.exists(user_jarvis):
|
|
26
|
+
try:
|
|
27
|
+
with open(user_jarvis, "r", encoding="utf-8") as f:
|
|
28
|
+
user_tasks = yaml.safe_load(f)
|
|
29
|
+
|
|
30
|
+
if isinstance(user_tasks, dict):
|
|
31
|
+
# 验证并添加用户目录的任务
|
|
32
|
+
for name, desc in user_tasks.items():
|
|
33
|
+
if desc: # 确保描述不为空
|
|
34
|
+
tasks[str(name)] = str(desc)
|
|
35
|
+
else:
|
|
36
|
+
PrettyOutput.print("Warning: ~/.jarvis file should contain a dictionary of task_name: task_description", OutputType.ERROR)
|
|
37
|
+
except Exception as e:
|
|
38
|
+
PrettyOutput.print(f"Error loading ~/.jarvis file: {str(e)}", OutputType.ERROR)
|
|
39
|
+
|
|
40
|
+
# 检查当前目录下的 .jarvis
|
|
41
|
+
if os.path.exists(".jarvis"):
|
|
42
|
+
try:
|
|
43
|
+
with open(".jarvis", "r", encoding="utf-8") as f:
|
|
44
|
+
local_tasks = yaml.safe_load(f)
|
|
45
|
+
|
|
46
|
+
if isinstance(local_tasks, dict):
|
|
47
|
+
# 验证并添加当前目录的任务,如果有重名则覆盖用户目录的任务
|
|
48
|
+
for name, desc in local_tasks.items():
|
|
49
|
+
if desc: # 确保描述不为空
|
|
50
|
+
tasks[str(name)] = str(desc)
|
|
51
|
+
else:
|
|
52
|
+
PrettyOutput.print("Warning: .jarvis file should contain a dictionary of task_name: task_description", OutputType.ERROR)
|
|
53
|
+
except Exception as e:
|
|
54
|
+
PrettyOutput.print(f"Error loading .jarvis file: {str(e)}", OutputType.ERROR)
|
|
55
|
+
|
|
56
|
+
return tasks
|
|
57
|
+
|
|
58
|
+
def select_task(tasks: dict) -> str:
|
|
59
|
+
"""Let user select a task from the list or skip. Returns task description if selected."""
|
|
60
|
+
if not tasks:
|
|
61
|
+
return ""
|
|
62
|
+
|
|
63
|
+
# Convert tasks to list for ordered display
|
|
64
|
+
task_names = list(tasks.keys())
|
|
65
|
+
|
|
66
|
+
PrettyOutput.print("\nAvailable tasks:", OutputType.INFO)
|
|
67
|
+
for i, name in enumerate(task_names, 1):
|
|
68
|
+
PrettyOutput.print(f"[{i}] {name}", OutputType.INFO)
|
|
69
|
+
PrettyOutput.print("[0] Skip predefined tasks", OutputType.INFO)
|
|
70
|
+
|
|
71
|
+
while True:
|
|
72
|
+
try:
|
|
73
|
+
choice = input("\nSelect a task number (0 to skip): ").strip()
|
|
74
|
+
if not choice:
|
|
75
|
+
return ""
|
|
76
|
+
|
|
77
|
+
choice = int(choice)
|
|
78
|
+
if choice == 0:
|
|
79
|
+
return ""
|
|
80
|
+
elif 1 <= choice <= len(task_names):
|
|
81
|
+
selected_name = task_names[choice - 1]
|
|
82
|
+
return tasks[selected_name] # Return the task description
|
|
83
|
+
else:
|
|
84
|
+
PrettyOutput.print("Invalid choice. Please try again.", OutputType.ERROR)
|
|
85
|
+
except ValueError:
|
|
86
|
+
PrettyOutput.print("Please enter a valid number.", OutputType.ERROR)
|
|
87
|
+
|
|
88
|
+
def main():
|
|
89
|
+
"""Main entry point for Jarvis."""
|
|
90
|
+
# Add argument parser
|
|
91
|
+
parser = argparse.ArgumentParser(description='Jarvis AI Assistant')
|
|
92
|
+
parser.add_argument('-f', '--files', nargs='*', help='List of files to process')
|
|
93
|
+
args = parser.parse_args()
|
|
94
|
+
|
|
95
|
+
load_env_from_file()
|
|
96
|
+
|
|
97
|
+
try:
|
|
98
|
+
kimi_api_key = os.getenv("KIMI_API_KEY")
|
|
99
|
+
if not kimi_api_key:
|
|
100
|
+
PrettyOutput.section("环境配置缺失", OutputType.ERROR)
|
|
101
|
+
PrettyOutput.print("\n需要设置 KIMI_API_KEY 才能使用 Jarvis。请按以下步骤操作:", OutputType.INFO, timestamp=False)
|
|
102
|
+
PrettyOutput.print("\n1. 获取 Kimi API Key:", OutputType.INFO, timestamp=False)
|
|
103
|
+
PrettyOutput.print(" • 访问 Kimi AI 平台: https://kimi.moonshot.cn", OutputType.INFO, timestamp=False)
|
|
104
|
+
PrettyOutput.print(" • 登录您的账号", OutputType.INFO, timestamp=False)
|
|
105
|
+
PrettyOutput.print(" • 打开浏览器开发者工具 (F12 或右键 -> 检查)", OutputType.INFO, timestamp=False)
|
|
106
|
+
PrettyOutput.print(" • 切换到 Network 标签页", OutputType.INFO, timestamp=False)
|
|
107
|
+
PrettyOutput.print(" • 发送任意消息", OutputType.INFO, timestamp=False)
|
|
108
|
+
PrettyOutput.print(" • 在请求中找到 Authorization 头部", OutputType.INFO, timestamp=False)
|
|
109
|
+
PrettyOutput.print(" • 复制 token 值(去掉 'Bearer ' 前缀)", OutputType.INFO, timestamp=False)
|
|
110
|
+
|
|
111
|
+
PrettyOutput.print("\n2. 设置环境变量:", OutputType.INFO, timestamp=False)
|
|
112
|
+
PrettyOutput.print(" 方法 1: 创建或编辑 ~/.jarvis_env 文件:", OutputType.INFO, timestamp=False)
|
|
113
|
+
PrettyOutput.print(" echo 'KIMI_API_KEY=your_key_here' > ~/.jarvis_env", OutputType.CODE, timestamp=False)
|
|
114
|
+
|
|
115
|
+
PrettyOutput.print("\n 方法 2: 直接设置环境变量:", OutputType.INFO, timestamp=False)
|
|
116
|
+
PrettyOutput.print(" export KIMI_API_KEY=your_key_here", OutputType.CODE, timestamp=False)
|
|
117
|
+
|
|
118
|
+
PrettyOutput.print("\n设置完成后重新运行 Jarvis。", OutputType.INFO, timestamp=False)
|
|
119
|
+
return 1
|
|
120
|
+
|
|
121
|
+
model = KimiModel(kimi_api_key)
|
|
122
|
+
|
|
123
|
+
tool_registry = ToolRegistry(model)
|
|
124
|
+
agent = Agent(model, tool_registry)
|
|
125
|
+
|
|
126
|
+
# 欢迎信息
|
|
127
|
+
PrettyOutput.print(f"Jarvis 已初始化 - With Kimi", OutputType.SYSTEM)
|
|
128
|
+
|
|
129
|
+
# 加载预定义任务
|
|
130
|
+
tasks = load_tasks()
|
|
131
|
+
if tasks:
|
|
132
|
+
selected_task = select_task(tasks)
|
|
133
|
+
if selected_task:
|
|
134
|
+
PrettyOutput.print(f"\n执行任务: {selected_task}", OutputType.INFO)
|
|
135
|
+
agent.run(selected_task, args.files)
|
|
136
|
+
return 0
|
|
137
|
+
|
|
138
|
+
# 如果没有选择预定义任务,进入交互模式
|
|
139
|
+
while True:
|
|
140
|
+
try:
|
|
141
|
+
user_input = get_multiline_input("请输入您的任务(输入空行退出):")
|
|
142
|
+
if not user_input or user_input == "__interrupt__":
|
|
143
|
+
break
|
|
144
|
+
agent.run(user_input, args.files)
|
|
145
|
+
except Exception as e:
|
|
146
|
+
PrettyOutput.print(f"错误: {str(e)}", OutputType.ERROR)
|
|
147
|
+
|
|
148
|
+
except Exception as e:
|
|
149
|
+
PrettyOutput.print(f"初始化错误: {str(e)}", OutputType.ERROR)
|
|
150
|
+
return 1
|
|
151
|
+
|
|
152
|
+
return 0
|
|
153
|
+
|
|
154
|
+
if __name__ == "__main__":
|
|
155
|
+
exit(main())
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
import sys
|
|
3
3
|
import time
|
|
4
|
+
import os
|
|
4
5
|
from typing import Dict, Optional
|
|
5
6
|
from enum import Enum
|
|
6
7
|
from datetime import datetime
|
|
7
8
|
import colorama
|
|
8
|
-
from colorama import Fore, Style
|
|
9
|
-
import
|
|
9
|
+
from colorama import Fore, Style as ColoramaStyle
|
|
10
|
+
from prompt_toolkit import PromptSession
|
|
11
|
+
from prompt_toolkit.styles import Style as PromptStyle
|
|
12
|
+
from prompt_toolkit.formatted_text import FormattedText
|
|
10
13
|
|
|
11
14
|
# 初始化colorama
|
|
12
15
|
colorama.init()
|
|
@@ -84,10 +87,10 @@ class PrettyOutput:
|
|
|
84
87
|
prefix = PrettyOutput.PREFIXES.get(output_type, "")
|
|
85
88
|
|
|
86
89
|
# 添加时间戳 - 使用白色
|
|
87
|
-
time_str = f"{Fore.WHITE}[{datetime.now().strftime('%H:%M:%S')}]{
|
|
90
|
+
time_str = f"{Fore.WHITE}[{datetime.now().strftime('%H:%M:%S')}]{ColoramaStyle.RESET_ALL} " if timestamp else ""
|
|
88
91
|
|
|
89
92
|
# 格式化输出
|
|
90
|
-
formatted_text = f"{time_str}{color}{icon} {prefix}: {text}{
|
|
93
|
+
formatted_text = f"{time_str}{color}{icon} {prefix}: {text}{ColoramaStyle.RESET_ALL}"
|
|
91
94
|
|
|
92
95
|
return formatted_text
|
|
93
96
|
|
|
@@ -101,15 +104,15 @@ class PrettyOutput:
|
|
|
101
104
|
"""打印带分隔线的段落标题"""
|
|
102
105
|
width = 60
|
|
103
106
|
color = PrettyOutput.COLORS.get(output_type, "")
|
|
104
|
-
print(f"\n{color}" + "=" * width + f"{
|
|
107
|
+
print(f"\n{color}" + "=" * width + f"{ColoramaStyle.RESET_ALL}")
|
|
105
108
|
PrettyOutput.print(title.center(width - 10), output_type, timestamp=False)
|
|
106
|
-
print(f"{color}" + "=" * width + f"{
|
|
109
|
+
print(f"{color}" + "=" * width + f"{ColoramaStyle.RESET_ALL}\n")
|
|
107
110
|
|
|
108
111
|
@staticmethod
|
|
109
112
|
def print_stream(text: str, output_type: OutputType):
|
|
110
113
|
"""打印流式输出,不换行"""
|
|
111
114
|
color = PrettyOutput.COLORS.get(output_type, "")
|
|
112
|
-
sys.stdout.write(f"{color}{text}{
|
|
115
|
+
sys.stdout.write(f"{color}{text}{ColoramaStyle.RESET_ALL}")
|
|
113
116
|
sys.stdout.flush()
|
|
114
117
|
|
|
115
118
|
@staticmethod
|
|
@@ -119,29 +122,44 @@ class PrettyOutput:
|
|
|
119
122
|
sys.stdout.flush()
|
|
120
123
|
|
|
121
124
|
def get_multiline_input(tip: str) -> str:
|
|
122
|
-
"""
|
|
125
|
+
"""获取多行输入,支持方向键、历史记录等功能"""
|
|
123
126
|
PrettyOutput.print(tip + "\n", OutputType.INFO)
|
|
124
|
-
lines = []
|
|
125
127
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
# 创建输入会话,启用历史记录
|
|
129
|
+
session = PromptSession(history=None) # 使用默认历史记录
|
|
130
|
+
|
|
131
|
+
# 定义提示符样式
|
|
132
|
+
style = PromptStyle.from_dict({
|
|
133
|
+
'prompt': 'ansicyan',
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
lines = []
|
|
137
|
+
try:
|
|
138
|
+
while True:
|
|
139
|
+
# 设置提示符
|
|
140
|
+
prompt = FormattedText([
|
|
141
|
+
('class:prompt', '... ' if lines else '>>> ')
|
|
142
|
+
])
|
|
131
143
|
|
|
132
|
-
|
|
144
|
+
# 获取输入
|
|
145
|
+
line = session.prompt(
|
|
146
|
+
prompt,
|
|
147
|
+
style=style,
|
|
148
|
+
).strip()
|
|
149
|
+
|
|
150
|
+
# 空行处理
|
|
133
151
|
if not line:
|
|
134
|
-
if not lines: #
|
|
152
|
+
if not lines: # 第一行就输入空行
|
|
135
153
|
return ""
|
|
136
|
-
break
|
|
137
|
-
|
|
154
|
+
break # 结束多行输入
|
|
155
|
+
|
|
138
156
|
lines.append(line)
|
|
139
157
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
158
|
+
except KeyboardInterrupt:
|
|
159
|
+
PrettyOutput.print("\n输入已取消", OutputType.ERROR)
|
|
160
|
+
return "__interrupt__"
|
|
143
161
|
|
|
144
|
-
return "\n".join(lines)
|
|
162
|
+
return "\n".join(lines)
|
|
145
163
|
|
|
146
164
|
def load_env_from_file():
|
|
147
165
|
"""从~/.jarvis_env加载环境变量"""
|
{jarvis_ai_assistant-0.1.12 → jarvis_ai_assistant-0.1.14}/src/jarvis_ai_assistant.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: jarvis-ai-assistant
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.14
|
|
4
4
|
Summary: Jarvis: An AI assistant that uses tools to interact with the system
|
|
5
5
|
Home-page: https://github.com/skyfireitdiy/Jarvis
|
|
6
6
|
Author: skyfire
|
|
@@ -19,6 +19,7 @@ Description-Content-Type: text/markdown
|
|
|
19
19
|
Requires-Dist: requests>=2.25.1
|
|
20
20
|
Requires-Dist: pyyaml>=5.1
|
|
21
21
|
Requires-Dist: colorama>=0.4.6
|
|
22
|
+
Requires-Dist: prompt_toolkit>=3.0.0
|
|
22
23
|
Provides-Extra: dev
|
|
23
24
|
Requires-Dist: pytest; extra == "dev"
|
|
24
25
|
Requires-Dist: black; extra == "dev"
|
|
@@ -72,6 +73,42 @@ Dynamic: requires-python
|
|
|
72
73
|
- Multi-line input support
|
|
73
74
|
- Colored output with progress indicators
|
|
74
75
|
|
|
76
|
+
|
|
77
|
+
## ⚙️ Environment Setup
|
|
78
|
+
|
|
79
|
+
Before using Jarvis, you need to set up your environment:
|
|
80
|
+
|
|
81
|
+
1. **API Key Configuration**
|
|
82
|
+
|
|
83
|
+
Create a `.jarvis_env` file in your home directory (`~/.jarvis_env`):
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
KIMI_API_KEY=your_kimi_api_key_here
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
To get your Kimi API key:
|
|
90
|
+
1. Visit [Kimi AI Platform](https://kimi.moonshot.cn) in your browser
|
|
91
|
+
2. Login to your account
|
|
92
|
+
3. Open browser Developer Tools (F12 or right-click -> Inspect)
|
|
93
|
+
4. Go to Network tab
|
|
94
|
+
5. Make any request (e.g., send a message)
|
|
95
|
+
6. Find a request to the Kimi API
|
|
96
|
+
7. Look for the `Authorization` header in the request headers
|
|
97
|
+
8. Copy the token value (remove the "Bearer " prefix)
|
|
98
|
+
9. Use this token as your `KIMI_API_KEY` in the `.jarvis_env` file
|
|
99
|
+
|
|
100
|
+
2. **Task Configuration (Optional)**
|
|
101
|
+
|
|
102
|
+
Create a `.jarvis` file in your working directory to define predefined tasks:
|
|
103
|
+
|
|
104
|
+
```yaml
|
|
105
|
+
# .jarvis
|
|
106
|
+
analyze_code: Analyze the code structure and quality in the current directory
|
|
107
|
+
fix_bugs: Help me find and fix potential bugs in the code
|
|
108
|
+
optimize: Suggest optimizations for the code
|
|
109
|
+
document: Generate documentation for the code
|
|
110
|
+
```
|
|
111
|
+
|
|
75
112
|
## 🚀 Installation
|
|
76
113
|
|
|
77
114
|
```bash
|
|
@@ -80,19 +117,44 @@ pip install jarvis-ai-assistant
|
|
|
80
117
|
|
|
81
118
|
## 💡 Usage
|
|
82
119
|
|
|
120
|
+
1. **Basic Usage**
|
|
83
121
|
```bash
|
|
84
|
-
#
|
|
122
|
+
# Start Jarvis
|
|
85
123
|
jarvis
|
|
86
124
|
|
|
87
|
-
# Process files
|
|
125
|
+
# Process specific files
|
|
88
126
|
jarvis -f file1.txt file2.py
|
|
127
|
+
```
|
|
89
128
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
129
|
+
2. **Using Predefined Tasks**
|
|
130
|
+
|
|
131
|
+
If you have a `.jarvis` file in your working directory:
|
|
132
|
+
```bash
|
|
133
|
+
# Jarvis will show available tasks on startup
|
|
134
|
+
# Select a task number or start a new conversation
|
|
94
135
|
```
|
|
95
136
|
|
|
137
|
+
3. **Interactive Features**
|
|
138
|
+
- Multi-line input support (press Enter twice to submit)
|
|
139
|
+
- File understanding and analysis
|
|
140
|
+
- Context-aware conversations
|
|
141
|
+
- Tool integration for system operations
|
|
142
|
+
|
|
143
|
+
4. **Environment Variables**
|
|
144
|
+
- `KIMI_API_KEY`: Your Kimi AI API key (required)
|
|
145
|
+
- Location: `~/.jarvis_env`
|
|
146
|
+
- Format: `KEY=value` (one per line)
|
|
147
|
+
|
|
148
|
+
5. **Task Configuration**
|
|
149
|
+
- File: `.jarvis` in working directory
|
|
150
|
+
- Format: `task_name: task_description`
|
|
151
|
+
- Purpose: Define commonly used tasks for quick access
|
|
152
|
+
- Example tasks:
|
|
153
|
+
- Code analysis
|
|
154
|
+
- Bug finding
|
|
155
|
+
- Documentation generation
|
|
156
|
+
- Performance optimization
|
|
157
|
+
|
|
96
158
|
## 🧰 Tools
|
|
97
159
|
|
|
98
160
|
| Tool | Description | Example |
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""Command line interface for Jarvis."""
|
|
3
|
-
|
|
4
|
-
import argparse
|
|
5
|
-
import yaml
|
|
6
|
-
import os
|
|
7
|
-
import sys
|
|
8
|
-
from pathlib import Path
|
|
9
|
-
|
|
10
|
-
# 添加父目录到Python路径以支持导入
|
|
11
|
-
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
12
|
-
|
|
13
|
-
from jarvis.agent import Agent
|
|
14
|
-
from jarvis.tools import ToolRegistry
|
|
15
|
-
from jarvis.models import KimiModel
|
|
16
|
-
from jarvis.utils import PrettyOutput, OutputType, get_multiline_input, load_env_from_file
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def load_tasks() -> dict:
|
|
20
|
-
"""Load tasks from .jarvis file if it exists."""
|
|
21
|
-
if not os.path.exists(".jarvis"):
|
|
22
|
-
return {}
|
|
23
|
-
|
|
24
|
-
try:
|
|
25
|
-
with open(".jarvis", "r", encoding="utf-8") as f:
|
|
26
|
-
tasks = yaml.safe_load(f)
|
|
27
|
-
|
|
28
|
-
if not isinstance(tasks, dict):
|
|
29
|
-
PrettyOutput.print("Warning: .jarvis file should contain a dictionary of task_name: task_description", OutputType.ERROR)
|
|
30
|
-
return {}
|
|
31
|
-
|
|
32
|
-
# Validate format and convert all values to strings
|
|
33
|
-
validated_tasks = {}
|
|
34
|
-
for name, desc in tasks.items():
|
|
35
|
-
if desc: # Ensure description is not empty
|
|
36
|
-
validated_tasks[str(name)] = str(desc)
|
|
37
|
-
|
|
38
|
-
return validated_tasks
|
|
39
|
-
except Exception as e:
|
|
40
|
-
PrettyOutput.print(f"Error loading .jarvis file: {str(e)}", OutputType.ERROR)
|
|
41
|
-
return {}
|
|
42
|
-
|
|
43
|
-
def select_task(tasks: dict) -> str:
|
|
44
|
-
"""Let user select a task from the list or skip. Returns task description if selected."""
|
|
45
|
-
if not tasks:
|
|
46
|
-
return ""
|
|
47
|
-
|
|
48
|
-
# Convert tasks to list for ordered display
|
|
49
|
-
task_names = list(tasks.keys())
|
|
50
|
-
|
|
51
|
-
PrettyOutput.print("\nAvailable tasks:", OutputType.INFO)
|
|
52
|
-
for i, name in enumerate(task_names, 1):
|
|
53
|
-
PrettyOutput.print(f"[{i}] {name}", OutputType.INFO)
|
|
54
|
-
PrettyOutput.print("[0] Skip predefined tasks", OutputType.INFO)
|
|
55
|
-
|
|
56
|
-
while True:
|
|
57
|
-
try:
|
|
58
|
-
choice = input("\nSelect a task number (0 to skip): ").strip()
|
|
59
|
-
if not choice:
|
|
60
|
-
return ""
|
|
61
|
-
|
|
62
|
-
choice = int(choice)
|
|
63
|
-
if choice == 0:
|
|
64
|
-
return ""
|
|
65
|
-
elif 1 <= choice <= len(task_names):
|
|
66
|
-
selected_name = task_names[choice - 1]
|
|
67
|
-
return tasks[selected_name] # Return the task description
|
|
68
|
-
else:
|
|
69
|
-
PrettyOutput.print("Invalid choice. Please try again.", OutputType.ERROR)
|
|
70
|
-
except ValueError:
|
|
71
|
-
PrettyOutput.print("Please enter a valid number.", OutputType.ERROR)
|
|
72
|
-
|
|
73
|
-
def main():
|
|
74
|
-
"""Main entry point for Jarvis."""
|
|
75
|
-
# Add argument parser
|
|
76
|
-
parser = argparse.ArgumentParser(description='Jarvis AI Assistant')
|
|
77
|
-
parser.add_argument('-f', '--files', nargs='*', help='List of files to process')
|
|
78
|
-
args = parser.parse_args()
|
|
79
|
-
|
|
80
|
-
load_env_from_file()
|
|
81
|
-
|
|
82
|
-
try:
|
|
83
|
-
kimi_api_key = os.getenv("KIMI_API_KEY")
|
|
84
|
-
if not kimi_api_key:
|
|
85
|
-
PrettyOutput.print("Kimi API key 未设置", OutputType.ERROR)
|
|
86
|
-
return 1
|
|
87
|
-
|
|
88
|
-
model = KimiModel(kimi_api_key)
|
|
89
|
-
|
|
90
|
-
tool_registry = ToolRegistry(model)
|
|
91
|
-
agent = Agent(model, tool_registry)
|
|
92
|
-
|
|
93
|
-
# 欢迎信息
|
|
94
|
-
PrettyOutput.print(f"Jarvis 已初始化 - With Kimi", OutputType.SYSTEM)
|
|
95
|
-
|
|
96
|
-
# 加载预定义任务
|
|
97
|
-
tasks = load_tasks()
|
|
98
|
-
if tasks:
|
|
99
|
-
selected_task = select_task(tasks)
|
|
100
|
-
if selected_task:
|
|
101
|
-
PrettyOutput.print(f"\n执行任务: {selected_task}", OutputType.INFO)
|
|
102
|
-
agent.run(selected_task, args.files)
|
|
103
|
-
return 0
|
|
104
|
-
|
|
105
|
-
# 如果没有选择预定义任务,进入交互模式
|
|
106
|
-
while True:
|
|
107
|
-
try:
|
|
108
|
-
user_input = get_multiline_input("请输入您的任务(输入空行退出):")
|
|
109
|
-
if not user_input or user_input == "__interrupt__":
|
|
110
|
-
break
|
|
111
|
-
agent.run(user_input, args.files)
|
|
112
|
-
except Exception as e:
|
|
113
|
-
PrettyOutput.print(f"错误: {str(e)}", OutputType.ERROR)
|
|
114
|
-
|
|
115
|
-
except Exception as e:
|
|
116
|
-
PrettyOutput.print(f"初始化错误: {str(e)}", OutputType.ERROR)
|
|
117
|
-
return 1
|
|
118
|
-
|
|
119
|
-
return 0
|
|
120
|
-
|
|
121
|
-
if __name__ == "__main__":
|
|
122
|
-
exit(main())
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|