重构缓存处理逻辑

- 提取通用缓存处理逻辑到新函数 handle_cache 和 save_to_cache
- 使用 CacheData 类统一缓存数据结构
- 优化嵌入式缓存和常规缓存的处理流程
- 添加模式参数以支持不同查询模式的缓存策略
- 重构 get_best_cached_response 函数,提高缓存查询效率
This commit is contained in:
yuanxiaobin
2024-12-06 14:29:16 +08:00
parent 7c4bbe2474
commit 584258078f
3 changed files with 277 additions and 309 deletions

View File

@@ -474,7 +474,9 @@ async def kg_query(
use_model_func = global_config["llm_model_func"]
kw_prompt_temp = PROMPTS["keywords_extraction"]
kw_prompt = kw_prompt_temp.format(query=query, examples=examples, language=language)
result = await use_model_func(kw_prompt, keyword_extraction=True)
result = await use_model_func(
kw_prompt, keyword_extraction=True, mode=query_param.mode
)
logger.info("kw_prompt result:")
print(result)
try:
@@ -534,6 +536,7 @@ async def kg_query(
response = await use_model_func(
query,
system_prompt=sys_prompt,
mode=query_param.mode,
)
if len(response) > len(sys_prompt):
response = (
@@ -1035,6 +1038,7 @@ async def naive_query(
response = await use_model_func(
query,
system_prompt=sys_prompt,
mode=query_param.mode,
)
if len(response) > len(sys_prompt):