pro-craft 0.1.35__tar.gz → 0.1.36__tar.gz
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-0.1.35 → pro_craft-0.1.36}/PKG-INFO +2 -1
- {pro_craft-0.1.35 → pro_craft-0.1.36}/pyproject.toml +2 -2
- pro_craft-0.1.36/src/pro_craft/__init__.py +18 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft/log.py +14 -14
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft/prompt_craft/async_.py +209 -247
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft.egg-info/PKG-INFO +2 -1
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft.egg-info/SOURCES.txt +1 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft.egg-info/requires.txt +1 -0
- pro_craft-0.1.36/tests/test_11.py +42 -0
- pro_craft-0.1.35/src/pro_craft/__init__.py +0 -23
- {pro_craft-0.1.35 → pro_craft-0.1.36}/README.md +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/setup.cfg +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft/code_helper/coder.py +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft/code_helper/designer.py +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft/database.py +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft/file_manager.py +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft/prompt_craft/__init__.py +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft/prompt_craft/new.py +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft/prompt_craft/sync.py +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft/server/mcp/__init__.py +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft/server/mcp/prompt.py +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft/server/router/__init__.py +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft/server/router/prompt.py +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft/utils.py +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft.egg-info/dependency_links.txt +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/src/pro_craft.egg-info/top_level.txt +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/tests/test22.py +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/tests/test_coder.py +0 -0
- {pro_craft-0.1.35 → pro_craft-0.1.36}/tests/test_designer.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pro-craft
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.36
|
|
4
4
|
Summary: Add your description here
|
|
5
5
|
Requires-Python: >=3.12
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -9,6 +9,7 @@ Requires-Dist: anyio>=4.11.0
|
|
|
9
9
|
Requires-Dist: db-help>=0.2.2
|
|
10
10
|
Requires-Dist: fastapi>=0.119.0
|
|
11
11
|
Requires-Dist: llmada>=1.1.11
|
|
12
|
+
Requires-Dist: plotly>=6.3.1
|
|
12
13
|
Requires-Dist: pyyaml>=6.0.3
|
|
13
14
|
Requires-Dist: toml>=0.10.2
|
|
14
15
|
Requires-Dist: utils-tool==0.1.3
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pro-craft"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.36"
|
|
4
4
|
description = "Add your description here"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.12"
|
|
7
|
-
dependencies = [ "aiomysql>=0.2.0", "anyio>=4.11.0", "db-help>=0.2.2", "fastapi>=0.119.0", "llmada>=1.1.11", "pyyaml>=6.0.3", "toml>=0.10.2", "utils-tool==0.1.3", "uvicorn>=0.38.0",]
|
|
7
|
+
dependencies = [ "aiomysql>=0.2.0", "anyio>=4.11.0", "db-help>=0.2.2", "fastapi>=0.119.0", "llmada>=1.1.11", "plotly>=6.3.1", "pyyaml>=6.0.3", "toml>=0.10.2", "utils-tool==0.1.3", "uvicorn>=0.38.0",]
|
|
8
8
|
|
|
9
9
|
[tool.setuptools.package-data]
|
|
10
10
|
pro_craft = [ "config.yaml",]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from dotenv import load_dotenv, find_dotenv
|
|
5
|
+
|
|
6
|
+
dotenv_path = find_dotenv()
|
|
7
|
+
load_dotenv(".env", override=True)
|
|
8
|
+
|
|
9
|
+
from .log import Log
|
|
10
|
+
import logging
|
|
11
|
+
Log_ = Log(console_level = logging.WARNING, # 显示控制台的等级
|
|
12
|
+
log_file_name="app.log")
|
|
13
|
+
logger = Log_.logger
|
|
14
|
+
Log_.set_super_log(logger.critical) # 控制superlog 打印的等级 默认是最高级单独存储一个文件
|
|
15
|
+
super_log = Log_.super_log # 调试工具
|
|
16
|
+
inference_save_case = False
|
|
17
|
+
|
|
18
|
+
from .prompt_craft import AsyncIntel, Intel, IntelNew
|
|
@@ -12,6 +12,7 @@ class Log:
|
|
|
12
12
|
def __init__(self, console_level = logging.INFO, log_file_name="app.log"):
|
|
13
13
|
self.Console_LOG_LEVEL = console_level
|
|
14
14
|
self.log_file_name = log_file_name
|
|
15
|
+
os.makedirs("logs", exist_ok=False)
|
|
15
16
|
self.LOG_FILE_PATH = os.path.join("logs", log_file_name)
|
|
16
17
|
self.logger = self.get_logger()
|
|
17
18
|
self.super_log_level = self.logger.critical
|
|
@@ -60,23 +61,22 @@ class Log:
|
|
|
60
61
|
)
|
|
61
62
|
file_handler_debug.setLevel(logging.WARNING) # 文件中显示所有指定级别的日志
|
|
62
63
|
file_handler_debug.setFormatter(formatter)
|
|
63
|
-
|
|
64
|
+
|
|
65
|
+
file_handler_cri = RotatingFileHandler(
|
|
66
|
+
self.LOG_FILE_PATH.replace('.log','_slog.log'),
|
|
67
|
+
maxBytes=5 * 1024 * 1024, # 10 MB
|
|
68
|
+
backupCount=5,
|
|
69
|
+
encoding="utf-8",
|
|
70
|
+
)
|
|
71
|
+
file_handler_cri.setLevel(logging.CRITICAL) # 文件中显示所有指定级别的日志
|
|
72
|
+
file_handler_cri.setFormatter(formatter)
|
|
73
|
+
logger.addHandler(file_handler_cri)
|
|
64
74
|
return logger
|
|
65
75
|
|
|
66
76
|
def set_super_log(self,logger_info):
|
|
67
77
|
self.super_log_level = logger_info
|
|
68
78
|
|
|
69
|
-
def super_log(self,s, target: str = "target"):
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
COLOR_YELLOW = "\033[93m"
|
|
73
|
-
COLOR_BLUE = "\033[94m"
|
|
74
|
-
COLOR_RESET = "\033[0m" # 重置颜色
|
|
75
|
-
log_ = self.super_log_level
|
|
76
|
-
|
|
77
|
-
log_("\n"+f"{COLOR_GREEN}=={COLOR_RESET}" * 50)
|
|
78
|
-
log_(target + "\n "+"--" * 40)
|
|
79
|
-
log_(type(s))
|
|
80
|
-
log_(s)
|
|
81
|
-
log_("\n"+f"{COLOR_GREEN}=={COLOR_RESET}" * 50)
|
|
79
|
+
def super_log(self,s, target: str = "target",logger = None):
|
|
80
|
+
logger = logger or self.super_log_level
|
|
81
|
+
logger("\n" + "=="*25 + target +"=="*25 + f"\n type: {str(type(s))}" + f"\ncontent: {s}")
|
|
82
82
|
|
|
@@ -28,25 +28,11 @@ from sqlalchemy.orm import class_mapper # 用于检查对象是否是持久化
|
|
|
28
28
|
import tqdm
|
|
29
29
|
from tqdm.asyncio import tqdm
|
|
30
30
|
import pandas as pd
|
|
31
|
+
import plotly.graph_objects as go
|
|
32
|
+
from pro_craft import super_log
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
pass
|
|
34
|
-
|
|
35
|
-
class IntellectRemoveError(Exception):
|
|
36
|
-
pass
|
|
34
|
+
BATCH_SIZE = int(os.getenv("DATABASE_SYNC_BATCH_SIZE",100))
|
|
37
35
|
|
|
38
|
-
BATCH_SIZE = 100
|
|
39
|
-
MIN_SUCCESS_RATE = 00.0 # 这里定义通过阈值, 高于该比例则通过
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def slog(s, target: str = "target",logger = None):
|
|
43
|
-
COLOR_GREEN = "\033[92m"
|
|
44
|
-
COLOR_RESET = "\033[0m" # 重置颜色
|
|
45
|
-
logger("\n"+f"{COLOR_GREEN}=={COLOR_RESET}" * 50)
|
|
46
|
-
logger(target + "\n "+"--" * 40)
|
|
47
|
-
logger(type(s))
|
|
48
|
-
logger(s)
|
|
49
|
-
logger("\n"+f"{COLOR_GREEN}=={COLOR_RESET}" * 50)
|
|
50
36
|
|
|
51
37
|
def fix_broken_json_string(broken_json_str):
|
|
52
38
|
# 移除 BOM
|
|
@@ -73,27 +59,6 @@ def fix_broken_json_string(broken_json_str):
|
|
|
73
59
|
|
|
74
60
|
return fixed_json_str
|
|
75
61
|
|
|
76
|
-
|
|
77
|
-
# def get_last_sync_time(target_session) -> datetime:
|
|
78
|
-
# """从目标数据库获取上次同步时间"""
|
|
79
|
-
# metadata_entry = target_session.query(SyncMetadata).filter_by(table_name="sync_metadata").first()
|
|
80
|
-
# if metadata_entry:
|
|
81
|
-
# return metadata_entry.last_sync_time
|
|
82
|
-
# return datetime(1970, 1, 1) # 默认一个很早的时间
|
|
83
|
-
|
|
84
|
-
# def update_last_sync_time(target_session, new_sync_time: datetime):
|
|
85
|
-
# """更新目标数据库的上次同步时间"""
|
|
86
|
-
# metadata_entry = target_session.query(SyncMetadata).filter_by(table_name="sync_metadata").first()
|
|
87
|
-
# if metadata_entry:
|
|
88
|
-
# metadata_entry.last_sync_time = new_sync_time
|
|
89
|
-
# else:
|
|
90
|
-
# # 如果不存在,则创建
|
|
91
|
-
# new_metadata = SyncMetadata(table_name="sync_metadata", last_sync_time=new_sync_time)
|
|
92
|
-
# target_session.add(new_metadata)
|
|
93
|
-
# target_session.commit()
|
|
94
|
-
# print(f"Updated last sync time to: {new_sync_time}")
|
|
95
|
-
|
|
96
|
-
|
|
97
62
|
async def get_last_sync_time(target_session: AsyncSession) -> datetime:
|
|
98
63
|
"""从目标数据库获取上次同步时间"""
|
|
99
64
|
# 修正点:使用 select() 和 execute()
|
|
@@ -106,10 +71,6 @@ async def get_last_sync_time(target_session: AsyncSession) -> datetime:
|
|
|
106
71
|
return metadata_entry.last_sync_time
|
|
107
72
|
return datetime(1970, 1, 1) # 默认一个很早的时间
|
|
108
73
|
|
|
109
|
-
|
|
110
|
-
# from your_module import SyncMetadata # 假设 SyncMetadata 已导入
|
|
111
|
-
# from sqlalchemy import select # 确保引入 select
|
|
112
|
-
|
|
113
74
|
async def update_last_sync_time(target_session: AsyncSession, new_sync_time: datetime):
|
|
114
75
|
"""更新目标数据库的上次同步时间"""
|
|
115
76
|
# 修正点:使用 select() 和 execute()
|
|
@@ -129,8 +90,14 @@ async def update_last_sync_time(target_session: AsyncSession, new_sync_time: dat
|
|
|
129
90
|
await target_session.commit() # TODO
|
|
130
91
|
print(f"Updated last sync time to: {new_sync_time}")
|
|
131
92
|
|
|
93
|
+
class IntellectRemoveFormatError(Exception):
|
|
94
|
+
pass
|
|
132
95
|
|
|
96
|
+
class IntellectRemoveError(Exception):
|
|
97
|
+
pass
|
|
133
98
|
|
|
99
|
+
class ModelNameError(Exception):
|
|
100
|
+
pass
|
|
134
101
|
|
|
135
102
|
|
|
136
103
|
|
|
@@ -151,7 +118,7 @@ class AsyncIntel():
|
|
|
151
118
|
assert database_url
|
|
152
119
|
assert 'aio' in database_url
|
|
153
120
|
except AssertionError as e:
|
|
154
|
-
|
|
121
|
+
super_log(database_url,'database_url',logger=self.logger.warning)
|
|
155
122
|
raise IntellectRemoveFormatError(f"异步服务url必须提供, 且必须是aiomysql配置") from e
|
|
156
123
|
|
|
157
124
|
self.engine = create_async_engine(database_url, echo=False,
|
|
@@ -162,16 +129,16 @@ class AsyncIntel():
|
|
|
162
129
|
pool_timeout=30 # 等待连接池中连接的最长时间(秒)
|
|
163
130
|
)
|
|
164
131
|
|
|
165
|
-
if
|
|
132
|
+
if "gemini" in model_name:
|
|
166
133
|
self.llm = BianXieAdapter(model_name = model_name)
|
|
167
|
-
elif
|
|
134
|
+
elif "doubao" in model_name:
|
|
168
135
|
self.llm = ArkAdapter(model_name = model_name)
|
|
169
136
|
else:
|
|
170
|
-
raise
|
|
171
|
-
|
|
172
|
-
self.
|
|
137
|
+
raise ModelNameError("AsyncIntel init get error model_name from zxf")
|
|
138
|
+
|
|
139
|
+
self.eval_df = pd.DataFrame({"name":[],'status':[],"score":[],"total":[],"bad_case":[]})
|
|
173
140
|
|
|
174
|
-
async def
|
|
141
|
+
async def create_main_database(self):
|
|
175
142
|
tables_to_create_names = ["ai_prompts","ai_usecase"]
|
|
176
143
|
async with self.engine.begin() as conn:
|
|
177
144
|
# 从 metadata 中获取对应的 Table 对象
|
|
@@ -190,51 +157,31 @@ class AsyncIntel():
|
|
|
190
157
|
async def create_database(self,engine):
|
|
191
158
|
async with engine.begin() as conn:
|
|
192
159
|
await conn.run_sync(PromptBase.metadata.create_all)
|
|
193
|
-
|
|
194
|
-
async def
|
|
160
|
+
|
|
161
|
+
async def get_prompt(self,prompt_id,version,session):
|
|
195
162
|
"""
|
|
196
163
|
获取指定 prompt_id 的最新版本数据,通过创建时间判断。
|
|
197
164
|
"""
|
|
198
|
-
|
|
199
|
-
Prompt.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
165
|
+
if version:
|
|
166
|
+
stmt_ = select(Prompt).filter(
|
|
167
|
+
Prompt.prompt_id == prompt_id,
|
|
168
|
+
Prompt.version == version
|
|
169
|
+
)
|
|
170
|
+
else:
|
|
171
|
+
stmt_ = select(Prompt).filter(
|
|
172
|
+
Prompt.prompt_id == prompt_id,
|
|
173
|
+
)
|
|
174
|
+
stmt = stmt_.order_by(
|
|
175
|
+
desc(Prompt.timestamp), # 使用 sqlalchemy.desc() 来指定降序
|
|
176
|
+
desc(Prompt.version) # 使用 sqlalchemy.desc() 来指定降序
|
|
177
|
+
)
|
|
178
|
+
|
|
205
179
|
result = await session.execute(stmt)
|
|
206
|
-
# 3. 从 Result 对象中获取第一个模型实例
|
|
207
|
-
# .scalars() 用于从结果行中获取第一个列的值(这里是Prompt对象本身)
|
|
208
|
-
# .first() 获取第一个结果
|
|
209
180
|
result = result.scalars().first()
|
|
210
181
|
|
|
211
182
|
return result
|
|
212
183
|
|
|
213
|
-
async def
|
|
214
|
-
"""
|
|
215
|
-
获取指定 prompt_id 和特定版本的数据。
|
|
216
|
-
|
|
217
|
-
Args:
|
|
218
|
-
target_prompt_id (str): 目标提示词的唯一标识符。
|
|
219
|
-
target_version (int): 目标提示词的版本号。
|
|
220
|
-
table_name (str): 存储提示词数据的数据库表名。
|
|
221
|
-
db_manager (DBManager): 数据库管理器的实例,用于执行查询。
|
|
222
|
-
|
|
223
|
-
Returns:
|
|
224
|
-
dict or None: 如果找到,返回包含 id, prompt_id, version, timestamp, prompt 字段的字典;
|
|
225
|
-
否则返回 None。
|
|
226
|
-
"""
|
|
227
|
-
stmt = select(Prompt).filter(
|
|
228
|
-
Prompt.prompt_id == target_prompt_id,
|
|
229
|
-
Prompt.version == target_version
|
|
230
|
-
)
|
|
231
|
-
result = await session.execute(stmt)
|
|
232
|
-
|
|
233
|
-
specific_prompt = result.scalars().one_or_none()
|
|
234
|
-
|
|
235
|
-
return specific_prompt
|
|
236
|
-
|
|
237
|
-
async def sync_prompt_data_to_database(self,database_url:str):
|
|
184
|
+
async def sync_production_database(self,database_url:str):
|
|
238
185
|
target_engine = create_async_engine(database_url, echo=False)
|
|
239
186
|
await self.create_database(target_engine)
|
|
240
187
|
async with create_async_session(self.engine) as source_session:
|
|
@@ -328,24 +275,23 @@ class AsyncIntel():
|
|
|
328
275
|
print("No new records to sync.")
|
|
329
276
|
|
|
330
277
|
|
|
331
|
-
async def
|
|
278
|
+
async def get_prompt_safe(self,
|
|
332
279
|
prompt_id: str,
|
|
333
280
|
version = None,
|
|
334
281
|
session = None) -> Prompt:
|
|
335
282
|
"""
|
|
336
283
|
从sql获取提示词
|
|
337
284
|
"""
|
|
338
|
-
|
|
339
|
-
if
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
285
|
+
prompt_obj = await self.get_prompt(prompt_id=prompt_id,version=version,session=session)
|
|
286
|
+
if prompt_obj:
|
|
287
|
+
return prompt_obj
|
|
288
|
+
|
|
289
|
+
print("warnning 未找到制定版本, 默认使用最新版本")
|
|
290
|
+
prompt_obj = await self.get_prompt(prompt_id=prompt_id,version=None,session=session)
|
|
291
|
+
return prompt_obj
|
|
292
|
+
|
|
346
293
|
|
|
347
|
-
|
|
348
|
-
async def save_prompt_increment_version(self,
|
|
294
|
+
async def save_prompt(self,
|
|
349
295
|
prompt_id: str,
|
|
350
296
|
new_prompt: str,
|
|
351
297
|
use_case:str = "",
|
|
@@ -358,7 +304,7 @@ class AsyncIntel():
|
|
|
358
304
|
input_data 指的是输入用例, 可以为空
|
|
359
305
|
"""
|
|
360
306
|
# 查看是否已经存在
|
|
361
|
-
prompts_obj = await self.
|
|
307
|
+
prompts_obj = await self.get_prompt_safe(prompt_id=prompt_id,session=session)
|
|
362
308
|
|
|
363
309
|
if prompts_obj:
|
|
364
310
|
# 如果存在版本加1
|
|
@@ -385,7 +331,7 @@ class AsyncIntel():
|
|
|
385
331
|
session.add(prompt1)
|
|
386
332
|
await session.commit() # 提交事务,将数据写入数据库
|
|
387
333
|
|
|
388
|
-
async def
|
|
334
|
+
async def get_use_case(self,
|
|
389
335
|
target_prompt_id: str,
|
|
390
336
|
session = None
|
|
391
337
|
):
|
|
@@ -400,7 +346,7 @@ class AsyncIntel():
|
|
|
400
346
|
use_case = result.scalars().all()
|
|
401
347
|
return use_case
|
|
402
348
|
|
|
403
|
-
async def
|
|
349
|
+
async def save_use_case(self,
|
|
404
350
|
prompt_id: str,
|
|
405
351
|
use_case:str = "",
|
|
406
352
|
timestamp = "",
|
|
@@ -414,7 +360,7 @@ class AsyncIntel():
|
|
|
414
360
|
从sql保存提示词
|
|
415
361
|
"""
|
|
416
362
|
#TODO 存之前保证数据库中相同的prompt_id中没有重复的use_case
|
|
417
|
-
use_cases = await self.
|
|
363
|
+
use_cases = await self.get_use_case(target_prompt_id = prompt_id,
|
|
418
364
|
session = session)
|
|
419
365
|
for use_case_old in use_cases:
|
|
420
366
|
if use_case == use_case_old.use_case:
|
|
@@ -432,86 +378,8 @@ class AsyncIntel():
|
|
|
432
378
|
session.add(use_case)
|
|
433
379
|
await session.commit() # 提交事务,将数据写入数据库
|
|
434
380
|
|
|
435
|
-
async def summary_to_sql(
|
|
436
|
-
self,
|
|
437
|
-
prompt_id:str,
|
|
438
|
-
version = None,
|
|
439
|
-
prompt = "",
|
|
440
|
-
session = None
|
|
441
|
-
):
|
|
442
|
-
"""
|
|
443
|
-
让大模型微调已经存在的 system_prompt
|
|
444
|
-
"""
|
|
445
|
-
system_prompt_created_prompt = """
|
|
446
|
-
很棒, 我们已经达成了某种默契, 我们之间合作无间, 但是, 可悲的是, 当我关闭这个窗口的时候, 你就会忘记我们之间经历的种种磨合, 这是可惜且心痛的, 所以你能否将目前这一套处理流程结晶成一个优质的prompt 这样, 我们下一次只要将prompt输入, 你就能想起我们今天的磨合过程,
|
|
447
|
-
对了,我提示一点, 这个prompt的主角是你, 也就是说, 你在和未来的你对话, 你要教会未来的你今天这件事, 是否让我看懂到时其次
|
|
448
|
-
|
|
449
|
-
只要输出提示词内容即可, 不需要任何的说明和解释
|
|
450
|
-
"""
|
|
451
|
-
system_result = await self.llm.aproduct(prompt + system_prompt_created_prompt)
|
|
452
|
-
|
|
453
|
-
s_prompt = extract_(system_result,pattern_key=r"prompt")
|
|
454
|
-
chat_history = s_prompt or system_result
|
|
455
|
-
await self.save_prompt_increment_version(prompt_id,
|
|
456
|
-
new_prompt = chat_history,
|
|
457
|
-
use_case = "",
|
|
458
|
-
score = 60,
|
|
459
|
-
session = session)
|
|
460
|
-
|
|
461
|
-
async def prompt_finetune_to_sql(
|
|
462
|
-
self,
|
|
463
|
-
prompt_id:str,
|
|
464
|
-
version = None,
|
|
465
|
-
demand: str = "",
|
|
466
|
-
session = None,
|
|
467
|
-
):
|
|
468
|
-
"""
|
|
469
|
-
让大模型微调已经存在的 system_prompt
|
|
470
|
-
"""
|
|
471
|
-
change_by_opinion_prompt = """
|
|
472
|
-
你是一个资深AI提示词工程师,具备卓越的Prompt设计与优化能力。
|
|
473
|
-
我将为你提供一段现有System Prompt。你的核心任务是基于这段Prompt进行修改,以实现我提出的特定目标和功能需求。
|
|
474
|
-
请你绝对严格地遵循以下原则:
|
|
475
|
-
极端最小化修改原则(核心):
|
|
476
|
-
在满足所有功能需求的前提下,只进行我明确要求的修改。
|
|
477
|
-
即使你认为有更“优化”、“清晰”或“简洁”的表达方式,只要我没有明确要求,也绝不允许进行任何未经指令的修改。
|
|
478
|
-
目的就是尽可能地保留原有Prompt的字符和结构不变,除非我的功能要求必须改变。
|
|
479
|
-
例如,如果我只要求你修改一个词,你就不应该修改整句话的结构。
|
|
480
|
-
严格遵循我的指令:
|
|
481
|
-
你必须精确地执行我提出的所有具体任务和要求。
|
|
482
|
-
绝不允许自行添加任何超出指令范围的说明、角色扮演、约束条件或任何非我指令要求的内容。
|
|
483
|
-
保持原有Prompt的风格和语调:
|
|
484
|
-
尽可能地与现有Prompt的语言风格、正式程度和语调保持一致。
|
|
485
|
-
不要改变不相关的句子或其表达方式。
|
|
486
|
-
只提供修改后的Prompt:
|
|
487
|
-
直接输出修改后的完整System Prompt文本。
|
|
488
|
-
不要包含任何解释、说明或额外对话。
|
|
489
|
-
在你开始之前,请务必确认你已理解并能绝对严格地遵守这些原则。任何未经明确指令的改动都将视为未能完成任务。
|
|
490
|
-
|
|
491
|
-
现有System Prompt:
|
|
492
|
-
{old_system_prompt}
|
|
493
|
-
|
|
494
|
-
功能需求:
|
|
495
|
-
{opinion}
|
|
496
|
-
"""
|
|
497
|
-
|
|
498
|
-
prompt_ = await self.get_prompts_from_sql(prompt_id = prompt_id,version = version,
|
|
499
|
-
session=session)
|
|
500
|
-
if demand:
|
|
501
|
-
new_prompt = await self.llm.aproduct(
|
|
502
|
-
change_by_opinion_prompt.format(old_system_prompt=prompt_.prompt, opinion=demand)
|
|
503
|
-
)
|
|
504
|
-
else:
|
|
505
|
-
new_prompt = prompt_
|
|
506
|
-
await self.save_prompt_increment_version(prompt_id = prompt_id,
|
|
507
|
-
new_prompt = new_prompt,
|
|
508
|
-
use_case = "",
|
|
509
|
-
score = 60,
|
|
510
|
-
session = session)
|
|
511
|
-
|
|
512
|
-
|
|
513
381
|
async def push_action_order(self,demand : str,prompt_id: str,
|
|
514
|
-
action_type = 'train')
|
|
382
|
+
action_type = 'train'):# init
|
|
515
383
|
|
|
516
384
|
"""
|
|
517
385
|
从sql保存提示词
|
|
@@ -522,9 +390,9 @@ class AsyncIntel():
|
|
|
522
390
|
# 查看是否已经存在
|
|
523
391
|
async with create_async_session(self.engine) as session:
|
|
524
392
|
|
|
525
|
-
latest_prompt = await self.
|
|
393
|
+
latest_prompt = await self.get_prompt_safe(prompt_id=prompt_id,session=session)
|
|
526
394
|
if latest_prompt:
|
|
527
|
-
await self.
|
|
395
|
+
await self.save_prompt(prompt_id=latest_prompt.prompt_id,
|
|
528
396
|
new_prompt = latest_prompt.prompt,
|
|
529
397
|
use_case = latest_prompt.use_case,
|
|
530
398
|
action_type=action_type,
|
|
@@ -534,9 +402,9 @@ class AsyncIntel():
|
|
|
534
402
|
)
|
|
535
403
|
return "success"
|
|
536
404
|
else:
|
|
537
|
-
await self.
|
|
405
|
+
await self.save_prompt(prompt_id=prompt_id,
|
|
538
406
|
new_prompt = demand,
|
|
539
|
-
use_case = "
|
|
407
|
+
use_case = "",
|
|
540
408
|
action_type="inference",
|
|
541
409
|
demand=demand,
|
|
542
410
|
score=60,
|
|
@@ -545,8 +413,7 @@ class AsyncIntel():
|
|
|
545
413
|
return "init"
|
|
546
414
|
|
|
547
415
|
|
|
548
|
-
|
|
549
|
-
async def intellect_remove(self,
|
|
416
|
+
async def intellect(self,
|
|
550
417
|
input_data: dict | str,
|
|
551
418
|
output_format: str,
|
|
552
419
|
prompt_id: str,
|
|
@@ -561,7 +428,7 @@ class AsyncIntel():
|
|
|
561
428
|
|
|
562
429
|
# 查数据库, 获取最新提示词对象
|
|
563
430
|
async with create_async_session(self.engine) as session:
|
|
564
|
-
result_obj = await self.
|
|
431
|
+
result_obj = await self.get_prompt_safe(prompt_id=prompt_id,session=session)
|
|
565
432
|
if result_obj is None:
|
|
566
433
|
raise IntellectRemoveError("不存在的prompt_id")
|
|
567
434
|
|
|
@@ -570,7 +437,8 @@ class AsyncIntel():
|
|
|
570
437
|
# 直接推理即可
|
|
571
438
|
ai_result = await self.llm.aproduct(prompt + output_format + "\nuser:" + input_)
|
|
572
439
|
if inference_save_case:
|
|
573
|
-
|
|
440
|
+
# 设计一个机制, 传输说获取300数据, 那么数据就一直流转获取, 知道300截止
|
|
441
|
+
await self.save_use_case(prompt_id,
|
|
574
442
|
use_case = input_,
|
|
575
443
|
timestamp = datetime.now(),
|
|
576
444
|
output = ai_result,
|
|
@@ -584,9 +452,6 @@ class AsyncIntel():
|
|
|
584
452
|
# 则训练推广
|
|
585
453
|
|
|
586
454
|
# 新版本 默人修改会 inference 状态
|
|
587
|
-
chat_history = prompt
|
|
588
|
-
before_input = result_obj.use_case
|
|
589
|
-
demand = result_obj.demand
|
|
590
455
|
|
|
591
456
|
|
|
592
457
|
# assert demand
|
|
@@ -601,7 +466,7 @@ class AsyncIntel():
|
|
|
601
466
|
|
|
602
467
|
# ai_result = await self.llm.aproduct(input_prompt)
|
|
603
468
|
# chat_history = input_prompt + "\nassistant:\n" + ai_result # 用聊天记录作为完整提示词
|
|
604
|
-
# await self.
|
|
469
|
+
# await self.save_prompt(prompt_id, chat_history,
|
|
605
470
|
# use_case = input_,
|
|
606
471
|
# score = 60,
|
|
607
472
|
# session = session)
|
|
@@ -619,14 +484,17 @@ class AsyncIntel():
|
|
|
619
484
|
# save_new_prompt = new_prompt + "\nassistant:\n" + ai_result
|
|
620
485
|
|
|
621
486
|
|
|
622
|
-
# await self.
|
|
487
|
+
# await self.save_prompt(
|
|
623
488
|
# prompt_id,
|
|
624
489
|
# new_prompt=save_new_prompt,
|
|
625
490
|
# use_case = input_,
|
|
626
491
|
# action_type = "inference",
|
|
627
492
|
# score = 60,
|
|
628
493
|
# session = session)
|
|
629
|
-
|
|
494
|
+
chat_history = prompt
|
|
495
|
+
before_input = result_obj.use_case
|
|
496
|
+
demand = result_obj.demand
|
|
497
|
+
input_data = input_
|
|
630
498
|
if before_input == "" or change_case is True:
|
|
631
499
|
result_obj.use_case = input_
|
|
632
500
|
await session.commit()
|
|
@@ -641,7 +509,7 @@ class AsyncIntel():
|
|
|
641
509
|
save_new_prompt = new_prompt + "\nassistant:\n" + ai_result
|
|
642
510
|
|
|
643
511
|
|
|
644
|
-
await self.
|
|
512
|
+
await self.save_prompt(
|
|
645
513
|
prompt_id,
|
|
646
514
|
new_prompt=save_new_prompt,
|
|
647
515
|
use_case = input_,
|
|
@@ -650,42 +518,118 @@ class AsyncIntel():
|
|
|
650
518
|
session = session)
|
|
651
519
|
|
|
652
520
|
elif result_obj.action_type == "summary":
|
|
521
|
+
system_prompt_summary = """
|
|
522
|
+
很棒, 我们已经达成了某种默契, 我们之间合作无间, 但是, 可悲的是, 当我关闭这个窗口的时候, 你就会忘记我们之间经历的种种磨合, 这是可惜且心痛的, 所以你能否将目前这一套处理流程结晶成一个优质的prompt 这样, 我们下一次只要将prompt输入, 你就能想起我们今天的磨合过程,
|
|
523
|
+
对了,我提示一点, 这个prompt的主角是你, 也就是说, 你在和未来的你对话, 你要教会未来的你今天这件事, 是否让我看懂到时其次
|
|
524
|
+
|
|
525
|
+
只要输出提示词内容即可, 不需要任何的说明和解释
|
|
526
|
+
"""
|
|
527
|
+
|
|
528
|
+
latest_prompt = await self.get_prompt_safe(prompt_id=prompt_id,session=session)
|
|
529
|
+
|
|
530
|
+
system_result = await self.llm.aproduct(prompt + system_prompt_summary)
|
|
531
|
+
s_prompt = extract_(system_result,pattern_key=r"prompt")
|
|
532
|
+
new_prompt = s_prompt or system_result
|
|
533
|
+
await self.save_prompt(
|
|
534
|
+
prompt_id,
|
|
535
|
+
new_prompt = new_prompt,
|
|
536
|
+
use_case = latest_prompt.use_case,
|
|
537
|
+
score = 65,
|
|
538
|
+
action_type = "inference",
|
|
539
|
+
session = session
|
|
540
|
+
)
|
|
653
541
|
|
|
654
|
-
await self.summary_to_sql(prompt_id = prompt_id,
|
|
655
|
-
prompt = prompt,
|
|
656
|
-
session = session
|
|
657
|
-
)
|
|
658
542
|
ai_result = await self.llm.aproduct(prompt + output_format + "\nuser:" + input_)
|
|
659
543
|
|
|
660
544
|
elif result_obj.action_type == "finetune":
|
|
661
545
|
demand = result_obj.demand
|
|
662
|
-
|
|
546
|
+
change_by_opinion_prompt = """
|
|
547
|
+
你是一个资深AI提示词工程师,具备卓越的Prompt设计与优化能力。
|
|
548
|
+
我将为你提供一段现有System Prompt。你的核心任务是基于这段Prompt进行修改,以实现我提出的特定目标和功能需求。
|
|
549
|
+
请你绝对严格地遵循以下原则:
|
|
550
|
+
极端最小化修改原则(核心):
|
|
551
|
+
在满足所有功能需求的前提下,只进行我明确要求的修改。
|
|
552
|
+
即使你认为有更“优化”、“清晰”或“简洁”的表达方式,只要我没有明确要求,也绝不允许进行任何未经指令的修改。
|
|
553
|
+
目的就是尽可能地保留原有Prompt的字符和结构不变,除非我的功能要求必须改变。
|
|
554
|
+
例如,如果我只要求你修改一个词,你就不应该修改整句话的结构。
|
|
555
|
+
严格遵循我的指令:
|
|
556
|
+
你必须精确地执行我提出的所有具体任务和要求。
|
|
557
|
+
绝不允许自行添加任何超出指令范围的说明、角色扮演、约束条件或任何非我指令要求的内容。
|
|
558
|
+
保持原有Prompt的风格和语调:
|
|
559
|
+
尽可能地与现有Prompt的语言风格、正式程度和语调保持一致。
|
|
560
|
+
不要改变不相关的句子或其表达方式。
|
|
561
|
+
只提供修改后的Prompt:
|
|
562
|
+
直接输出修改后的完整System Prompt文本。
|
|
563
|
+
不要包含任何解释、说明或额外对话。
|
|
564
|
+
在你开始之前,请务必确认你已理解并能绝对严格地遵守这些原则。任何未经明确指令的改动都将视为未能完成任务。
|
|
565
|
+
|
|
566
|
+
现有System Prompt:
|
|
567
|
+
{old_system_prompt}
|
|
568
|
+
|
|
569
|
+
功能需求:
|
|
570
|
+
{opinion}
|
|
571
|
+
"""
|
|
572
|
+
|
|
573
|
+
latest_prompt = await self.get_prompt_safe(prompt_id=prompt_id,session=session)
|
|
574
|
+
prompt_ = await self.get_prompt_safe(prompt_id = prompt_id,version = version,
|
|
575
|
+
session=session)
|
|
663
576
|
assert demand
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
577
|
+
|
|
578
|
+
if demand:
|
|
579
|
+
new_prompt = await self.llm.aproduct(
|
|
580
|
+
change_by_opinion_prompt.format(old_system_prompt=prompt_.prompt, opinion=demand)
|
|
581
|
+
)
|
|
582
|
+
else:
|
|
583
|
+
new_prompt = prompt_
|
|
584
|
+
await self.save_prompt(
|
|
585
|
+
prompt_id,
|
|
586
|
+
new_prompt = new_prompt,
|
|
587
|
+
use_case = latest_prompt.use_case,
|
|
588
|
+
score = 70,
|
|
589
|
+
action_type = "inference",
|
|
590
|
+
session = session
|
|
591
|
+
)
|
|
592
|
+
|
|
668
593
|
ai_result = await self.llm.aproduct(prompt + output_format + "\nuser:" + input_)
|
|
669
594
|
|
|
670
595
|
elif result_obj.action_type == "patch":
|
|
671
596
|
demand = result_obj.demand
|
|
672
597
|
assert demand
|
|
598
|
+
latest_prompt = await self.get_prompt_safe(prompt_id=prompt_id,session=session)
|
|
599
|
+
|
|
673
600
|
chat_history = prompt + demand
|
|
601
|
+
await self.save_prompt(prompt_id,
|
|
602
|
+
chat_history,
|
|
603
|
+
use_case = latest_prompt.use_case,
|
|
604
|
+
score = 70,
|
|
605
|
+
action_type = "inference",
|
|
606
|
+
session = session)
|
|
607
|
+
|
|
674
608
|
ai_result = await self.llm.aproduct(chat_history + output_format + "\nuser:" + input_)
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
609
|
+
|
|
610
|
+
elif result_obj.action_type.startswith("to:"):
|
|
611
|
+
target_version = result_obj.action_type.split(":")[-1]
|
|
612
|
+
latest_prompt = await self.get_prompt_safe(prompt_id=prompt_id,session=session)
|
|
613
|
+
prompt_obj = await self.get_prompt_safe(prompt_id=prompt_id,
|
|
614
|
+
version=target_version,
|
|
615
|
+
session=session)
|
|
616
|
+
|
|
617
|
+
await self.save_prompt(prompt_id,
|
|
618
|
+
prompt_obj.prompt,
|
|
619
|
+
use_case = latest_prompt.use_case,
|
|
620
|
+
score = prompt_obj.score,
|
|
621
|
+
action_type = "inference",
|
|
622
|
+
session = session)
|
|
623
|
+
ai_result = await self.llm.aproduct(prompt_obj.prompt + output_format + "\nuser:" + input_)
|
|
624
|
+
|
|
681
625
|
else:
|
|
682
626
|
raise
|
|
683
627
|
|
|
684
628
|
return ai_result
|
|
685
629
|
|
|
686
|
-
async def
|
|
630
|
+
async def intellect_format(self,
|
|
687
631
|
input_data: dict | str,
|
|
688
|
-
OutputFormat: object,
|
|
632
|
+
OutputFormat: object | None,
|
|
689
633
|
prompt_id: str,
|
|
690
634
|
ExtraFormats: list[object] = [],
|
|
691
635
|
version: str = None,
|
|
@@ -699,9 +643,11 @@ class AsyncIntel():
|
|
|
699
643
|
"```json([\s\S]*?)```"
|
|
700
644
|
使用以下方式验证
|
|
701
645
|
"""
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
646
|
+
if OutputFormat:
|
|
647
|
+
output_format = base_format_prompt + "\n".join([inspect.getsource(outputformat) for outputformat in ExtraFormats]) + inspect.getsource(OutputFormat)
|
|
648
|
+
else:
|
|
649
|
+
output_format = ""
|
|
650
|
+
ai_result = await self.intellect(
|
|
705
651
|
input_data=input_data,
|
|
706
652
|
output_format=output_format,
|
|
707
653
|
prompt_id=prompt_id,
|
|
@@ -711,17 +657,17 @@ class AsyncIntel():
|
|
|
711
657
|
|
|
712
658
|
try:
|
|
713
659
|
json_str = extract_(ai_result,r'json')
|
|
714
|
-
# json_str = fix_broken_json_string(json_str)
|
|
715
660
|
ai_result = json.loads(json_str)
|
|
716
|
-
OutputFormat
|
|
661
|
+
if OutputFormat:
|
|
662
|
+
OutputFormat(**ai_result)
|
|
717
663
|
|
|
718
664
|
except JSONDecodeError as e:
|
|
719
|
-
slog(ai_result,logger=self.logger.error)
|
|
720
665
|
try:
|
|
721
666
|
self.logger.error(f"尝试补救")
|
|
722
667
|
json_str = fix_broken_json_string(json_str)
|
|
723
668
|
ai_result = json.loads(json_str)
|
|
724
|
-
OutputFormat
|
|
669
|
+
if OutputFormat:
|
|
670
|
+
OutputFormat(**ai_result)
|
|
725
671
|
|
|
726
672
|
except JSONDecodeError as e:
|
|
727
673
|
raise IntellectRemoveFormatError(f"prompt_id: {prompt_id} 生成的内容为无法被Json解析 {e}") from e
|
|
@@ -732,19 +678,10 @@ class AsyncIntel():
|
|
|
732
678
|
|
|
733
679
|
except Exception as e:
|
|
734
680
|
raise Exception(f"Error {prompt_id} : {e}") from e
|
|
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
|
-
# )
|
|
681
|
+
|
|
745
682
|
return ai_result
|
|
746
683
|
|
|
747
|
-
async def
|
|
684
|
+
async def intellect_formats(self,
|
|
748
685
|
input_datas: list[dict | str],
|
|
749
686
|
OutputFormat: object,
|
|
750
687
|
prompt_id: str,
|
|
@@ -754,7 +691,7 @@ class AsyncIntel():
|
|
|
754
691
|
):
|
|
755
692
|
|
|
756
693
|
async with create_async_session(self.engine) as session:
|
|
757
|
-
prompt_result = await self.
|
|
694
|
+
prompt_result = await self.get_prompt_safe(prompt_id=prompt_id,
|
|
758
695
|
session=session)
|
|
759
696
|
if prompt_result is None:
|
|
760
697
|
raise IntellectRemoveError("不存在的prompt_id")
|
|
@@ -763,7 +700,7 @@ class AsyncIntel():
|
|
|
763
700
|
tasks = []
|
|
764
701
|
for input_data in input_datas:
|
|
765
702
|
tasks.append(
|
|
766
|
-
self.
|
|
703
|
+
self.intellect_format(
|
|
767
704
|
input_data = input_data,
|
|
768
705
|
prompt_id = prompt_id,
|
|
769
706
|
OutputFormat = OutputFormat,
|
|
@@ -775,7 +712,7 @@ class AsyncIntel():
|
|
|
775
712
|
results = await asyncio.gather(*tasks, return_exceptions=False)
|
|
776
713
|
return results
|
|
777
714
|
|
|
778
|
-
def
|
|
715
|
+
def intellect_warp(self,prompt_id: str):
|
|
779
716
|
def outer_packing(func):
|
|
780
717
|
@functools.wraps(func)
|
|
781
718
|
async def wrapper(*args, **kwargs):
|
|
@@ -790,7 +727,7 @@ class AsyncIntel():
|
|
|
790
727
|
elif isinstance(input_data,str):
|
|
791
728
|
input_ = output_ = input_data
|
|
792
729
|
|
|
793
|
-
output_ = await self.
|
|
730
|
+
output_ = await self.intellect_format(
|
|
794
731
|
input_data = input_data,
|
|
795
732
|
prompt_id = prompt_id,
|
|
796
733
|
OutputFormat = OutputFormat,
|
|
@@ -803,7 +740,7 @@ class AsyncIntel():
|
|
|
803
740
|
return wrapper
|
|
804
741
|
return outer_packing
|
|
805
742
|
|
|
806
|
-
async def
|
|
743
|
+
async def intellect_format_eval(self,
|
|
807
744
|
OutputFormat: object,
|
|
808
745
|
prompt_id: str,
|
|
809
746
|
ExtraFormats: list[object] = [],
|
|
@@ -811,10 +748,14 @@ class AsyncIntel():
|
|
|
811
748
|
MIN_SUCCESS_RATE = 80.0,
|
|
812
749
|
ConTent_Function = None,
|
|
813
750
|
):
|
|
814
|
-
|
|
751
|
+
"""
|
|
752
|
+
ConTent_Function:
|
|
753
|
+
# TODO 人类评价 eval
|
|
754
|
+
# TODO llm 评价 eval
|
|
755
|
+
"""
|
|
815
756
|
async with create_async_session(self.engine) as session:
|
|
816
|
-
use_cases = await self.
|
|
817
|
-
prompt_result = await self.
|
|
757
|
+
use_cases = await self.get_use_case(target_prompt_id=prompt_id,session=session)
|
|
758
|
+
prompt_result = await self.get_prompt_safe(prompt_id=prompt_id,
|
|
818
759
|
session=session)
|
|
819
760
|
if prompt_result is None:
|
|
820
761
|
raise IntellectRemoveError("不存在的prompt_id")
|
|
@@ -828,7 +769,7 @@ class AsyncIntel():
|
|
|
828
769
|
async def evals_func(use_case,prompt_id,OutputFormat,ExtraFormats,version):
|
|
829
770
|
try:
|
|
830
771
|
# 这里将参数传入
|
|
831
|
-
await self.
|
|
772
|
+
ai_result = await self.intellect_format(
|
|
832
773
|
input_data = use_case.use_case,
|
|
833
774
|
prompt_id = prompt_id,
|
|
834
775
|
OutputFormat = OutputFormat,
|
|
@@ -836,23 +777,20 @@ class AsyncIntel():
|
|
|
836
777
|
version = version,
|
|
837
778
|
inference_save_case = False,
|
|
838
779
|
)
|
|
839
|
-
# TODO base_eval
|
|
840
|
-
# TODO 人类评价 eval
|
|
841
|
-
# TODO llm 评价 eval
|
|
842
780
|
if ConTent_Function:
|
|
843
781
|
ConTent_Function()
|
|
844
782
|
result_cases.append({"type":"Successful","case":use_case.use_case,"reply":f"pass"})
|
|
845
|
-
use_case.output =
|
|
783
|
+
use_case.output = ai_result
|
|
846
784
|
except IntellectRemoveFormatError as e:
|
|
847
785
|
result_cases.append({"type":"FAILED","case":use_case.use_case,"reply":f"{e}"})
|
|
848
786
|
use_case.output = f"{"FAILED"}-{e}"
|
|
849
787
|
except Exception as e: # 捕获其他可能的错误
|
|
850
788
|
result_cases.append({"type":"FAILED","case":use_case.use_case,"reply":f"Exp {e}"})
|
|
851
789
|
use_case.output = f"{"FAILED"}-{e}"
|
|
852
|
-
|
|
790
|
+
await session.commit()
|
|
853
791
|
|
|
854
792
|
tasks = []
|
|
855
|
-
for use_case in
|
|
793
|
+
for use_case in use_cases:
|
|
856
794
|
tasks.append(
|
|
857
795
|
evals_func(
|
|
858
796
|
use_case = use_case,
|
|
@@ -884,7 +822,7 @@ class AsyncIntel():
|
|
|
884
822
|
|
|
885
823
|
|
|
886
824
|
def draw_data(self):
|
|
887
|
-
df = self.
|
|
825
|
+
df = self.eval_df
|
|
888
826
|
# --- 可视化部分 ---
|
|
889
827
|
fig = go.Figure()
|
|
890
828
|
|
|
@@ -938,13 +876,37 @@ class AsyncIntel():
|
|
|
938
876
|
margin=dict(l=100, r=20, t=60, b=50),
|
|
939
877
|
height=400 + len(df) * 30
|
|
940
878
|
)
|
|
879
|
+
error_message =str(df['bad_case'].to_dict())
|
|
880
|
+
fig.add_annotation(
|
|
881
|
+
text=f"<b>bad_case:</b> {error_message}", # 要显示的文本
|
|
882
|
+
xref="paper", yref="paper", # 使用“paper”坐标系,表示相对于图表区域
|
|
883
|
+
x=0.01, y=-0.15, # x=0.01 靠近左侧,y=-0.15 在图表底部下方 (您可以调整这些值)
|
|
884
|
+
showarrow=False, # 不显示箭头
|
|
885
|
+
align="left",
|
|
886
|
+
font=dict(
|
|
887
|
+
family="Arial, sans-serif",
|
|
888
|
+
size=12,
|
|
889
|
+
color="red" # 错误信息通常用红色
|
|
890
|
+
),
|
|
891
|
+
bgcolor="white", # 背景颜色
|
|
892
|
+
bordercolor="red", # 边框颜色
|
|
893
|
+
borderwidth=1,
|
|
894
|
+
borderpad=4,
|
|
895
|
+
xanchor='left', # 文本框左对齐到x坐标
|
|
896
|
+
yanchor='top' # 文本框顶部对齐到y坐标
|
|
897
|
+
)
|
|
898
|
+
# 可能还需要调整底部的边距以容纳错误信息
|
|
899
|
+
fig.update_layout(
|
|
900
|
+
margin=dict(l=100, r=20, t=60, b=100), # 增加底部边距
|
|
901
|
+
height=400 + len(df) * 30 + 50 # 增加图表高度以适应文本框
|
|
902
|
+
)
|
|
941
903
|
|
|
942
904
|
fig.show()
|
|
943
905
|
pass
|
|
944
906
|
|
|
945
907
|
async def _evals(self,prompt_id, OutputFormat, ExtraFormats_list = [],**kwargs):
|
|
946
908
|
|
|
947
|
-
status,score, total, bad_case = await self.
|
|
909
|
+
status,score, total, bad_case = await self.intellect_format_eval(
|
|
948
910
|
prompt_id=prompt_id,
|
|
949
911
|
OutputFormat = OutputFormat,
|
|
950
912
|
ExtraFormats = ExtraFormats_list,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pro-craft
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.36
|
|
4
4
|
Summary: Add your description here
|
|
5
5
|
Requires-Python: >=3.12
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -9,6 +9,7 @@ Requires-Dist: anyio>=4.11.0
|
|
|
9
9
|
Requires-Dist: db-help>=0.2.2
|
|
10
10
|
Requires-Dist: fastapi>=0.119.0
|
|
11
11
|
Requires-Dist: llmada>=1.1.11
|
|
12
|
+
Requires-Dist: plotly>=6.3.1
|
|
12
13
|
Requires-Dist: pyyaml>=6.0.3
|
|
13
14
|
Requires-Dist: toml>=0.10.2
|
|
14
15
|
Requires-Dist: utils-tool==0.1.3
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from pro_craft.prompt_craft.async_ import AsyncIntel
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
async def test_1():
|
|
6
|
+
intels = AsyncIntel(database_url=os.getenv("adatabase_url"),model_name="doubao-1-5-pro-32k-250115")
|
|
7
|
+
# 先使用该函数,实现,创建, 初始化, 训练等等
|
|
8
|
+
result = await intels.push_action_order(
|
|
9
|
+
# demand='以下是一个代码模板, 我希望你做的是, 根据要求微调代码模板来构建代码```pythonfrom pydantic import BaseModel, Fieldfrom pro_craft import AsyncIntelinference_save_case = Falsemodel_name = "doubao-1-5-pro-256k-250115"inters = AsyncIntel(model_name = model_name)## modelsclass Chapter(BaseModel): """ 表示文档中的一个记忆卡片(章节)。 """ title: str = Field(..., description="记忆卡片的标题") content: str = Field(..., description="记忆卡片的内容")class Document(BaseModel): """ 表示一个包含标题和多个记忆卡片的文档。 """ title: str = Field(..., description="整个文档的标题内容") chapters: List[Chapter] = Field(..., description="文档中包含的记忆卡片列表") ## modelsasync def amemory_card_merge(memory_cards: list[str]): memoryCards_str, memoryCards_time_str = memoryCards2str(memory_cards) input_data = memoryCards_str + "各记忆卡片的时间" + memoryCards_time_str result = await inters.intellect_remove_format( input_data= input_data, prompt_id = "memorycard-merge", version = None, inference_save_case=inference_save_case, OutputFormat = Document, ExtraFormats=[Chapter], ) return result```',
|
|
10
|
+
demand="添加一些注释",
|
|
11
|
+
prompt_id="zxf_code_template_2",
|
|
12
|
+
action_type="to:1.8"
|
|
13
|
+
)
|
|
14
|
+
print(result)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def test_work():
|
|
19
|
+
intels = AsyncIntel(database_url=os.getenv("adatabase_url"),model_name="doubao-1-5-pro-32k-250115")
|
|
20
|
+
# @intels.intellect_warp("zxf_code_template")
|
|
21
|
+
# async def work_test(input_data, OutputFormat):
|
|
22
|
+
# print(input_data)
|
|
23
|
+
await intels.create_main_database()
|
|
24
|
+
# 期间不断使用这个函数进行配合
|
|
25
|
+
input_data = "我要一个生成记忆卡片的程序,只包括文本即可"
|
|
26
|
+
result = await intels.intellect(input_data=input_data,
|
|
27
|
+
output_format="",
|
|
28
|
+
prompt_id="zxf_code_template_2")
|
|
29
|
+
|
|
30
|
+
print(result)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
async def test_work2():
|
|
34
|
+
intels = AsyncIntel(database_url=os.getenv("adatabase_url"),model_name="doubao-1-5-pro-32k-250115")
|
|
35
|
+
|
|
36
|
+
@intels.intellect_warp("zxf_code_template_2")
|
|
37
|
+
async def work_test(input_data, OutputFormat):
|
|
38
|
+
print(input_data)
|
|
39
|
+
input_data = "我要一个生成记忆卡片的程序, 记忆卡片包括标题(title), 内容(content), 时间(time), 标签(tag)"
|
|
40
|
+
|
|
41
|
+
print(await work_test(input_data = input_data,
|
|
42
|
+
OutputFormat = ""))
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
from dotenv import load_dotenv, find_dotenv
|
|
2
|
-
dotenv_path = find_dotenv()
|
|
3
|
-
load_dotenv(".env", override=True)
|
|
4
|
-
|
|
5
|
-
from .log import Log
|
|
6
|
-
import logging
|
|
7
|
-
Log_ = Log(console_level = logging.WARNING,
|
|
8
|
-
log_file_name="app.log")
|
|
9
|
-
logger = Log_.logger
|
|
10
|
-
Log_.set_super_log(logger.critical)
|
|
11
|
-
|
|
12
|
-
super_log = Log_.super_log # 调试工具
|
|
13
|
-
|
|
14
|
-
def slog(s, target: str = "target",logger = logger.info):
|
|
15
|
-
COLOR_GREEN = "\033[92m"
|
|
16
|
-
COLOR_RESET = "\033[0m" # 重置颜色
|
|
17
|
-
logger("\n"+f"{COLOR_GREEN}=={COLOR_RESET}" * 50)
|
|
18
|
-
logger(target + "\n "+"--" * 40)
|
|
19
|
-
logger(type(s))
|
|
20
|
-
logger(s)
|
|
21
|
-
logger("\n"+f"{COLOR_GREEN}=={COLOR_RESET}" * 50)
|
|
22
|
-
|
|
23
|
-
from .prompt_craft import AsyncIntel, Intel, IntelNew
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|