pro-craft 0.1.54__py3-none-any.whl → 0.1.55__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.

@@ -25,6 +25,7 @@ from datetime import datetime, timedelta
25
25
  from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine, async_sessionmaker
26
26
  from sqlalchemy import select, and_ # 引入 select 和 and_
27
27
  from sqlalchemy.orm import class_mapper # 用于检查对象是否是持久化的
28
+ from datetime import datetime, timedelta
28
29
 
29
30
  from tqdm.asyncio import tqdm
30
31
  import pandas as pd
@@ -333,6 +334,8 @@ class AsyncIntel():
333
334
 
334
335
  async def get_use_case(self,
335
336
  target_prompt_id: str,
337
+ start_time: datetime = None, # 新增:开始时间
338
+ end_time: datetime = None, # 新增:结束时间
336
339
  session = None
337
340
  ):
338
341
  """
@@ -341,6 +344,11 @@ class AsyncIntel():
341
344
  stmt = select(UseCase).filter(UseCase.is_deleted == 0,
342
345
  UseCase.prompt_id == target_prompt_id)
343
346
 
347
+ if start_time:
348
+ stmt = stmt.filter(UseCase.created_at >= start_time) # 假设你的UseCase模型有一个created_at字段
349
+
350
+ if end_time:
351
+ stmt = stmt.filter(UseCase.created_at <= end_time)
344
352
  result = await session.execute(stmt)
345
353
  # use_case = result.scalars().one_or_none()
346
354
  use_case = result.scalars().all()
@@ -665,8 +673,7 @@ class AsyncIntel():
665
673
  output_format = ""
666
674
 
667
675
  if logger:
668
- logger.info(f'{type(input_data)} $ intellect输入 input_data $ {input_data}')
669
- logger.info(f'{type(output_format)} $ intellect输入 output_format $ {output_format}')
676
+ logger.info(f'{type(input_data)} $ intellect-输入 $ {input_data} \noutput_format: \n{output_format}')
670
677
 
671
678
  ai_result = await self.intellect(
672
679
  input_data=input_data,
@@ -792,6 +799,122 @@ class AsyncIntel():
792
799
  if prompt_result.action_type != "inference":
793
800
  raise IntellectRemoveError("请在inference模式下使用次类")
794
801
 
802
+ if database_url:
803
+ eval_engine = create_async_engine(database_url, echo=False,
804
+ pool_size=10, # 连接池中保持的连接数
805
+ max_overflow=20, # 当pool_size不够时,允许临时创建的额外连接数
806
+ pool_recycle=3600, # 每小时回收一次连接
807
+ pool_pre_ping=True, # 使用前检查连接活性
808
+ pool_timeout=30 # 等待连接池中连接的最长时间(秒)
809
+ )
810
+ else:
811
+ eval_engine = self.engine
812
+ async with create_async_session(eval_engine) as eval_session:
813
+ # start = datetime(2023, 1, 1, 10, 0, 0)
814
+ # end = datetime(2023, 1, 15, 12, 30, 0)
815
+ use_cases = await self.get_use_case(target_prompt_id=prompt_id,session=eval_session,
816
+ start_time=None,
817
+ end_time=None,)
818
+
819
+ total_assertions = len(use_cases)
820
+ result_cases = []
821
+
822
+ async def evals_func(use_case,prompt_id,OutputFormat,ExtraFormats,version):
823
+ try:
824
+
825
+ # 这里将参数传入
826
+ ai_result = await self.intellect_format(
827
+ input_data = use_case.use_case,
828
+ prompt_id = prompt_id,
829
+ OutputFormat = OutputFormat,
830
+ ExtraFormats = ExtraFormats,
831
+ version = version,
832
+ inference_save_case = False,
833
+ ConTent_Function = ConTent_Function,
834
+ AConTent_Function = AConTent_Function,
835
+ )
836
+
837
+ result_cases.append({"type":"Successful","case":use_case.use_case,"reply":f"pass"})
838
+ use_case.output = json.dumps(ai_result,ensure_ascii=False,indent=4)
839
+
840
+
841
+ except IntellectRemoveFormatError as e:
842
+ result_cases.append({"type":"FAILED","case":use_case.use_case,"reply":f"{e}"})
843
+ use_case.output = f"{"FAILED"}-{e}"
844
+ use_case.faired_time +=1
845
+
846
+ except Exception as e: # 捕获其他可能的错误
847
+ result_cases.append({"type":"FAILED","case":use_case.use_case,"reply":f"Exp {e}"})
848
+ use_case.output = f"{"FAILED"}-{e}"
849
+ use_case.faired_time +=1
850
+
851
+
852
+ tasks = []
853
+ for use_case in use_cases:
854
+ tasks.append(
855
+ evals_func(
856
+ use_case = use_case,
857
+ prompt_id = prompt_id,
858
+ OutputFormat = OutputFormat,
859
+ ExtraFormats = ExtraFormats,
860
+ version = version
861
+ )
862
+ )
863
+ await tqdm.gather(*tasks,total=len(tasks))
864
+ # await asyncio.gather(*tasks, return_exceptions=False)
865
+
866
+ await eval_session.commit()
867
+
868
+ successful_assertions = 0
869
+ bad_case = []
870
+ for i in result_cases:
871
+ if i['type'] == "Successful":
872
+ successful_assertions += 1
873
+ else:
874
+ bad_case.append(i)
875
+
876
+ success_rate = (successful_assertions / total_assertions) * 100
877
+
878
+
879
+ if success_rate >= MIN_SUCCESS_RATE:
880
+ self.eval_df.loc[len(self.eval_df)] = {"name":prompt_id,
881
+ 'status':"通过",
882
+ "score":success_rate,
883
+ "total":str(total_assertions),
884
+ "bad_case":json.dumps(bad_case,ensure_ascii=False)}
885
+ return "通过", success_rate, str(total_assertions), json.dumps(bad_case,ensure_ascii=False),
886
+ else:
887
+ self.eval_df.loc[len(self.eval_df)] = {"name":prompt_id,
888
+ 'status':"未通过",
889
+ "score":success_rate,
890
+ "total":str(total_assertions),
891
+ "bad_case":json.dumps(bad_case,ensure_ascii=False)}
892
+ return "未通过",success_rate, str(total_assertions), json.dumps(bad_case,ensure_ascii=False),
893
+
894
+
895
+ async def function_eval(self,
896
+ OutputFormat: object,
897
+ prompt_id: str,
898
+ database_url = None,
899
+ ExtraFormats: list[object] = [],
900
+ version: str = None,
901
+ MIN_SUCCESS_RATE = 80.0,
902
+ ConTent_Function = None,
903
+ AConTent_Function = None,
904
+ ):
905
+ """
906
+ ConTent_Function:
907
+ # TODO 人类评价 eval
908
+ # TODO llm 评价 eval
909
+ """
910
+ async with create_async_session(self.engine) as session:
911
+ prompt_result = await self.get_prompt_safe(prompt_id=prompt_id,
912
+ session=session)
913
+ if prompt_result is None:
914
+ raise IntellectRemoveError("不存在的prompt_id")
915
+ if prompt_result.action_type != "inference":
916
+ raise IntellectRemoveError("请在inference模式下使用次类")
917
+
795
918
  if database_url:
796
919
  eval_engine = create_async_engine(database_url, echo=False,
797
920
  pool_size=10, # 连接池中保持的连接数
@@ -880,6 +1003,7 @@ class AsyncIntel():
880
1003
  "bad_case":json.dumps(bad_case,ensure_ascii=False)}
881
1004
  return "未通过",success_rate, str(total_assertions), json.dumps(bad_case,ensure_ascii=False),
882
1005
 
1006
+
883
1007
  def draw_data(self,save_html_path = ""):
884
1008
  df = self.eval_df
885
1009
  # --- 可视化部分 ---
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pro-craft
3
- Version: 0.1.54
3
+ Version: 0.1.55
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
@@ -6,7 +6,7 @@ pro_craft/utils.py,sha256=R1DFkS4dsm5dIhg8lLTgBBvItvIYyyojROdh-ykqiYk,5250
6
6
  pro_craft/code_helper/coder.py,sha256=L6pRQr0pYRIHrMFZ4-pO_tZf1koxgGgF3L7Vl-GIyjM,24687
7
7
  pro_craft/code_helper/designer.py,sha256=3gyCqrjcw61sHzDjUPKhL1LOAE8xWLLbNT8NlK2mFLc,4739
8
8
  pro_craft/prompt_craft/__init__.py,sha256=83ruWO1Oci-DWvdVhPqcQrgdZTNfbmK72VQCkWASk7A,80
9
- pro_craft/prompt_craft/async_.py,sha256=AkHU06zJE0gVLJC1s_5ViQ3htO0hzaqLFkzpIjieh4w,43191
9
+ pro_craft/prompt_craft/async_.py,sha256=KPWhzlFmLVm93-oRPvMJQlzzPX00qbjlvIUVaEfjiNI,49079
10
10
  pro_craft/prompt_craft/new.py,sha256=ULjGGl95vmHrOs7XECJGlaqj1NE9BypE5WnFYhGugRY,25903
11
11
  pro_craft/prompt_craft/sync.py,sha256=4bms8Qvzq5QqgwHWwiyjrcl7hdkSqE7Kne5s3Ex8bBU,26217
12
12
  pro_craft/server/mcp/__init__.py,sha256=4dbl-lFcm0r2tkOP04OxqiZG2jR-rqF181qi2AfU6UA,123
@@ -15,7 +15,7 @@ pro_craft/server/mcp/prompt.py,sha256=zZ58zb422vhwoL_uYCVBdOwOR-xy69MLQ5tyVfbpBl
15
15
  pro_craft/server/router/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  pro_craft/server/router/models.py,sha256=o60_qHjFIHwH3Pp6jNmg3V23GyFeXJXH-V6uBVoztXQ,1340
17
17
  pro_craft/server/router/prompt.py,sha256=goKipoCX62BqtNXE2DSzpmqM2yzs2wvSzhvoDuuG5Ik,6862
18
- pro_craft-0.1.54.dist-info/METADATA,sha256=Mz50Pcur2gMzh1--beNQsEYslXnaqfswZvjz6TX32jc,1782
19
- pro_craft-0.1.54.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
20
- pro_craft-0.1.54.dist-info/top_level.txt,sha256=yqYDHArnYMWpeCxkmGRwlL6sJtxiOUnYylLDx9EOgFg,10
21
- pro_craft-0.1.54.dist-info/RECORD,,
18
+ pro_craft-0.1.55.dist-info/METADATA,sha256=XXKESMgyd07rmPPBGF5BirCvTOAsPJUpgmo87b6T7rI,1782
19
+ pro_craft-0.1.55.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
20
+ pro_craft-0.1.55.dist-info/top_level.txt,sha256=yqYDHArnYMWpeCxkmGRwlL6sJtxiOUnYylLDx9EOgFg,10
21
+ pro_craft-0.1.55.dist-info/RECORD,,