fix(chat): fall back to streaming when provider rejects function calling
Local models (e.g. Gemma on LM Studio) return HTTP 400 when sent a tools-spec request. Catch litellm.BadRequestError in the tool-use loop, inform the user once that tools are disabled, and retry as a plain streaming call so the conversation continues normally. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -282,6 +282,7 @@ def _call_ai(
|
||||
return render_streaming_response(stream)
|
||||
|
||||
# Plugin tool-use loop (non-streaming for tool calls, renders final response)
|
||||
try:
|
||||
for _iteration in range(10):
|
||||
response = litellm.completion(
|
||||
**base_kwargs,
|
||||
@@ -302,6 +303,15 @@ def _call_ai(
|
||||
|
||||
return render_text_response("Error: tool-use loop exceeded maximum iterations.")
|
||||
|
||||
except litellm.BadRequestError:
|
||||
render_info("This model does not support function calling — tools disabled.")
|
||||
stream = litellm.completion(
|
||||
**base_kwargs,
|
||||
messages=history.build_for_api(),
|
||||
stream=True,
|
||||
)
|
||||
return render_streaming_response(stream)
|
||||
|
||||
|
||||
def _show_help(plugin_slash: dict) -> None:
|
||||
lines = ["[bold]Slash commands:[/bold]"]
|
||||
|
||||
Reference in New Issue
Block a user