jarvis-ai-assistant 0.1.159__tar.gz → 0.1.160__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.159/src/jarvis_ai_assistant.egg-info → jarvis_ai_assistant-0.1.160}/PKG-INFO +2 -2
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/README.md +1 -1
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/pyproject.toml +1 -1
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/setup.py +1 -1
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/__init__.py +1 -1
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_agent/file_input_handler.py +2 -3
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_agent/patch.py +74 -78
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/code_review.py +29 -35
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_git_utils/git_commiter.py +27 -59
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_methodology/main.py +2 -2
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_platform/base.py +43 -30
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_platform/kimi.py +2 -2
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/file_analyzer.py +2 -2
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/file_operation.py +1 -1
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/read_webpage.py +1 -1
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/registry.py +33 -41
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/search_web.py +1 -1
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_utils/methodology.py +71 -61
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_utils/utils.py +5 -12
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160/src/jarvis_ai_assistant.egg-info}/PKG-INFO +2 -2
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/MANIFEST.in +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/setup.cfg +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_agent/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_agent/builtin_input_handler.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_agent/jarvis.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_agent/main.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_agent/output_handler.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_agent/shell_input_handler.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_agent/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_agent/code_agent.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/c_cpp.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/csharp.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/data_format.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/devops.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/docs.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/go.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/infrastructure.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/java.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/javascript.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/kotlin.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/loader.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/php.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/python.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/ruby.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/rust.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/shell.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/sql.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/swift.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_code_analysis/checklists/web.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_dev/main.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_git_details/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_git_details/main.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_git_squash/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_git_squash/main.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_lsp/base.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_lsp/cpp.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_lsp/go.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_lsp/python.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_lsp/registry.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_lsp/rust.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_mcp/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_mcp/sse_mcp_client.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_mcp/stdio_mcp_client.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_multi_agent/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_multi_agent/main.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_platform/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_platform/human.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_platform/registry.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_platform/yuanbao.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_platform_manager/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_platform_manager/main.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_smart_shell/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_smart_shell/main.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/ask_codebase.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/ask_user.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/base.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/chdir.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/code_plan.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/create_code_agent.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/create_sub_agent.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/execute_script.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/find_methodology.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/lsp_get_diagnostics.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/methodology.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/read_code.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_tools/virtual_tty.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_utils/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_utils/builtin_replace_map.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_utils/config.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_utils/embedding.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_utils/file_processors.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_utils/git_utils.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_utils/globals.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_utils/input.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_utils/output.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_utils/tag.py +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis_ai_assistant.egg-info/SOURCES.txt +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis_ai_assistant.egg-info/dependency_links.txt +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis_ai_assistant.egg-info/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis_ai_assistant.egg-info/requires.txt +0 -0
- {jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis_ai_assistant.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: jarvis-ai-assistant
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.160
|
|
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
|
|
@@ -194,7 +194,7 @@ jarvis-methodology --help
|
|
|
194
194
|
### 环境变量配置
|
|
195
195
|
| 变量名称 | 默认值 | 说明 |
|
|
196
196
|
|----------|--------|------|
|
|
197
|
-
| `JARVIS_MAX_TOKEN_COUNT` | 102400000 |
|
|
197
|
+
| `JARVIS_MAX_TOKEN_COUNT` | 102400000 | 上下文窗口的最大token数量 |
|
|
198
198
|
| `JARVIS_MAX_INPUT_TOKEN_COUNT` | 32000 | 输入的最大token数量 |
|
|
199
199
|
| `JARVIS_AUTO_COMPLETE` | false | 是否启用自动完成功能(任务判定完成的时候会自动终止) |
|
|
200
200
|
| `JARVIS_SHELL_NAME` | bash | 系统shell名称 |
|
|
@@ -125,7 +125,7 @@ jarvis-methodology --help
|
|
|
125
125
|
### 环境变量配置
|
|
126
126
|
| 变量名称 | 默认值 | 说明 |
|
|
127
127
|
|----------|--------|------|
|
|
128
|
-
| `JARVIS_MAX_TOKEN_COUNT` | 102400000 |
|
|
128
|
+
| `JARVIS_MAX_TOKEN_COUNT` | 102400000 | 上下文窗口的最大token数量 |
|
|
129
129
|
| `JARVIS_MAX_INPUT_TOKEN_COUNT` | 32000 | 输入的最大token数量 |
|
|
130
130
|
| `JARVIS_AUTO_COMPLETE` | false | 是否启用自动完成功能(任务判定完成的时候会自动终止) |
|
|
131
131
|
| `JARVIS_SHELL_NAME` | bash | 系统shell名称 |
|
|
@@ -8,7 +8,7 @@ default = true
|
|
|
8
8
|
|
|
9
9
|
[project]
|
|
10
10
|
name = "jarvis-ai-assistant"
|
|
11
|
-
version = "0.1.
|
|
11
|
+
version = "0.1.160"
|
|
12
12
|
description = "Jarvis: An AI assistant that uses tools to interact with the system"
|
|
13
13
|
readme = "README.md"
|
|
14
14
|
authors = [{ name = "skyfire", email = "skyfireitdiy@hotmail.com" }]
|
|
@@ -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.160",
|
|
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",
|
|
@@ -7,9 +7,8 @@ from typing import Any, Tuple
|
|
|
7
7
|
from yaspin import yaspin
|
|
8
8
|
|
|
9
9
|
from jarvis.jarvis_tools.file_operation import FileOperationTool
|
|
10
|
-
from jarvis.jarvis_utils.config import INPUT_WINDOW_REVERSE_SIZE, get_max_input_token_count
|
|
11
|
-
from jarvis.jarvis_utils.embedding import get_context_token_count
|
|
12
10
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
11
|
+
from jarvis.jarvis_utils.utils import is_context_overflow
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
def file_input_handler(user_input: str, agent: Any) -> Tuple[str, bool]:
|
|
@@ -86,7 +85,7 @@ def file_input_handler(user_input: str, agent: Any) -> Tuple[str, bool]:
|
|
|
86
85
|
spinner.text = "文件读取完成"
|
|
87
86
|
spinner.ok("✅")
|
|
88
87
|
prompt = result["stdout"] + "\n" + prompt
|
|
89
|
-
if
|
|
88
|
+
if is_context_overflow(prompt):
|
|
90
89
|
return old_prompt, False
|
|
91
90
|
|
|
92
91
|
return prompt, False
|
{jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_agent/patch.py
RENAMED
|
@@ -2,20 +2,19 @@ import re
|
|
|
2
2
|
from typing import Dict, Any, Tuple
|
|
3
3
|
import os
|
|
4
4
|
|
|
5
|
-
from yaspin import yaspin
|
|
5
|
+
from yaspin import yaspin # type: ignore
|
|
6
6
|
|
|
7
7
|
from jarvis.jarvis_agent.output_handler import OutputHandler
|
|
8
8
|
from jarvis.jarvis_platform.base import BasePlatform
|
|
9
9
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
10
10
|
from jarvis.jarvis_git_utils.git_commiter import GitCommitTool
|
|
11
11
|
from jarvis.jarvis_tools.file_operation import FileOperationTool
|
|
12
|
-
from jarvis.jarvis_utils.config import
|
|
13
|
-
from jarvis.jarvis_utils.embedding import get_context_token_count
|
|
12
|
+
from jarvis.jarvis_utils.config import is_confirm_before_apply_patch
|
|
14
13
|
from jarvis.jarvis_utils.git_utils import get_commits_between, get_latest_commit_hash
|
|
15
14
|
from jarvis.jarvis_utils.globals import add_read_file_record, has_read_file
|
|
16
15
|
from jarvis.jarvis_utils.input import get_multiline_input
|
|
17
16
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
18
|
-
from jarvis.jarvis_utils.utils import get_file_line_count, user_confirm
|
|
17
|
+
from jarvis.jarvis_utils.utils import is_context_overflow, get_file_line_count, user_confirm
|
|
19
18
|
from jarvis.jarvis_utils.tag import ot, ct
|
|
20
19
|
|
|
21
20
|
|
|
@@ -95,7 +94,7 @@ def add(a, b):
|
|
|
95
94
|
- 保持代码风格一致性,遵循项目现有的编码规范
|
|
96
95
|
- 在修改前仔细分析原代码的格式风格,确保补丁与之完全兼容
|
|
97
96
|
- 绝不提供完整文件内容,除非是新建文件
|
|
98
|
-
-
|
|
97
|
+
- 每个文件的修改是独立的,不能出现“参照xxx文件的修改”这样的描述
|
|
99
98
|
- 不要出现未实现的代码,如:TODO
|
|
100
99
|
"""
|
|
101
100
|
|
|
@@ -377,6 +376,7 @@ def handle_small_code_operation(filepath: str, patch_content: str) -> bool:
|
|
|
377
376
|
try:
|
|
378
377
|
model = PlatformRegistry().get_normal_platform()
|
|
379
378
|
file_content = FileOperationTool().execute({"operation":"read", "files":[{"path":filepath}]})["stdout"]
|
|
379
|
+
|
|
380
380
|
model.set_suppress_output(True)
|
|
381
381
|
|
|
382
382
|
prompt = f"""
|
|
@@ -407,6 +407,7 @@ def handle_small_code_operation(filepath: str, patch_content: str) -> bool:
|
|
|
407
407
|
{ot("MERGED_CODE")}
|
|
408
408
|
[合并后的完整代码,包括所有空行和缩进]
|
|
409
409
|
{ct("MERGED_CODE")}
|
|
410
|
+
|
|
410
411
|
# 原始代码
|
|
411
412
|
{file_content}
|
|
412
413
|
"""
|
|
@@ -466,18 +467,23 @@ def handle_small_code_operation(filepath: str, patch_content: str) -> bool:
|
|
|
466
467
|
return False
|
|
467
468
|
|
|
468
469
|
|
|
470
|
+
|
|
469
471
|
def handle_large_code_operation(filepath: str, patch_content: str, model: BasePlatform) -> bool:
|
|
470
472
|
"""处理大型代码文件的补丁操作,使用差异化补丁格式"""
|
|
471
473
|
with yaspin(text=f"正在处理文件 {filepath}...", color="cyan") as spinner:
|
|
472
474
|
try:
|
|
473
475
|
file_content = FileOperationTool().execute({"operation":"read", "files":[{"path":filepath}]})["stdout"]
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
476
|
+
need_upload_file = is_context_overflow(file_content)
|
|
477
|
+
upload_success = False
|
|
478
|
+
# 读取原始文件内容
|
|
479
|
+
with spinner.hidden():
|
|
480
|
+
if need_upload_file and model.upload_files([filepath]):
|
|
481
|
+
upload_success = True
|
|
482
|
+
|
|
483
|
+
|
|
478
484
|
model.set_suppress_output(True)
|
|
479
485
|
|
|
480
|
-
|
|
486
|
+
main_prompt = f"""
|
|
481
487
|
# 代码补丁生成专家指南
|
|
482
488
|
|
|
483
489
|
## 任务描述
|
|
@@ -487,8 +493,7 @@ def handle_large_code_operation(filepath: str, patch_content: str, model: BasePl
|
|
|
487
493
|
```
|
|
488
494
|
{patch_content}
|
|
489
495
|
```
|
|
490
|
-
|
|
491
|
-
suffix_prompt = """
|
|
496
|
+
|
|
492
497
|
## 补丁生成要求
|
|
493
498
|
1. **精确性**:严格按照补丁的意图修改代码
|
|
494
499
|
2. **格式一致性**:严格保持原始代码的格式风格
|
|
@@ -523,77 +528,68 @@ def handle_large_code_operation(filepath: str, patch_content: str, model: BasePl
|
|
|
523
528
|
<<<<<< REPLACE
|
|
524
529
|
{ct("DIFF")}
|
|
525
530
|
"""
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
response = model.chat_until_success(
|
|
531
|
+
|
|
532
|
+
for _ in range(3):
|
|
533
|
+
file_prompt = ""
|
|
534
|
+
if not need_upload_file:
|
|
535
|
+
file_prompt = f"""
|
|
536
|
+
# 原始代码
|
|
537
|
+
{file_content}
|
|
538
|
+
"""
|
|
539
|
+
response = model.chat_until_success(main_prompt + file_prompt)
|
|
535
540
|
else:
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
model,
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
if modified_content.count(search_text) > 1:
|
|
573
|
-
prompt = f"补丁 #{patch_count} 应用失败:找到多个匹配的代码段"
|
|
574
|
-
spinner.write(f"❌ 补丁 #{patch_count} 应用失败:找到多个匹配的代码段")
|
|
541
|
+
if upload_success:
|
|
542
|
+
response = model.chat_until_success(main_prompt)
|
|
543
|
+
else:
|
|
544
|
+
response = model.chat_big_content(file_content, main_prompt)
|
|
545
|
+
|
|
546
|
+
# 解析差异化补丁
|
|
547
|
+
diff_blocks = re.finditer(ot("DIFF")+r'\s*>{4,} SEARCH\n?(.*?)\n?={4,}\n?(.*?)\s*<{4,} REPLACE\n?'+ct("DIFF"),
|
|
548
|
+
response, re.DOTALL)
|
|
549
|
+
|
|
550
|
+
# 读取原始文件内容
|
|
551
|
+
with open(filepath, 'r', encoding='utf-8', errors="ignore") as f:
|
|
552
|
+
file_content = f.read()
|
|
553
|
+
|
|
554
|
+
# 应用所有差异化补丁
|
|
555
|
+
modified_content = file_content
|
|
556
|
+
patch_count = 0
|
|
557
|
+
success = True
|
|
558
|
+
for match in diff_blocks:
|
|
559
|
+
search_text = match.group(1).strip()
|
|
560
|
+
replace_text = match.group(2).strip()
|
|
561
|
+
patch_count += 1
|
|
562
|
+
# 检查搜索文本是否存在于文件中
|
|
563
|
+
if search_text in modified_content:
|
|
564
|
+
# 如果有多处,报错
|
|
565
|
+
if modified_content.count(search_text) > 1:
|
|
566
|
+
prompt = f"补丁 #{patch_count} 应用失败:找到多个匹配的代码段"
|
|
567
|
+
spinner.write(f"❌ 补丁 #{patch_count} 应用失败:找到多个匹配的代码段")
|
|
568
|
+
success = False
|
|
569
|
+
break
|
|
570
|
+
# 应用替换
|
|
571
|
+
modified_content = modified_content.replace(
|
|
572
|
+
search_text, replace_text)
|
|
573
|
+
spinner.write(f"✅ 补丁 #{patch_count} 应用成功")
|
|
574
|
+
else:
|
|
575
|
+
spinner.write(f"❌ 补丁 #{patch_count} 应用失败:无法找到匹配的代码段")
|
|
576
|
+
prompt = f"补丁 #{patch_count} 应用失败:无法找到匹配的代码段"
|
|
575
577
|
success = False
|
|
576
578
|
break
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
spinner.write(f"✅ 补丁 #{patch_count} 应用成功")
|
|
581
|
-
else:
|
|
582
|
-
spinner.write(f"❌ 补丁 #{patch_count} 应用失败:无法找到匹配的代码段")
|
|
583
|
-
prompt = f"补丁 #{patch_count} 应用失败:无法找到匹配的代码段"
|
|
584
|
-
success = False
|
|
585
|
-
break
|
|
586
|
-
if not success:
|
|
587
|
-
revert_file(filepath)
|
|
588
|
-
return False
|
|
579
|
+
if not success:
|
|
580
|
+
revert_file(filepath)
|
|
581
|
+
continue
|
|
589
582
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
583
|
+
# 写入修改后的内容
|
|
584
|
+
with open(filepath, 'w', encoding='utf-8', errors="ignore") as f:
|
|
585
|
+
f.write(modified_content)
|
|
593
586
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
587
|
+
spinner.text = f"文件 {filepath} 修改完成,应用了 {patch_count} 个补丁"
|
|
588
|
+
spinner.ok("✅")
|
|
589
|
+
return True
|
|
590
|
+
spinner.text = f"文件 {filepath} 修改失败"
|
|
591
|
+
spinner.fail("❌")
|
|
592
|
+
return False
|
|
597
593
|
|
|
598
594
|
except Exception as e:
|
|
599
595
|
spinner.text = f"文件修改失败: {str(e)}"
|
|
@@ -10,10 +10,8 @@ from jarvis.jarvis_tools.read_code import ReadCodeTool
|
|
|
10
10
|
from jarvis.jarvis_tools.registry import ToolRegistry
|
|
11
11
|
from jarvis.jarvis_agent import Agent
|
|
12
12
|
|
|
13
|
-
from jarvis.jarvis_utils.config import INPUT_WINDOW_REVERSE_SIZE, get_max_input_token_count
|
|
14
|
-
from jarvis.jarvis_utils.embedding import get_context_token_count
|
|
15
13
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
16
|
-
from jarvis.jarvis_utils.utils import init_env,
|
|
14
|
+
from jarvis.jarvis_utils.utils import init_env, is_context_overflow
|
|
17
15
|
from jarvis.jarvis_utils.tag import ot, ct
|
|
18
16
|
from jarvis.jarvis_code_analysis.checklists.loader import get_language_checklist
|
|
19
17
|
|
|
@@ -587,28 +585,27 @@ class CodeReviewTool:
|
|
|
587
585
|
temp_file.flush()
|
|
588
586
|
|
|
589
587
|
try:
|
|
590
|
-
|
|
591
|
-
|
|
588
|
+
upload_success = False
|
|
589
|
+
# Check if content is too large
|
|
590
|
+
is_large_content = is_context_overflow(diff_output)
|
|
592
591
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
if
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
spinner.ok("✅")
|
|
601
|
-
PrettyOutput.print(f"已成功上传代码差异文件", OutputType.SUCCESS)
|
|
602
|
-
else:
|
|
603
|
-
spinner.fail("❌")
|
|
604
|
-
PrettyOutput.print(f"文件上传失败,将使用chat_with_files处理", OutputType.WARNING)
|
|
592
|
+
# Upload the file to the agent's model
|
|
593
|
+
with yaspin(text="正在上传代码差异文件...", color="cyan") as spinner:
|
|
594
|
+
if is_large_content and agent.model and hasattr(agent.model, 'upload_files'):
|
|
595
|
+
upload_success = agent.model.upload_files([temp_file_path])
|
|
596
|
+
if upload_success:
|
|
597
|
+
spinner.ok("✅")
|
|
598
|
+
PrettyOutput.print(f"已成功上传代码差异文件", OutputType.SUCCESS)
|
|
605
599
|
else:
|
|
606
600
|
spinner.fail("❌")
|
|
607
|
-
PrettyOutput.print(f"
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
601
|
+
PrettyOutput.print(f"上传代码差异文件失败,将使用分块处理", OutputType.WARNING)
|
|
602
|
+
else:
|
|
603
|
+
upload_success = False
|
|
604
|
+
|
|
605
|
+
# Prepare the prompt based on upload status
|
|
606
|
+
if upload_success:
|
|
607
|
+
# When file is uploaded, reference it in the prompt
|
|
608
|
+
complete_prompt = user_prompt + f"""
|
|
612
609
|
|
|
613
610
|
我已上传了一个包含代码差异的文件。该文件包含:
|
|
614
611
|
- 审查类型: {review_type}
|
|
@@ -616,20 +613,17 @@ class CodeReviewTool:
|
|
|
616
613
|
- 检测到的编程语言: {', '.join(detected_languages) if detected_languages else '未检测到特定语言'}
|
|
617
614
|
|
|
618
615
|
请基于上传的代码差异文件进行全面审查,并生成详细的代码审查报告。"""
|
|
619
|
-
|
|
620
|
-
else:
|
|
621
|
-
# 文件上传失败,使用chat_with_files
|
|
622
|
-
PrettyOutput.print("使用chat_with_files处理大文件...", OutputType.INFO)
|
|
623
|
-
result = chat_with_files(
|
|
624
|
-
[temp_file_path],
|
|
625
|
-
agent.model,
|
|
626
|
-
user_prompt,
|
|
627
|
-
"请基于以上代码差异进行全面审查,并生成详细的代码审查报告。"
|
|
628
|
-
)
|
|
629
|
-
else:
|
|
630
|
-
# 文件较小,直接包含在prompt中
|
|
631
|
-
complete_prompt = user_prompt + "\n\n代码差异内容:\n```diff\n" + diff_output + "\n```"
|
|
616
|
+
# Run the agent with the prompt
|
|
632
617
|
result = agent.run(complete_prompt)
|
|
618
|
+
else:
|
|
619
|
+
# If upload failed or not needed, handle based on context size
|
|
620
|
+
if is_large_content and agent.model and hasattr(agent.model, 'chat_big_content'):
|
|
621
|
+
# Use chat_big_content for large content when upload fails
|
|
622
|
+
result = agent.model.chat_big_content(diff_output, user_prompt)
|
|
623
|
+
else:
|
|
624
|
+
# Include the diff directly in the prompt for smaller content
|
|
625
|
+
complete_prompt = user_prompt + "\n\n代码差异内容:\n```diff\n" + diff_output + "\n```"
|
|
626
|
+
result = agent.run(complete_prompt)
|
|
633
627
|
finally:
|
|
634
628
|
# Clean up the temporary file
|
|
635
629
|
if os.path.exists(temp_file_path):
|
|
@@ -10,11 +10,9 @@ import sys
|
|
|
10
10
|
import argparse
|
|
11
11
|
import os
|
|
12
12
|
|
|
13
|
-
from jarvis.jarvis_utils.config import INPUT_WINDOW_REVERSE_SIZE, get_max_input_token_count
|
|
14
|
-
from jarvis.jarvis_utils.embedding import get_context_token_count
|
|
15
13
|
from jarvis.jarvis_utils.git_utils import find_git_root, has_uncommitted_changes
|
|
16
14
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
17
|
-
from jarvis.jarvis_utils.utils import init_env,
|
|
15
|
+
from jarvis.jarvis_utils.utils import init_env, is_context_overflow
|
|
18
16
|
from jarvis.jarvis_utils.tag import ot, ct
|
|
19
17
|
|
|
20
18
|
|
|
@@ -107,7 +105,7 @@ class GitCommitTool:
|
|
|
107
105
|
diff = process.communicate()[0].decode()
|
|
108
106
|
spinner.write(f"✅ 获取差异 ({file_count} 个文件)")
|
|
109
107
|
try:
|
|
110
|
-
|
|
108
|
+
temp_diff_file_path = None
|
|
111
109
|
# 生成提交信息
|
|
112
110
|
spinner.text = "正在生成提交消息..."
|
|
113
111
|
|
|
@@ -132,13 +130,12 @@ class GitCommitTool:
|
|
|
132
130
|
|
|
133
131
|
# 获取模型并尝试上传文件
|
|
134
132
|
platform = PlatformRegistry().get_normal_platform()
|
|
133
|
+
upload_success = False
|
|
135
134
|
|
|
136
|
-
#
|
|
137
|
-
|
|
135
|
+
# Check if content is too large
|
|
136
|
+
is_large_content = is_context_overflow(diff)
|
|
138
137
|
|
|
139
|
-
if
|
|
140
|
-
# 文件较大,尝试上传
|
|
141
|
-
upload_success = False
|
|
138
|
+
if is_large_content and hasattr(platform, 'upload_files'):
|
|
142
139
|
spinner.text = "正在上传代码差异文件..."
|
|
143
140
|
try:
|
|
144
141
|
with spinner.hidden():
|
|
@@ -148,72 +145,43 @@ class GitCommitTool:
|
|
|
148
145
|
temp_diff_file.write(diff)
|
|
149
146
|
temp_diff_file.flush()
|
|
150
147
|
spinner.write(f"✅ 差异内容已写入临时文件")
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
else:
|
|
157
|
-
spinner.write("⚠️ 上传代码差异文件失败,将使用chat_with_files处理")
|
|
158
|
-
else:
|
|
159
|
-
spinner.write("⚠️ 模型不支持文件上传,将使用chat_with_files处理")
|
|
148
|
+
upload_success = platform.upload_files([temp_diff_file_path])
|
|
149
|
+
if upload_success:
|
|
150
|
+
spinner.write("✅ 成功上传代码差异文件")
|
|
151
|
+
else:
|
|
152
|
+
spinner.write("⚠️ 上传代码差异文件失败,将使用分块处理")
|
|
160
153
|
except Exception as e:
|
|
161
154
|
spinner.write(f"⚠️ 上传文件时出错: {str(e)}")
|
|
162
155
|
upload_success = False
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
156
|
+
|
|
157
|
+
# 根据上传状态准备完整的提示
|
|
158
|
+
if upload_success:
|
|
159
|
+
# 使用上传的文件
|
|
160
|
+
prompt = base_prompt + f'''
|
|
167
161
|
# 变更概述
|
|
168
162
|
- 变更文件数量: {file_count} 个文件
|
|
169
163
|
- 已上传包含完整代码差异的文件
|
|
170
164
|
|
|
171
165
|
请详细分析已上传的代码差异文件,生成符合上述格式的提交信息。
|
|
172
166
|
'''
|
|
173
|
-
else:
|
|
174
|
-
# 使用chat_with_files处理大文件
|
|
175
|
-
spinner.write("使用chat_with_files处理大文件...")
|
|
176
|
-
commit_message = chat_with_files(
|
|
177
|
-
[temp_diff_file_path],
|
|
178
|
-
platform,
|
|
179
|
-
base_prompt,
|
|
180
|
-
"请基于以上代码差异生成符合格式的提交信息。"
|
|
181
|
-
)
|
|
182
|
-
commit_message = self._extract_commit_message(commit_message)
|
|
183
|
-
if commit_message:
|
|
184
|
-
spinner.write("✅ 生成提交消息")
|
|
185
|
-
# 执行提交
|
|
186
|
-
spinner.text = "正在准备提交..."
|
|
187
|
-
with tempfile.NamedTemporaryFile(mode='w', delete=True) as tmp_file:
|
|
188
|
-
tmp_file.write(commit_message)
|
|
189
|
-
tmp_file.flush()
|
|
190
|
-
spinner.text = "正在执行提交..."
|
|
191
|
-
commit_cmd = ["git", "commit", "-F", tmp_file.name]
|
|
192
|
-
subprocess.Popen(
|
|
193
|
-
commit_cmd,
|
|
194
|
-
stdout=subprocess.DEVNULL,
|
|
195
|
-
stderr=subprocess.DEVNULL
|
|
196
|
-
).wait()
|
|
197
|
-
spinner.write("✅ 提交")
|
|
198
|
-
return {
|
|
199
|
-
"success": True,
|
|
200
|
-
"stdout": yaml.safe_dump({
|
|
201
|
-
"commit_hash": self._get_last_commit_hash(),
|
|
202
|
-
"commit_message": commit_message
|
|
203
|
-
}),
|
|
204
|
-
"stderr": ""
|
|
205
|
-
}
|
|
206
167
|
else:
|
|
207
|
-
#
|
|
208
|
-
|
|
168
|
+
# 如果上传失败但内容较大,使用chat_big_content
|
|
169
|
+
if is_large_content and hasattr(platform, 'chat_big_content'):
|
|
170
|
+
spinner.text = "正在使用分块处理生成提交信息..."
|
|
171
|
+
commit_message = platform.chat_big_content(diff, base_prompt)
|
|
172
|
+
else:
|
|
173
|
+
# 直接在提示中包含差异内容
|
|
174
|
+
prompt = base_prompt + f'''
|
|
209
175
|
# 分析材料
|
|
210
176
|
{diff}
|
|
211
177
|
'''
|
|
178
|
+
commit_message = platform.chat_until_success(prompt)
|
|
212
179
|
|
|
213
180
|
# 尝试生成提交信息
|
|
214
181
|
spinner.text = "正在生成提交消息..."
|
|
215
182
|
while True:
|
|
216
|
-
|
|
183
|
+
if not upload_success and not is_large_content:
|
|
184
|
+
commit_message = platform.chat_until_success(prompt)
|
|
217
185
|
commit_message = self._extract_commit_message(commit_message)
|
|
218
186
|
# 如果成功提取,就跳出循环
|
|
219
187
|
if commit_message:
|
|
@@ -246,7 +214,7 @@ class GitCommitTool:
|
|
|
246
214
|
spinner.ok("✅")
|
|
247
215
|
finally:
|
|
248
216
|
# 清理临时差异文件
|
|
249
|
-
if
|
|
217
|
+
if temp_diff_file_path is not None and os.path.exists(temp_diff_file_path):
|
|
250
218
|
try:
|
|
251
219
|
os.unlink(temp_diff_file_path)
|
|
252
220
|
except Exception as e:
|
{jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_methodology/main.py
RENAMED
|
@@ -11,14 +11,14 @@ import hashlib
|
|
|
11
11
|
import os
|
|
12
12
|
import json
|
|
13
13
|
import argparse
|
|
14
|
-
import yaml
|
|
14
|
+
import yaml # type: ignore
|
|
15
15
|
from jarvis.jarvis_utils.methodology import (
|
|
16
16
|
_get_methodology_directory,
|
|
17
17
|
_load_all_methodologies
|
|
18
18
|
)
|
|
19
19
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
20
20
|
from jarvis.jarvis_utils.output import PrettyOutput, OutputType
|
|
21
|
-
from yaspin import yaspin
|
|
21
|
+
from yaspin import yaspin # type: ignore
|
|
22
22
|
|
|
23
23
|
def import_methodology(input_file):
|
|
24
24
|
"""导入方法论文件(合并策略)"""
|
{jarvis_ai_assistant-0.1.159 → jarvis_ai_assistant-0.1.160}/src/jarvis/jarvis_platform/base.py
RENAMED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
2
|
import re
|
|
3
3
|
from typing import List, Tuple
|
|
4
|
+
from jarvis.jarvis_utils.config import get_max_input_token_count
|
|
5
|
+
from jarvis.jarvis_utils.embedding import split_text_into_chunks
|
|
4
6
|
from jarvis.jarvis_utils.globals import clear_read_file_record
|
|
5
7
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
6
8
|
from jarvis.jarvis_utils.utils import get_context_token_count, while_success, while_true
|
|
@@ -37,38 +39,49 @@ class BasePlatform(ABC):
|
|
|
37
39
|
@abstractmethod
|
|
38
40
|
def upload_files(self, file_list: List[str]) -> bool:
|
|
39
41
|
raise NotImplementedError("upload_files is not implemented")
|
|
42
|
+
|
|
43
|
+
def chat_big_content(self, content: str, prompt: str) -> str:
|
|
44
|
+
prefix_prompt = f"""
|
|
45
|
+
我将分多次提供大量的上下文内容,在我明确告诉你内容已经全部提供完毕之前,每次仅需要输出“已收到”。
|
|
46
|
+
"""
|
|
47
|
+
self.chat_until_success(prefix_prompt)
|
|
48
|
+
split_content = split_text_into_chunks(content, get_max_input_token_count() - 1024)
|
|
49
|
+
for chunk in split_content:
|
|
50
|
+
self.chat_until_success(f"<part_content>{chunk}</part_content>")
|
|
51
|
+
return self.chat_until_success(f"内容已经全部提供完毕\n\n{prompt}")
|
|
40
52
|
|
|
53
|
+
|
|
54
|
+
def _chat(self, message: str):
|
|
55
|
+
import time
|
|
56
|
+
start_time = time.time()
|
|
57
|
+
response = self.chat(message)
|
|
58
|
+
|
|
59
|
+
end_time = time.time()
|
|
60
|
+
duration = end_time - start_time
|
|
61
|
+
char_count = len(response)
|
|
62
|
+
|
|
63
|
+
# Calculate token count and tokens per second
|
|
64
|
+
try:
|
|
65
|
+
token_count = get_context_token_count(response)
|
|
66
|
+
tokens_per_second = token_count / duration if duration > 0 else 0
|
|
67
|
+
except Exception as e:
|
|
68
|
+
PrettyOutput.print(f"Tokenization failed: {str(e)}", OutputType.WARNING)
|
|
69
|
+
token_count = 0
|
|
70
|
+
tokens_per_second = 0
|
|
71
|
+
|
|
72
|
+
# Print statistics
|
|
73
|
+
if not self.suppress_output:
|
|
74
|
+
PrettyOutput.print(
|
|
75
|
+
f"对话完成 - 耗时: {duration:.2f}秒, 输出字符数: {char_count}, 输出Token数量: {token_count}, 每秒Token数量: {tokens_per_second:.2f}",
|
|
76
|
+
OutputType.INFO,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
# Keep original think tag handling
|
|
80
|
+
response = re.sub(ot("think")+r'.*?'+ct("think"), '', response, flags=re.DOTALL)
|
|
81
|
+
return response
|
|
82
|
+
|
|
41
83
|
def chat_until_success(self, message: str) -> str:
|
|
42
|
-
|
|
43
|
-
import time
|
|
44
|
-
start_time = time.time()
|
|
45
|
-
response = self.chat(message)
|
|
46
|
-
|
|
47
|
-
end_time = time.time()
|
|
48
|
-
duration = end_time - start_time
|
|
49
|
-
char_count = len(response)
|
|
50
|
-
|
|
51
|
-
# Calculate token count and tokens per second
|
|
52
|
-
try:
|
|
53
|
-
token_count = get_context_token_count(response)
|
|
54
|
-
tokens_per_second = token_count / duration if duration > 0 else 0
|
|
55
|
-
except Exception as e:
|
|
56
|
-
PrettyOutput.print(f"Tokenization failed: {str(e)}", OutputType.WARNING)
|
|
57
|
-
token_count = 0
|
|
58
|
-
tokens_per_second = 0
|
|
59
|
-
|
|
60
|
-
# Print statistics
|
|
61
|
-
if not self.suppress_output:
|
|
62
|
-
PrettyOutput.print(
|
|
63
|
-
f"对话完成 - 耗时: {duration:.2f}秒, 输出字符数: {char_count}, 输出Token数量: {token_count}, 每秒Token数量: {tokens_per_second:.2f}",
|
|
64
|
-
OutputType.INFO,
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
# Keep original think tag handling
|
|
68
|
-
response = re.sub(ot("think")+r'.*?'+ct("think"), '', response, flags=re.DOTALL)
|
|
69
|
-
return response
|
|
70
|
-
|
|
71
|
-
return while_true(lambda: while_success(lambda: _chat(), 5), 5)
|
|
84
|
+
return while_true(lambda: while_success(lambda: self._chat(message), 5), 5)
|
|
72
85
|
|
|
73
86
|
@abstractmethod
|
|
74
87
|
def name(self) -> str:
|