jarvis-ai-assistant 0.1.12__py3-none-any.whl → 0.1.14__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.

Potentially problematic release.


This version of jarvis-ai-assistant might be problematic. Click here for more details.

jarvis/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """Jarvis AI Assistant"""
2
2
 
3
- __version__ = "0.1.12"
3
+ __version__ = "0.1.14"
Binary file
Binary file
Binary file
jarvis/main.py CHANGED
@@ -17,28 +17,43 @@ from jarvis.utils import PrettyOutput, OutputType, get_multiline_input, load_env
17
17
 
18
18
 
19
19
  def load_tasks() -> dict:
20
- """Load tasks from .jarvis file if it exists."""
21
- if not os.path.exists(".jarvis"):
22
- return {}
20
+ """Load tasks from .jarvis files in user home and current directory."""
21
+ tasks = {}
23
22
 
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)
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)
37
29
 
38
- return validated_tasks
39
- except Exception as e:
40
- PrettyOutput.print(f"Error loading .jarvis file: {str(e)}", OutputType.ERROR)
41
- return {}
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
42
57
 
43
58
  def select_task(tasks: dict) -> str:
44
59
  """Let user select a task from the list or skip. Returns task description if selected."""
@@ -82,7 +97,25 @@ def main():
82
97
  try:
83
98
  kimi_api_key = os.getenv("KIMI_API_KEY")
84
99
  if not kimi_api_key:
85
- PrettyOutput.print("Kimi API key 未设置", OutputType.ERROR)
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)
86
119
  return 1
87
120
 
88
121
  model = KimiModel(kimi_api_key)
jarvis/utils.py CHANGED
@@ -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 os
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')}]{Style.RESET_ALL} " if timestamp else ""
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}{Style.RESET_ALL}"
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"{Style.RESET_ALL}")
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"{Style.RESET_ALL}\n")
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}{Style.RESET_ALL}")
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
- while True:
127
- try:
128
- prompt = "... " if lines else ">>> "
129
- sys.stdout.write(f"{Fore.GREEN}{prompt}{Style.RESET_ALL}")
130
- sys.stdout.flush()
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
- line = input().strip()
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
- except KeyboardInterrupt:
141
- PrettyOutput.print("\n输入已取消", OutputType.ERROR)
142
- return "__interrupt__"
158
+ except KeyboardInterrupt:
159
+ PrettyOutput.print("\n输入已取消", OutputType.ERROR)
160
+ return "__interrupt__"
143
161
 
144
- return "\n".join(lines).strip()
162
+ return "\n".join(lines)
145
163
 
146
164
  def load_env_from_file():
147
165
  """从~/.jarvis_env加载环境变量"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: jarvis-ai-assistant
3
- Version: 0.1.12
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
- # Quick Start
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
- # Using predefined tasks
91
- # Create .jarvis file in your working directory:
92
- analyze_code: Analyze the code in the current directory
93
- fix_bugs: Help me find and fix bugs in the code
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 |
@@ -1,13 +1,13 @@
1
- jarvis/__init__.py,sha256=famvLolv2Q7BJtAyM81Gi64oXQv1nh1rjb1kJ_f5hKc,50
1
+ jarvis/__init__.py,sha256=ASmWOyubd5yF30GOCGKZ5qOTjVIoSmQ4eOT7ImnQHpw,50
2
2
  jarvis/agent.py,sha256=xo5YdY8UbgE3AJaitT1dXoNoVm769LrWyFzEXxVCG7A,8672
3
- jarvis/main.py,sha256=_1hE0MZ1OsIJpmlipUwtqFszh9rm7VmQcnnWr80o3p4,4176
4
- jarvis/utils.py,sha256=3hLtv-HcBL8Ngw69cowhARuIFrjcQ6yRP3Y1o9CvtsI,5992
5
- jarvis/__pycache__/__init__.cpython-313.pyc,sha256=GspJR-EdT1vU33bJjBm_IcUrNBtFKVEhKoHJnyIYY5s,209
3
+ jarvis/main.py,sha256=QD8FlhpJ-PFUEOjt77gllpHEgqtfNKV_S8NQZSWRTbE,6760
4
+ jarvis/utils.py,sha256=YipQpEuIRwFE3y3YrgGlSVLEPDrlbBNY1gRiOJix9DU,6602
5
+ jarvis/__pycache__/__init__.cpython-313.pyc,sha256=LOM8mV9fUUpfEt-eCawXu9EW44gzfiAAUY7tOmgtjBM,209
6
6
  jarvis/__pycache__/agent.cpython-313.pyc,sha256=DP0zgyKjGuwc62rH_vpoy_hXmGMI3zoHPlXZYu0qqp4,9956
7
- jarvis/__pycache__/main.cpython-313.pyc,sha256=o80rvS95KbpeL4MSEoMC0rt0Y91-asDHbHPJU8M8kxo,5933
7
+ jarvis/__pycache__/main.cpython-313.pyc,sha256=vsL4l0JZFp805S22a0uZR_9k6NhpHrb-YHFY61JXF4M,9279
8
8
  jarvis/__pycache__/models.cpython-313.pyc,sha256=uWuRIjGrY4YDB3dGW5PGDLWaS03et8g11O725TjY_eU,5960
9
9
  jarvis/__pycache__/tools.cpython-313.pyc,sha256=lAD4LrnnWzNZQmHXGfZ_2l7oskOpr2_2OC-gdFhxQY8,33933
10
- jarvis/__pycache__/utils.cpython-313.pyc,sha256=k4jyAlx4tlW0MKLMLzV7OOH9zsKrK0H955kY6M2SuFU,8772
10
+ jarvis/__pycache__/utils.cpython-313.pyc,sha256=Jpkf2GOA1d_fgrRftqZch1yiO0mB75LWHzQk8IfhHRU,8977
11
11
  jarvis/__pycache__/zte_llm.cpython-313.pyc,sha256=kMm9IGundGmOPqjsgrm9oIaWLDagYGCPRAaE3ipkc-0,5662
12
12
  jarvis/models/__init__.py,sha256=B_IJFvKTaxdg19FAD1ea288tYp3-bRYRpkeGI0_OcBI,262
13
13
  jarvis/models/base.py,sha256=GgVl5N0qDqn-yqRcX_PX3wHjogouE6GPFAWktG40cXg,403
@@ -32,8 +32,8 @@ jarvis/tools/__pycache__/user_confirmation.cpython-313.pyc,sha256=wK3Ev10lHSUSRv
32
32
  jarvis/tools/__pycache__/user_input.cpython-313.pyc,sha256=JjTFOhObKsKF4Pn8KBRuKfV1_Ssj083fjU7Mfc_5z7c,2531
33
33
  jarvis/tools/__pycache__/user_interaction.cpython-313.pyc,sha256=RuVZ-pmiPBDywY3efgXSfohMAciC1avMGPmBK5qlnew,3305
34
34
  jarvis/tools/__pycache__/webpage.cpython-313.pyc,sha256=BjzSfnNzsKCrLETCcWjt32lNDLzwnjqcVGg4JfWd9OM,3008
35
- jarvis_ai_assistant-0.1.12.dist-info/METADATA,sha256=BDwc5sbj9q6qHxq5KDMKdZCod0_PrMX-6H9YHWd0Pkg,3507
36
- jarvis_ai_assistant-0.1.12.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
37
- jarvis_ai_assistant-0.1.12.dist-info/entry_points.txt,sha256=iKu7OMfew9dtfGhW71gIMTg4wvafuPqKb4wyQOnMAGU,44
38
- jarvis_ai_assistant-0.1.12.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
39
- jarvis_ai_assistant-0.1.12.dist-info/RECORD,,
35
+ jarvis_ai_assistant-0.1.14.dist-info/METADATA,sha256=c9CfamgEPsk1HeSU6wx7onzQ7rWerFpOkh1Jz7IgkYU,5270
36
+ jarvis_ai_assistant-0.1.14.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
37
+ jarvis_ai_assistant-0.1.14.dist-info/entry_points.txt,sha256=iKu7OMfew9dtfGhW71gIMTg4wvafuPqKb4wyQOnMAGU,44
38
+ jarvis_ai_assistant-0.1.14.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
39
+ jarvis_ai_assistant-0.1.14.dist-info/RECORD,,