Support model that not support on tool calling
This commit is contained in:
parent
48e5f398fb
commit
f121c6cbb0
@ -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})
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user