pro-craft 0.1.5__py3-none-any.whl → 0.1.7__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 pro-craft might be problematic. Click here for more details.

@@ -23,6 +23,33 @@ from datetime import datetime
23
23
  from pro_craft.utils import extract_
24
24
  logger = Log.logger
25
25
  editing_log = logger.debug
26
+ import re
27
+
28
+ def fix_broken_json_string(broken_json_str):
29
+ # 移除 BOM
30
+ broken_json_str = broken_json_str.lstrip('\ufeff')
31
+ # 移除大部分非法 ASCII 控制字符
32
+ broken_json_str = re.sub(r'[\x00-\x08\x0b\x0c\x0e-\x1f]', '', broken_json_str)
33
+
34
+ # 尝试找到 "content": " 和它对应的结束 "
35
+ # 这是一个挑战,因为中间有未转义的换行。
36
+ # 我们会寻找 "content": ",然后捕获从那以后直到最后一个 " 的所有内容,并替换其中的裸换行。
37
+
38
+ # 注意:这个正则假设 "content" 的值是最后一个键值对,并且直到字符串末尾的 " 才结束
39
+ # 并且假设其他字段都是合法的单行字符串
40
+ fixed_json_str = re.sub(
41
+ r'("content":\s*")(.+?)"\s*}', # 匹配 "content": ",然后捕获所有内容直到最后一个 " }
42
+ lambda m: m.group(1) + m.group(2).replace('\n', '\\n').replace('\r', '\\r') + '"\n}',
43
+ broken_json_str,
44
+ flags=re.DOTALL # 允许 . 匹配换行
45
+ )
46
+
47
+ # 修正可能的最后一行丢失的 }
48
+ if not fixed_json_str.strip().endswith('}'):
49
+ fixed_json_str += '\n}' # 补上结束的 }
50
+
51
+ return fixed_json_str
52
+
26
53
 
27
54
  class IntellectType(Enum):
28
55
  train = "train"
@@ -501,6 +528,7 @@ class AsyncIntel():
501
528
  input_data: dict | str,
502
529
  OutputFormat: object,
503
530
  prompt_id: str,
531
+ ExtraFormats: list[object] = [],
504
532
  version: str = None,
505
533
  inference_save_case = True,
506
534
  ):
@@ -512,7 +540,7 @@ class AsyncIntel():
512
540
  "```json([\s\S]*?)```"
513
541
  使用以下方式验证
514
542
  """
515
- output_format = base_format_prompt + inspect.getsource(OutputFormat)
543
+ output_format = base_format_prompt + "\n".join([inspect.getsource(outputformat) for outputformat in ExtraFormats]) + inspect.getsource(OutputFormat)
516
544
 
517
545
  ai_result = await self.aintellect_remove(
518
546
  input_data=input_data,
@@ -523,7 +551,10 @@ class AsyncIntel():
523
551
  )
524
552
 
525
553
  try:
526
- ai_result = json.loads(extract_(ai_result,r'json'))
554
+
555
+ json_str = extract_(ai_result,r'json')
556
+ json_str = fix_broken_json_string(json_str)
557
+ ai_result = json.loads(json_str)
527
558
  OutputFormat(**ai_result)
528
559
  except ValidationError as e:
529
560
  log_ = "记忆卡片合并 - 大模型生成的格式未通过校验"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pro-craft
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
@@ -5,7 +5,7 @@ pro_craft/evals.py,sha256=1T86jur4k3cLk43j1GyAW4JS0nPNfl6P0ZOQmu-SgpA,1928
5
5
  pro_craft/file_manager.py,sha256=2j7lCt9L4mtvAy8_76ibTthXLwKKmVatWIB3DSvQM7U,3805
6
6
  pro_craft/log.py,sha256=MZf9jCZsiRoAq8v4FxVnJqeSXxgzAiiKf7mxz6bFtwM,4263
7
7
  pro_craft/prompt_helper.py,sha256=SFIhju0Y3rRdb-T1WocUgz7qCocq1Ja2zlaEZo1RM3o,23832
8
- pro_craft/prompt_helper_async.py,sha256=tvs2NywEqv_THvMpalu5PfewhhTm9wP89JqdKiKIUbU,25004
8
+ pro_craft/prompt_helper_async.py,sha256=Hk4xr-5_l2ApUlSpuQj6uj6qJ8ISq8yuNvf19j8otao,26406
9
9
  pro_craft/server.py,sha256=fPAosQIU0d7gxICiALl8u6QwbLI4cawVFyoRYebRES0,2827
10
10
  pro_craft/utils.py,sha256=27A3CFhbRsEAP5GY6oxAz2M-beiIuPgCNSjQUyzOVW0,5685
11
11
  pro_craft/code_helper/coder.py,sha256=NXglF1KiPtGe4HZN0MZvFJ8p9Iyd5kzIt72DQGgRwXA,24715
@@ -17,7 +17,7 @@ pro_craft/server/mcp/math.py,sha256=OOzGXx64nK4bOVlu33PtVddcCQ9ilqA3Em9yxjSX9cg,
17
17
  pro_craft/server/mcp/resource.py,sha256=z94jP3qZofO-1lZCM3TuOfLajw41HARs1ojXab1ymas,776
18
18
  pro_craft/server/mcp/weather.py,sha256=RAGuf4sgjlTQSfRRZ1Fo18JnuMQRS_Db9p6AqBQrl8E,455
19
19
  pro_craft/server/router/recommended.py,sha256=IAZFdmb8HSl2_TOJeuv5uOKIX47XyX4p4sEwxG-0vt0,9968
20
- pro_craft-0.1.5.dist-info/METADATA,sha256=5k1tJo4_cu_HdDlHPGfnewUC50IlCl1HN495U5t5_rw,1768
21
- pro_craft-0.1.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
22
- pro_craft-0.1.5.dist-info/top_level.txt,sha256=yqYDHArnYMWpeCxkmGRwlL6sJtxiOUnYylLDx9EOgFg,10
23
- pro_craft-0.1.5.dist-info/RECORD,,
20
+ pro_craft-0.1.7.dist-info/METADATA,sha256=dTEP9fECNy_xPQ1KsKnn5A8K3mzm5s3acltOqkjxZeQ,1768
21
+ pro_craft-0.1.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
22
+ pro_craft-0.1.7.dist-info/top_level.txt,sha256=yqYDHArnYMWpeCxkmGRwlL6sJtxiOUnYylLDx9EOgFg,10
23
+ pro_craft-0.1.7.dist-info/RECORD,,