@@ -7,10 +7,11 @@ Routes:
|
|||||||
GET /memory/config/emotion - 获取情绪引擎配置
|
GET /memory/config/emotion - 获取情绪引擎配置
|
||||||
POST /memory/config/emotion - 更新情绪引擎配置
|
POST /memory/config/emotion - 更新情绪引擎配置
|
||||||
"""
|
"""
|
||||||
|
import uuid
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, Query, HTTPException, status
|
from fastapi import APIRouter, Depends, Query, HTTPException, status
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing import Optional
|
from typing import Optional, Union
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ class EmotionConfigQuery(BaseModel):
|
|||||||
|
|
||||||
class EmotionConfigUpdate(BaseModel):
|
class EmotionConfigUpdate(BaseModel):
|
||||||
"""情绪配置更新请求模型"""
|
"""情绪配置更新请求模型"""
|
||||||
config_id: UUID = Field(..., description="配置ID")
|
config_id: Union[uuid.UUID, int, str]= Field(..., description="配置ID")
|
||||||
emotion_enabled: bool = Field(..., description="是否启用情绪提取")
|
emotion_enabled: bool = Field(..., description="是否启用情绪提取")
|
||||||
emotion_model_id: Optional[str] = Field(None, description="情绪分析专用模型ID")
|
emotion_model_id: Optional[str] = Field(None, description="情绪分析专用模型ID")
|
||||||
emotion_extract_keywords: bool = Field(..., description="是否提取情绪关键词")
|
emotion_extract_keywords: bool = Field(..., description="是否提取情绪关键词")
|
||||||
@@ -159,6 +160,7 @@ def update_emotion_config(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
config.config_id=resolve_config_id(config.config_id, db)
|
||||||
try:
|
try:
|
||||||
api_logger.info(
|
api_logger.info(
|
||||||
f"用户 {current_user.username} 请求更新情绪配置",
|
f"用户 {current_user.username} 请求更新情绪配置",
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ async def save_reflection_config(
|
|||||||
"""Save reflection configuration to data_comfig table"""
|
"""Save reflection configuration to data_comfig table"""
|
||||||
try:
|
try:
|
||||||
config_id = request.config_id
|
config_id = request.config_id
|
||||||
|
config_id = resolve_config_id(config_id, db)
|
||||||
if not config_id:
|
if not config_id:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
@@ -164,6 +165,7 @@ async def start_reflection_configs(
|
|||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""通过config_id查询memory_config表中的反思配置信息"""
|
"""通过config_id查询memory_config表中的反思配置信息"""
|
||||||
|
config_id = resolve_config_id(config_id, db)
|
||||||
try:
|
try:
|
||||||
config_id=resolve_config_id(config_id,db)
|
config_id=resolve_config_id(config_id,db)
|
||||||
api_logger.info(f"用户 {current_user.username} 查询反思配置,config_id: {config_id}")
|
api_logger.info(f"用户 {current_user.username} 查询反思配置,config_id: {config_id}")
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ from fastapi import APIRouter, Depends
|
|||||||
from fastapi.responses import StreamingResponse
|
from fastapi.responses import StreamingResponse
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from app.utils.config_utils import resolve_config_id
|
||||||
|
|
||||||
# Get API logger
|
# Get API logger
|
||||||
api_logger = get_api_logger()
|
api_logger = get_api_logger()
|
||||||
|
|
||||||
@@ -141,7 +143,6 @@ def create_config(
|
|||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
) -> dict:
|
) -> dict:
|
||||||
workspace_id = current_user.current_workspace_id
|
workspace_id = current_user.current_workspace_id
|
||||||
|
|
||||||
# 检查用户是否已选择工作空间
|
# 检查用户是否已选择工作空间
|
||||||
if workspace_id is None:
|
if workspace_id is None:
|
||||||
api_logger.warning(f"用户 {current_user.username} 尝试创建配置但未选择工作空间")
|
api_logger.warning(f"用户 {current_user.username} 尝试创建配置但未选择工作空间")
|
||||||
@@ -161,12 +162,12 @@ def create_config(
|
|||||||
|
|
||||||
@router.delete("/delete_config", response_model=ApiResponse) # 删除数据库中的内容(按配置名称)
|
@router.delete("/delete_config", response_model=ApiResponse) # 删除数据库中的内容(按配置名称)
|
||||||
def delete_config(
|
def delete_config(
|
||||||
config_id: UUID,
|
config_id: UUID|int,
|
||||||
current_user: User = Depends(get_current_user),
|
current_user: User = Depends(get_current_user),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
) -> dict:
|
) -> dict:
|
||||||
workspace_id = current_user.current_workspace_id
|
workspace_id = current_user.current_workspace_id
|
||||||
|
config_id=resolve_config_id(config_id, db)
|
||||||
# 检查用户是否已选择工作空间
|
# 检查用户是否已选择工作空间
|
||||||
if workspace_id is None:
|
if workspace_id is None:
|
||||||
api_logger.warning(f"用户 {current_user.username} 尝试删除配置但未选择工作空间")
|
api_logger.warning(f"用户 {current_user.username} 尝试删除配置但未选择工作空间")
|
||||||
@@ -188,7 +189,7 @@ def update_config(
|
|||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
) -> dict:
|
) -> dict:
|
||||||
workspace_id = current_user.current_workspace_id
|
workspace_id = current_user.current_workspace_id
|
||||||
|
payload.config_id = resolve_config_id(payload.config_id, db)
|
||||||
# 检查用户是否已选择工作空间
|
# 检查用户是否已选择工作空间
|
||||||
if workspace_id is None:
|
if workspace_id is None:
|
||||||
api_logger.warning(f"用户 {current_user.username} 尝试更新配置但未选择工作空间")
|
api_logger.warning(f"用户 {current_user.username} 尝试更新配置但未选择工作空间")
|
||||||
@@ -211,7 +212,7 @@ def update_config_extracted(
|
|||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
) -> dict:
|
) -> dict:
|
||||||
workspace_id = current_user.current_workspace_id
|
workspace_id = current_user.current_workspace_id
|
||||||
|
payload.config_id = resolve_config_id(payload.config_id, db)
|
||||||
# 检查用户是否已选择工作空间
|
# 检查用户是否已选择工作空间
|
||||||
if workspace_id is None:
|
if workspace_id is None:
|
||||||
api_logger.warning(f"用户 {current_user.username} 尝试更新提取配置但未选择工作空间")
|
api_logger.warning(f"用户 {current_user.username} 尝试更新提取配置但未选择工作空间")
|
||||||
@@ -238,7 +239,7 @@ def read_config_extracted(
|
|||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
) -> dict:
|
) -> dict:
|
||||||
workspace_id = current_user.current_workspace_id
|
workspace_id = current_user.current_workspace_id
|
||||||
|
config_id = resolve_config_id(config_id, db)
|
||||||
# 检查用户是否已选择工作空间
|
# 检查用户是否已选择工作空间
|
||||||
if workspace_id is None:
|
if workspace_id is None:
|
||||||
api_logger.warning(f"用户 {current_user.username} 尝试读取提取配置但未选择工作空间")
|
api_logger.warning(f"用户 {current_user.username} 尝试读取提取配置但未选择工作空间")
|
||||||
@@ -286,6 +287,7 @@ async def pilot_run(
|
|||||||
f"Pilot run requested: config_id={payload.config_id}, "
|
f"Pilot run requested: config_id={payload.config_id}, "
|
||||||
f"dialogue_text_length={len(payload.dialogue_text)}"
|
f"dialogue_text_length={len(payload.dialogue_text)}"
|
||||||
)
|
)
|
||||||
|
payload.config_id = resolve_config_id(payload.config_id, db)
|
||||||
svc = DataConfigService(db)
|
svc = DataConfigService(db)
|
||||||
return StreamingResponse(
|
return StreamingResponse(
|
||||||
svc.pilot_run_stream(payload),
|
svc.pilot_run_stream(payload),
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing import Optional
|
from typing import Optional, Union
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
@@ -10,7 +12,7 @@ class OptimizationStrategy(str, Enum):
|
|||||||
ACCURACY_FIRST = "accuracy_first"
|
ACCURACY_FIRST = "accuracy_first"
|
||||||
BALANCED = "balanced"
|
BALANCED = "balanced"
|
||||||
class Memory_Reflection(BaseModel):
|
class Memory_Reflection(BaseModel):
|
||||||
config_id: Optional[UUID] = None
|
config_id: Union[uuid.UUID, int, str] = None
|
||||||
reflection_enabled: bool
|
reflection_enabled: bool
|
||||||
reflection_period_in_hours: str
|
reflection_period_in_hours: str
|
||||||
reflexion_range: Optional[str] = "partial"
|
reflexion_range: Optional[str] = "partial"
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ class ReflexionResultSchema(BaseModel):
|
|||||||
# Composite key identifying a config row
|
# Composite key identifying a config row
|
||||||
class ConfigKey(BaseModel): # 配置参数键模型
|
class ConfigKey(BaseModel): # 配置参数键模型
|
||||||
model_config = ConfigDict(populate_by_name=True, extra="forbid")
|
model_config = ConfigDict(populate_by_name=True, extra="forbid")
|
||||||
config_id: Union[uuid.UUID, int] = Field(..., description="配置唯一标识(UUID或int)")
|
config_id:Union[uuid.UUID, int, str] = Field(..., description="配置唯一标识(UUID或int)")
|
||||||
user_id: str = Field("user_id", description="用户标识(字符串)")
|
user_id: str = Field("user_id", description="用户标识(字符串)")
|
||||||
apply_id: str = Field("apply_id", description="应用或场景标识(字符串)")
|
apply_id: str = Field("apply_id", description="应用或场景标识(字符串)")
|
||||||
|
|
||||||
@@ -238,17 +238,17 @@ class ConfigParamsCreate(BaseModel): # 创建配置参数模型(仅 body,
|
|||||||
class ConfigParamsDelete(BaseModel): # 删除配置参数模型(请求体)
|
class ConfigParamsDelete(BaseModel): # 删除配置参数模型(请求体)
|
||||||
model_config = ConfigDict(populate_by_name=True, extra="forbid")
|
model_config = ConfigDict(populate_by_name=True, extra="forbid")
|
||||||
# config_name: str = Field("配置名称", description="配置名称(字符串)")
|
# config_name: str = Field("配置名称", description="配置名称(字符串)")
|
||||||
config_id: uuid.UUID = Field("配置ID", description="配置ID(UUID)")
|
config_id:Union[uuid.UUID, int, str] = Field(..., description="配置ID(支持UUID、整数或字符串)")
|
||||||
|
|
||||||
|
|
||||||
class ConfigUpdate(BaseModel): # 更新记忆萃取引擎配置参数时使用的模型
|
class ConfigUpdate(BaseModel): # 更新记忆萃取引擎配置参数时使用的模型
|
||||||
config_id: Optional[uuid.UUID] = None
|
config_id: Union[uuid.UUID, int, str] = None
|
||||||
config_name: str = Field("配置名称", description="配置名称(字符串)")
|
config_name: str = Field("配置名称", description="配置名称(字符串)")
|
||||||
config_desc: str = Field("配置描述", description="配置描述(字符串)")
|
config_desc: str = Field("配置描述", description="配置描述(字符串)")
|
||||||
|
|
||||||
|
|
||||||
class ConfigUpdateExtracted(BaseModel): # 更新记忆萃取引擎配置参数时使用的模型
|
class ConfigUpdateExtracted(BaseModel): # 更新记忆萃取引擎配置参数时使用的模型
|
||||||
config_id: Optional[uuid.UUID] = None
|
config_id:Union[uuid.UUID, int, str] = None
|
||||||
llm_id: Optional[str] = Field(None, description="LLM模型配置ID")
|
llm_id: Optional[str] = Field(None, description="LLM模型配置ID")
|
||||||
embedding_id: Optional[str] = Field(None, description="嵌入模型配置ID")
|
embedding_id: Optional[str] = Field(None, description="嵌入模型配置ID")
|
||||||
rerank_id: Optional[str] = Field(None, description="重排序模型配置ID")
|
rerank_id: Optional[str] = Field(None, description="重排序模型配置ID")
|
||||||
@@ -315,14 +315,14 @@ class ConfigUpdateExtracted(BaseModel): # 更新记忆萃取引擎配置参数
|
|||||||
|
|
||||||
class ConfigUpdateForget(BaseModel): # 更新遗忘引擎配置参数时使用的模型
|
class ConfigUpdateForget(BaseModel): # 更新遗忘引擎配置参数时使用的模型
|
||||||
# 遗忘引擎配置参数更新模型
|
# 遗忘引擎配置参数更新模型
|
||||||
config_id: Optional[uuid.UUID] = None
|
config_id:Union[uuid.UUID, int, str] = None
|
||||||
lambda_time: Optional[float] = Field(0.5, ge=0.0, le=1.0, description="最低保持度,0-1 小数;默认 0.5")
|
lambda_time: Optional[float] = Field(0.5, ge=0.0, le=1.0, description="最低保持度,0-1 小数;默认 0.5")
|
||||||
lambda_mem: Optional[float] = Field(0.5, ge=0.0, le=1.0, description="遗忘率,0-1 小数;默认 0.5")
|
lambda_mem: Optional[float] = Field(0.5, ge=0.0, le=1.0, description="遗忘率,0-1 小数;默认 0.5")
|
||||||
offset: Optional[float] = Field(0.0, ge=0.0, le=1.0, description="偏移度,0-1 小数;默认 0.0")
|
offset: Optional[float] = Field(0.0, ge=0.0, le=1.0, description="偏移度,0-1 小数;默认 0.0")
|
||||||
|
|
||||||
|
|
||||||
class ConfigPilotRun(BaseModel): # 试运行触发请求模型
|
class ConfigPilotRun(BaseModel): # 试运行触发请求模型
|
||||||
config_id: uuid.UUID = Field(..., description="配置ID(唯一)")
|
config_id:Union[uuid.UUID, int, str] = Field(..., description="配置ID(唯一,支持UUID、整数或字符串)")
|
||||||
dialogue_text: str = Field(..., description="前端传入的对话文本,格式如 '用户: ...\nAI: ...' 可多行,试运行必填")
|
dialogue_text: str = Field(..., description="前端传入的对话文本,格式如 '用户: ...\nAI: ...' 可多行,试运行必填")
|
||||||
model_config = ConfigDict(populate_by_name=True, extra="forbid")
|
model_config = ConfigDict(populate_by_name=True, extra="forbid")
|
||||||
|
|
||||||
@@ -330,7 +330,7 @@ class ConfigPilotRun(BaseModel): # 试运行触发请求模型
|
|||||||
class ConfigFilter(BaseModel): # 查询配置参数时使用的模型
|
class ConfigFilter(BaseModel): # 查询配置参数时使用的模型
|
||||||
model_config = ConfigDict(populate_by_name=True, extra="forbid")
|
model_config = ConfigDict(populate_by_name=True, extra="forbid")
|
||||||
|
|
||||||
config_id: Optional[uuid.UUID] = None
|
config_id: Union[uuid.UUID, int, str] = None
|
||||||
user_id: Optional[str] = None
|
user_id: Optional[str] = None
|
||||||
apply_id: Optional[str] = None
|
apply_id: Optional[str] = None
|
||||||
|
|
||||||
@@ -406,7 +406,7 @@ class ForgettingConfigResponse(BaseModel):
|
|||||||
"""遗忘引擎配置响应模型"""
|
"""遗忘引擎配置响应模型"""
|
||||||
model_config = ConfigDict(populate_by_name=True, extra="forbid")
|
model_config = ConfigDict(populate_by_name=True, extra="forbid")
|
||||||
|
|
||||||
config_id: uuid.UUID = Field(..., description="配置ID")
|
config_id: Union[uuid.UUID, int, str] = Field(..., description="配置ID(支持UUID、整数或字符串)")
|
||||||
decay_constant: float = Field(..., description="衰减常数 d")
|
decay_constant: float = Field(..., description="衰减常数 d")
|
||||||
lambda_time: float = Field(..., description="时间衰减参数")
|
lambda_time: float = Field(..., description="时间衰减参数")
|
||||||
lambda_mem: float = Field(..., description="记忆衰减参数")
|
lambda_mem: float = Field(..., description="记忆衰减参数")
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ from app.repositories.neo4j.neo4j_connector import Neo4jConnector
|
|||||||
from app.models.app_model import App
|
from app.models.app_model import App
|
||||||
from app.models.app_release_model import AppRelease
|
from app.models.app_release_model import AppRelease
|
||||||
from app.models.end_user_model import EndUser
|
from app.models.end_user_model import EndUser
|
||||||
|
from app.utils.config_utils import resolve_config_id
|
||||||
|
|
||||||
api_logger = get_api_logger()
|
api_logger = get_api_logger()
|
||||||
|
|
||||||
@@ -88,8 +89,7 @@ class WorkspaceAppService:
|
|||||||
|
|
||||||
for release in app_releases:
|
for release in app_releases:
|
||||||
memory_content = self._extract_memory_content(release.config)
|
memory_content = self._extract_memory_content(release.config)
|
||||||
|
memory_content=resolve_config_id(memory_content, self.db)
|
||||||
|
|
||||||
if memory_content and memory_content in processed_configs:
|
if memory_content and memory_content in processed_configs:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -102,7 +102,6 @@ class WorkspaceAppService:
|
|||||||
if memory_content:
|
if memory_content:
|
||||||
processed_configs.add(memory_content)
|
processed_configs.add(memory_content)
|
||||||
memory_config_info = self._get_memory_config(memory_content)
|
memory_config_info = self._get_memory_config(memory_content)
|
||||||
|
|
||||||
if memory_config_info:
|
if memory_config_info:
|
||||||
if not any(dc["config_id"] == memory_config_info["config_id"] for dc in app_info["memory_configs"]):
|
if not any(dc["config_id"] == memory_config_info["config_id"] for dc in app_info["memory_configs"]):
|
||||||
app_info["memory_configs"].append(memory_config_info)
|
app_info["memory_configs"].append(memory_config_info)
|
||||||
@@ -157,6 +156,8 @@ class WorkspaceAppService:
|
|||||||
"app_id": str(end_user.app_id)
|
"app_id": str(end_user.app_id)
|
||||||
}
|
}
|
||||||
app_info["end_users"].append(end_user_info)
|
app_info["end_users"].append(end_user_info)
|
||||||
|
print(100*'-')
|
||||||
|
print(app_info)
|
||||||
|
|
||||||
def get_end_user_reflection_time(self, end_user_id: str) -> Optional[Any]:
|
def get_end_user_reflection_time(self, end_user_id: str) -> Optional[Any]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user