Backend (FastAPI + SQLAlchemy + Claude API + RAG): - Config management with Pydantic v2 - Database engine with connection pooling and SQL injection prevention - AI engine with Claude API integration (support custom base URL) - RAG engine with ChromaDB and sentence-transformers - Requirement analysis service - Config generation service - Executor engine with SQL validation - REST API endpoints: /analyze, /generate, /execute Frontend (Vue 3 + Element Plus + Pinia): - Complete 3-step workflow: analyze → generate → execute - Step indicator with progress visualization - Analysis result display with field table - SQL preview with monospace font - Execute confirmation dialog with safety warning - Execution result display - State management with Pinia - API service integration Security: - SQL injection prevention with parameterized queries - Dangerous SQL operation blocking - Database password URL encoding - Transaction auto-rollback - Pydantic config validation Features: - Natural language requirement analysis - Automated SQL configuration generation - Safe execution with human review - LAN access support - Custom Claude API endpoint support Documentation: - README with quick start guide - Quick start guide - LAN access configuration - Dependency fixes guide - Claude API configuration - Git operation guide - Implementation report Dependencies fixed: - numpy<2.0.0 for chromadb compatibility - sentence-transformers==2.7.0 for huggingface_hub compatibility Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
from pydantic_settings import BaseSettings
|
||
from pydantic import ConfigDict, field_validator
|
||
from functools import lru_cache
|
||
from urllib.parse import quote_plus
|
||
|
||
|
||
class Settings(BaseSettings):
|
||
# Application
|
||
APP_NAME: str = "ERP AI Assistant"
|
||
APP_ENV: str = "development"
|
||
DEBUG: bool = True
|
||
SECRET_KEY: str
|
||
|
||
# Database
|
||
DB_DRIVER: str
|
||
DB_SERVER: str
|
||
DB_PORT: int = 1433
|
||
DB_NAME: str
|
||
DB_USER: str
|
||
DB_PASSWORD: str
|
||
|
||
# Claude API
|
||
ANTHROPIC_API_KEY: str
|
||
ANTHROPIC_BASE_URL: str | None = None # Optional custom base URL for proxy/self-hosted
|
||
CLAUDE_MODEL: str = "claude-sonnet-4-6"
|
||
CLAUDE_MAX_TOKENS: int = 8192
|
||
CLAUDE_TEMPERATURE: float = 0.7
|
||
|
||
# Knowledge Base
|
||
KNOWLEDGE_BASE_PATH: str = "./knowledge_base"
|
||
CHROMA_DB_PATH: str = "./knowledge_base/chroma_db"
|
||
EMBEDDING_MODEL: str = "all-MiniLM-L6-v2"
|
||
CHUNK_SIZE: int = 500
|
||
CHUNK_OVERLAP: int = 50
|
||
|
||
@property
|
||
def DATABASE_URL(self) -> str:
|
||
"""构建数据库连接 URL(密码安全编码)"""
|
||
password = quote_plus(self.DB_PASSWORD)
|
||
return (
|
||
f"mssql+pyodbc://{self.DB_USER}:{password}"
|
||
f"@{self.DB_SERVER}:{self.DB_PORT}/{self.DB_NAME}"
|
||
f"?driver={quote_plus(self.DB_DRIVER)}"
|
||
)
|
||
|
||
@field_validator('CLAUDE_TEMPERATURE')
|
||
@classmethod
|
||
def validate_temperature(cls, v):
|
||
if not 0 <= v <= 2:
|
||
raise ValueError('CLAUDE_TEMPERATURE must be between 0 and 2')
|
||
return v
|
||
|
||
@field_validator('CHUNK_OVERLAP')
|
||
@classmethod
|
||
def validate_chunk_overlap(cls, v, info):
|
||
chunk_size = info.data.get('CHUNK_SIZE', 500)
|
||
if v >= chunk_size:
|
||
raise ValueError('CHUNK_OVERLAP must be less than CHUNK_SIZE')
|
||
return v
|
||
|
||
model_config = ConfigDict(env_file=".env", case_sensitive=True)
|
||
|
||
|
||
@lru_cache()
|
||
def get_settings() -> Settings:
|
||
"""获取配置单例"""
|
||
return Settings()
|