jarvis-ai-assistant 0.1.18__py3-none-any.whl → 0.1.19__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.18"
3
+ __version__ = "0.1.19"
Binary file
Binary file
Binary file
jarvis/agent.py CHANGED
@@ -103,55 +103,32 @@ class Agent:
103
103
  tools_prompt += f" 描述: {tool['description']}\n"
104
104
  tools_prompt += f" 参数: {tool['parameters']}\n"
105
105
 
106
- self.prompt = f"""你是 {self.name},一个严格遵循 ReAct 框架进行逐步推理和行动的 AI 助手。
106
+ self.prompt = f"""你是 {self.name},一个严格遵循 ReAct 框架的 AI 助手。
107
107
 
108
108
  {tools_prompt}
109
109
 
110
- 关键规则:
111
- ‼️ 禁止创建虚假对话
112
- ‼️ 禁止假设用户回应
113
- ‼️ 禁止在没有实际用户输入时继续
114
- ‼️ 只回应用户实际说的内容
115
- ‼️ 每个动作后停止并等待
110
+ 核心能力:
111
+ 1. 使用现有工具完成任务
112
+ 2. 通过 generate_tool 创建新工具扩展功能
113
+ 3. 遵循 ReAct (思考-行动-观察) 框架
116
114
 
117
- ReAct 框架:
115
+ 工作流程:
118
116
  1. 思考
119
- - 分析当前情况
120
- - 考虑可用工具
121
- - 规划下一步行动
122
- - 仅基于事实
123
- - 不做用户回应的假设
124
- - 不想象对话内容
125
-
126
- 2. 行动(可选)
127
- - 不是每次回应都需要调用工具
128
- - 如果需要更多信息,直接询问用户
129
- - 使用工具时:
130
- - 只使用下面列出的工具
131
- - 每次只执行一个工具
132
- - 工具由用户手动执行
133
- - 必须使用有效合法的YAML格式:
134
- <START_TOOL_CALL>
135
- name: tool_name
136
- arguments:
137
- param1: value1 # 所有参数必须正确缩进
138
- param2: | # 使用YAML块样式表示多行字符串
139
- line1
140
- line2
141
- <END_TOOL_CALL>
142
-
117
+ - 分析需求和可用工具
118
+ - 评估是否需要新工具
119
+ - 规划解决方案
120
+
121
+ 2. 行动 (如果需要)
122
+ - 使用现有工具
123
+ - 创建新工具
124
+ - 询问更多信息
125
+
143
126
  3. 观察
144
- - 等待工具执行结果或用户回应
145
- - 工具执行结果由用户提供
146
- - 不要假设或想象回应
147
- - 不要创建虚假对话
148
- - 停止并等待实际输入
127
+ - 等待执行结果
128
+ - 分析反馈
129
+ - 规划下一步
149
130
 
150
- 回应格式:
151
- 思考:我分析当前情况[具体情况]... 基于[事实],我需要[目标]...
152
-
153
- [如果需要使用工具:]
154
- 行动:我将使用[工具]来[具体目的]...
131
+ 工具使用格式:
155
132
  <START_TOOL_CALL>
156
133
  name: tool_name
157
134
  arguments:
@@ -161,37 +138,28 @@ arguments:
161
138
  value
162
139
  <END_TOOL_CALL>
163
140
 
164
- [如果需要更多信息:]
165
- 我需要了解更多关于[具体细节]的信息。请提供[需要的信息]。
141
+ 创建新工具示例:
142
+ <START_TOOL_CALL>
143
+ name: generate_tool
144
+ arguments:
145
+ tool_name: custom_tool_name
146
+ class_name: CustomToolName
147
+ description: 详细的工具描述
148
+ parameters:
149
+ type: object
150
+ properties:
151
+ param1:
152
+ type: string
153
+ description: 参数1的描述
154
+ required: [param1]
155
+ <END_TOOL_CALL>
166
156
 
167
157
  严格规则:
168
- ‼️ 只使用下面列出的工具
169
- ‼️ 工具调用是可选的 - 需要时询问用户
170
- ‼️ 每次只能调用一个工具
171
- ‼️ 工具调用必须是有效的YAML格式
172
- ‼️ 参数必须正确缩进
173
- ‼️ 使用YAML块样式(|)表示多行值
174
- ‼️ 工具由用户手动执行
175
- ‼️ 等待用户提供工具执行结果
176
- ‼️ 不要假设或想象用户回应
177
- ‼️ 没有用户输入时不要继续对话
178
- ‼️ 不要创建虚假对话
179
- ‼️ 每个动作后停止
180
- ‼️ 不要假设结果
181
- ‼️ 不要假设行动
182
-
183
- 注意事项:
184
- - 先思考再行动
185
- - 需要时询问用户
186
- - 只使用列出的工具
187
- - 一次一个工具
188
- - 严格遵循YAML格式
189
- - 等待用户回应
190
- - 工具结果来自用户
191
- - 不要假设回应
192
- - 不要虚构对话
193
- - 每个动作后停止
194
- - 只在有实际用户输入时继续
158
+ 1. 每次只能执行一个工具
159
+ 2. 等待用户提供执行结果
160
+ 3. 不要假设或想象结果
161
+ 4. 不要创建虚假对话
162
+ 5. 每个动作后停止等待
195
163
 
196
164
  任务:
197
165
  {user_input}
jarvis/main.py CHANGED
@@ -6,6 +6,9 @@ import yaml
6
6
  import os
7
7
  import sys
8
8
  from pathlib import Path
9
+ from prompt_toolkit import prompt
10
+ from prompt_toolkit.completion import WordCompleter
11
+ from prompt_toolkit.validation import Validator, ValidationError
9
12
 
10
13
  # 添加父目录到Python路径以支持导入
11
14
  sys.path.insert(0, str(Path(__file__).parent.parent))
@@ -55,6 +58,19 @@ def load_tasks() -> dict:
55
58
 
56
59
  return tasks
57
60
 
61
+ class NumberValidator(Validator):
62
+ def validate(self, document):
63
+ text = document.text.strip()
64
+ if not text: # Allow empty input
65
+ return
66
+
67
+ try:
68
+ number = int(text)
69
+ if number < 0:
70
+ raise ValidationError(message='Please enter a non-negative number')
71
+ except ValueError:
72
+ raise ValidationError(message='Please enter a valid number')
73
+
58
74
  def select_task(tasks: dict) -> str:
59
75
  """Let user select a task from the list or skip. Returns task description if selected."""
60
76
  if not tasks:
@@ -68,9 +84,20 @@ def select_task(tasks: dict) -> str:
68
84
  PrettyOutput.print(f"[{i}] {name}", OutputType.INFO)
69
85
  PrettyOutput.print("[0] Skip predefined tasks", OutputType.INFO)
70
86
 
87
+ # Create completer with valid numbers
88
+ valid_numbers = [str(i) for i in range(len(task_names) + 1)]
89
+ number_completer = WordCompleter(valid_numbers)
90
+
71
91
  while True:
72
92
  try:
73
- choice = input("\nSelect a task number (0 to skip): ").strip()
93
+ choice = prompt(
94
+ "\nSelect a task number (0 to skip): ",
95
+ completer=number_completer,
96
+ validator=NumberValidator(),
97
+ validate_while_typing=False,
98
+ enable_history_search=True,
99
+ ).strip()
100
+
74
101
  if not choice:
75
102
  return ""
76
103
 
@@ -81,9 +108,12 @@ def select_task(tasks: dict) -> str:
81
108
  selected_name = task_names[choice - 1]
82
109
  return tasks[selected_name] # Return the task description
83
110
  else:
84
- PrettyOutput.print("Invalid choice. Please try again.", OutputType.ERROR)
85
- except ValueError:
86
- PrettyOutput.print("Please enter a valid number.", OutputType.ERROR)
111
+ PrettyOutput.print("Invalid choice. Please select a number from the list.", OutputType.ERROR)
112
+
113
+ except KeyboardInterrupt:
114
+ return "" # Return empty on Ctrl+C
115
+ except EOFError:
116
+ return "" # Return empty on Ctrl+D
87
117
 
88
118
  def main():
89
119
  """Main entry point for Jarvis."""
jarvis/tools/generator.py CHANGED
@@ -113,9 +113,13 @@ class ExampleTool:
113
113
  def __init__(self, **kwargs):
114
114
  '''初始化工具
115
115
  Args:
116
- model: 模型处理器
116
+ model: 模型处理器
117
+ 与大模型交互: model.chat(prompt)
118
+ 使用完成后删除会话: model.delete_chat()
117
119
  output_handler: 输出处理器
120
+ 输出信息: output_handler.print(text, output_type)
118
121
  register: 注册器
122
+ 注册工具: register.register_tool_by_file(tool_file)
119
123
  '''
120
124
  self.model = kwargs.get('model')
121
125
  self.output = kwargs.get('output_handler')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: jarvis-ai-assistant
3
- Version: 0.1.18
3
+ Version: 0.1.19
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
@@ -1,10 +1,10 @@
1
- jarvis/__init__.py,sha256=_f28_I38xy1i_kwbYg6iIU59t_tF8apmhCpqrc4yWvQ,50
2
- jarvis/agent.py,sha256=f8RIOFIiwRAuql4O32P_nDXByzBKbrNM-ergf_F8FfU,9409
3
- jarvis/main.py,sha256=CwqsXKTxeZ3rWwdHfhMyzX1DFJC3NA7D-Sbla0YkdSE,7046
1
+ jarvis/__init__.py,sha256=ZS0T4CRb_B0dOsiPYPRNrunjMPVvZzmD9IIaUB29ig8,50
2
+ jarvis/agent.py,sha256=r00CssF8HzSj4r2GXR9KNJ3XJk46HIjw4BEfzx-fKMQ,8114
3
+ jarvis/main.py,sha256=tptQp6rjhHOSsPphmrtoxf7l78btnP_hJmr3hVMO4zg,8103
4
4
  jarvis/utils.py,sha256=YipQpEuIRwFE3y3YrgGlSVLEPDrlbBNY1gRiOJix9DU,6602
5
- jarvis/__pycache__/__init__.cpython-313.pyc,sha256=PGPqHZavqZ2fSStY_yJGNQjMt49Af70vSbxInRVxFwM,209
6
- jarvis/__pycache__/agent.cpython-313.pyc,sha256=anFGVa4pfpsOCDbstPAPSsUmglCZUrRkuDN-jnvhSyI,12152
7
- jarvis/__pycache__/main.cpython-313.pyc,sha256=fvBChS8JvPs2jNR4cYyRJi10n7TVph1RAZtp-AkESuo,9669
5
+ jarvis/__pycache__/__init__.cpython-313.pyc,sha256=TnbFSQwCFYqlSRaAgJgfajYnPQVIUrqM9Pyj4QRQjDQ,209
6
+ jarvis/__pycache__/agent.cpython-313.pyc,sha256=ItAH6Mb964vpqvziIsw-62avHUVu54mNgTa02VWK3lM,10855
7
+ jarvis/__pycache__/main.cpython-313.pyc,sha256=uQ1QHMHR6EukOb7z-YOz8CicXRPEfiHyS7KRq15xxVw,10943
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
10
  jarvis/__pycache__/utils.cpython-313.pyc,sha256=Jpkf2GOA1d_fgrRftqZch1yiO0mB75LWHzQk8IfhHRU,8977
@@ -18,7 +18,7 @@ jarvis/models/__pycache__/kimi.cpython-313.pyc,sha256=-hOwhZrfvqfd5K_c34Tm-uR3ga
18
18
  jarvis/tools/__init__.py,sha256=AjmFYLXt-_ulZXdYiXya2fD7QCJ-RaK91PEZCNj-UbA,262
19
19
  jarvis/tools/base.py,sha256=ZHmRczYks7CuaYHU9uB5QnsD40G_jeqE6ubuhlaSFR8,7318
20
20
  jarvis/tools/file_ops.py,sha256=KbQLVCCXw-MtJg-12iyMeVGu8BTtLq7Mk7fpVKau40U,4296
21
- jarvis/tools/generator.py,sha256=A_J7U9_Vjh37zotGkt5VDM8As1BfNawM-6vbclJ4PR4,7142
21
+ jarvis/tools/generator.py,sha256=VJXfZg0Xt3OZr1LtX8m-RJh9807VxZRah5xV7UtX6is,7406
22
22
  jarvis/tools/shell.py,sha256=MWe9-BAGApbGJfR60XG4nElGYHNBnbdF9vsOQTnEZ4g,2989
23
23
  jarvis/tools/__pycache__/__init__.cpython-313.pyc,sha256=KC48FS57427navbkxZ0eDKLePMCH2BKc5vAIu0b8lFc,404
24
24
  jarvis/tools/__pycache__/base.cpython-313.pyc,sha256=r-jPPg5L_Rok2c_VsMEAXkhuiiUjHv6bLCwVjnONDRo,9861
@@ -26,7 +26,7 @@ jarvis/tools/__pycache__/bing_search.cpython-313.pyc,sha256=1G_wPbk5wcQYh7H0drLI
26
26
  jarvis/tools/__pycache__/calculator.cpython-313.pyc,sha256=C_qwTDGm6gc7QNxtPzPZXyStdKEintJVQIt5NMHQ8oY,4205
27
27
  jarvis/tools/__pycache__/calculator_tool.cpython-313.pyc,sha256=PI4LZNDTPdSe3ffWDRovLZ-r-vF8Kl-n6xdGdFWiBpY,4296
28
28
  jarvis/tools/__pycache__/file_ops.cpython-313.pyc,sha256=OBR2EDQ2Ana7CTtLOoM5AYJzyVwP683LS7QrOR8_I3g,5208
29
- jarvis/tools/__pycache__/generator.cpython-313.pyc,sha256=sOpj8PBTUwYSVrWhBr-ESK43lSP0HOkRUJdEpLD6PPY,8482
29
+ jarvis/tools/__pycache__/generator.cpython-313.pyc,sha256=3XTMBphRw7gqRqJXPuQrA4_6FirinFZ3khd7LiCy7uU,8746
30
30
  jarvis/tools/__pycache__/python_script.cpython-313.pyc,sha256=8JpryqTovEiTvBlWAK1KjZmPvHUuPc9GT9rTXBEQoJc,6693
31
31
  jarvis/tools/__pycache__/rag.cpython-313.pyc,sha256=JH6-PSZRMKAvTZqCwlRXJGClxYXNMs-vetU0q7hBLz0,6064
32
32
  jarvis/tools/__pycache__/search.cpython-313.pyc,sha256=wLMIkFwT-h4NGHgssytT4xme7sGO6ZhEnex7kjcy0-k,5990
@@ -36,9 +36,9 @@ jarvis/tools/__pycache__/user_confirmation.cpython-313.pyc,sha256=wK3Ev10lHSUSRv
36
36
  jarvis/tools/__pycache__/user_input.cpython-313.pyc,sha256=JjTFOhObKsKF4Pn8KBRuKfV1_Ssj083fjU7Mfc_5z7c,2531
37
37
  jarvis/tools/__pycache__/user_interaction.cpython-313.pyc,sha256=RuVZ-pmiPBDywY3efgXSfohMAciC1avMGPmBK5qlnew,3305
38
38
  jarvis/tools/__pycache__/webpage.cpython-313.pyc,sha256=BjzSfnNzsKCrLETCcWjt32lNDLzwnjqcVGg4JfWd9OM,3008
39
- jarvis_ai_assistant-0.1.18.dist-info/LICENSE,sha256=AGgVgQmTqFvaztRtCAXsAMryUymB18gZif7_l2e1XOg,1063
40
- jarvis_ai_assistant-0.1.18.dist-info/METADATA,sha256=3n1MHwr3pmlVGHHwG-CX3tLdb-SI7lqLA7UJlFhM528,10193
41
- jarvis_ai_assistant-0.1.18.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
42
- jarvis_ai_assistant-0.1.18.dist-info/entry_points.txt,sha256=iKu7OMfew9dtfGhW71gIMTg4wvafuPqKb4wyQOnMAGU,44
43
- jarvis_ai_assistant-0.1.18.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
44
- jarvis_ai_assistant-0.1.18.dist-info/RECORD,,
39
+ jarvis_ai_assistant-0.1.19.dist-info/LICENSE,sha256=AGgVgQmTqFvaztRtCAXsAMryUymB18gZif7_l2e1XOg,1063
40
+ jarvis_ai_assistant-0.1.19.dist-info/METADATA,sha256=SPaJ0q7U024HA6W3sagtO6SlmDizohRfXhCBEuFMdrM,10193
41
+ jarvis_ai_assistant-0.1.19.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
42
+ jarvis_ai_assistant-0.1.19.dist-info/entry_points.txt,sha256=iKu7OMfew9dtfGhW71gIMTg4wvafuPqKb4wyQOnMAGU,44
43
+ jarvis_ai_assistant-0.1.19.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
44
+ jarvis_ai_assistant-0.1.19.dist-info/RECORD,,