Skip to content

Commit 2258973

Browse files
committed
update chat handler
1 parent db6ee16 commit 2258973

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

llama_cpp/llama_chat_format.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4681,7 +4681,7 @@ def __init__(
46814681
- False: Doesn't count the images. Can save tokens with single-image.
46824682
"""
46834683
super().__init__(**kwargs)
4684-
4684+
self.force_reasoning = force_reasoning
46854685
self.extra_template_arguments["force_reasoning"] = force_reasoning
46864686
self.extra_template_arguments["add_vision_id"] = add_vision_id
46874687

@@ -4697,7 +4697,7 @@ def __call__(self, **kwargs):
46974697
# Use parent implementation
46984698
return super().__call__(**kwargs)
46994699

4700-
class Qwen35ChatHandler(Llava15ChatHandler):
4700+
class Qwen35ChatHandler(MTMDChatHandler):
47014701
CHAT_FORMAT = (
47024702
"{%- set image_count = namespace(value=0) -%}"
47034703
"{%- set video_count = namespace(value=0) -%}"
@@ -4864,22 +4864,22 @@ class Qwen35ChatHandler(Llava15ChatHandler):
48644864

48654865
def __init__(
48664866
self,
4867-
reasoning: bool = True,
4867+
enable_thinking: bool = True,
48684868
add_vision_id: bool = True,
48694869
**kwargs,
48704870
):
48714871
"""
48724872
Parameters:
4873-
- reasoning (bool):
4873+
- enable_thinking (bool):
48744874
- True (default): Enables reasoning for better results.
48754875
- False: Disables reasoning for faster results.
48764876
- add_vision_id (bool):
48774877
- True (default): Count all the images. Recommended for multi-image.
48784878
- False: Doesn't count the images. Can save tokens with single-image.
48794879
"""
48804880
super().__init__(**kwargs)
4881-
4882-
self.extra_template_arguments["enable_thinking"] = reasoning
4881+
self.enable_thinking = enable_thinking
4882+
self.extra_template_arguments["enable_thinking"] = enable_thinking
48834883
self.extra_template_arguments["add_vision_id"] = add_vision_id
48844884

48854885
def __call__(self, **kwargs):
@@ -4888,18 +4888,8 @@ def __call__(self, **kwargs):
48884888
if hasattr(llama, 'input_ids'):
48894889
llama.input_ids.fill(0)
48904890

4891-
# Clear any handler state
4892-
if hasattr(self, '_last_image_embed'):
4893-
self._last_image_embed = None
4894-
self._last_image_hash = None
4895-
48964891
if self.verbose:
4897-
messages = kwargs.get('messages', [])
4898-
try:
4899-
image_count = len(self.get_image_urls(messages))
4900-
print(f"Qwen35ChatHandler - Cleared state, processing {image_count} images", file=sys.stderr)
4901-
except Exception:
4902-
print(f"Qwen35ChatHandler - Cleared state", file=sys.stderr)
4892+
print(f"{self.log_prefix}(enable_thinking={self.enable_thinking}) - Start processing")
49034893

49044894
# Use parent implementation
49054895
return super().__call__(**kwargs)

0 commit comments

Comments
 (0)