feat: add graceful prompt-based fallback for local LLMs without tool calling support#46
Open
androemeda wants to merge 1 commit intovirtualcell:mainfrom
Open
feat: add graceful prompt-based fallback for local LLMs without tool calling support#46androemeda wants to merge 1 commit intovirtualcell:mainfrom
androemeda wants to merge 1 commit intovirtualcell:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #45
Summary
Modifies the backend to gracefully handle local LLM models (like
deepseek-r1) that do not natively support tool/function calling. Instead of crashing with a400 Bad Request, the backend now falls back to a prompt-based tool selection approach.Also updates
SETUP.mdto clarify model recommendations.Explanation of Implementation
Try-Catch Fallback (
llms_service.py)get_response_with_toolsnow attempts to use the native tool calling API first.If a
400error occurs (specifically catching"does not support tools"), a warning is logged and the workflow shifts to_get_response_with_prompt_tools.Prompt-Based Tool Execution
The fallback uses a two-step approach:
Decoupled Prompts (
tool_selection_prompt.py)Moved the new
TOOL_SELECTION_PROMPTinto:app/utils/tool_selection_prompt.pyThis maintains the existing pattern of separating prompts from service logic.
Documentation Update (
SETUP.md)Updated the guide to recommend tool-calling capable models (e.g.,
llama3.1:8b) as the primary choice for the best experience.deepseek-r1models remain listed as alternatives with a note explaining the fallback limitations.Screenshots
Before (Crash)
After (Graceful Fallback)
Testing
Native Path Verification
Set:
Successfully triggered native tool calling (e.g.,
"List all calcium models") with no errors.Fallback Path Verification
Set:
Confirmed that sending a query:
ValueError