Handle Claude refusal without retry
This commit is contained in:
1 parent
bcda218cda
commit
a195bdc101
3 files changed
+7
-1
No files matched your search
@@ -6,7 +6,7 @@ SuperGrok Local Proxy - CLI
|
||||
python assets/supergrok_proxy.py login
|
||||
python assets/supergrok_proxy.py serve --port 15433
|
||||
python assets/supergrok_proxy.py models
|
||||
python assets/supergrok_proxy.py test --model grok-4.3
|
||||
python assets/supergrok_proxy.py test --model grok-4.5
|
||||
|
||||
GenericAgent/mykey 配置示例:
|
||||
native_oai_config_supergrok_proxy = {
|
||||
|
||||
@@ -88,6 +88,7 @@ def get_controller():
|
||||
threading.Thread(target=ag.run, daemon=True).start()
|
||||
while True:
|
||||
b['ev'].wait(); b['ev'].clear()
|
||||
if ag.llm_no != agent.llm_no: ag.next_llm(agent.llm_no)
|
||||
dq = ag.put_task(build_prompt(b['obj']), source="controller")
|
||||
while 'done' not in (it := dq.get()): pass
|
||||
ms = re.findall(r'<next_prompt>(.*?)</next_prompt>', it['done'], re.S)
|
||||
|
||||
@@ -117,6 +117,10 @@ def auto_make_url(base, path):
|
||||
return f"{b}/{p}" if re.search(r'/v\d+(/|$)', b) else f"{b}/v1/{p}"
|
||||
|
||||
def _parse_claude_json(data):
|
||||
if data.get("stop_reason") == "refusal":
|
||||
err = "[Error: Claude refusal]"
|
||||
yield err
|
||||
return [{"type": "text", "text": err}]
|
||||
content_blocks = data.get("content", [])
|
||||
_record_usage(data.get("usage", {}), "messages")
|
||||
for b in content_blocks:
|
||||
@@ -182,6 +186,7 @@ def _parse_claude_sse(resp_lines):
|
||||
if not warn:
|
||||
if not got_message_stop and not stop_reason: warn = "\n\n[!!! 流异常中断,未收到完整响应 !!!]"
|
||||
elif stop_reason == "max_tokens": warn = "\n\n[!!! Response truncated: max_tokens !!!]"
|
||||
elif stop_reason == "refusal": warn = "\n\n[Error: Claude refusal]"
|
||||
if current_block:
|
||||
if current_block["type"] == "tool_use":
|
||||
try: current_block["input"] = json.loads(tool_json_buf) if tool_json_buf else {}
|
||||
|
||||
Reference in new issue
Block a user