diff --git a/scripts/llm_client.py b/scripts/llm_client.py index 05a84af..93049ab 100644 --- a/scripts/llm_client.py +++ b/scripts/llm_client.py @@ -7,6 +7,7 @@ class LLMClient: def __init__(self, msg): self.content = msg.get('content', '') self.tool_calls = msg.get('tool_calls', None) + self.warning = None def __init__(self, base_url, model, api_key, timeout=600): self.base_url = base_url.rstrip('/') @@ -35,6 +36,15 @@ class LLMClient: message = response['choices'][0]['message'] return self.Message(message) except urllib.error.HTTPError as e: + if tools and e.code == 404: + try: + body = json.loads(e.read().decode('utf-8')) + if 'tool use' in body.get('error', {}).get('message', '').lower(): + result = self.chat(messages, tools=None) + result.warning = "Tool calling not supported by this model. Running in chat-only mode." + return result + except Exception: + pass return self.Message({'content': f"HTTP Error: {e.code} {e.reason}", 'tool_calls': None}) except Exception as e: return self.Message({'content': f"Error: {str(e)}", 'tool_calls': None}) diff --git a/tui/agent.py b/tui/agent.py index 87646ae..4b6e918 100644 --- a/tui/agent.py +++ b/tui/agent.py @@ -59,6 +59,9 @@ def _agent_loop(app): app.log.pop() + if response.warning: + log(app, "system", f" {response.warning}") + if response.tool_calls: amsg = { "role": "assistant",