Save keywords to cache only when it's no empty

This commit is contained in:
yangdx
2025-02-01 22:54:23 +08:00
parent 3c3cdba499
commit 2d387fa6de

View File

@@ -760,7 +760,7 @@ async def extract_keywords_only(
# 6. Parse out JSON from the LLM response # 6. Parse out JSON from the LLM response
match = re.search(r"\{.*\}", result, re.DOTALL) match = re.search(r"\{.*\}", result, re.DOTALL)
if not match: if not match:
logger.error("No JSON-like structure found in the result.") logger.error("No JSON-like structure found in the LLM respond.")
return [], [] return [], []
try: try:
keywords_data = json.loads(match.group(0)) keywords_data = json.loads(match.group(0))
@@ -772,20 +772,21 @@ async def extract_keywords_only(
ll_keywords = keywords_data.get("low_level_keywords", []) ll_keywords = keywords_data.get("low_level_keywords", [])
# 7. Cache only the processed keywords with cache type # 7. Cache only the processed keywords with cache type
cache_data = {"high_level_keywords": hl_keywords, "low_level_keywords": ll_keywords} if hl_keywords or ll_keywords:
await save_to_cache( cache_data = {"high_level_keywords": hl_keywords, "low_level_keywords": ll_keywords}
hashing_kv, await save_to_cache(
CacheData( hashing_kv,
args_hash=args_hash, CacheData(
content=json.dumps(cache_data), args_hash=args_hash,
prompt=text, content=json.dumps(cache_data),
quantized=quantized, prompt=text,
min_val=min_val, quantized=quantized,
max_val=max_val, min_val=min_val,
mode=param.mode, max_val=max_val,
cache_type="keywords", mode=param.mode,
), cache_type="keywords",
) ),
)
return hl_keywords, ll_keywords return hl_keywords, ll_keywords