jarvis-ai-assistant 0.1.141__tar.gz → 0.1.142__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.

Files changed (101) hide show
  1. {jarvis_ai_assistant-0.1.141/src/jarvis_ai_assistant.egg-info → jarvis_ai_assistant-0.1.142}/PKG-INFO +1 -1
  2. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/pyproject.toml +1 -1
  3. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/setup.py +1 -1
  4. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/__init__.py +1 -1
  5. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_agent/patch.py +76 -49
  6. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_agent/shell_input_handler.py +1 -0
  7. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/code_review.py +8 -13
  8. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_git_utils/git_commiter.py +11 -13
  9. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_platform/kimi.py +0 -1
  10. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_platform/yuanbao.py +60 -55
  11. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/file_analyzer.py +5 -5
  12. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/registry.py +7 -7
  13. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_utils/config.py +4 -0
  14. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_utils/methodology.py +26 -26
  15. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142/src/jarvis_ai_assistant.egg-info}/PKG-INFO +1 -1
  16. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/LICENSE +0 -0
  17. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/MANIFEST.in +0 -0
  18. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/README.md +0 -0
  19. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/setup.cfg +0 -0
  20. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_agent/__init__.py +0 -0
  21. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_agent/builtin_input_handler.py +0 -0
  22. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_agent/file_input_handler.py +0 -0
  23. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_agent/jarvis.py +0 -0
  24. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_agent/main.py +0 -0
  25. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_agent/output_handler.py +0 -0
  26. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_agent/__init__.py +0 -0
  27. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_agent/code_agent.py +0 -0
  28. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/__init__.py +0 -0
  29. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/c_cpp.py +0 -0
  30. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/csharp.py +0 -0
  31. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/data_format.py +0 -0
  32. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/devops.py +0 -0
  33. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/docs.py +0 -0
  34. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/go.py +0 -0
  35. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/infrastructure.py +0 -0
  36. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/java.py +0 -0
  37. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/javascript.py +0 -0
  38. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/kotlin.py +0 -0
  39. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/loader.py +0 -0
  40. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/php.py +0 -0
  41. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/python.py +0 -0
  42. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/ruby.py +0 -0
  43. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/rust.py +0 -0
  44. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/shell.py +0 -0
  45. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/sql.py +0 -0
  46. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/swift.py +0 -0
  47. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_code_analysis/checklists/web.py +0 -0
  48. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_dev/main.py +0 -0
  49. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_git_details/__init__.py +0 -0
  50. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_git_details/main.py +0 -0
  51. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_git_squash/__init__.py +0 -0
  52. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_git_squash/main.py +0 -0
  53. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_init/__init__.py +0 -0
  54. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_init/main.py +0 -0
  55. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_lsp/base.py +0 -0
  56. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_lsp/cpp.py +0 -0
  57. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_lsp/go.py +0 -0
  58. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_lsp/python.py +0 -0
  59. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_lsp/registry.py +0 -0
  60. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_lsp/rust.py +0 -0
  61. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_methodology/main.py +0 -0
  62. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_multi_agent/__init__.py +0 -0
  63. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_multi_agent/main.py +0 -0
  64. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_platform/__init__.py +0 -0
  65. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_platform/base.py +0 -0
  66. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_platform/openai.py +0 -0
  67. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_platform/registry.py +0 -0
  68. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_platform_manager/__init__.py +0 -0
  69. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_platform_manager/main.py +0 -0
  70. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_platform_manager/openai_test.py +0 -0
  71. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_smart_shell/__init__.py +0 -0
  72. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_smart_shell/main.py +0 -0
  73. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/__init__.py +0 -0
  74. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/ask_codebase.py +0 -0
  75. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/ask_user.py +0 -0
  76. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/base.py +0 -0
  77. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/chdir.py +0 -0
  78. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/create_code_agent.py +0 -0
  79. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/create_sub_agent.py +0 -0
  80. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/execute_script.py +0 -0
  81. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/file_operation.py +0 -0
  82. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/find_methodology.py +0 -0
  83. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/lsp_get_diagnostics.py +0 -0
  84. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/methodology.py +0 -0
  85. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/read_code.py +0 -0
  86. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/read_webpage.py +0 -0
  87. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/search_web.py +0 -0
  88. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_tools/virtual_tty.py +0 -0
  89. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_utils/__init__.py +0 -0
  90. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_utils/embedding.py +0 -0
  91. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_utils/file_processors.py +0 -0
  92. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_utils/git_utils.py +0 -0
  93. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_utils/globals.py +0 -0
  94. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_utils/input.py +0 -0
  95. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_utils/output.py +0 -0
  96. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis/jarvis_utils/utils.py +0 -0
  97. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis_ai_assistant.egg-info/SOURCES.txt +0 -0
  98. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis_ai_assistant.egg-info/dependency_links.txt +0 -0
  99. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis_ai_assistant.egg-info/entry_points.txt +0 -0
  100. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis_ai_assistant.egg-info/requires.txt +0 -0
  101. {jarvis_ai_assistant-0.1.141 → jarvis_ai_assistant-0.1.142}/src/jarvis_ai_assistant.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jarvis-ai-assistant
3
- Version: 0.1.141
3
+ Version: 0.1.142
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "jarvis-ai-assistant"
7
- version = "0.1.141"
7
+ version = "0.1.142"
8
8
  description = "Jarvis: An AI assistant that uses tools to interact with the system"
9
9
  readme = "README.md"
10
10
  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.141",
5
+ version="0.1.142",
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",
@@ -1,3 +1,3 @@
1
1
  """Jarvis AI Assistant"""
2
2
 
3
- __version__ = "0.1.141"
3
+ __version__ = "0.1.142"
@@ -9,7 +9,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 is_confirm_before_apply_patch
12
+ from jarvis.jarvis_utils.config import INPUT_WINDOW_REVERSE_SIZE, get_max_input_token_count, is_confirm_before_apply_patch
13
+ from jarvis.jarvis_utils.embedding import get_context_token_count
13
14
  from jarvis.jarvis_utils.git_utils import get_commits_between, get_latest_commit_hash
14
15
  from jarvis.jarvis_utils.globals import add_read_file_record, has_read_file
15
16
  from jarvis.jarvis_utils.input import get_multiline_input
@@ -308,8 +309,11 @@ def handle_small_code_operation(filepath: str, patch_content: str) -> bool:
308
309
  with yaspin(text=f"正在修改文件 {filepath}...", color="cyan") as spinner:
309
310
  try:
310
311
  model = PlatformRegistry().get_normal_platform()
312
+ upload_success = False
313
+ file_content = FileOperationTool().execute({"operation":"read", "files":[{"path":filepath}]})["stdout"]
311
314
  with spinner.hidden():
312
- model.upload_files([filepath])
315
+ if get_context_token_count(file_content) > get_max_input_token_count() - INPUT_WINDOW_REVERSE_SIZE and model.upload_files([filepath]):
316
+ upload_success = True
313
317
 
314
318
  model.set_suppress_output(False)
315
319
 
@@ -342,7 +346,12 @@ def handle_small_code_operation(filepath: str, patch_content: str) -> bool:
342
346
  [合并后的完整代码,包括所有空行和缩进]
343
347
  {ct("MERGED_CODE")}
344
348
  """
345
-
349
+ if not upload_success:
350
+ prompt += f"""
351
+ # 原始代码
352
+ {file_content}
353
+ """
354
+
346
355
  count = 30
347
356
  start_line = -1
348
357
  end_line = -1
@@ -403,9 +412,13 @@ def handle_large_code_operation(filepath: str, patch_content: str, model: BasePl
403
412
  """处理大型代码文件的补丁操作,使用差异化补丁格式"""
404
413
  with yaspin(text=f"正在处理文件 {filepath}...", color="cyan") as spinner:
405
414
  try:
415
+ file_content = FileOperationTool().execute({"operation":"read", "files":[{"path":filepath}]})["stdout"]
416
+ upload_success = False
406
417
  # 读取原始文件内容
407
418
  with spinner.hidden():
408
- model.upload_files([filepath])
419
+ if get_context_token_count(file_content) > get_max_input_token_count() - INPUT_WINDOW_REVERSE_SIZE and model.upload_files([filepath]):
420
+ upload_success = True
421
+
409
422
 
410
423
  model.set_suppress_output(False)
411
424
 
@@ -434,13 +447,13 @@ def handle_large_code_operation(filepath: str, patch_content: str, model: BasePl
434
447
  - 每个{ot("DIFF")}块必须包含SEARCH部分和REPLACE部分
435
448
  - SEARCH部分是需要查找的原始代码
436
449
  - REPLACE部分是替换后的新代码
437
- - 确保SEARCH部分能在原文件中唯一匹配
450
+ - 确保SEARCH部分能在原文件中**唯一匹配**
438
451
  - 如果修改较大,可以使用多个{ot("DIFF")}块
439
452
 
440
453
  ## 输出模板
441
454
  {ot("DIFF")}
442
455
  >>>>>> SEARCH
443
- [需要查找的原始代码,包含足够上下文]
456
+ [需要查找的原始代码,包含足够上下文,避免出现可匹配多处的情况]
444
457
  ======
445
458
  [替换后的新代码]
446
459
  <<<<<< REPLACE
@@ -448,55 +461,69 @@ def handle_large_code_operation(filepath: str, patch_content: str, model: BasePl
448
461
 
449
462
  {ot("DIFF")}
450
463
  >>>>>> SEARCH
451
- [另一处需要查找的原始代码]
464
+ [另一处需要查找的原始代码,包含足够上下文,避免出现可匹配多处的情况]
452
465
  ======
453
466
  [另一处替换后的新代码]
454
467
  <<<<<< REPLACE
455
468
  {ct("DIFF")}
456
469
  """
457
- # 获取补丁内容
458
- with spinner.hidden():
459
- response = model.chat_until_success(prompt)
460
-
461
- # 解析差异化补丁
462
- diff_blocks = re.finditer(ot("DIFF")+r'\s*>{4,} SEARCH\n?(.*?)\n?={4,}\n?(.*?)\s*<{4,} REPLACE\n?'+ct("DIFF"),
463
- response, re.DOTALL)
464
-
465
- # 读取原始文件内容
466
- with open(filepath, 'r', encoding='utf-8', errors="ignore") as f:
467
- file_content = f.read()
468
-
469
- # 应用所有差异化补丁
470
- modified_content = file_content
471
- patch_count = 0
472
-
473
- for match in diff_blocks:
474
- search_text = match.group(1).strip()
475
- replace_text = match.group(2).strip()
476
- patch_count += 1
477
- # 检查搜索文本是否存在于文件中
478
- if search_text in modified_content:
479
- # 如果有多处,报错
480
- if modified_content.count(search_text) > 1:
481
- spinner.text = f"补丁 #{patch_count} 应用失败:找到多个匹配的代码段"
470
+ if not upload_success:
471
+ prompt += f"""
472
+ # 原始代码
473
+ {file_content}
474
+ """
475
+ for _ in range(3):
476
+ # 获取补丁内容
477
+ with spinner.hidden():
478
+ response = model.chat_until_success(prompt)
479
+
480
+ # 解析差异化补丁
481
+ diff_blocks = re.finditer(ot("DIFF")+r'\s*>{4,} SEARCH\n?(.*?)\n?={4,}\n?(.*?)\s*<{4,} REPLACE\n?'+ct("DIFF"),
482
+ response, re.DOTALL)
483
+
484
+ # 读取原始文件内容
485
+ with open(filepath, 'r', encoding='utf-8', errors="ignore") as f:
486
+ file_content = f.read()
487
+
488
+ # 应用所有差异化补丁
489
+ modified_content = file_content
490
+ patch_count = 0
491
+ success = True
492
+ for match in diff_blocks:
493
+ search_text = match.group(1).strip()
494
+ replace_text = match.group(2).strip()
495
+ patch_count += 1
496
+ # 检查搜索文本是否存在于文件中
497
+ if search_text in modified_content:
498
+ # 如果有多处,报错
499
+ if modified_content.count(search_text) > 1:
500
+ spinner.text = f"补丁 #{patch_count} 应用失败:找到多个匹配的代码段"
501
+ prompt = f"补丁 #{patch_count} 应用失败:找到多个匹配的代码段"
502
+ spinner.fail("❌")
503
+ success = False
504
+ break
505
+ # 应用替换
506
+ modified_content = modified_content.replace(
507
+ search_text, replace_text)
508
+ spinner.write(f"✅ 补丁 #{patch_count} 应用成功")
509
+ else:
510
+ spinner.text = f"补丁 #{patch_count} 应用失败:无法找到匹配的代码段"
511
+ prompt = f"补丁 #{patch_count} 应用失败:无法找到匹配的代码段"
482
512
  spinner.fail("❌")
483
- return False
484
- # 应用替换
485
- modified_content = modified_content.replace(
486
- search_text, replace_text)
487
- spinner.write(f"✅ 补丁 #{patch_count} 应用成功")
488
- else:
489
- spinner.text = f"补丁 #{patch_count} 应用失败:无法找到匹配的代码段"
490
- spinner.fail("")
491
- return False
492
-
493
- # 写入修改后的内容
494
- with open(filepath, 'w', encoding='utf-8', errors="ignore") as f:
495
- f.write(modified_content)
496
-
497
- spinner.text = f"文件 {filepath} 修改完成,应用了 {patch_count} 个补丁"
498
- spinner.ok("✅")
499
- return True
513
+ success = False
514
+ break
515
+ if not success:
516
+ revert_file(filepath)
517
+ continue
518
+
519
+ # 写入修改后的内容
520
+ with open(filepath, 'w', encoding='utf-8', errors="ignore") as f:
521
+ f.write(modified_content)
522
+
523
+ spinner.text = f"文件 {filepath} 修改完成,应用了 {patch_count} 个补丁"
524
+ spinner.ok("")
525
+ return True
526
+ return False
500
527
 
501
528
  except Exception as e:
502
529
  spinner.text = f"文件修改失败: {str(e)}"
@@ -16,6 +16,7 @@ def shell_input_handler(user_input: str, agent: Any) -> Tuple[str, bool]:
16
16
  from jarvis.jarvis_tools.registry import ToolRegistry
17
17
  output = ToolRegistry().handle_tool_calls({
18
18
  "name": "execute_script",
19
+ "want": "提取命令执行结果关键信息",
19
20
  "arguments": {
20
21
  "interpreter": "bash",
21
22
  "script_content": script
@@ -4,12 +4,15 @@ import os
4
4
  import re
5
5
  import tempfile
6
6
 
7
+ from httpx import get
7
8
  from yaspin import yaspin
8
9
  from jarvis.jarvis_platform.registry import PlatformRegistry
9
10
  from jarvis.jarvis_tools.read_code import ReadCodeTool
10
11
  from jarvis.jarvis_tools.registry import ToolRegistry
11
12
  from jarvis.jarvis_agent import Agent
12
13
 
14
+ from jarvis.jarvis_utils.config import INPUT_WINDOW_REVERSE_SIZE, get_max_input_token_count
15
+ from jarvis.jarvis_utils.embedding import get_context_token_count
13
16
  from jarvis.jarvis_utils.output import OutputType, PrettyOutput
14
17
  from jarvis.jarvis_utils.utils import ct, ot, init_env
15
18
  from jarvis.jarvis_code_analysis.checklists.loader import get_language_checklist
@@ -341,14 +344,7 @@ class CodeReviewTool:
341
344
  # Add language-specific checklists
342
345
  if detected_languages:
343
346
  review_info += "\n\n----- 检测到的编程语言 -----"
344
- language_names = {
345
- 'c_cpp': 'C/C++',
346
- 'go': 'Go',
347
- 'python': 'Python',
348
- 'rust': 'Rust'
349
- }
350
- detected_lang_names = [language_names.get(lang, lang) for lang in detected_languages]
351
- review_info += f"\n检测到的语言: {', '.join(detected_lang_names)}"
347
+ review_info += f"\n检测到的语言: {', '.join(detected_languages)}"
352
348
 
353
349
  review_info += "\n\n----- 语言特定审查清单 -----"
354
350
  for lang in detected_languages:
@@ -533,22 +529,21 @@ class CodeReviewTool:
533
529
  with tempfile.NamedTemporaryFile(mode='w', suffix='.diff', delete=False) as temp_file:
534
530
  temp_file_path = temp_file.name
535
531
  temp_file.write(diff_output)
532
+ temp_file.flush()
536
533
 
537
534
  try:
535
+ upload_success = False
538
536
  # Upload the file to the agent's model
539
537
  with yaspin(text="正在上传代码差异文件...", color="cyan") as spinner:
540
- if agent.model and hasattr(agent.model, 'upload_files'):
538
+ if get_context_token_count(diff_output) > get_max_input_token_count() - INPUT_WINDOW_REVERSE_SIZE and agent.model and hasattr(agent.model, 'upload_files'):
541
539
  upload_success = agent.model.upload_files([temp_file_path])
542
540
  if upload_success:
543
541
  spinner.ok("✅")
544
542
  PrettyOutput.print(f"已成功上传代码差异文件", OutputType.SUCCESS)
543
+ upload_success = True
545
544
  else:
546
- spinner.fail("❌")
547
- PrettyOutput.print(f"上传代码差异文件失败", OutputType.WARNING)
548
545
  upload_success = False
549
546
  else:
550
- spinner.fail("❌")
551
- PrettyOutput.print(f"当前模型不支持文件上传", OutputType.WARNING)
552
547
  upload_success = False
553
548
 
554
549
  # Prepare the prompt based on upload status
@@ -11,7 +11,7 @@ import sys
11
11
  import argparse
12
12
  import os
13
13
 
14
- from jarvis.jarvis_utils.config import get_max_input_token_count
14
+ from jarvis.jarvis_utils.config import INPUT_WINDOW_REVERSE_SIZE, get_max_input_token_count
15
15
  from jarvis.jarvis_utils.embedding import get_context_token_count
16
16
  from jarvis.jarvis_utils.git_utils import find_git_root, has_uncommitted_changes
17
17
  from jarvis.jarvis_utils.output import OutputType, PrettyOutput
@@ -106,17 +106,8 @@ class GitCommitTool:
106
106
  )
107
107
  diff = process.communicate()[0].decode()
108
108
  spinner.write(f"✅ 获取差异 ({file_count} 个文件)")
109
-
110
- # 写入差异文件
111
- temp_diff_file = None
112
109
  try:
113
- # 创建临时文件并写入差异内容
114
- temp_diff_file = tempfile.NamedTemporaryFile(mode='w', suffix='.diff', delete=False)
115
- temp_diff_file_path = temp_diff_file.name
116
- temp_diff_file.write(diff)
117
- temp_diff_file.flush()
118
- temp_diff_file.close()
119
- spinner.write(f"✅ 差异内容已写入临时文件")
110
+ temp_diff_file = None
120
111
  # 生成提交信息
121
112
  spinner.text = "正在生成提交消息..."
122
113
 
@@ -143,10 +134,16 @@ class GitCommitTool:
143
134
  platform = PlatformRegistry().get_normal_platform()
144
135
  upload_success = False
145
136
 
146
- if hasattr(platform, 'upload_files') and os.path.exists(temp_diff_file_path):
137
+ if get_context_token_count(diff) > get_max_input_token_count() - INPUT_WINDOW_REVERSE_SIZE and hasattr(platform, 'upload_files'):
147
138
  spinner.text = "正在上传代码差异文件..."
148
139
  try:
149
140
  with spinner.hidden():
141
+ # 创建临时文件并写入差异内容
142
+ with tempfile.NamedTemporaryFile(mode='w', suffix='.diff', delete=False) as temp_diff_file:
143
+ temp_diff_file_path = temp_diff_file.name
144
+ temp_diff_file.write(diff)
145
+ temp_diff_file.flush()
146
+ spinner.write(f"✅ 差异内容已写入临时文件")
150
147
  upload_success = platform.upload_files([temp_diff_file_path])
151
148
  if upload_success:
152
149
  spinner.write("✅ 成功上传代码差异文件")
@@ -217,12 +214,13 @@ class GitCommitTool:
217
214
  "commit_message": commit_message
218
215
  }),
219
216
  "stderr": ""
220
- }
217
+ }
221
218
  finally:
222
219
  # Always restore original directory
223
220
  os.chdir(original_dir)
224
221
 
225
222
  except Exception as e:
223
+ PrettyOutput.print(f"提交失败: {str(e)}", OutputType.ERROR)
226
224
  return {
227
225
  "success": False,
228
226
  "stdout": "",
@@ -231,7 +231,6 @@ class KimiModel(BasePlatform):
231
231
  return False
232
232
 
233
233
  self.uploaded_files = uploaded_files
234
- self.chat_until_success("我上传了文件,收到请回复“收到”")
235
234
  return True
236
235
 
237
236
 
@@ -11,12 +11,13 @@ from pathlib import Path
11
11
  from PIL import Image
12
12
  from yaspin import yaspin
13
13
  from yaspin.spinners import Spinners
14
+ from yaspin.api import Yaspin
14
15
  from jarvis.jarvis_platform.base import BasePlatform
15
16
  from jarvis.jarvis_utils.output import OutputType, PrettyOutput
16
17
  from jarvis.jarvis_utils.utils import while_success
17
18
 
18
19
  class YuanbaoPlatform(BasePlatform):
19
- """Hunyuan model implementation"""
20
+ """Hunyuan模型实现"""
20
21
 
21
22
  platform_name = "yuanbao"
22
23
 
@@ -63,7 +64,7 @@ class YuanbaoPlatform(BasePlatform):
63
64
  self.multimedia = []
64
65
 
65
66
  def set_system_message(self, message: str):
66
- """Set system message"""
67
+ """设置系统消息"""
67
68
  self.system_message = message
68
69
 
69
70
  def set_model_name(self, model_name: str):
@@ -76,7 +77,7 @@ class YuanbaoPlatform(BasePlatform):
76
77
  PrettyOutput.print(f"错误:不支持的模型: {model_name}", OutputType.ERROR)
77
78
 
78
79
  def _get_base_headers(self):
79
- """Get base headers for API requests"""
80
+ """获取API请求的基础头部信息"""
80
81
  return {
81
82
  'Host': 'yuanbao.tencent.com',
82
83
  'X-Language': 'zh-CN',
@@ -101,7 +102,7 @@ class YuanbaoPlatform(BasePlatform):
101
102
  }
102
103
 
103
104
  def _create_conversation(self) -> bool:
104
- """Create a new conversation session"""
105
+ """创建一个新的对话会话"""
105
106
  url = "https://yuanbao.tencent.com/api/user/agent/conversation/create"
106
107
 
107
108
  headers = self._get_base_headers()
@@ -125,13 +126,13 @@ class YuanbaoPlatform(BasePlatform):
125
126
  return False
126
127
 
127
128
  def upload_files(self, file_list: List[str]) -> bool:
128
- """Upload files to Yuanbao platform
129
+ """上传文件到元宝平台
129
130
 
130
- Args:
131
- file_list: List of file paths to upload
131
+ 参数:
132
+ file_list: 要上传的文件路径列表
132
133
 
133
- Returns:
134
- List of file metadata dictionaries for use in chat messages
134
+ 返回:
135
+ 用于聊天消息的文件元数据字典列表
135
136
  """
136
137
  if not self.cookies:
137
138
  PrettyOutput.print("未设置YUANBAO_COOKIES,无法上传文件", OutputType.ERROR)
@@ -149,27 +150,29 @@ class YuanbaoPlatform(BasePlatform):
149
150
  file_size = os.path.getsize(file_path)
150
151
  file_extension = os.path.splitext(file_path)[1].lower().lstrip('.')
151
152
 
152
- # Determine file_type using mimetypes
153
- mime_type, _ = mimetypes.guess_type(file_path)
153
+ # Determine file_type using file extension
154
+ file_type = "txt" # Default type
154
155
 
155
- # Default to txt if mime_type couldn't be determined
156
- if not mime_type:
157
- file_type = "txt"
158
156
  # Image types
159
- elif mime_type.startswith('image/'):
157
+ if file_extension in ['jpg', 'jpeg', 'png', 'webp', 'bmp', 'gif']:
160
158
  file_type = "image"
161
159
  # PDF type
162
- elif mime_type == 'application/pdf':
160
+ elif file_extension == 'pdf':
163
161
  file_type = "pdf"
162
+ # Spreadsheet types
163
+ elif file_extension in ['xls', 'xlsx', 'csv']:
164
+ file_type = "excel"
165
+ # Presentation types
166
+ elif file_extension in ['ppt', 'pptx']:
167
+ file_type = "ppt"
164
168
  # Document types
165
- elif mime_type in ['application/msword',
166
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
167
- 'application/rtf',
168
- 'application/vnd.oasis.opendocument.text']:
169
+ elif file_extension in ['doc', 'docx', 'txt', 'text', 'md']:
169
170
  file_type = "doc"
170
- # Default to txt for all other types
171
- else:
172
- file_type = "txt"
171
+ # Code file types
172
+ elif file_extension in ['bat', 'c', 'cpp', 'cs', 'css', 'go', 'h', 'hpp', 'ini',
173
+ 'java', 'js', 'json', 'log', 'lua', 'php', 'pl', 'py', 'rb',
174
+ 'sh', 'sql', 'swift', 'tex', 'toml', 'vue', 'yaml', 'yml']:
175
+ file_type = "code"
173
176
 
174
177
  # 2. Generate upload information
175
178
  spinner.text = f"获取上传信息: {file_name}"
@@ -181,7 +184,7 @@ class YuanbaoPlatform(BasePlatform):
181
184
 
182
185
  # 3. Upload the file to COS
183
186
  spinner.text = f"上传文件到云存储: {file_name}"
184
- upload_success = self._upload_file_to_cos(file_path, upload_info)
187
+ upload_success = self._upload_file_to_cos(file_path, upload_info, spinner)
185
188
  if not upload_success:
186
189
  spinner.text = f"上传文件 {file_name} 失败"
187
190
  spinner.fail("❌")
@@ -200,7 +203,7 @@ class YuanbaoPlatform(BasePlatform):
200
203
  }
201
204
 
202
205
  # Get image dimensions if it's an image file
203
- if file_type == "img":
206
+ if file_type == "image":
204
207
  try:
205
208
  with Image.open(file_path) as img:
206
209
  file_metadata["width"] = img.width
@@ -221,13 +224,13 @@ class YuanbaoPlatform(BasePlatform):
221
224
  return True
222
225
 
223
226
  def _generate_upload_info(self, file_name: str) -> Dict:
224
- """Generate upload information from Yuanbao API
227
+ """从元宝API生成上传信息
225
228
 
226
- Args:
227
- file_name: Name of the file to upload
229
+ 参数:
230
+ file_name: 要上传的文件名
228
231
 
229
- Returns:
230
- Dictionary containing upload information or empty dict if failed
232
+ 返回:
233
+ 包含上传信息的字典,如果失败则返回空字典
231
234
  """
232
235
  url = "https://yuanbao.tencent.com/api/resource/genUploadInfo"
233
236
 
@@ -258,15 +261,15 @@ class YuanbaoPlatform(BasePlatform):
258
261
  PrettyOutput.print(f"获取上传信息时出错: {str(e)}", OutputType.ERROR)
259
262
  return {}
260
263
 
261
- def _upload_file_to_cos(self, file_path: str, upload_info: Dict) -> bool:
262
- """Upload file to Tencent COS using the provided upload information
264
+ def _upload_file_to_cos(self, file_path: str, upload_info: Dict, spinner: Yaspin) -> bool:
265
+ """使用提供的上传信息将文件上传到腾讯COS
263
266
 
264
- Args:
265
- file_path: Path to the file to upload
266
- upload_info: Upload information from generate_upload_info
267
+ 参数:
268
+ file_path: 要上传的文件路径
269
+ upload_info: generate_upload_info获取的上传信息
267
270
 
268
- Returns:
269
- Boolean indicating success or failure
271
+ 返回:
272
+ 布尔值表示成功或失败
270
273
  """
271
274
  try:
272
275
  # Extract required information from upload_info
@@ -285,6 +288,8 @@ class YuanbaoPlatform(BasePlatform):
285
288
  # Read file content
286
289
  with open(file_path, 'rb') as file:
287
290
  file_content = file.read()
291
+
292
+ spinner.write(f"ℹ️ 上传文件大小: {len(file_content)}")
288
293
 
289
294
  # Prepare headers for PUT request
290
295
  host = f"{upload_info['bucketName']}.{upload_info.get('accelerateDomain', 'cos.accelerate.myqcloud.com')}"
@@ -329,18 +334,18 @@ class YuanbaoPlatform(BasePlatform):
329
334
 
330
335
  def _generate_cos_signature(self, secret_key: str, method: str, path: str,
331
336
  params: Dict, headers: Dict, key_time: str) -> str:
332
- """Generate COS signature according to Tencent Cloud COS documentation
337
+ """根据腾讯云COS文档生成COS签名
333
338
 
334
- Args:
335
- secret_key: Temporary secret key
336
- method: HTTP method (GET, PUT, etc.)
337
- path: Object path
338
- params: URL parameters
339
- headers: HTTP headers
340
- key_time: Time range for signature
339
+ 参数:
340
+ secret_key: 临时密钥
341
+ method: HTTP方法(GET, PUT)
342
+ path: 对象路径
343
+ params: URL参数
344
+ headers: HTTP头部
345
+ key_time: 签名时间范围
341
346
 
342
- Returns:
343
- Signature string
347
+ 返回:
348
+ 签名字符串
344
349
  """
345
350
  try:
346
351
  # 1. Generate SignKey
@@ -377,14 +382,14 @@ class YuanbaoPlatform(BasePlatform):
377
382
  raise e
378
383
 
379
384
  def chat(self, message: str) -> str:
380
- """Send message and get response with optional file attachments
385
+ """发送消息并获取响应,可选文件附件
381
386
 
382
- Args:
383
- message: Message text to send
384
- file_list: Optional list of file paths to upload and attach
387
+ 参数:
388
+ message: 要发送的消息文本
389
+ file_list: 可选的上传和附加文件路径列表
385
390
 
386
- Returns:
387
- Response from the model
391
+ 返回:
392
+ 模型的响应
388
393
  """
389
394
  if not self.conversation_id:
390
395
  if not self._create_conversation():
@@ -489,7 +494,7 @@ class YuanbaoPlatform(BasePlatform):
489
494
  raise Exception(f"对话失败: {str(e)}")
490
495
 
491
496
  def delete_chat(self) -> bool:
492
- """Delete current session"""
497
+ """删除当前会话"""
493
498
  if not self.conversation_id:
494
499
  return True # 如果没有会话ID,视为删除成功
495
500
 
@@ -526,5 +531,5 @@ class YuanbaoPlatform(BasePlatform):
526
531
  return False
527
532
 
528
533
  def name(self) -> str:
529
- """Model name"""
534
+ """模型名称"""
530
535
  return self.model_name
@@ -79,7 +79,8 @@ class FileAnalyzerTool:
79
79
  # 上传文件
80
80
  with yaspin(Spinners.dots, text="正在上传文件...") as spinner:
81
81
  try:
82
- upload_result = platform.upload_files(valid_files)
82
+ with spinner.hidden():
83
+ upload_result = platform.upload_files(valid_files)
83
84
  if not upload_result:
84
85
  spinner.text = "文件上传失败"
85
86
  spinner.fail("❌")
@@ -88,6 +89,7 @@ class FileAnalyzerTool:
88
89
  "stdout": "",
89
90
  "stderr": "文件上传失败"
90
91
  }
92
+ spinner.text = "文件上传成功"
91
93
  spinner.ok("✅")
92
94
  except Exception as e:
93
95
  spinner.text = "文件上传失败"
@@ -97,9 +99,6 @@ class FileAnalyzerTool:
97
99
  "stdout": "",
98
100
  "stderr": f"文件上传失败: {str(e)}"
99
101
  }
100
-
101
- prompt = f"""我上传了文件,收到请回复“已接收到文件”"""
102
- platform.chat_until_success(prompt)
103
102
 
104
103
  platform.set_suppress_output(False)
105
104
 
@@ -112,7 +111,8 @@ class FileAnalyzerTool:
112
111
 
113
112
  # 发送请求并获取分析结果
114
113
  with yaspin(Spinners.dots, text="正在分析文件...") as spinner:
115
- analysis_result = platform.chat_until_success(analysis_request)
114
+ with spinner.hidden():
115
+ analysis_result = platform.chat_until_success(analysis_request)
116
116
  spinner.text = "分析完成"
117
117
  spinner.ok("✅")
118
118
 
@@ -1,5 +1,4 @@
1
1
  import json
2
- import os
3
2
  from pathlib import Path
4
3
  import re
5
4
  import sys
@@ -12,7 +11,7 @@ from yaspin import yaspin
12
11
  from jarvis.jarvis_agent.output_handler import OutputHandler
13
12
  from jarvis.jarvis_platform.registry import PlatformRegistry
14
13
  from jarvis.jarvis_tools.base import Tool
15
- from jarvis.jarvis_utils.config import get_max_input_token_count
14
+ from jarvis.jarvis_utils.config import INPUT_WINDOW_REVERSE_SIZE, get_max_input_token_count
16
15
  from jarvis.jarvis_utils.embedding import get_context_token_count
17
16
  from jarvis.jarvis_utils.output import OutputType, PrettyOutput
18
17
  from jarvis.jarvis_utils.utils import ct, ot, init_env
@@ -133,7 +132,7 @@ class ToolRegistry(OutputHandler):
133
132
  # 加载内置工具和外部工具
134
133
  self._load_builtin_tools()
135
134
  self._load_external_tools()
136
- self.max_input_token_count = get_max_input_token_count() - 2048
135
+ self.max_input_token_count = get_max_input_token_count() - INPUT_WINDOW_REVERSE_SIZE
137
136
 
138
137
  def use_tools(self, name: List[str]):
139
138
  """使用指定工具"""
@@ -336,12 +335,13 @@ class ToolRegistry(OutputHandler):
336
335
 
337
336
  # 处理结果
338
337
  if get_context_token_count(output) > self.max_input_token_count:
339
- output_file = os.path.join(tempfile.gettempdir(), f"jarvis_output_{os.getpid()}.txt")
340
- with open(output_file, "w", encoding="utf-8") as f:
341
- f.write(output)
338
+ with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as tmp_file:
339
+ output_file = tmp_file.name
340
+ tmp_file.write(output)
341
+ tmp_file.flush()
342
342
  model = PlatformRegistry().get_normal_platform()
343
343
  model.set_suppress_output(False)
344
- model.upload_files([output_file])
344
+ model.upload_files([output_file]) # TODO 处理错误
345
345
  prompt = f"该文件为工具执行结果,请阅读文件内容,并根据文件提取出以下信息:{want}"
346
346
  return f"""工具调用原始输出过长,以下是根据输出提出的信息:
347
347
 
@@ -9,6 +9,10 @@ import os
9
9
  - 执行配置
10
10
  - 文本处理配置
11
11
  """
12
+
13
+ # 输出窗口预留大小
14
+ INPUT_WINDOW_REVERSE_SIZE = 2048
15
+
12
16
  def get_max_token_count() -> int:
13
17
  """
14
18
  获取模型允许的最大token数量。
@@ -8,9 +8,11 @@
8
8
  """
9
9
  import os
10
10
  import json
11
- import hashlib
12
11
  import tempfile
13
- from typing import Dict, List, Optional
12
+ from typing import Dict, Optional
13
+
14
+ from jarvis.jarvis_utils.config import INPUT_WINDOW_REVERSE_SIZE, get_max_input_token_count
15
+ from jarvis.jarvis_utils.embedding import get_context_token_count
14
16
  from jarvis.jarvis_utils.output import PrettyOutput, OutputType
15
17
  from jarvis.jarvis_platform.registry import PlatformRegistry
16
18
 
@@ -82,6 +84,7 @@ def _create_methodology_temp_file(methodologies: Dict[str, str]) -> Optional[str
82
84
  f.write(f"## {problem_type}\n\n")
83
85
  f.write(f"{content}\n\n")
84
86
  f.write("---\n\n")
87
+ f.flush()
85
88
 
86
89
  return temp_path
87
90
  except Exception as e:
@@ -115,33 +118,28 @@ def load_methodology(user_input: str) -> str:
115
118
  return ""
116
119
  spinner.text = f"加载方法论文件完成 (共 {len(methodologies)} 个)"
117
120
  spinner.ok("✅")
118
-
119
- # 创建临时文件
120
- with yaspin(text="创建方法论临时文件...", color="yellow") as spinner:
121
- temp_file_path = _create_methodology_temp_file(methodologies)
122
- if not temp_file_path:
123
- spinner.text = "创建方法论临时文件失败"
124
- spinner.fail("❌")
125
- return ""
126
- spinner.text = f"创建方法论临时文件完成: {temp_file_path}"
127
- spinner.ok("✅")
128
121
 
129
122
  # 获取当前平台
130
- platform = PlatformRegistry().get_thinking_platform()
123
+ platform = PlatformRegistry().get_normal_platform()
131
124
 
132
- # 上传文件到大模型
133
- with yaspin(text="上传方法论文件到大模型...", color="yellow") as spinner:
134
- with spinner.hidden():
135
- # 上传文件
136
- upload_result = platform.upload_files([temp_file_path])
137
- if not upload_result:
138
- spinner.text = "上传方法论文件失败"
125
+ upload_result = False
126
+ if get_context_token_count(user_input) > get_max_input_token_count() - INPUT_WINDOW_REVERSE_SIZE:
127
+ # 创建临时文件
128
+ with yaspin(text="创建方法论临时文件...", color="yellow") as spinner:
129
+ temp_file_path = _create_methodology_temp_file(methodologies)
130
+ if not temp_file_path:
131
+ spinner.text = "创建方法论临时文件失败"
139
132
  spinner.fail("❌")
140
133
  return ""
134
+ spinner.text = f"创建方法论临时文件完成: {temp_file_path}"
135
+ spinner.ok("✅")
136
+ if platform.upload_files([temp_file_path]):
137
+ upload_result = True
141
138
 
142
139
  spinner.text = "上传方法论文件成功"
143
140
  spinner.ok("✅")
144
141
 
142
+ platform.set_suppress_output(False)
145
143
  # 构建提示信息
146
144
  prompt = f"""根据用户需求: {user_input}
147
145
 
@@ -151,13 +149,15 @@ def load_methodology(user_input: str) -> str:
151
149
  1. [步骤1描述]
152
150
  2. [步骤2描述]
153
151
 
154
- 如果没有匹配的方法论,请提供执行计划并注明:
155
- (未参考任何现有方法论)
156
-
157
- ### 执行计划
158
- 1. [步骤1描述]
159
- 2. [步骤2描述]
152
+ 如果没有匹配的方法论,请输出:没有历史方法论可参考
153
+ 除以上要求外,不要输出任何内容
160
154
  """
155
+ if not upload_result:
156
+ prompt += f"""
157
+ # 方法论内容
158
+ """
159
+ for problem_type, content in methodologies.items():
160
+ prompt += f"## {problem_type}\n\n{content}\n\n---\n\n"
161
161
  return platform.chat_until_success(prompt)
162
162
 
163
163
  except Exception as e:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jarvis-ai-assistant
3
- Version: 0.1.141
3
+ Version: 0.1.142
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