知你客服

This commit is contained in:
rjb
2026-03-06 22:31:41 +08:00
parent 171a6edf94
commit 9d3198f6bc
31 changed files with 6579 additions and 80 deletions

View File

@@ -63,7 +63,26 @@ async def list_tools(
)
tools = query.order_by(Tool.use_count.desc(), Tool.created_at.desc()).all()
return tools
# 转换为响应格式,确保日期时间字段转换为字符串
result = []
for tool in tools:
result.append({
"id": tool.id,
"name": tool.name,
"description": tool.description,
"category": tool.category,
"function_schema": tool.function_schema,
"implementation_type": tool.implementation_type,
"implementation_config": tool.implementation_config,
"is_public": tool.is_public,
"use_count": tool.use_count,
"user_id": tool.user_id,
"created_at": tool.created_at.isoformat() if tool.created_at else "",
"updated_at": tool.updated_at.isoformat() if tool.updated_at else ""
})
return result
@router.get("/builtin")
@@ -82,7 +101,22 @@ async def get_tool(
tool = db.query(Tool).filter(Tool.id == tool_id).first()
if not tool:
raise HTTPException(status_code=404, detail="工具不存在")
return tool
# 转换为响应格式,确保日期时间字段转换为字符串
return {
"id": tool.id,
"name": tool.name,
"description": tool.description,
"category": tool.category,
"function_schema": tool.function_schema,
"implementation_type": tool.implementation_type,
"implementation_config": tool.implementation_config,
"is_public": tool.is_public,
"use_count": tool.use_count,
"user_id": tool.user_id,
"created_at": tool.created_at.isoformat() if tool.created_at else "",
"updated_at": tool.updated_at.isoformat() if tool.updated_at else ""
}
@router.post("", response_model=ToolResponse, status_code=201)
@@ -112,7 +146,21 @@ async def create_tool(
db.commit()
db.refresh(tool)
return tool
# 转换为响应格式,确保日期时间字段转换为字符串
return {
"id": tool.id,
"name": tool.name,
"description": tool.description,
"category": tool.category,
"function_schema": tool.function_schema,
"implementation_type": tool.implementation_type,
"implementation_config": tool.implementation_config,
"is_public": tool.is_public,
"use_count": tool.use_count,
"user_id": tool.user_id,
"created_at": tool.created_at.isoformat() if tool.created_at else "",
"updated_at": tool.updated_at.isoformat() if tool.updated_at else ""
}
@router.put("/{tool_id}", response_model=ToolResponse)
@@ -148,7 +196,21 @@ async def update_tool(
db.commit()
db.refresh(tool)
return tool
# 转换为响应格式,确保日期时间字段转换为字符串
return {
"id": tool.id,
"name": tool.name,
"description": tool.description,
"category": tool.category,
"function_schema": tool.function_schema,
"implementation_type": tool.implementation_type,
"implementation_config": tool.implementation_config,
"is_public": tool.is_public,
"use_count": tool.use_count,
"user_id": tool.user_id,
"created_at": tool.created_at.isoformat() if tool.created_at else "",
"updated_at": tool.updated_at.isoformat() if tool.updated_at else ""
}
@router.delete("/{tool_id}", status_code=200)