llama-stack-mirror/llama_stack/models/llama/llama4
skamenan7 857496ea3e fix: Resolve Llama4 tool calling 500 errors (Issue #2584)
This commit fixes the tool calling failures with Llama4 models that were
returning 500 errors while Together API worked correctly. The root cause
was that the system was using Llama3's JSON format for all models instead
of Llama4's python_list format.

Key changes:
- NEW: llama_stack/models/llama/llama4/interface.py - Complete Llama4 interface
  with python_list tool format support
- MODIFIED: prompt_adapter.py - Added model-aware decode_assistant_message()
  that uses Llama4ChatFormat for llama4 models and Llama3ChatFormat for others
- MODIFIED: openai_compat.py - Updated to pass model_id parameter to enable
  model-specific format detection
- MODIFIED: sku_list.py - Enhanced with provider alias support for better
  model resolution
- NEW: tests/unit/models/test_decode_assistant_message.py - Comprehensive unit
  tests for the new decode_assistant_message function

The fix ensures that:
- Llama4 models (meta-llama/Llama-4-*) use python_list format: [func(args)]
- Other models continue using JSON format: {"type": "function", ...}
- Backward compatibility is maintained for existing models
- Tool calling works correctly across different model families
- Graceful fallback when Llama4 dependencies are unavailable

Testing:
- All 17 unit tests pass (9 original + 8 new)
- Conditional imports prevent torch dependency issues
- Comprehensive test coverage for different model types and scenarios

Fixes #2584
2025-07-15 11:47:05 -04:00
..
prompt_templates ci: add python package build test (#2457) 2025-06-19 18:57:32 +05:30
quantization chore: enable pyupgrade fixes (#1806) 2025-05-01 14:23:50 -07:00
vision ci: add python package build test (#2457) 2025-06-19 18:57:32 +05:30
__init__.py feat: introduce llama4 support (#1877) 2025-04-05 11:53:35 -07:00
args.py chore: enable pyupgrade fixes (#1806) 2025-05-01 14:23:50 -07:00
chat_format.py chore: enable pyupgrade fixes (#1806) 2025-05-01 14:23:50 -07:00
datatypes.py chore: enable pyupgrade fixes (#1806) 2025-05-01 14:23:50 -07:00
ffn.py chore: enable pyupgrade fixes (#1806) 2025-05-01 14:23:50 -07:00
generation.py chore: make cprint write to stderr (#2250) 2025-05-24 23:39:57 -07:00
interface.py fix: Resolve Llama4 tool calling 500 errors (Issue #2584) 2025-07-15 11:47:05 -04:00
model.py chore: enable pyupgrade fixes (#1806) 2025-05-01 14:23:50 -07:00
moe.py chore: enable pyupgrade fixes (#1806) 2025-05-01 14:23:50 -07:00
preprocess.py chore: enable pyupgrade fixes (#1806) 2025-05-01 14:23:50 -07:00
prompt_format.md fix: llama4 tool use prompt fix (#2103) 2025-05-06 22:18:31 -07:00
prompts.py chore: enable pyupgrade fixes (#1806) 2025-05-01 14:23:50 -07:00
tokenizer.model feat(pre-commit): enhance pre-commit hooks with additional checks (#2014) 2025-04-30 11:35:49 -07:00
tokenizer.py chore: remove usage of load_tiktoken_bpe (#2276) 2025-06-02 07:33:37 -07:00