mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 23:41:12 +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:
|
||||
|
||||
@@ -265,6 +265,8 @@ class LLMBundle(LLM4Tenant):
|
||||
generation.end()
|
||||
|
||||
def _remove_reasoning_content(self, txt: str) -> str:
|
||||
if txt is None:
|
||||
return None
|
||||
first_think_start = txt.find("<think>")
|
||||
if first_think_start == -1:
|
||||
return txt
|
||||
|
||||
Reference in New Issue
Block a user