feat: add Case, TaskLog, LLMConfig, SystemConfig models
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -217,3 +217,100 @@ class SystemConfig(Base):
|
|||||||
"created_at": self.created_at.isoformat() if self.created_at else None,
|
"created_at": self.created_at.isoformat() if self.created_at else None,
|
||||||
"updated_at": self.updated_at.isoformat() if self.updated_at else None,
|
"updated_at": self.updated_at.isoformat() if self.updated_at else None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# --- 新增模型:案例库 ---
|
||||||
|
class Case(Base):
|
||||||
|
__tablename__ = "cases"
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
||||||
|
title = Column(String, nullable=False)
|
||||||
|
field = Column(String, nullable=False) # 对应四大支柱及其子领域
|
||||||
|
summary = Column(Text, nullable=False)
|
||||||
|
key_metrics = Column(Text, nullable=True) # 关键数据,JSON字符串或纯文本
|
||||||
|
date = Column(String, nullable=True) # 年份或具体日期,如 "2024"
|
||||||
|
source = Column(String, nullable=False)
|
||||||
|
source_url = Column(String, nullable=True)
|
||||||
|
credibility_rating = Column(String, nullable=True) # 如 "⭐⭐⭐"
|
||||||
|
china_applicability = Column(String, nullable=True) # 如 "⭐⭐⭐⭐"
|
||||||
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||||
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {
|
||||||
|
"id": self.id,
|
||||||
|
"title": self.title,
|
||||||
|
"field": self.field,
|
||||||
|
"summary": self.summary,
|
||||||
|
"key_metrics": self.key_metrics,
|
||||||
|
"date": self.date,
|
||||||
|
"source": self.source,
|
||||||
|
"source_url": self.source_url,
|
||||||
|
"credibility_rating": self.credibility_rating,
|
||||||
|
"china_applicability": self.china_applicability,
|
||||||
|
"created_at": self.created_at.isoformat() if self.created_at else None,
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- 新增模型:任务日志 ---
|
||||||
|
class TaskLog(Base):
|
||||||
|
__tablename__ = "task_logs"
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
||||||
|
task_name = Column(String, nullable=False) # collector/creator/optimizer/research/outline/writer
|
||||||
|
topic_id = Column(String, nullable=True) # 关联选题ID
|
||||||
|
status = Column(String, nullable=False) # started/completed/failed
|
||||||
|
message = Column(Text, nullable=True)
|
||||||
|
started_at = Column(DateTime(timezone=True), nullable=False)
|
||||||
|
finished_at = Column(DateTime(timezone=True), nullable=True)
|
||||||
|
duration_seconds = Column(Integer, nullable=True)
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {
|
||||||
|
"id": self.id,
|
||||||
|
"task_name": self.task_name,
|
||||||
|
"topic_id": self.topic_id,
|
||||||
|
"status": self.status,
|
||||||
|
"message": self.message,
|
||||||
|
"started_at": self.started_at.isoformat() if self.starthed_at else None,
|
||||||
|
"finished_at": self.finished_at.isoformat() if self.finished_at else None,
|
||||||
|
"duration_seconds": self.duration_seconds,
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- 新增模型:LLM 配置 ---
|
||||||
|
class LLMConfig(Base):
|
||||||
|
__tablename__ = "llm_configs"
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
||||||
|
name = Column(String, unique=True, nullable=False) # e.g., "default_expand"
|
||||||
|
system_prompt = Column(Text, nullable=False)
|
||||||
|
user_prompt_template = Column(Text, nullable=False)
|
||||||
|
temperature = Column(Float, default=0.7)
|
||||||
|
max_tokens = Column(Integer, default=1000)
|
||||||
|
model = Column(String, nullable=True) # e.g., "stepfun-ai/step-3.5-flash"
|
||||||
|
is_active = Column(Boolean, default=True)
|
||||||
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||||
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {
|
||||||
|
"id": self.id,
|
||||||
|
"name": self.name,
|
||||||
|
"system_prompt": self.system_prompt,
|
||||||
|
"user_prompt_template": self.user_prompt_template,
|
||||||
|
"temperature": self.temperature,
|
||||||
|
"max_tokens": self.max_tokens,
|
||||||
|
"model": self.model,
|
||||||
|
"is_active": self.is_active,
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- 新增模型:系统配置(键值对) ---
|
||||||
|
class SystemConfig(Base):
|
||||||
|
__tablename__ = "system_configs"
|
||||||
|
|
||||||
|
key = Column(String, primary_key=True)
|
||||||
|
value = Column(Text, nullable=True) # JSON 字符串或普通文本
|
||||||
|
description = Column(String, nullable=True)
|
||||||
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {"key": self.key, "value": self.value, "description": self.description}
|
||||||
|
|||||||
Reference in New Issue
Block a user