gary-boon Claude Opus 4.5 commited on
Commit
474927d
·
1 Parent(s): 8d85da8

fix: Check chat_template is set before using apply_chat_template

Browse files

The tokenizer has the apply_chat_template method but no template
configured. Now we check tokenizer.chat_template is not None
before attempting to use it, falling back to manual [INST] format.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Files changed (1) hide show
  1. backend/model_service.py +6 -1
backend/model_service.py CHANGED
@@ -1467,7 +1467,12 @@ async def analyze_research_attention(request: Dict[str, Any], authenticated: boo
1467
 
1468
  # Format prompt for chat/instruct models
1469
  if uses_chat_template:
1470
- if hasattr(manager.tokenizer, 'apply_chat_template'):
 
 
 
 
 
1471
  # Use tokenizer's built-in chat template
1472
  messages = [{"role": "user", "content": f"Complete the following code:\n{prompt}"}]
1473
  formatted_prompt = manager.tokenizer.apply_chat_template(
 
1467
 
1468
  # Format prompt for chat/instruct models
1469
  if uses_chat_template:
1470
+ # Check if tokenizer has a chat template actually configured (not just the method)
1471
+ has_template = (
1472
+ hasattr(manager.tokenizer, 'chat_template') and
1473
+ manager.tokenizer.chat_template is not None
1474
+ )
1475
+ if has_template:
1476
  # Use tokenizer's built-in chat template
1477
  messages = [{"role": "user", "content": f"Complete the following code:\n{prompt}"}]
1478
  formatted_prompt = manager.tokenizer.apply_chat_template(