ReMe/old/retrieve/parse_params_worker.py
2024-06-20 22:18:57 +08:00

36 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
from config.bailian_memory_config import BailianMemoryConfig
from constants.common_constants import REQUEST, CONFIG
from pipeline.memory import MemoryServiceRequestModel
from worker.base_worker import BaseWorker
class ParseParamsWorker(BaseWorker):
def _run(self):
# 参数合并
memory_config = {}
# 更新环境变量
memory_config.update(self.context_handler.env_configs)
# 更新请求参数
request: MemoryServiceRequestModel = self.context_handler.get_context(REQUEST)
memory_config.update(request.model_dump(exclude=set("ext_info", )))
# 更新ext_info
if request.ext_info:
memory_config.update(request.ext_info)
# 存入上下文
memory_config_model: BailianMemoryConfig = BailianMemoryConfig(**memory_config)
self.context_handler.set_context(CONFIG, memory_config_model)
# 打印
self.logger.info(f"memory_config_model={json.dumps(memory_config_model.model_dump(), ensure_ascii=False)}")
# 上游可能没有传这个参数可能隐藏在memory_id做区分
if request.user_profile:
for user_attr in request.user_profile:
user_attr.scene = request.scene