Fix stop signal handling and Sider streaming wrapper
This commit is contained in:
@@ -85,8 +85,7 @@ class GeneraticAgent:
|
||||
try:
|
||||
full_response = ""; last_pos = 0
|
||||
for chunk in gen:
|
||||
if self.stop_sig:
|
||||
self.abort(); break
|
||||
if self.stop_sig: break
|
||||
full_response += chunk
|
||||
if len(full_response) - last_pos > 50:
|
||||
self.display_queue.put({'next': f'{full_response}', 'source': source})
|
||||
@@ -103,4 +102,6 @@ class GeneraticAgent:
|
||||
self.stop_sig = False
|
||||
self.current_source = 'none'
|
||||
self.task_queue.task_done()
|
||||
if self.handler is not None: self.handler.code_stop_signal.append(1)
|
||||
|
||||
|
||||
|
||||
2
ga.py
2
ga.py
@@ -410,7 +410,7 @@ class GenericAgentHandler(BaseHandler):
|
||||
# 1. 空回复保护:要求模型重新生成内容或调用工具
|
||||
if not response or not content.strip():
|
||||
yield "[Warn] LLM returned an empty response. Retrying...\n"
|
||||
next_prompt = "[System] 检测到空回复,请重新生成内容或调用工具。"
|
||||
next_prompt = "[System] 回复为空,请重新生成内容或调用工具。"
|
||||
return StepOutcome({}, next_prompt=next_prompt, should_exit=False)
|
||||
# 2. 检测“包含较大代码块但未调用工具”的情况
|
||||
# 这里通过三引号代码块 + 最少字符数的方式粗略判断“大段代码”
|
||||
|
||||
@@ -15,11 +15,8 @@ class SiderLLMSession:
|
||||
if len(prompt) > 28000:
|
||||
print(f"[Warn] Prompt too long ({len(prompt)} chars), truncating.")
|
||||
prompt = prompt[-28000:]
|
||||
gen = self._core.chat(prompt, model)
|
||||
full_text = ''.join(list(gen))
|
||||
if stream:
|
||||
def wrap_as_stream(): yield full_text
|
||||
return wrap_as_stream() # gen有奇怪的死循环行为,sider足够快
|
||||
full_text = self._core.chat(prompt, model, stream=False)
|
||||
if stream: return iter([full_text]) # gen有奇怪的空回复或死循环行为,sider足够快
|
||||
return full_text
|
||||
|
||||
class LLMSession:
|
||||
|
||||
Reference in New Issue
Block a user