增加代码知识库;修复文档处理内容;增加API设置
This commit is contained in:
@@ -2,7 +2,16 @@ from .user import User
|
||||
from .knowledge import KnowledgeBase, Document, DocumentChunk
|
||||
from .chat import Chat, Message
|
||||
from .api_key import APIKey
|
||||
from .tooling import ToolJob, SRSExtraction, SRSRequirement, TestingGeneration
|
||||
from .model_config import UserModelConfig
|
||||
from .tooling import (
|
||||
CodeKnowledgeBase,
|
||||
ConsistencyJob,
|
||||
ConsistencyResult,
|
||||
SRSExtraction,
|
||||
SRSRequirement,
|
||||
TestingGeneration,
|
||||
ToolJob,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"User",
|
||||
@@ -12,8 +21,12 @@ __all__ = [
|
||||
"Chat",
|
||||
"Message",
|
||||
"APIKey",
|
||||
"UserModelConfig",
|
||||
"ToolJob",
|
||||
"SRSExtraction",
|
||||
"SRSRequirement",
|
||||
"TestingGeneration",
|
||||
"CodeKnowledgeBase",
|
||||
"ConsistencyJob",
|
||||
"ConsistencyResult",
|
||||
]
|
||||
|
||||
34
rag-web-ui/backend/app/models/model_config.py
Normal file
34
rag-web-ui/backend/app/models/model_config.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.models.base import Base, TimestampMixin
|
||||
|
||||
|
||||
class UserModelConfig(Base, TimestampMixin):
|
||||
__tablename__ = "user_model_configs"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True)
|
||||
name = Column(String(255), nullable=False)
|
||||
provider = Column(String(64), nullable=False, default="dashscope")
|
||||
api_key = Column(Text, nullable=False)
|
||||
api_base = Column(String(512), nullable=True)
|
||||
chat_model = Column(String(128), nullable=False)
|
||||
embedding_model = Column(String(128), nullable=False)
|
||||
is_active = Column(Boolean, default=True, nullable=False, index=True)
|
||||
last_used_at = Column(DateTime(timezone=True), nullable=True)
|
||||
|
||||
user = relationship("User", back_populates="model_configs")
|
||||
|
||||
@property
|
||||
def has_api_key(self) -> bool:
|
||||
return bool((self.api_key or "").strip())
|
||||
|
||||
@property
|
||||
def api_key_masked(self) -> str:
|
||||
value = (self.api_key or "").strip()
|
||||
if not value:
|
||||
return ""
|
||||
if len(value) <= 10:
|
||||
return "*" * len(value)
|
||||
return f"{value[:4]}{'*' * 8}{value[-4:]}"
|
||||
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, Integer, JSON, String, Text
|
||||
from sqlalchemy import Column, DateTime, Float, ForeignKey, Integer, JSON, String, Text
|
||||
from sqlalchemy.dialects.mysql import LONGTEXT
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
@@ -102,3 +102,70 @@ class TestingGeneration(Base, TimestampMixin):
|
||||
|
||||
job = relationship("ToolJob", back_populates="testing_generation", foreign_keys=[job_id])
|
||||
|
||||
|
||||
class CodeKnowledgeBase(Base, TimestampMixin):
|
||||
__tablename__ = "code_knowledge_bases"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True)
|
||||
name = Column(String(255), nullable=False)
|
||||
project_path = Column(String(1024), nullable=True)
|
||||
vector_path = Column(String(1024), nullable=False)
|
||||
metadata_path = Column(String(1024), nullable=False)
|
||||
graph_path = Column(String(1024), nullable=False)
|
||||
status = Column(String(32), nullable=False, default="active", index=True)
|
||||
metadata_summary = Column(JSON, nullable=True)
|
||||
|
||||
user = relationship("User")
|
||||
consistency_jobs = relationship(
|
||||
"ConsistencyJob",
|
||||
back_populates="code_kb",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
|
||||
|
||||
class ConsistencyJob(Base, TimestampMixin):
|
||||
__tablename__ = "consistency_jobs"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True)
|
||||
srs_extraction_id = Column(Integer, ForeignKey("srs_extractions.id"), nullable=False, index=True)
|
||||
code_kb_id = Column(Integer, ForeignKey("code_knowledge_bases.id"), nullable=False, index=True)
|
||||
status = Column(String(32), nullable=False, default="pending", index=True)
|
||||
total_requirements = Column(Integer, nullable=False, default=0)
|
||||
completed_requirements = Column(Integer, nullable=False, default=0)
|
||||
output_summary = Column(JSON, nullable=True)
|
||||
error_message = Column(Text, nullable=True)
|
||||
started_at = Column(DateTime, nullable=True)
|
||||
completed_at = Column(DateTime, nullable=True)
|
||||
|
||||
user = relationship("User")
|
||||
srs_extraction = relationship("SRSExtraction")
|
||||
code_kb = relationship("CodeKnowledgeBase", back_populates="consistency_jobs")
|
||||
results = relationship(
|
||||
"ConsistencyResult",
|
||||
back_populates="job",
|
||||
cascade="all, delete-orphan",
|
||||
order_by="ConsistencyResult.id",
|
||||
)
|
||||
|
||||
|
||||
class ConsistencyResult(Base, TimestampMixin):
|
||||
__tablename__ = "consistency_results"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
job_id = Column(Integer, ForeignKey("consistency_jobs.id", ondelete="CASCADE"), nullable=False, index=True)
|
||||
requirement_uid = Column(String(64), nullable=False, index=True)
|
||||
verdict = Column(String(32), nullable=False, index=True)
|
||||
coverage_score = Column(Float, nullable=False, default=0.0)
|
||||
confidence = Column(Float, nullable=False, default=0.0)
|
||||
matched_functions = Column(JSON, nullable=False)
|
||||
covered_points = Column(JSON, nullable=False)
|
||||
missing_points = Column(JSON, nullable=False)
|
||||
conflict_points = Column(JSON, nullable=False)
|
||||
call_chain_evidence = Column(JSON, nullable=False)
|
||||
suggestion = Column(Text, nullable=True)
|
||||
raw_judgment = Column(JSON, nullable=True)
|
||||
|
||||
job = relationship("ConsistencyJob", back_populates="results")
|
||||
|
||||
|
||||
@@ -15,4 +15,5 @@ class User(Base, TimestampMixin):
|
||||
# Relationships
|
||||
knowledge_bases = relationship("KnowledgeBase", back_populates="user")
|
||||
chats = relationship("Chat", back_populates="user")
|
||||
api_keys = relationship("APIKey", back_populates="user", cascade="all, delete-orphan")
|
||||
api_keys = relationship("APIKey", back_populates="user", cascade="all, delete-orphan")
|
||||
model_configs = relationship("UserModelConfig", back_populates="user", cascade="all, delete-orphan")
|
||||
|
||||
Reference in New Issue
Block a user