pro-craft 0.1.33__py3-none-any.whl → 0.1.35__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.
- pro_craft/prompt_craft/async_.py +115 -141
- {pro_craft-0.1.33.dist-info → pro_craft-0.1.35.dist-info}/METADATA +1 -1
- {pro_craft-0.1.33.dist-info → pro_craft-0.1.35.dist-info}/RECORD +5 -5
- {pro_craft-0.1.33.dist-info → pro_craft-0.1.35.dist-info}/WHEEL +0 -0
- {pro_craft-0.1.33.dist-info → pro_craft-0.1.35.dist-info}/top_level.txt +0 -0
pro_craft/prompt_craft/async_.py
CHANGED
|
@@ -25,7 +25,9 @@ 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
|
-
|
|
28
|
+
import tqdm
|
|
29
|
+
from tqdm.asyncio import tqdm
|
|
30
|
+
import pandas as pd
|
|
29
31
|
|
|
30
32
|
class IntellectRemoveFormatError(Exception):
|
|
31
33
|
pass
|
|
@@ -166,6 +168,8 @@ class AsyncIntel():
|
|
|
166
168
|
self.llm = ArkAdapter(model_name = model_name)
|
|
167
169
|
else:
|
|
168
170
|
raise Exception("error llm name")
|
|
171
|
+
|
|
172
|
+
self.df = pd.DataFrame({"name":[],'status':[],"score":[],"total":[],"bad_case":[]})
|
|
169
173
|
|
|
170
174
|
async def create_specific_database(self):
|
|
171
175
|
tables_to_create_names = ["ai_prompts","ai_usecase"]
|
|
@@ -399,19 +403,30 @@ class AsyncIntel():
|
|
|
399
403
|
async def save_use_case_by_sql(self,
|
|
400
404
|
prompt_id: str,
|
|
401
405
|
use_case:str = "",
|
|
406
|
+
timestamp = "",
|
|
402
407
|
output = "",
|
|
403
408
|
solution: str = "",
|
|
409
|
+
faired_time = 0,
|
|
404
410
|
session = None
|
|
405
411
|
):
|
|
412
|
+
|
|
406
413
|
"""
|
|
407
414
|
从sql保存提示词
|
|
408
415
|
"""
|
|
409
416
|
#TODO 存之前保证数据库中相同的prompt_id中没有重复的use_case
|
|
410
|
-
|
|
411
|
-
|
|
417
|
+
use_cases = await self.get_use_case_by_sql(target_prompt_id = prompt_id,
|
|
418
|
+
session = session)
|
|
419
|
+
for use_case_old in use_cases:
|
|
420
|
+
if use_case == use_case_old.use_case:
|
|
421
|
+
print("用例已经存在")
|
|
422
|
+
return
|
|
423
|
+
|
|
424
|
+
use_case = UseCase(prompt_id=prompt_id,
|
|
412
425
|
use_case = use_case,
|
|
426
|
+
timestamp = timestamp,
|
|
413
427
|
output = output,
|
|
414
428
|
solution = solution,
|
|
429
|
+
faired_time = faired_time,
|
|
415
430
|
)
|
|
416
431
|
|
|
417
432
|
session.add(use_case)
|
|
@@ -557,8 +572,10 @@ class AsyncIntel():
|
|
|
557
572
|
if inference_save_case:
|
|
558
573
|
await self.save_use_case_by_sql(prompt_id,
|
|
559
574
|
use_case = input_,
|
|
575
|
+
timestamp = datetime.now(),
|
|
560
576
|
output = ai_result,
|
|
561
|
-
solution =
|
|
577
|
+
solution = output_format,
|
|
578
|
+
faired_time = 0,
|
|
562
579
|
session = session,
|
|
563
580
|
)
|
|
564
581
|
|
|
@@ -649,6 +666,7 @@ class AsyncIntel():
|
|
|
649
666
|
session = session
|
|
650
667
|
)
|
|
651
668
|
ai_result = await self.llm.aproduct(prompt + output_format + "\nuser:" + input_)
|
|
669
|
+
|
|
652
670
|
elif result_obj.action_type == "patch":
|
|
653
671
|
demand = result_obj.demand
|
|
654
672
|
assert demand
|
|
@@ -664,138 +682,7 @@ class AsyncIntel():
|
|
|
664
682
|
raise
|
|
665
683
|
|
|
666
684
|
return ai_result
|
|
667
|
-
|
|
668
|
-
async def intellect_stream_remove(self,
|
|
669
|
-
input_data: dict | str,
|
|
670
|
-
output_format: str,
|
|
671
|
-
prompt_id: str,
|
|
672
|
-
version: str = None,
|
|
673
|
-
inference_save_case = True,
|
|
674
|
-
push_patch = False,
|
|
675
|
-
):
|
|
676
|
-
if isinstance(input_data,dict):
|
|
677
|
-
input_ = json.dumps(input_data,ensure_ascii=False)
|
|
678
|
-
elif isinstance(input_data,str):
|
|
679
|
-
input_ = input_data
|
|
680
|
-
|
|
681
685
|
|
|
682
|
-
# 查数据库, 获取最新提示词对象
|
|
683
|
-
with create_session(self.engine) as session:
|
|
684
|
-
result_obj = await self.get_prompts_from_sql(prompt_id=prompt_id,session=session)
|
|
685
|
-
|
|
686
|
-
'''
|
|
687
|
-
if result_obj is None:
|
|
688
|
-
await self.save_prompt_increment_version(
|
|
689
|
-
prompt_id = prompt_id,
|
|
690
|
-
new_prompt = "做一些处理",
|
|
691
|
-
use_case = input_,
|
|
692
|
-
session = session
|
|
693
|
-
)
|
|
694
|
-
ai_result = await self.intellect_stream_remove(input_data = input_data,
|
|
695
|
-
output_format = output_format,
|
|
696
|
-
prompt_id = prompt_id,
|
|
697
|
-
version = version,
|
|
698
|
-
inference_save_case = inference_save_case
|
|
699
|
-
)
|
|
700
|
-
return ai_result'''
|
|
701
|
-
|
|
702
|
-
prompt = result_obj.prompt
|
|
703
|
-
if result_obj.action_type == "inference":
|
|
704
|
-
# 直接推理即可
|
|
705
|
-
|
|
706
|
-
ai_generate_result = self.llm.aproduct_stream(prompt + output_format + "\n-----input----\n" + input_)
|
|
707
|
-
ai_result = ""
|
|
708
|
-
async for word in ai_generate_result:
|
|
709
|
-
ai_result += word
|
|
710
|
-
yield word
|
|
711
|
-
if inference_save_case:
|
|
712
|
-
await self.save_use_case_by_sql(prompt_id,
|
|
713
|
-
use_case = input_,
|
|
714
|
-
output = ai_result,
|
|
715
|
-
solution = "备注/理想回复",
|
|
716
|
-
session = session,
|
|
717
|
-
)
|
|
718
|
-
|
|
719
|
-
elif result_obj.action_type == "train":
|
|
720
|
-
assert result_obj.demand # 如果type = train 且 demand 是空 则报错
|
|
721
|
-
# 则训练推广
|
|
722
|
-
|
|
723
|
-
# 新版本 默人修改会 inference 状态
|
|
724
|
-
chat_history = prompt
|
|
725
|
-
before_input = result_obj.use_case
|
|
726
|
-
demand = result_obj.demand
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
assert demand
|
|
730
|
-
# 注意, 这里的调整要求使用最初的那个输入, 最好一口气调整好
|
|
731
|
-
chat_history = prompt
|
|
732
|
-
if input_ == before_input: # 输入没变, 说明还是针对同一个输入进行讨论
|
|
733
|
-
# input_prompt = chat_history + "\nuser:" + demand
|
|
734
|
-
input_prompt = chat_history + "\nuser:" + demand + output_format
|
|
735
|
-
else:
|
|
736
|
-
# input_prompt = chat_history + "\nuser:" + demand + "\n-----input----\n" + input_
|
|
737
|
-
input_prompt = chat_history + "\nuser:" + demand + output_format + "\n-----input----\n" + input_
|
|
738
|
-
|
|
739
|
-
ai_generate_result = self.llm.aproduct_stream(input_prompt)
|
|
740
|
-
ai_result = ""
|
|
741
|
-
async for word in ai_generate_result:
|
|
742
|
-
ai_result += word
|
|
743
|
-
yield word
|
|
744
|
-
|
|
745
|
-
chat_history = input_prompt + "\nassistant:\n" + ai_result # 用聊天记录作为完整提示词
|
|
746
|
-
await self.save_prompt_increment_version(prompt_id, chat_history,
|
|
747
|
-
use_case = input_,
|
|
748
|
-
score = 60,
|
|
749
|
-
session = session)
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
elif result_obj.action_type == "summary":
|
|
753
|
-
|
|
754
|
-
await self.summary_to_sql(prompt_id = prompt_id,
|
|
755
|
-
prompt = prompt,
|
|
756
|
-
session = session
|
|
757
|
-
)
|
|
758
|
-
input_prompt = prompt + output_format + "\n-----input----\n" + input_
|
|
759
|
-
ai_generate_result = self.llm.aproduct_stream(input_prompt)
|
|
760
|
-
ai_result = ""
|
|
761
|
-
async for word in ai_generate_result:
|
|
762
|
-
ai_result += word
|
|
763
|
-
yield word
|
|
764
|
-
|
|
765
|
-
elif result_obj.action_type == "finetune":
|
|
766
|
-
demand = result_obj.demand
|
|
767
|
-
|
|
768
|
-
assert demand
|
|
769
|
-
await self.prompt_finetune_to_sql(prompt_id = prompt_id,
|
|
770
|
-
demand = demand,
|
|
771
|
-
session = session
|
|
772
|
-
)
|
|
773
|
-
input_prompt = prompt + output_format + "\n-----input----\n" + input_
|
|
774
|
-
ai_generate_result = self.llm.aproduct_stream(input_prompt)
|
|
775
|
-
ai_result = ""
|
|
776
|
-
async for word in ai_generate_result:
|
|
777
|
-
ai_result += word
|
|
778
|
-
yield word
|
|
779
|
-
|
|
780
|
-
elif result_obj.action_type == "patch":
|
|
781
|
-
|
|
782
|
-
demand = result_obj.demand
|
|
783
|
-
assert demand
|
|
784
|
-
|
|
785
|
-
chat_history = prompt + demand
|
|
786
|
-
ai_generate_result = self.llm.aproduct_stream(chat_history + output_format + "\n-----input----\n" + input_)
|
|
787
|
-
ai_result = ""
|
|
788
|
-
async for word in ai_generate_result:
|
|
789
|
-
ai_result += word
|
|
790
|
-
yield word
|
|
791
|
-
if push_patch:
|
|
792
|
-
self.save_prompt_increment_version(prompt_id, chat_history,
|
|
793
|
-
use_case = input_,
|
|
794
|
-
score = 60,
|
|
795
|
-
session = session)
|
|
796
|
-
else:
|
|
797
|
-
raise
|
|
798
|
-
|
|
799
686
|
async def intellect_remove_format(self,
|
|
800
687
|
input_data: dict | str,
|
|
801
688
|
OutputFormat: object,
|
|
@@ -845,7 +732,16 @@ class AsyncIntel():
|
|
|
845
732
|
|
|
846
733
|
except Exception as e:
|
|
847
734
|
raise Exception(f"Error {prompt_id} : {e}") from e
|
|
848
|
-
|
|
735
|
+
|
|
736
|
+
# finally:
|
|
737
|
+
# await self.save_use_case_by_sql(prompt_id,
|
|
738
|
+
# use_case = input_data,
|
|
739
|
+
# timestamp = datetime.now(),
|
|
740
|
+
# output = ai_result,
|
|
741
|
+
# solution = output_format,
|
|
742
|
+
# faired_time = 1,
|
|
743
|
+
# session = session,
|
|
744
|
+
# )
|
|
849
745
|
return ai_result
|
|
850
746
|
|
|
851
747
|
async def intellect_remove_formats(self,
|
|
@@ -912,7 +808,8 @@ class AsyncIntel():
|
|
|
912
808
|
prompt_id: str,
|
|
913
809
|
ExtraFormats: list[object] = [],
|
|
914
810
|
version: str = None,
|
|
915
|
-
MIN_SUCCESS_RATE = 80.0
|
|
811
|
+
MIN_SUCCESS_RATE = 80.0,
|
|
812
|
+
ConTent_Function = None,
|
|
916
813
|
):
|
|
917
814
|
|
|
918
815
|
async with create_async_session(self.engine) as session:
|
|
@@ -942,6 +839,8 @@ class AsyncIntel():
|
|
|
942
839
|
# TODO base_eval
|
|
943
840
|
# TODO 人类评价 eval
|
|
944
841
|
# TODO llm 评价 eval
|
|
842
|
+
if ConTent_Function:
|
|
843
|
+
ConTent_Function()
|
|
945
844
|
result_cases.append({"type":"Successful","case":use_case.use_case,"reply":f"pass"})
|
|
946
845
|
use_case.output = "Successful"
|
|
947
846
|
except IntellectRemoveFormatError as e:
|
|
@@ -953,7 +852,7 @@ class AsyncIntel():
|
|
|
953
852
|
await session.commit()
|
|
954
853
|
|
|
955
854
|
tasks = []
|
|
956
|
-
for use_case in use_cases:
|
|
855
|
+
for use_case in tqdm.tqdm(use_cases):
|
|
957
856
|
tasks.append(
|
|
958
857
|
evals_func(
|
|
959
858
|
use_case = use_case,
|
|
@@ -963,7 +862,8 @@ class AsyncIntel():
|
|
|
963
862
|
version = version
|
|
964
863
|
)
|
|
965
864
|
)
|
|
966
|
-
await
|
|
865
|
+
await tqdm.gather(*tasks,total=len(tasks))
|
|
866
|
+
# await asyncio.gather(*tasks, return_exceptions=False)
|
|
967
867
|
|
|
968
868
|
|
|
969
869
|
successful_assertions = 0
|
|
@@ -977,8 +877,82 @@ class AsyncIntel():
|
|
|
977
877
|
success_rate = (successful_assertions / total_assertions) * 100
|
|
978
878
|
|
|
979
879
|
if success_rate >= MIN_SUCCESS_RATE:
|
|
980
|
-
return "通过", success_rate, total_assertions, json.dumps(bad_case,ensure_ascii=False),
|
|
880
|
+
return "通过", success_rate, str(total_assertions), json.dumps(bad_case,ensure_ascii=False),
|
|
981
881
|
else:
|
|
982
|
-
return "未通过",success_rate, total_assertions, json.dumps(bad_case,ensure_ascii=False),
|
|
882
|
+
return "未通过",success_rate, str(total_assertions), json.dumps(bad_case,ensure_ascii=False),
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
def draw_data(self):
|
|
887
|
+
df = self.df
|
|
888
|
+
# --- 可视化部分 ---
|
|
889
|
+
fig = go.Figure()
|
|
890
|
+
|
|
891
|
+
# 为每个条形图动态设置颜色
|
|
892
|
+
colors = []
|
|
893
|
+
for status_val in df['status']:
|
|
894
|
+
if status_val == '通过':
|
|
895
|
+
colors.append('mediumseagreen') # 通过为绿色
|
|
896
|
+
else: # 假设其他所有状态都视为“未通过”
|
|
897
|
+
colors.append('lightcoral') # 未通过为红色
|
|
898
|
+
|
|
899
|
+
fig.add_trace(go.Bar(
|
|
900
|
+
y=df['name'], # Y轴显示项目名称
|
|
901
|
+
x=df['score'], # X轴显示通过百分比 (score列现在代表通过百分比)
|
|
902
|
+
orientation='h', # 设置为横向
|
|
903
|
+
name='通过率', # 这个 name 可能会在图例中显示
|
|
904
|
+
marker_color=colors, # !!! 这里根据 status 动态设置颜色 !!!
|
|
905
|
+
text=df['score'].apply(lambda x: f'{x:.2f}%'), # 在条形图上显示百分比文本
|
|
906
|
+
textposition='inside',
|
|
907
|
+
insidetextanchor='middle',
|
|
908
|
+
hovertemplate="<b>prompt:</b> %{y}<br><b>状态:</b> " + df['status'] + "<br><b>总量:</b> "+ df['total'] + "<br><b>通过百分比:</b> %{x:.2f}%<extra></extra>"
|
|
909
|
+
))
|
|
910
|
+
|
|
911
|
+
# 添加一个辅助的条形图作为背景,表示总的100%
|
|
912
|
+
fig.add_trace(go.Bar(
|
|
913
|
+
y=df['name'],
|
|
914
|
+
x=[100] * len(df), # 所有项目都填充到100%
|
|
915
|
+
orientation='h',
|
|
916
|
+
name='总计',
|
|
917
|
+
marker_color='lightgray', # 背景用灰色
|
|
918
|
+
hoverinfo='none', # 不显示hover信息
|
|
919
|
+
opacity=0.5, # 设置透明度
|
|
920
|
+
showlegend=False # 不显示图例
|
|
921
|
+
))
|
|
922
|
+
|
|
923
|
+
fig.update_layout(
|
|
924
|
+
title='各项目/批次通过百分比及状态',
|
|
925
|
+
xaxis=dict(
|
|
926
|
+
title='通过百分比 (%)',
|
|
927
|
+
range=[0, 100], # X轴范围0-100
|
|
928
|
+
tickvals=[0, 25, 50, 75, 100],
|
|
929
|
+
showgrid=True,
|
|
930
|
+
gridcolor='lightgray'
|
|
931
|
+
),
|
|
932
|
+
yaxis=dict(
|
|
933
|
+
title='项目/批次',
|
|
934
|
+
autorange="reversed"
|
|
935
|
+
),
|
|
936
|
+
barmode='overlay', # 仍使用 overlay 模式,因为背景条是独立的
|
|
937
|
+
hovermode="y unified",
|
|
938
|
+
margin=dict(l=100, r=20, t=60, b=50),
|
|
939
|
+
height=400 + len(df) * 30
|
|
940
|
+
)
|
|
941
|
+
|
|
942
|
+
fig.show()
|
|
943
|
+
pass
|
|
944
|
+
|
|
945
|
+
async def _evals(self,prompt_id, OutputFormat, ExtraFormats_list = [],**kwargs):
|
|
946
|
+
|
|
947
|
+
status,score, total, bad_case = await self.intellect_remove_format_eval(
|
|
948
|
+
prompt_id=prompt_id,
|
|
949
|
+
OutputFormat = OutputFormat,
|
|
950
|
+
ExtraFormats = ExtraFormats_list,
|
|
951
|
+
version = None,
|
|
952
|
+
**kwargs
|
|
953
|
+
)
|
|
954
|
+
self.df.loc[len(self.df)] = {"name":prompt_id,
|
|
955
|
+
'status':status,"score":score,
|
|
956
|
+
"total":total,"bad_case":bad_case}
|
|
983
957
|
|
|
984
958
|
# 整体测试d, 测试未通过d, 大模型调整再测试, 依旧不通过, 大模型裂变, 仍不通过, 互换人力
|
|
@@ -6,14 +6,14 @@ 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=
|
|
9
|
+
pro_craft/prompt_craft/async_.py,sha256=egt_C0SSWSHJ0MhcHMLTDEePPzfslA57x_A6BAZVPUE,41702
|
|
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
|
|
13
13
|
pro_craft/server/mcp/prompt.py,sha256=OZrsyUfSQMOY_KX7dWthW209adz5JfELsQ0ODfuQR44,1245
|
|
14
14
|
pro_craft/server/router/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
15
|
pro_craft/server/router/prompt.py,sha256=Wa4FfYRL6oeyA3F-79pmPeIH0Vo8wSEv7RH1lP6jXck,2907
|
|
16
|
-
pro_craft-0.1.
|
|
17
|
-
pro_craft-0.1.
|
|
18
|
-
pro_craft-0.1.
|
|
19
|
-
pro_craft-0.1.
|
|
16
|
+
pro_craft-0.1.35.dist-info/METADATA,sha256=fG6de7HZSZdzh75n5_nurl6jv-udfwWcQ1oXzYqNenk,1689
|
|
17
|
+
pro_craft-0.1.35.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
18
|
+
pro_craft-0.1.35.dist-info/top_level.txt,sha256=yqYDHArnYMWpeCxkmGRwlL6sJtxiOUnYylLDx9EOgFg,10
|
|
19
|
+
pro_craft-0.1.35.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|