pycoze 0.1.440__py3-none-any.whl → 0.1.442__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.
pycoze/bot/chat.py CHANGED
@@ -8,7 +8,7 @@ from pycoze import utils
8
8
  import tempfile
9
9
  import re
10
10
  import datetime
11
- from pathlib import Path
11
+ import atexit
12
12
 
13
13
 
14
14
  def eclipse_tool_result(text, threshold=100):
@@ -78,6 +78,10 @@ async def run_with_interrupt_check(
78
78
  check_task = asyncio.create_task(
79
79
  check_interrupt_file(0.5, interrupt_file, chat_task)
80
80
  )
81
+ def cleanup():
82
+ chat_task.cancel()
83
+ check_task.cancel()
84
+ atexit.register(cleanup)
81
85
  result = await chat_task
82
86
  return result
83
87
  except asyncio.CancelledError:
pycoze/bot/chat_base.py CHANGED
@@ -300,8 +300,7 @@ async def handle_user_inputs(
300
300
  )
301
301
 
302
302
  assistant_content = (
303
- "Executing tool: \n"
304
- + dumps_markdown_json(tool_request)
303
+ dumps_markdown_json(tool_request)
305
304
  + "\n\n[Tool Result Begin]\n"
306
305
  + result
307
306
  + "\n[Tool Result End]\n"
pycoze/bot/lib.py CHANGED
@@ -83,6 +83,7 @@ def get_system_prompt(abilities, bot_setting):
83
83
  "allow_list_files": False,
84
84
  "allow_access_webpage": False,
85
85
  "folder_context": bot_setting["folderContext"],
86
+ "use_draft": bot_setting["useDraft"]
86
87
  }
87
88
 
88
89
  context.update(bot_setting["systemAbility"])
pycoze/bot/prompt.md CHANGED
@@ -1,5 +1,9 @@
1
1
  {{ prompt }}
2
2
 
3
+ {% if use_draft %}
4
+ Think step by step, but only keep a minimum draft for each thinking step, with 5 words at most. Return the answer at the end of the response after a separator ####.
5
+ {% endif %}
6
+
3
7
  {% if has_any_tool %}
4
8
  ==== Tool Usage
5
9
  You have access to a set of tools running on the {{ system }} system that are executed upon user approval. Only one tool can be used per message, and you will receive the result of the tool's execution in the user's response. You progressively use these tools to accomplish tasks, with each tool's usage being based on the outcome of the previous tool.
pycoze/bot/tools.py CHANGED
@@ -132,17 +132,38 @@ class ReplaceInFileTool(Tool):
132
132
  with open(path, "r", encoding="utf-8") as f:
133
133
  content = f.read()
134
134
 
135
+ # 初始化成功和失败的计数器
136
+ success_count = 0
137
+ failure_count = 0
138
+ failure_details = [] # 用于记录匹配失败的详细信息
139
+
135
140
  # 处理差异内容
136
141
  diff_content = self.params["diff"]
137
142
  for diff_block in diff_content.split("<<<<<<< SEARCH")[1:]:
138
143
  search, replace = diff_block.split("=======")
139
144
  search = search.strip()
140
145
  replace = replace.split(">>>>>>> REPLACE")[0].strip()
141
- content = content.replace(search, replace, 1)
146
+ if search in content:
147
+ content = content.replace(search, replace, 1)
148
+ success_count += 1
149
+ else:
150
+ failure_count += 1
151
+ # 记录匹配失败的前20个字符
152
+ failure_details.append(f"Failed to match: '{search[:20]}...'")
142
153
 
143
154
  with open(path, "w", encoding="utf-8") as f:
144
155
  f.write(content)
145
- return f"The content of the file {path} has been replaced successfully."
156
+
157
+ # 构建返回结果
158
+ result = (
159
+ f"The content of the file {path} has been replaced successfully. "
160
+ f"Successfully replaced {success_count} occurrences. "
161
+ f"Failed to replace {failure_count} occurrences."
162
+ )
163
+ if failure_details:
164
+ result += "\nFailure details:\n" + "\n".join(failure_details)
165
+
166
+ return result
146
167
 
147
168
 
148
169
  class SearchFilesTool(Tool):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pycoze
3
- Version: 0.1.440
3
+ Version: 0.1.442
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -10,12 +10,12 @@ pycoze/api/lib/view.py,sha256=_PIpTfeuTPPlMDKshMGsqFQYMq7ZiO4Hg5XwHwDoU60,7357
10
10
  pycoze/api/lib/web.py,sha256=l56koyd7RUzK-4mQE_5W-POyqSD79mvwusIN0rxND-Q,2347
11
11
  pycoze/api/lib/window.py,sha256=dkzWfLwn5pE_L0DfQ38K8nx9tQyT5KO-GYyXi0rytFc,2073
12
12
  pycoze/bot/__init__.py,sha256=rL3Q-ycczRpSFfKn84fg3QBl5k22WpyeIU5qOEjEby8,79
13
- pycoze/bot/chat.py,sha256=qEuMxH0cVFU9QSU36FrOsjhRAxtsvOv7CQtuXvM3F6Y,6446
14
- pycoze/bot/chat_base.py,sha256=uwAVhhvpKHQytJYMsIOHsTThkr45xRehbXF0-kDbvjM,12614
15
- pycoze/bot/lib.py,sha256=_bQ52mKsWgFGAogFHnmRBJbvK_tPOwsAJ8NqJNMR5K4,7210
13
+ pycoze/bot/chat.py,sha256=bScsMc0hGh2NlvhQxzWEbnA_WXU9JdAJv-rx27SpEB8,6554
14
+ pycoze/bot/chat_base.py,sha256=I_QOB22Ud1HpBDg8kip9AW4stGbbLOrKpZPSMCHEMAE,12567
15
+ pycoze/bot/lib.py,sha256=RivPA2f5fqzqbW6jL0sx9X9pwgFPxwkk8lt62CWvaZo,7255
16
16
  pycoze/bot/message.py,sha256=udnIi-h4QgGzkbr_5VcAsVGjoLp9wXJSfBCeuOz7_Bk,802
17
- pycoze/bot/prompt.md,sha256=t7NQdiiNe-jCDVfeVbvTPfq5WK5nF8CxFUQUFMyXJlo,13880
18
- pycoze/bot/tools.py,sha256=uFvGIQ4VzkiH-TM9U9RenWfYVYyeUv_bP-094hB9rTc,10367
17
+ pycoze/bot/prompt.md,sha256=UtwZ31wFvNtvM9ZTA4BU2yT1Rb-qnUdU3Ny1O37Tt3Q,14077
18
+ pycoze/bot/tools.py,sha256=BWMdwvqLzvcyaW38lzxUWtc0K1V-C_qPSEZ3OKlAQvU,11108
19
19
  pycoze/reference/__init__.py,sha256=zgqGqvmA9HaqytEM33B6vi0kQVk8IiCwJaXa22xsFz8,114
20
20
  pycoze/reference/bot.py,sha256=UZK24Qm8kpqpwXJy_zNZeTEEDee05luXdSBeUm0NCt0,2029
21
21
  pycoze/reference/lib.py,sha256=T-oBOKxkus5dTouc0oDgfRzUyi6aTyY-FF4yX7SzF5M,3755
@@ -31,8 +31,8 @@ pycoze/utils/arg.py,sha256=jop1tBfe5hYkHW1NSpCeaZBEznkgguBscj_7M2dWfrs,503
31
31
  pycoze/utils/env.py,sha256=5pWlXfM1F5ZU9hhv1rHlDEanjEW5wf0nbyez9bNRqqA,559
32
32
  pycoze/utils/socket.py,sha256=bZbFFRH4mfThzRqt55BAAGQ6eICx_ja4x8UGGrUdAm8,2428
33
33
  pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
34
- pycoze-0.1.440.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
35
- pycoze-0.1.440.dist-info/METADATA,sha256=c-1yayy-SaotLhwt9UK_dm7XGCa9uEhnaSeuGA4Gq10,854
36
- pycoze-0.1.440.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
37
- pycoze-0.1.440.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
38
- pycoze-0.1.440.dist-info/RECORD,,
34
+ pycoze-0.1.442.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
35
+ pycoze-0.1.442.dist-info/METADATA,sha256=j6lqjhDVXZyB9H-3cykwPuOvfKK4AWr5ji9ct9VFpEc,854
36
+ pycoze-0.1.442.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
37
+ pycoze-0.1.442.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
38
+ pycoze-0.1.442.dist-info/RECORD,,