update:提示词上下文按模板按需获取(位置/天气/动态上下文)

This commit is contained in:
3030332422
2025-12-18 16:34:37 +08:00
parent 7ba180752a
commit e8d0bb0c54
@@ -184,10 +184,25 @@ class PromptManager:
def update_context_info(self, conn, client_ip: str): def update_context_info(self, conn, client_ip: str):
"""同步更新上下文信息""" """同步更新上下文信息"""
try: try:
# 获取位置信息(使用全局缓存) local_address = ""
local_address = self._get_location_info(client_ip) if (
# 获取天气信息(使用全局缓存) client_ip
self._get_weather_info(conn, local_address) and self.base_prompt_template
and (
"local_address" in self.base_prompt_template
or "weather_info" in self.base_prompt_template
)
):
# 获取位置信息(使用全局缓存)
local_address = self._get_location_info(client_ip)
if (
self.base_prompt_template
and "weather_info" in self.base_prompt_template
and local_address
):
# 获取天气信息(使用全局缓存)
self._get_weather_info(conn, local_address)
# 获取配置的上下文数据 # 获取配置的上下文数据
if hasattr(conn, "device_id") and conn.device_id: if hasattr(conn, "device_id") and conn.device_id: