mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-02 22:07:31 +08:00
fix: handle null response in LLM and improve JSON parsing in agent (#13187)
Fixes AttributeError in _remove_reasoning_content() when LLM returns None, and improves JSON parsing regex for markdown code fences in agent_with_tools.py
This commit is contained in:
@@ -383,7 +383,10 @@ class Agent(LLM, ToolBase):
|
||||
token_count += tk or 0
|
||||
hist.append({"role": "assistant", "content": response})
|
||||
try:
|
||||
functions = json_repair.loads(re.sub(r"```.*", "", response))
|
||||
# Remove markdown code fences properly
|
||||
cleaned_response = re.sub(r"^.*```json\s*", "", response, flags=re.DOTALL)
|
||||
cleaned_response = re.sub(r"```\s*$", "", cleaned_response, flags=re.DOTALL)
|
||||
functions = json_repair.loads(cleaned_response)
|
||||
if not isinstance(functions, list):
|
||||
raise TypeError(f"List should be returned, but `{functions}`")
|
||||
for f in functions:
|
||||
|
||||
Reference in New Issue
Block a user