pro-craft 0.1.51__tar.gz → 0.1.53__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.51 → pro_craft-0.1.53}/PKG-INFO +1 -1
- {pro_craft-0.1.51 → pro_craft-0.1.53}/pyproject.toml +1 -1
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/prompt_craft/async_.py +16 -6
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/server/router/models.py +2 -1
- pro_craft-0.1.53/src/pro_craft/server/router/prompt copy.py +183 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/server/router/prompt.py +21 -3
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft.egg-info/PKG-INFO +1 -1
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft.egg-info/SOURCES.txt +1 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/README.md +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/setup.cfg +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/__init__.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/code_helper/coder.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/code_helper/designer.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/database.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/file_manager.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/log.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/prompt_craft/__init__.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/prompt_craft/new.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/prompt_craft/sync.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/server/mcp/__init__.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/server/mcp/models.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/server/mcp/prompt.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/server/router/__init__.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft/utils.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft.egg-info/dependency_links.txt +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft.egg-info/requires.txt +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/src/pro_craft.egg-info/top_level.txt +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/tests/test22.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/tests/test_11.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/tests/test_coder.py +0 -0
- {pro_craft-0.1.51 → pro_craft-0.1.53}/tests/test_designer.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# 测试1
|
|
2
2
|
from pro_craft.utils import extract_
|
|
3
3
|
from pro_craft import logger as pro_craft_logger
|
|
4
|
-
from
|
|
4
|
+
from modusched.core import BianXieAdapter, ArkAdapter
|
|
5
5
|
from datetime import datetime
|
|
6
6
|
from enum import Enum
|
|
7
7
|
import functools
|
|
@@ -626,6 +626,8 @@ class AsyncIntel():
|
|
|
626
626
|
session = session)
|
|
627
627
|
ai_result = await self.llm.aproduct(prompt_obj.prompt + output_format + "\nuser:" + input_)
|
|
628
628
|
|
|
629
|
+
elif result_obj.action_type == "pass":
|
|
630
|
+
pass
|
|
629
631
|
else:
|
|
630
632
|
raise
|
|
631
633
|
|
|
@@ -640,6 +642,7 @@ class AsyncIntel():
|
|
|
640
642
|
inference_save_case = True,
|
|
641
643
|
ConTent_Function = None,
|
|
642
644
|
AConTent_Function = None,
|
|
645
|
+
logger = None,
|
|
643
646
|
):
|
|
644
647
|
"""
|
|
645
648
|
这个format 是严格校验模式, 是interllect 的增强版, 会主动校验内容,并及时抛出异常(或者伺机修正)
|
|
@@ -647,8 +650,8 @@ class AsyncIntel():
|
|
|
647
650
|
AConTent_Function
|
|
648
651
|
两种方式的传入方式, 内容未通过就抛出异常
|
|
649
652
|
|
|
650
|
-
|
|
651
|
-
|
|
653
|
+
# TODO 增加兜底版本
|
|
654
|
+
"""
|
|
652
655
|
base_format_prompt = """
|
|
653
656
|
按照一定格式输出, 以便可以通过如下校验
|
|
654
657
|
|
|
@@ -660,6 +663,11 @@ class AsyncIntel():
|
|
|
660
663
|
output_format = base_format_prompt + "\n".join([inspect.getsource(outputformat) for outputformat in ExtraFormats]) + inspect.getsource(OutputFormat)
|
|
661
664
|
else:
|
|
662
665
|
output_format = ""
|
|
666
|
+
|
|
667
|
+
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}')
|
|
670
|
+
|
|
663
671
|
ai_result = await self.intellect(
|
|
664
672
|
input_data=input_data,
|
|
665
673
|
output_format=output_format,
|
|
@@ -691,11 +699,13 @@ class AsyncIntel():
|
|
|
691
699
|
raise Exception(f"Error {prompt_id} : {e}") from e
|
|
692
700
|
|
|
693
701
|
if ConTent_Function:
|
|
694
|
-
ConTent_Function(ai_result)
|
|
702
|
+
ConTent_Function(ai_result,input_data)
|
|
695
703
|
|
|
696
704
|
if AConTent_Function:
|
|
697
|
-
await AConTent_Function(ai_result)
|
|
705
|
+
await AConTent_Function(ai_result,input_data)
|
|
698
706
|
|
|
707
|
+
if logger:
|
|
708
|
+
logger.info(f'{type(ai_result)} $ intellect输出 ai_result $ {ai_result}')
|
|
699
709
|
return ai_result
|
|
700
710
|
|
|
701
711
|
async def intellect_formats(self,
|
|
@@ -869,7 +879,7 @@ class AsyncIntel():
|
|
|
869
879
|
"bad_case":json.dumps(bad_case,ensure_ascii=False)}
|
|
870
880
|
return "未通过",success_rate, str(total_assertions), json.dumps(bad_case,ensure_ascii=False),
|
|
871
881
|
|
|
872
|
-
def draw_data(self,save_html_path):
|
|
882
|
+
def draw_data(self,save_html_path = ""):
|
|
873
883
|
df = self.eval_df
|
|
874
884
|
# --- 可视化部分 ---
|
|
875
885
|
fig = go.Figure()
|
|
@@ -17,6 +17,7 @@ class PushOrderRequest(BaseModel):
|
|
|
17
17
|
|
|
18
18
|
class GetPromptRequest(BaseModel):
|
|
19
19
|
prompt_id: str = Field(..., description="提示词id")
|
|
20
|
+
version: str = Field(None, description="提示词id")
|
|
20
21
|
|
|
21
22
|
class UpdatePromptRequest(BaseModel):
|
|
22
23
|
prompt_id: str = Field(..., description="提示词id")
|
|
@@ -32,4 +33,4 @@ class RollBackPromptRequest(BaseModel):
|
|
|
32
33
|
|
|
33
34
|
class PromptResponse(BaseModel):
|
|
34
35
|
msg: str = Field(..., description="信息")
|
|
35
|
-
content: str = None
|
|
36
|
+
content: dict| str = None
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
from fastapi import APIRouter
|
|
4
|
+
from pro_craft import Intel,AsyncIntel
|
|
5
|
+
from pro_craft.utils import create_async_session
|
|
6
|
+
from fastapi import FastAPI, HTTPException
|
|
7
|
+
from .models import *
|
|
8
|
+
from fastapi import APIRouter, Depends, HTTPException, status, Header
|
|
9
|
+
import os
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def create_router(database_url: str,
|
|
13
|
+
slave_database_url: str,
|
|
14
|
+
model_name: str,
|
|
15
|
+
logger = None):
|
|
16
|
+
"""
|
|
17
|
+
# TODO 整理改为异步
|
|
18
|
+
创建一个包含 ProCraft 路由的 FastAPI APIRouter 实例。
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
database_url (str): 数据库连接字符串。
|
|
22
|
+
model_name (str): 用于 Intel 实例的模型名称。
|
|
23
|
+
api_key_secret (str, optional): 用于验证 API Key 的秘密字符串。
|
|
24
|
+
如果提供,它将覆盖环境变量 PRO_CRAFT_API_KEY。
|
|
25
|
+
如果都不提供,会使用硬编码的 'your_default_secret_key'。
|
|
26
|
+
Returns:
|
|
27
|
+
APIRouter: 配置好的 FastAPI APIRouter 实例。
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
intels = AsyncIntel(
|
|
31
|
+
database_url=database_url,
|
|
32
|
+
model_name=model_name,
|
|
33
|
+
logger=logger
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
async def verify_api_key(authorization: Optional[str] = Header(None)):
|
|
37
|
+
# if not authorization:
|
|
38
|
+
# raise HTTPException(status_code=401, detail="Invalid authorization scheme")
|
|
39
|
+
# if not authorization.startswith("Bearer "):
|
|
40
|
+
# raise HTTPException(status_code=401, detail="Invalid authorization scheme")
|
|
41
|
+
|
|
42
|
+
# token = authorization.split(" ")[1]
|
|
43
|
+
|
|
44
|
+
key = os.getenv("prompt_api_key")
|
|
45
|
+
key_ = "123578"
|
|
46
|
+
if key_ != key:
|
|
47
|
+
raise HTTPException(status_code=401, detail="Error Server Position2")
|
|
48
|
+
|
|
49
|
+
router = APIRouter(
|
|
50
|
+
tags=["prompt"], # 这里使用 Depends 确保每次请求都验证
|
|
51
|
+
dependencies = [Depends(verify_api_key)]
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# 自动修改
|
|
55
|
+
@router.post("/push_order",
|
|
56
|
+
description="可选 train,inference,summary,finetune,patch",
|
|
57
|
+
response_model=PromptResponse,
|
|
58
|
+
)
|
|
59
|
+
async def push_order(request: PushOrderRequest):
|
|
60
|
+
try:
|
|
61
|
+
result = await intels.push_action_order(
|
|
62
|
+
demand=request.demand,
|
|
63
|
+
prompt_id=request.prompt_id,
|
|
64
|
+
action_type=request.action_type
|
|
65
|
+
)
|
|
66
|
+
return PromptResponse(msg = "success",content=result)
|
|
67
|
+
except Exception as e:
|
|
68
|
+
raise HTTPException(
|
|
69
|
+
status_code=500, detail=f"{e}"
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
# 人为干预
|
|
73
|
+
|
|
74
|
+
@router.get("/registered_prompt",
|
|
75
|
+
description="获取以注册的提示词",
|
|
76
|
+
response_model=PromptResponse)
|
|
77
|
+
async def registered_prompt():
|
|
78
|
+
try:
|
|
79
|
+
result = ["memorycard-format",
|
|
80
|
+
"memorycard-polish",
|
|
81
|
+
"memorycard-merge",
|
|
82
|
+
"memorycard-score",
|
|
83
|
+
"memorycard-generate-content",
|
|
84
|
+
"user-overview",
|
|
85
|
+
"user-relationship-extraction",
|
|
86
|
+
"avatar-brief",
|
|
87
|
+
"avatar-personality-extraction",
|
|
88
|
+
"avatar-desensitization",
|
|
89
|
+
""
|
|
90
|
+
"biograph-free-writer",
|
|
91
|
+
"biograph-paid-title",
|
|
92
|
+
"biograph-outline",
|
|
93
|
+
"biograph-brief",
|
|
94
|
+
"biograph-extract-person-name",
|
|
95
|
+
"biograph-extract-place",
|
|
96
|
+
"biograph-extract-material",
|
|
97
|
+
"biograph_material_add",
|
|
98
|
+
"biograph_material_init",
|
|
99
|
+
"biograph-writer"]
|
|
100
|
+
|
|
101
|
+
return PromptResponse(msg = "success",content=' | '.join(result))
|
|
102
|
+
except Exception as e:
|
|
103
|
+
raise HTTPException(
|
|
104
|
+
status_code=500, detail=f"{e}"
|
|
105
|
+
)
|
|
106
|
+
@router.post("/get_prompt",
|
|
107
|
+
description="获得现行提示词",
|
|
108
|
+
response_model=PromptResponse)
|
|
109
|
+
async def get_prompt(request: GetPromptRequest):
|
|
110
|
+
try:
|
|
111
|
+
async with create_async_session(intels.engine) as session:
|
|
112
|
+
result = await intels.get_prompt_safe(
|
|
113
|
+
prompt_id=request.prompt_id,
|
|
114
|
+
version = request.version,
|
|
115
|
+
session=session
|
|
116
|
+
)
|
|
117
|
+
return PromptResponse(msg = "success",content={"prompt": result.prompt, "version": result.version})
|
|
118
|
+
|
|
119
|
+
except Exception as e:
|
|
120
|
+
raise HTTPException(
|
|
121
|
+
status_code=500, detail=f"{e}"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
@router.post("/update_prompt",
|
|
125
|
+
description="更新现行提示词",
|
|
126
|
+
response_model=PromptResponse)
|
|
127
|
+
async def update_prompt(request: UpdatePromptRequest):
|
|
128
|
+
try:
|
|
129
|
+
async with create_async_session(intels.engine) as session:
|
|
130
|
+
await intels.save_prompt(
|
|
131
|
+
prompt_id = request.prompt_id,
|
|
132
|
+
new_prompt = request.prompt,
|
|
133
|
+
use_case = "",
|
|
134
|
+
action_type = "inference",
|
|
135
|
+
demand = "上传",
|
|
136
|
+
score = 70,
|
|
137
|
+
session = session)
|
|
138
|
+
return PromptResponse(msg = "success",content="")
|
|
139
|
+
except Exception as e:
|
|
140
|
+
raise HTTPException(
|
|
141
|
+
status_code=500, detail=f"{e}"
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
@router.post("/rollback_prompt",
|
|
145
|
+
description="回滚现行提示词",
|
|
146
|
+
response_model=PromptResponse)
|
|
147
|
+
async def roll_back(request: RollBackPromptRequest):
|
|
148
|
+
try:
|
|
149
|
+
async with create_async_session(intels.engine) as session:
|
|
150
|
+
result = await intels.get_prompt_safe(
|
|
151
|
+
prompt_id=request.prompt_id,
|
|
152
|
+
version = request.version,
|
|
153
|
+
session=session
|
|
154
|
+
)
|
|
155
|
+
assert result.version == request.version
|
|
156
|
+
await intels.save_prompt(
|
|
157
|
+
prompt_id = request.prompt_id,
|
|
158
|
+
new_prompt = result.prompt,
|
|
159
|
+
use_case = result.use_case,
|
|
160
|
+
action_type = "inference",
|
|
161
|
+
demand = "",
|
|
162
|
+
score = 61,
|
|
163
|
+
session = session)
|
|
164
|
+
return PromptResponse(msg = "success",content="")
|
|
165
|
+
except Exception as e:
|
|
166
|
+
raise HTTPException(
|
|
167
|
+
status_code=500, detail=f"{e}"
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
#系统级别服务
|
|
172
|
+
|
|
173
|
+
@router.post("/sync_database")
|
|
174
|
+
async def sync_database():
|
|
175
|
+
try:
|
|
176
|
+
result = await intels.sync_production_database(slave_database_url)
|
|
177
|
+
return PromptResponse(msg = "success",content="")
|
|
178
|
+
except Exception as e:
|
|
179
|
+
raise HTTPException(
|
|
180
|
+
status_code=500, detail=f"{e}"
|
|
181
|
+
)
|
|
182
|
+
return router
|
|
183
|
+
|
|
@@ -5,6 +5,9 @@ from pro_craft import Intel,AsyncIntel
|
|
|
5
5
|
from pro_craft.utils import create_async_session
|
|
6
6
|
from fastapi import FastAPI, HTTPException
|
|
7
7
|
from .models import *
|
|
8
|
+
from fastapi import APIRouter, Depends, HTTPException, status, Header
|
|
9
|
+
import os
|
|
10
|
+
|
|
8
11
|
|
|
9
12
|
def create_router(database_url: str,
|
|
10
13
|
slave_database_url: str,
|
|
@@ -30,8 +33,22 @@ def create_router(database_url: str,
|
|
|
30
33
|
logger=logger
|
|
31
34
|
)
|
|
32
35
|
|
|
36
|
+
async def verify_api_key(authorization: Optional[str] = Header(None)):
|
|
37
|
+
# if not authorization:
|
|
38
|
+
# raise HTTPException(status_code=401, detail="Invalid authorization scheme")
|
|
39
|
+
# if not authorization.startswith("Bearer "):
|
|
40
|
+
# raise HTTPException(status_code=401, detail="Invalid authorization scheme")
|
|
41
|
+
|
|
42
|
+
# token = authorization.split(" ")[1]
|
|
43
|
+
|
|
44
|
+
key = os.getenv("prompt_api_key")
|
|
45
|
+
key_ = "123578"
|
|
46
|
+
if key_ != key:
|
|
47
|
+
raise HTTPException(status_code=401, detail="Error Server Position2")
|
|
48
|
+
|
|
33
49
|
router = APIRouter(
|
|
34
|
-
tags=["prompt"] # 这里使用 Depends 确保每次请求都验证
|
|
50
|
+
tags=["prompt"], # 这里使用 Depends 确保每次请求都验证
|
|
51
|
+
dependencies = [Depends(verify_api_key)]
|
|
35
52
|
)
|
|
36
53
|
|
|
37
54
|
# 自动修改
|
|
@@ -57,7 +74,7 @@ def create_router(database_url: str,
|
|
|
57
74
|
@router.get("/registered_prompt",
|
|
58
75
|
description="获取以注册的提示词",
|
|
59
76
|
response_model=PromptResponse)
|
|
60
|
-
async def
|
|
77
|
+
async def registered_prompt():
|
|
61
78
|
try:
|
|
62
79
|
result = ["memorycard-format",
|
|
63
80
|
"memorycard-polish",
|
|
@@ -94,9 +111,10 @@ def create_router(database_url: str,
|
|
|
94
111
|
async with create_async_session(intels.engine) as session:
|
|
95
112
|
result = await intels.get_prompt_safe(
|
|
96
113
|
prompt_id=request.prompt_id,
|
|
114
|
+
version = request.version,
|
|
97
115
|
session=session
|
|
98
116
|
)
|
|
99
|
-
return PromptResponse(msg = "success",content=
|
|
117
|
+
return PromptResponse(msg = "success",content={"prompt": result.prompt, "version": result.version})
|
|
100
118
|
|
|
101
119
|
except Exception as e:
|
|
102
120
|
raise HTTPException(
|
|
@@ -21,6 +21,7 @@ src/pro_craft/server/mcp/models.py
|
|
|
21
21
|
src/pro_craft/server/mcp/prompt.py
|
|
22
22
|
src/pro_craft/server/router/__init__.py
|
|
23
23
|
src/pro_craft/server/router/models.py
|
|
24
|
+
src/pro_craft/server/router/prompt copy.py
|
|
24
25
|
src/pro_craft/server/router/prompt.py
|
|
25
26
|
tests/test22.py
|
|
26
27
|
tests/test_11.py
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|