support JSON output for ollama and openai

This commit is contained in:
b10902118
2024-11-29 21:41:37 +08:00
parent 4223b4f603
commit 753c1e6714
3 changed files with 42 additions and 18 deletions

View File

@@ -461,12 +461,12 @@ 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)
result = await use_model_func(kw_prompt, keyword_extraction=True)
logger.info("kw_prompt result:")
print(result)
try:
json_text = locate_json_string_body_from_string(result)
keywords_data = json.loads(json_text)
# json_text = locate_json_string_body_from_string(result) # handled in use_model_func
keywords_data = json.loads(result)
hl_keywords = keywords_data.get("high_level_keywords", [])
ll_keywords = keywords_data.get("low_level_keywords", [])