Merge #19 into develop from fix/memory_reflection
统一输出
* fix/memory_reflection: (35 commits squashed)
- 新增反思功能(功能配置接口+反思celery后台检测反思的迭代周期)
- 新增反思功能(功能配置接口+反思celery后台检测反思的迭代周期)
- 新增反思功能(检测代码/规范化程序)
- 新增反思功能(检测代码/规范化程序)
- 新增反思功能(检测代码/规范化程序)
- 新增反思功能(检测代码/规范化程序)
- 新增反思功能(检测代码/规范化程序)
- 反思优化
- 反思优化
- 反思优化
- 反思优化
- 反思优化
- 反思优化
- 反思优化
- 反思优化
- 反思优化
- 反思优化
- 反思优化
- 反思优化
- 反思优化
- 反思优化
- 反思优化
- 反思优化
- 反思优化
- 反思优化
- Merge branch develop into fix/memory_reflection (Conflict resolved online)
# Conflicts:
# api/app/controllers/memory_reflection_controller.py
# api/app/schemas/memory_reflection_schemas.py
- 反思优化
- Merge remote-tracking branch 'origin/fix/memory_reflection' into fix/memory_reflection
- 统一输出
- 统一输出
- 统一输出
- Merge branch develop into fix/memory_reflection (Conflict resolved online)
# Conflicts:
# api/app/controllers/memory_reflection_controller.py
- 统一输出
- Merge remote-tracking branch 'origin/fix/memory_reflection' into fix/memory_reflection
- 统一输出
Signed-off-by: aliyun8644380055 <accounts_68c0f5d519f260d93ee2997e@mail.teambition.com>
Reviewed-by: aliyun6762716068 <accounts_68cb7c6b61f5dcc4200d6251@mail.teambition.com>
Merged-by: aliyun6762716068 <accounts_68cb7c6b61f5dcc4200d6251@mail.teambition.com>
CR-link: https://codeup.aliyun.com/redbearai/python/redbear-mem-open/change/19
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import time
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from fastapi import APIRouter, Depends, HTTPException, status
|
from fastapi import APIRouter, Depends, HTTPException, status
|
||||||
@@ -6,17 +7,17 @@ from sqlalchemy.orm import Session
|
|||||||
from sqlalchemy import text
|
from sqlalchemy import text
|
||||||
|
|
||||||
from app.core.logging_config import get_api_logger
|
from app.core.logging_config import get_api_logger
|
||||||
|
from app.core.response_utils import success
|
||||||
from app.core.memory.storage_services.reflection_engine.self_reflexion import ReflectionConfig, ReflectionEngine
|
from app.core.memory.storage_services.reflection_engine.self_reflexion import ReflectionConfig, ReflectionEngine
|
||||||
from app.dependencies import get_current_user
|
from app.dependencies import get_current_user
|
||||||
from app.db import get_db
|
from app.db import get_db
|
||||||
from app.models.user_model import User
|
from app.models.user_model import User
|
||||||
from app.repositories.data_config_repository import DataConfigRepository
|
from app.repositories.data_config_repository import DataConfigRepository
|
||||||
from app.repositories.neo4j.neo4j_connector import Neo4jConnector
|
from app.repositories.neo4j.neo4j_connector import Neo4jConnector
|
||||||
|
|
||||||
from app.services.memory_reflection_service import WorkspaceAppService, MemoryReflectionService
|
from app.services.memory_reflection_service import WorkspaceAppService, MemoryReflectionService
|
||||||
|
|
||||||
from app.schemas.memory_reflection_schemas import Memory_Reflection
|
from app.schemas.memory_reflection_schemas import Memory_Reflection
|
||||||
from app.services.model_service import ModelConfigService
|
from app.services.model_service import ModelConfigService
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
api_logger = get_api_logger()
|
api_logger = get_api_logger()
|
||||||
|
|
||||||
@@ -81,12 +82,7 @@ async def save_reflection_config(
|
|||||||
|
|
||||||
api_logger.info(f"成功保存反思配置到数据库,config_id: {config_id}")
|
api_logger.info(f"成功保存反思配置到数据库,config_id: {config_id}")
|
||||||
|
|
||||||
# 返回结果
|
reflection_result={
|
||||||
return {
|
|
||||||
"status": "成功",
|
|
||||||
"message": "反思配置已保存",
|
|
||||||
"config_id": config_id,
|
|
||||||
"database_record": {
|
|
||||||
"config_id": result.config_id,
|
"config_id": result.config_id,
|
||||||
"enable_self_reflexion": result.enable_self_reflexion,
|
"enable_self_reflexion": result.enable_self_reflexion,
|
||||||
"iteration_period": result.iteration_period,
|
"iteration_period": result.iteration_period,
|
||||||
@@ -95,9 +91,11 @@ async def save_reflection_config(
|
|||||||
"reflection_model_id": result.reflection_model_id,
|
"reflection_model_id": result.reflection_model_id,
|
||||||
"memory_verify": result.memory_verify,
|
"memory_verify": result.memory_verify,
|
||||||
"quality_assessment": result.quality_assessment,
|
"quality_assessment": result.quality_assessment,
|
||||||
"user_id": result.user_id
|
"user_id": result.user_id}
|
||||||
}
|
|
||||||
}
|
return success(data=reflection_result, msg="反思配置成功")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
except ValueError as ve:
|
except ValueError as ve:
|
||||||
api_logger.error(f"参数错误: {str(ve)}")
|
api_logger.error(f"参数错误: {str(ve)}")
|
||||||
@@ -156,13 +154,7 @@ async def start_workspace_reflection(
|
|||||||
"reflection_result": reflection_result
|
"reflection_result": reflection_result
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return success(data=reflection_results, msg="反思配置成功")
|
||||||
"status": "完成",
|
|
||||||
"message": f"成功处理 {len(reflection_results)} 个反思任务",
|
|
||||||
"workspace_id": str(workspace_id),
|
|
||||||
"reflection_count": len(reflection_results),
|
|
||||||
"reflection_results": reflection_results
|
|
||||||
}
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
api_logger.error(f"启动workspace反思失败: {str(e)}")
|
api_logger.error(f"启动workspace反思失败: {str(e)}")
|
||||||
@@ -179,7 +171,6 @@ async def start_reflection_configs(
|
|||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""通过config_id查询data_config表中的反思配置信息"""
|
"""通过config_id查询data_config表中的反思配置信息"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
api_logger.info(f"用户 {current_user.username} 查询反思配置,config_id: {config_id}")
|
api_logger.info(f"用户 {current_user.username} 查询反思配置,config_id: {config_id}")
|
||||||
|
|
||||||
@@ -196,8 +187,8 @@ async def start_reflection_configs(
|
|||||||
# 构建返回数据
|
# 构建返回数据
|
||||||
reflection_config = {
|
reflection_config = {
|
||||||
"config_id": result.config_id,
|
"config_id": result.config_id,
|
||||||
"enable_self_reflexion": result.enable_self_reflexion,
|
"reflection_enabled": result.enable_self_reflexion,
|
||||||
"iteration_period": result.iteration_period,
|
"reflection_period_in_hours": result.iteration_period,
|
||||||
"reflexion_range": result.reflexion_range,
|
"reflexion_range": result.reflexion_range,
|
||||||
"baseline": result.baseline,
|
"baseline": result.baseline,
|
||||||
"reflection_model_id": result.reflection_model_id,
|
"reflection_model_id": result.reflection_model_id,
|
||||||
@@ -205,14 +196,9 @@ async def start_reflection_configs(
|
|||||||
"quality_assessment": result.quality_assessment,
|
"quality_assessment": result.quality_assessment,
|
||||||
"user_id": result.user_id
|
"user_id": result.user_id
|
||||||
}
|
}
|
||||||
|
|
||||||
api_logger.info(f"成功查询反思配置,config_id: {config_id}")
|
api_logger.info(f"成功查询反思配置,config_id: {config_id}")
|
||||||
|
return success(data=reflection_config, msg="反思配置查询成功")
|
||||||
|
|
||||||
return {
|
|
||||||
"status": "成功",
|
|
||||||
"message": "反思配置查询成功",
|
|
||||||
"data": reflection_config
|
|
||||||
}
|
|
||||||
|
|
||||||
except HTTPException:
|
except HTTPException:
|
||||||
# 重新抛出HTTP异常
|
# 重新抛出HTTP异常
|
||||||
@@ -276,4 +262,8 @@ async def reflection_run(
|
|||||||
)
|
)
|
||||||
|
|
||||||
result=await (engine.reflection_run())
|
result=await (engine.reflection_run())
|
||||||
return result
|
return success(data=result, msg="反思试运行")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import uuid
|
|||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from app.core.response_utils import success
|
||||||
from app.repositories.neo4j.cypher_queries import neo4j_query_part, neo4j_statement_part, neo4j_query_all, neo4j_statement_all
|
from app.repositories.neo4j.cypher_queries import neo4j_query_part, neo4j_statement_part, neo4j_query_all, neo4j_statement_all
|
||||||
from app.repositories.neo4j.neo4j_update import neo4j_data
|
from app.repositories.neo4j.neo4j_update import neo4j_data
|
||||||
from app.repositories.neo4j.neo4j_connector import Neo4jConnector
|
from app.repositories.neo4j.neo4j_connector import Neo4jConnector
|
||||||
@@ -314,8 +315,8 @@ class ReflectionEngine:
|
|||||||
for result in item['results']:
|
for result in item['results']:
|
||||||
reflexion_data.append(result['reflexion'])
|
reflexion_data.append(result['reflexion'])
|
||||||
result_data['reflexion_data'] = reflexion_data
|
result_data['reflexion_data'] = reflexion_data
|
||||||
execution_time = time.time() - start_time
|
return result_data
|
||||||
return {"status": "SUCCESS", "message": "反思试运行", "data": result_data, "time": execution_time}
|
|
||||||
|
|
||||||
async def extract_fields_from_json(self):
|
async def extract_fields_from_json(self):
|
||||||
"""从example.json中提取source_data和databasets字段"""
|
"""从example.json中提取source_data和databasets字段"""
|
||||||
|
|||||||
Reference in New Issue
Block a user