beswarm 0.1.75__py3-none-any.whl → 0.1.76__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.
@@ -1,9 +1,10 @@
1
1
  import os
2
2
  import re
3
+ import difflib
3
4
  from ..aient.src.aient.plugins import register_tool
4
5
 
5
6
  @register_tool()
6
- def edit_file(file_path, diff_content, match_precision=0.8):
7
+ def edit_file(file_path, diff_content, match_precision=0.9):
7
8
  """
8
9
  使用diff模式编辑代码文件。**重要:此函数每次调用只能对文件进行一处修改。**
9
10
 
@@ -22,7 +23,7 @@ def edit_file(file_path, diff_content, match_precision=0.8):
22
23
  参数:
23
24
  file_path: 要编辑的文件路径。
24
25
  diff_content: 包含单次修改信息的diff字符串,格式必须符合上述要求。
25
- match_precision: 匹配精度 (0.0-1.0),值越高要求匹配越精确,默认0.8。当完全精确匹配失败时,此参数生效。
26
+ match_precision: 匹配精度 (0.0-1.0),值越高要求匹配越精确,默认为0.9。当完全精确匹配失败时,此参数生效。
26
27
 
27
28
  返回:
28
29
  编辑结果的状态信息,包括成功或错误信息。
@@ -93,27 +94,19 @@ def edit_file(file_path, diff_content, match_precision=0.8):
93
94
  for i in range(len(content_lines) - len(search_lines) + 1):
94
95
  # 计算当前位置的匹配分数
95
96
  match_score = 0
96
- total_chars = 0
97
+ lines_compared = 0
97
98
 
98
99
  for j in range(len(search_lines)):
99
100
  search_line = search_lines[j]
100
101
  content_line = content_lines[i + j]
101
102
 
102
- # 计算两行之间的相似度(使用更精确的算法)
103
- # 1. 字符级别的比较
104
- common_chars = sum(c1 == c2 for c1, c2 in zip(search_line, content_line))
105
- total_line_chars = max(len(search_line), len(content_line))
106
-
107
- if total_line_chars > 0:
108
- line_match = common_chars / total_line_chars
109
- match_score += line_match
110
- total_chars += 1
103
+ # 使用 difflib 计算行相似度,该算法对插入和删除更具鲁棒性
104
+ line_match = difflib.SequenceMatcher(None, search_line, content_line).ratio()
105
+ match_score += line_match
106
+ lines_compared += 1
111
107
 
112
108
  # 计算整体匹配分数
113
- if total_chars > 0:
114
- match_score = match_score / total_chars
115
- else:
116
- match_score = 0
109
+ match_score = match_score / lines_compared
117
110
 
118
111
  # 如果使用高精度匹配 (>0.95),我们需要更严格地检查匹配结果
119
112
  if match_precision > 0.95:
@@ -173,7 +166,7 @@ def edit_file(file_path, diff_content, match_precision=0.8):
173
166
  if __name__ == "__main__":
174
167
  edit_str = """
175
168
  <<<<<<< SEARCH
176
- parser.add_argument('--dataset', type=str, default='cifar10', choices=['cifar10', 'cifar100', 'imagenet'], help="Dataset to use.")
169
+ parser.add_argument('--dataset',type=str,default='cifar10', choices=['cifar10', 'cifar100', 'imagenet'],help="Dataset to use.")
177
170
  =======
178
171
  parser.add_argument('--dataset', type=str, default='cifar10', choices=['cifar10', 'cifar100', 'imagenet', 'tinyimagenet'], help="Dataset to use.")
179
172
  >>>>>>> REPLACE
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beswarm
3
- Version: 0.1.75
3
+ Version: 0.1.76
4
4
  Summary: MAS
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -122,7 +122,7 @@ beswarm/queries/tree-sitter-languages/scala-tags.scm,sha256=UxQjz80JIrrJ7Pm56uUn
122
122
  beswarm/queries/tree-sitter-languages/typescript-tags.scm,sha256=OMdCeedPiA24ky82DpgTMKXK_l2ySTuF2zrQ2fJAi9E,1253
123
123
  beswarm/tools/__init__.py,sha256=YXP65SJFE1dBNRlffapdd7zsB6M6tHZ6QaQykGq7KDU,1198
124
124
  beswarm/tools/click.py,sha256=TygaekCXTmU3fIu6Uom7ZcyzEgYMlCC_GX-5SmWHuLI,20762
125
- beswarm/tools/edit_file.py,sha256=npe_j0FHOtZu8q3cG4oFtaReVC02HY01NjPlSi3pJrE,8369
125
+ beswarm/tools/edit_file.py,sha256=B1rAKxgd9ZksRpZysF4SOglTIp-_k0hnFK5fZ5BBvGk,8039
126
126
  beswarm/tools/planner.py,sha256=lguBCS6kpwNPoXQvqH-WySabVubT82iyWOkJnjt6dXw,1265
127
127
  beswarm/tools/repomap.py,sha256=N09K0UgwjCN7Zjg_5TYlVsulp3n2fztYlS8twalChU8,45003
128
128
  beswarm/tools/screenshot.py,sha256=u6t8FCgW5YHJ_Oc4coo8e0F3wTusWE_-H8dFh1rBq9Q,1011
@@ -130,7 +130,7 @@ beswarm/tools/search_arxiv.py,sha256=9slwBemXjEqrd7-YgVmyMijPXlkhZCybEDRVhWVQ9B0
130
130
  beswarm/tools/search_web.py,sha256=B24amOnGHnmdV_6S8bw8O2PdhZRRIDtJjg-wXcfP7dQ,11859
131
131
  beswarm/tools/think.py,sha256=WLw-7jNIsnS6n8MMSYUin_f-BGLENFmnKM2LISEp0co,1760
132
132
  beswarm/tools/worker.py,sha256=DLYzMgKzpf4UYGNKKJix__DHw6LHtX_T9CLVaexDQMg,12909
133
- beswarm-0.1.75.dist-info/METADATA,sha256=cBw1e9pd4J_L77sYBtm4eyQlu3CMJbBGbG_YZljayaY,3553
134
- beswarm-0.1.75.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
135
- beswarm-0.1.75.dist-info/top_level.txt,sha256=pJw4O87wvt5882smuSO6DfByJz7FJ8SxxT8h9fHCmpo,8
136
- beswarm-0.1.75.dist-info/RECORD,,
133
+ beswarm-0.1.76.dist-info/METADATA,sha256=REGvO25NvgVgRw3qBdQf_172ht7ZgBIDfCBYNWnR6Uk,3553
134
+ beswarm-0.1.76.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
135
+ beswarm-0.1.76.dist-info/top_level.txt,sha256=pJw4O87wvt5882smuSO6DfByJz7FJ8SxxT8h9fHCmpo,8
136
+ beswarm-0.1.76.dist-info/RECORD,,