fix: non-greedy file_content extraction, empty response retry limit, vision template pass
This commit is contained in:
1 parent
b55b50a0ec
commit
74831f83f7
2 files changed
+7
-4
No files matched your search
@@ -374,10 +374,10 @@ class GenericAgentHandler(BaseHandler):
|
||||
yield f"[Action] {action_str} file: {os.path.basename(path)}\n"
|
||||
|
||||
def extract_robust_content(text):
|
||||
tag = re.search(r"<file_content[^>]*>(.*)</file_content>", text, re.DOTALL)
|
||||
if tag: return tag.group(1).strip()
|
||||
s, e = text.find("```"), text.rfind("```")
|
||||
if -1 < s < e: return text[text.find("\n", s)+1 : e].strip()
|
||||
tags = re.findall(r"<file_content[^>]*>(.*?)</file_content>", text, re.DOTALL)
|
||||
if tags: return tags[-1].strip()
|
||||
blocks = re.findall(r"```[^\n]*\n([\s\S]*?)```", text)
|
||||
if blocks: return blocks[-1].strip()
|
||||
return None
|
||||
|
||||
blocks = extract_robust_content(response.content)
|
||||
@@ -446,6 +446,8 @@ class GenericAgentHandler(BaseHandler):
|
||||
content = getattr(response, 'content', '') or ""
|
||||
thinking = getattr(response, 'thinking', '') or ""
|
||||
if not response or (not content.strip() and not thinking.strip()):
|
||||
self._empty_ct = getattr(self, '_empty_ct', 0) + 1
|
||||
if self._empty_ct >= 3: return StepOutcome({}, should_exit=True)
|
||||
yield "[Warn] LLM returned an empty response. Retrying...\n"
|
||||
return StepOutcome({}, next_prompt="[System] Blank response, regenerate and tooluse")
|
||||
if len(content) > 50 and ('[!!! 流异常中断' in content[-100:] or '!!!Error:' in content[-100:]):
|
||||
|
||||
@@ -111,3 +111,4 @@ def _call_openai_compat(b64, prompt, timeout, *, apibase, apikey, model, proxy=N
|
||||
return resp.json()['choices'][0]['message']['content']
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
||||
Reference in new issue
Block a user