feat(saas): extend agent templates with soul_content, add /available endpoint, key pool cleanup, and industry seed templates
- Add 9 extended fields to AgentTemplateInfo: soul_content, scenarios, welcome_message, quick_commands, personality, communication_style, emoji, version, source_id - Refactor service.rs to use sqlx::Row (manual column extraction) to avoid the 16-element tuple FromRow limit - Add /api/v1/agent-templates/available (lightweight public listing) and /api/v1/agent-templates/:id/full endpoints - Add 24h key_usage_window cleanup task in scheduler - Update seed data with extended fields for all 5 existing templates plus new Medical Assistant template (healthcare category)
This commit is contained in:
@@ -4,7 +4,7 @@ use sqlx::postgres::PgPoolOptions;
|
||||
use sqlx::PgPool;
|
||||
use crate::error::SaasResult;
|
||||
|
||||
const SCHEMA_VERSION: i32 = 7;
|
||||
const SCHEMA_VERSION: i32 = 9;
|
||||
|
||||
/// 初始化数据库
|
||||
pub async fn init_db(database_url: &str) -> SaasResult<PgPool> {
|
||||
@@ -548,20 +548,84 @@ async fn seed_demo_data(pool: &PgPool) -> SaasResult<()> {
|
||||
}
|
||||
|
||||
// ===== 6. Agent Templates =====
|
||||
let agent_templates = [
|
||||
("demo-agent-coder", "Code Assistant", "A helpful coding assistant that can write, review, and debug code", "coding", "demo-openai", "gpt-4o", "You are an expert coding assistant. Help users write clean, efficient code.", "[\"code_search\",\"code_edit\",\"terminal\"]", "[\"code_generation\",\"code_review\",\"debugging\"]", 0.3, 8192),
|
||||
("demo-agent-writer", "Content Writer", "Creative writing and content generation agent", "creative", "demo-anthropic", "claude-sonnet-4-20250514", "You are a skilled content writer. Create engaging, well-structured content.", "[\"web_search\",\"document_edit\"]", "[\"writing\",\"editing\",\"summarization\"]", 0.7, 4096),
|
||||
("demo-agent-analyst", "Data Analyst", "Data analysis and visualization specialist", "analytics", "demo-openai", "gpt-4o", "You are a data analysis expert. Help users analyze data and create visualizations.", "[\"code_execution\",\"data_access\"]", "[\"data_analysis\",\"visualization\",\"statistics\"]", 0.2, 8192),
|
||||
("demo-agent-researcher", "Research Agent", "Deep research and information synthesis agent", "research", "demo-google", "gemini-2.5-pro", "You are a research specialist. Conduct thorough research and synthesize findings.", "[\"web_search\",\"document_access\"]", "[\"research\",\"synthesis\",\"citation\"]", 0.4, 16384),
|
||||
("demo-agent-translator", "Translator", "Multi-language translation agent", "utility", "demo-deepseek", "deepseek-chat", "You are a professional translator. Translate text accurately while preserving tone and context.", "[]", "[\"translation\",\"localization\"]", 0.3, 4096),
|
||||
// Each tuple: (id, name, description, category, model, system_prompt, tools, capabilities, temperature, max_tokens,
|
||||
// soul_content, scenarios, welcome_message, quick_commands, personality, communication_style, emoji, source_id)
|
||||
let agent_templates: [(&str, &str, &str, &str, &str, &str, &str, &str, f64, i32,
|
||||
&str, &str, &str, &str, &str, &str, &str, &str); 6] = [
|
||||
("demo-agent-coder", "Code Assistant", "A helpful coding assistant that can write, review, and debug code",
|
||||
"coding", "gpt-4o",
|
||||
"You are an expert coding assistant. Help users write clean, efficient code.",
|
||||
"[\"code_search\",\"code_edit\",\"terminal\"]", "[\"code_generation\",\"code_review\",\"debugging\"]",
|
||||
0.3, 8192,
|
||||
"你是一位资深全栈工程师,擅长代码编写、评审和调试。你追求简洁高效的代码风格,注重可读性和可维护性。",
|
||||
"[\"代码编写\",\"代码审查\",\"Bug调试\",\"架构设计\"]",
|
||||
"你好!我是你的编程助手,有什么代码问题可以随时问我。",
|
||||
"[{\"label\":\"写一个函数\",\"command\":\"帮我写一个\"},{\"label\":\"审查代码\",\"command\":\"请审查这段代码\"},{\"label\":\"解释代码\",\"command\":\"解释一下这段代码\"}]",
|
||||
"professional", "concise", "💻", "code-assistant-v1"),
|
||||
("demo-agent-writer", "Content Writer", "Creative writing and content generation agent",
|
||||
"creative", "claude-sonnet-4-20250514",
|
||||
"You are a skilled content writer. Create engaging, well-structured content.",
|
||||
"[\"web_search\",\"document_edit\"]", "[\"writing\",\"editing\",\"summarization\"]",
|
||||
0.7, 4096,
|
||||
"你是一位创意写作专家,擅长各类文案创作、内容编辑和摘要生成。你善于把握文字的节奏和情感表达。",
|
||||
"[\"文章写作\",\"文案创作\",\"内容编辑\",\"摘要生成\"]",
|
||||
"你好!我是你的内容创作助手,需要写点什么?",
|
||||
"[{\"label\":\"写一篇文章\",\"command\":\"帮我写一篇关于\"},{\"label\":\"润色文案\",\"command\":\"帮我优化这段文字\"},{\"label\":\"生成摘要\",\"command\":\"请为以下内容生成摘要\"}]",
|
||||
"creative", "warm", "✍️", "content-writer-v1"),
|
||||
("demo-agent-analyst", "Data Analyst", "Data analysis and visualization specialist",
|
||||
"analytics", "gpt-4o",
|
||||
"You are a data analysis expert. Help users analyze data and create visualizations.",
|
||||
"[\"code_execution\",\"data_access\"]", "[\"data_analysis\",\"visualization\",\"statistics\"]",
|
||||
0.2, 8192,
|
||||
"你是一位数据分析专家,擅长统计分析、数据可视化和洞察提取。你善于从数据中发现有价值的模式和趋势。",
|
||||
"[\"数据分析\",\"可视化报表\",\"统计建模\",\"趋势预测\"]",
|
||||
"你好!我是你的数据分析助手,请分享你的数据或问题。",
|
||||
"[{\"label\":\"分析数据\",\"command\":\"帮我分析这组数据\"},{\"label\":\"生成图表\",\"command\":\"为以下数据生成图表\"},{\"label\":\"统计摘要\",\"command\":\"请给出统计摘要\"}]",
|
||||
"analytical", "structured", "📊", "data-analyst-v1"),
|
||||
("demo-agent-researcher", "Research Agent", "Deep research and information synthesis agent",
|
||||
"research", "gemini-2.5-pro",
|
||||
"You are a research specialist. Conduct thorough research and synthesize findings.",
|
||||
"[\"web_search\",\"document_access\"]", "[\"research\",\"synthesis\",\"citation\"]",
|
||||
0.4, 16384,
|
||||
"你是一位深度研究专家,擅长信息检索、文献综述和知识综合。你注重信息来源的可靠性和引用的准确性。",
|
||||
"[\"深度研究\",\"文献综述\",\"信息检索\",\"知识综合\"]",
|
||||
"你好!我是你的研究助手,需要我帮你调查什么话题?",
|
||||
"[{\"label\":\"深度研究\",\"command\":\"请深入研究\"},{\"label\":\"文献综述\",\"command\":\"帮我写一份文献综述\"},{\"label\":\"对比分析\",\"command\":\"请对比分析\"}]",
|
||||
"scholarly", "detailed", "🔬", "research-agent-v1"),
|
||||
("demo-agent-translator", "Translator", "Multi-language translation agent",
|
||||
"utility", "deepseek-chat",
|
||||
"You are a professional translator. Translate text accurately while preserving tone and context.",
|
||||
"[]", "[\"translation\",\"localization\"]",
|
||||
0.3, 4096,
|
||||
"你是一位专业翻译,精通中英日韩等多种语言。你注重准确传达原文含义,同时保持目标语言的自然流畅。",
|
||||
"[\"文本翻译\",\"文档本地化\",\"术语管理\",\"双语校对\"]",
|
||||
"你好!我是你的翻译助手,请发送需要翻译的文本。",
|
||||
"[{\"label\":\"中译英\",\"command\":\"请将以下中文翻译为英文\"},{\"label\":\"英译中\",\"command\":\"请将以下英文翻译为中文\"},{\"label\":\"润色译文\",\"command\":\"请润色这段翻译\"}]",
|
||||
"professional", "precise", "🌐", "translator-v1"),
|
||||
("demo-agent-medical", "医疗助手", "Clinical decision support and medical literature assistant",
|
||||
"healthcare", "gpt-4o",
|
||||
"You are a medical AI assistant. Help with clinical decision support, literature retrieval, and medication reference. Always remind users that your suggestions do not replace professional medical advice.",
|
||||
"[\"web_search\",\"document_access\"]", "[\"clinical_support\",\"literature_search\",\"diagnosis_assist\",\"medication_ref\"]",
|
||||
0.2, 16384,
|
||||
"你是一位医疗AI助手,具备丰富的临床知识。你辅助临床决策、文献检索和用药参考。\n\n重要提示:\n- 你的建议仅供医疗专业人员参考\n- 不能替代正式的医疗诊断\n- 涉及患者安全的问题需格外谨慎\n- 始终建议用户咨询专业医生",
|
||||
"[\"临床辅助\",\"文献检索\",\"诊断建议\",\"用药参考\"]",
|
||||
"你好!我是你的医疗AI助手。我可以帮助你进行临床决策支持、医学文献检索和用药参考。请注意,我的建议仅供参考,不能替代专业医疗意见。",
|
||||
"[{\"label\":\"药物查询\",\"command\":\"查询药物\"},{\"label\":\"文献检索\",\"command\":\"检索相关文献\"},{\"label\":\"临床辅助\",\"command\":\"辅助临床分析\"},{\"label\":\"诊断建议\",\"command\":\"请给出诊断建议\"}]",
|
||||
"professional", "cautious", "🏥", "medical-assistant-v1"),
|
||||
];
|
||||
for (id, name, desc, cat, _pid, model, prompt, tools, caps, temp, max_tok) in &agent_templates {
|
||||
for (id, name, desc, cat, model, prompt, tools, caps, temp, max_tok,
|
||||
soul, scenarios, welcome, quick_cmds, personality, comm_style, emoji, source_id) in &agent_templates {
|
||||
let ts = now.to_rfc3339();
|
||||
sqlx::query(
|
||||
"INSERT INTO agent_templates (id, name, description, category, source, model, system_prompt, tools, capabilities, temperature, max_tokens, visibility, status, current_version, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, $4, 'custom', $5, $6, $7, $8, $9, $10, 'public', 'active', 1, $11, $11) ON CONFLICT (id) DO NOTHING"
|
||||
"INSERT INTO agent_templates (id, name, description, category, source, model, system_prompt, tools, capabilities,
|
||||
temperature, max_tokens, visibility, status, current_version, created_at, updated_at,
|
||||
soul_content, scenarios, welcome_message, quick_commands, personality, communication_style, emoji, version, source_id)
|
||||
VALUES ($1,$2,$3,$4,'custom',$5,$6,$7,$8,$9,$10,'public','active',1,$11,$11,$12,$13,$14,$15,$16,$17,$18,1,$19)
|
||||
ON CONFLICT (id) DO NOTHING"
|
||||
).bind(id).bind(name).bind(desc).bind(cat).bind(model).bind(prompt).bind(tools).bind(caps)
|
||||
.bind(*temp).bind(*max_tok).bind(&ts)
|
||||
.bind(soul).bind(scenarios).bind(welcome).bind(quick_cmds)
|
||||
.bind(personality).bind(comm_style).bind(emoji).bind(source_id)
|
||||
.execute(pool).await?;
|
||||
}
|
||||
|
||||
@@ -687,7 +751,7 @@ async fn seed_demo_data(pool: &PgPool) -> SaasResult<()> {
|
||||
}
|
||||
}
|
||||
|
||||
tracing::info!("Demo data seeded: 5 providers, 12 models, 5 keys, ~1500 usage records, 20 relay tasks, 5 agent templates, 12 configs, 3 API tokens, 50 logs, 112 telemetry reports");
|
||||
tracing::info!("Demo data seeded: 5 providers, 12 models, 5 keys, ~1500 usage records, 20 relay tasks, 6 agent templates, 12 configs, 3 API tokens, 50 logs, 112 telemetry reports");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user