fix: use proper DSPY context for diagnose
This commit is contained in:
parent
f55317fbe8
commit
a14669790f
@ -1,17 +1,61 @@
|
||||
# test_diagnose.dspy - 直接诊断人事项目
|
||||
|
||||
from pipeline_service.agent_loop_v2 import AgentExecutor
|
||||
from pipeline_core.agent_config import SDLC_DEFAULT_CONFIG
|
||||
|
||||
uid = 'user-01'
|
||||
pid = 'T_2hWHTqqwgf8igNMHLQk' # 人事项目
|
||||
pid = 'T_2hWHTqqwgf8igNMHLQk'
|
||||
|
||||
executor = AgentExecutor(config=SDLC_DEFAULT_CONFIG, project_id=pid, user_id=uid)
|
||||
dbname = get_module_dbname('pipeline-sdlc')
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
# 任务统计
|
||||
submitted = await sor.sqlExe(
|
||||
"SELECT COUNT(*) as c FROM pipeline_tasks WHERE tenant_id=${pid}$ AND state='submitted'",
|
||||
{"pid": pid})
|
||||
running = await sor.sqlExe(
|
||||
"SELECT COUNT(*) as c FROM pipeline_tasks WHERE tenant_id=${pid}$ AND state='running'",
|
||||
{"pid": pid})
|
||||
failed = await sor.sqlExe(
|
||||
"SELECT COUNT(*) as c FROM pipeline_tasks WHERE tenant_id=${pid}$ AND state='failed'",
|
||||
{"pid": pid})
|
||||
review = await sor.sqlExe(
|
||||
"SELECT COUNT(*) as c FROM pipeline_tasks WHERE tenant_id=${pid}$ AND state='review'",
|
||||
{"pid": pid})
|
||||
approved = await sor.sqlExe(
|
||||
"SELECT COUNT(*) as c FROM pipeline_tasks WHERE tenant_id=${pid}$ AND state='approved'",
|
||||
{"pid": pid})
|
||||
completed = await sor.sqlExe(
|
||||
"SELECT COUNT(*) as c FROM pipeline_tasks WHERE tenant_id=${pid}$ AND state='completed'",
|
||||
{"pid": pid})
|
||||
|
||||
# 手动调用 diagnose 和 list_tasks
|
||||
async with DBPools().sqlorContext('pipeline') as sor:
|
||||
diag = await executor._t_diagnose_project(sor, {}, pid)
|
||||
tasks = await executor._t_list_tasks(sor, {}, pid)
|
||||
# 任务列表
|
||||
tasks = await sor.sqlExe(
|
||||
"SELECT id, title, role, state FROM pipeline_tasks WHERE tenant_id=${pid}$ ORDER BY created_at DESC LIMIT 20",
|
||||
{"pid": pid})
|
||||
task_list = [{"id": getattr(t,'id','')[:8], "title": getattr(t,'title',''),
|
||||
"role": getattr(t,'role',''), "state": getattr(t,'state','')}
|
||||
for t in (tasks or [])]
|
||||
|
||||
result = {"diagnose": diag, "tasks": tasks}
|
||||
return json.dumps(result, ensure_ascii=False)
|
||||
# 交付件
|
||||
delivs = await sor.sqlExe(
|
||||
"SELECT COUNT(*) as c FROM pipeline_deliverables WHERE project_id=${pid}$",
|
||||
{"pid": pid})
|
||||
|
||||
# 项目信息
|
||||
proj = await sor.sqlExe(
|
||||
"SELECT name, description, status FROM sd_projects WHERE id=${pid}$",
|
||||
{"pid": pid})
|
||||
pname = getattr(proj[0], 'name', '') if proj else ''
|
||||
|
||||
result = {
|
||||
"project": pname,
|
||||
"status": {
|
||||
"submitted": getattr(submitted[0], 'c', 0) if submitted else 0,
|
||||
"running": getattr(running[0], 'c', 0) if running else 0,
|
||||
"failed": getattr(failed[0], 'c', 0) if failed else 0,
|
||||
"review": getattr(review[0], 'c', 0) if review else 0,
|
||||
"approved": getattr(approved[0], 'c', 0) if approved else 0,
|
||||
"completed": getattr(completed[0], 'c', 0) if completed else 0,
|
||||
"deliverables": getattr(delivs[0], 'c', 0) if delivs else 0,
|
||||
},
|
||||
"tasks": task_list,
|
||||
}
|
||||
|
||||
return json.dumps(result, ensure_ascii=False, default=str)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user