feat: 增加 Agent Excel 批量测试
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from app.models.admin import Admin, Role
|
||||
from app.models.agent_batch import AgentBatchTest, AgentBatchTestItem
|
||||
from app.models.ai_config import ContentGenerationConfig, ModelConfig, Prompt, SystemConfig
|
||||
from app.models.base import Base
|
||||
from app.models.chat import ChatMessage, ChatSession, TopicSession
|
||||
@@ -29,6 +30,8 @@ from app.models.user import User
|
||||
|
||||
__all__ = [
|
||||
"Admin",
|
||||
"AgentBatchTest",
|
||||
"AgentBatchTestItem",
|
||||
"AiRequestLog",
|
||||
"Base",
|
||||
"ChatMessage",
|
||||
|
||||
71
ai_knowledge_base_v2/apps/backend/app/models/agent_batch.py
Normal file
71
ai_knowledge_base_v2/apps/backend/app/models/agent_batch.py
Normal file
@@ -0,0 +1,71 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import BigInteger, DateTime, ForeignKey, Index, Integer, String, Text, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.models.base import Base
|
||||
|
||||
|
||||
PRIMARY_KEY_TYPE = BigInteger().with_variant(Integer, "sqlite")
|
||||
|
||||
|
||||
class AgentBatchTest(Base):
|
||||
__tablename__ = "sys_agent_batch_test"
|
||||
__table_args__ = (
|
||||
Index("ix_agent_batch_test_creator_created", "created_by", "created_at"),
|
||||
Index("ix_agent_batch_test_status_created", "status", "created_at"),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(PRIMARY_KEY_TYPE, primary_key=True, autoincrement=True)
|
||||
name: Mapped[str] = mapped_column(String(160), nullable=False)
|
||||
original_filename: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
status: Mapped[str] = mapped_column(String(20), default="pending", nullable=False)
|
||||
total_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
success_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
failed_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
processed_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
prompt_content: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
model_id: Mapped[int] = mapped_column(ForeignKey("sys_model.id"), nullable=False)
|
||||
model_name: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
knowledge_ids: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
knowledge_names: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
generation_config: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
created_by: Mapped[int] = mapped_column(ForeignKey("sys_admin.id"), nullable=False)
|
||||
started_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
finished_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
cancelled_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), nullable=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False)
|
||||
|
||||
|
||||
class AgentBatchTestItem(Base):
|
||||
__tablename__ = "sys_agent_batch_test_item"
|
||||
__table_args__ = (
|
||||
Index("ix_agent_batch_item_job_order", "batch_id", "row_number"),
|
||||
Index("ix_agent_batch_item_claim", "status", "next_run_at", "id"),
|
||||
Index("ix_agent_batch_item_stale", "status", "locked_at"),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(PRIMARY_KEY_TYPE, primary_key=True, autoincrement=True)
|
||||
batch_id: Mapped[int] = mapped_column(ForeignKey("sys_agent_batch_test.id", ondelete="CASCADE"), nullable=False)
|
||||
row_number: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
external_no: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
||||
question: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
answer: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
status: Mapped[str] = mapped_column(String(20), default="pending", nullable=False)
|
||||
error_message: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
model_name: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
||||
knowledge_ids: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
retrieve_count: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
duration_ms: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
attempt_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
max_attempts: Mapped[int] = mapped_column(Integer, default=2, nullable=False)
|
||||
next_run_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
locked_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
locked_by: Mapped[str | None] = mapped_column(String(120), nullable=True)
|
||||
started_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
finished_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), nullable=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False)
|
||||
Reference in New Issue
Block a user