Refactor assistant configuration and database seeding
- Update Makefile to include new database seed commands for assistants and credentials. - Refactor assistant model to use explicit fields instead of a config dictionary, improving data integrity and clarity. - Implement new seeding SQL script for assistants, ensuring dependencies on credentials are respected. - Modify backend routes and frontend components to accommodate the new assistant structure, including direct field access for prompt, API URL, and keys. - Enhance the AssistantPage component to handle the new data structure and streamline the save process for different assistant types.
This commit is contained in:
@@ -95,8 +95,13 @@ class Assistant(Base):
|
||||
String(40), ForeignKey("knowledge_bases.id", ondelete="RESTRICT"), nullable=True
|
||||
)
|
||||
|
||||
# 类型专属字段(形态各异):prompt / graph / dify|fastgpt|opencode 端点+key(打码)
|
||||
config: Mapped[dict] = mapped_column(JSON, default=dict)
|
||||
# ---- 瘦类型专属字段(真列,稀疏:按 type 用其中几列) ----
|
||||
prompt: Mapped[str] = mapped_column(String(8192), default="") # prompt / opencode
|
||||
api_url: Mapped[str] = mapped_column(String(512), default="") # dify / fastgpt / opencode
|
||||
api_key: Mapped[str] = mapped_column(String(512), default="") # dify / fastgpt / opencode(打码/哨兵,同凭证)
|
||||
app_id: Mapped[str] = mapped_column(String(128), default="") # fastgpt
|
||||
# workflow 专属:图(nodes/edges)。要版本化时再迁出到 assistant_workflow 表
|
||||
graph: Mapped[dict] = mapped_column(JSON, default=dict)
|
||||
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
|
||||
51
backend/db/seed_assistants.sql
Normal file
51
backend/db/seed_assistants.sql
Normal file
@@ -0,0 +1,51 @@
|
||||
-- 知识库 + 助手种子数据(依赖 seed_credentials.sql 先灌入 model_xxx 凭证)。
|
||||
--
|
||||
-- 用法(从仓库根目录):
|
||||
-- docker compose exec -T postgres psql -U postgres -d postgres < backend/db/seed_assistants.sql
|
||||
-- 或:make db-seed-assistants(凭证已就绪时);make db-seed 会按顺序全灌。
|
||||
--
|
||||
-- 说明:
|
||||
-- * id 固定(kb_001 / asst_001..005)+ ON CONFLICT 幂等,可重复执行。
|
||||
-- * 引用 seed_credentials 的 model_001(LLM)/003(ASR)/005(TTS)/010(Embedding)。
|
||||
-- * 宽表 STI:瘦类型用真列(prompt/api_url/api_key/app_id),workflow 用 graph 列。
|
||||
-- * api_key 在库里明文(读取走 API 才打码),这里填示例占位。
|
||||
|
||||
-- 知识库(引用 Embedding 凭证 model_010)
|
||||
INSERT INTO knowledge_bases (id, name, description, embedding_credential_id, status)
|
||||
VALUES
|
||||
('kb_001', '政务政策知识库', '政策解读 / 办事指南示例库', 'model_010', 'active')
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
|
||||
-- 助手(一种类型一条)
|
||||
INSERT INTO assistants (
|
||||
id, name, type, runtime_mode, greeting, enable_interrupt,
|
||||
llm_credential_id, asr_credential_id, tts_credential_id,
|
||||
realtime_credential_id, knowledge_base_id,
|
||||
prompt, api_url, api_key, app_id, graph
|
||||
) VALUES
|
||||
-- 提示词:llm/asr/tts + 知识库,prompt 真列
|
||||
('asst_001', '政务咨询助手', 'prompt', 'pipeline', '您好,我是政务助手,请问有什么可以帮您?', TRUE,
|
||||
'model_001', 'model_003', 'model_005', NULL, 'kb_001',
|
||||
'你是一名专业的政务咨询助手,回答准确、简洁,不编造政策内容。', '', '', '', '{}'),
|
||||
|
||||
-- 工作流:asr/tts + graph 列(最小图)
|
||||
('asst_002', '热线工单助手', 'workflow', 'pipeline', '', TRUE,
|
||||
NULL, 'model_003', 'model_005', NULL, NULL,
|
||||
'', '', '', '',
|
||||
'{"nodes":[{"id":"1","type":"startCall","position":{"x":0,"y":0},"data":{"name":"开场","prompt":"你好,请问需要办理什么业务?"}}],"edges":[]}'),
|
||||
|
||||
-- Dify:asr/tts + api_url/api_key
|
||||
('asst_003', 'Dify 客服助手', 'dify', 'pipeline', '', TRUE,
|
||||
NULL, 'model_003', 'model_005', NULL, NULL,
|
||||
'', 'https://api.dify.ai/v1', 'app-dify-demo-key', '', '{}'),
|
||||
|
||||
-- FastGPT:asr/tts + app_id/api_url/api_key
|
||||
('asst_004', 'FastGPT 售后助手', 'fastgpt', 'pipeline', '', TRUE,
|
||||
NULL, 'model_003', 'model_005', NULL, NULL,
|
||||
'', 'https://api.fastgpt.in/api/v1/chat/completions', 'fastgpt-demo-key', 'app-fastgpt-001', '{}'),
|
||||
|
||||
-- OpenCode:asr/tts + prompt/api_url/api_key
|
||||
('asst_005', 'OpenCode 代码助手', 'opencode', 'pipeline', '', TRUE,
|
||||
NULL, 'model_003', 'model_005', NULL, NULL,
|
||||
'你是一个代码助手的语音界面,用简洁口语回答工程问题。', 'http://localhost:4096', 'opencode-demo-key', '', '{}')
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
Reference in New Issue
Block a user