mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 13:25:11 +00:00
Support Minimax M2. Extract its thinking from response
- Use qwen style <think> tags to extract Minimax M2 model thoughts - Use function to mark models that use in-stream thinking (including Kimi K2 thinking)
This commit is contained in:
@@ -142,7 +142,7 @@ def completion_with_backoff(
|
|||||||
else:
|
else:
|
||||||
updated_messages.append(message)
|
updated_messages.append(message)
|
||||||
formatted_messages = updated_messages
|
formatted_messages = updated_messages
|
||||||
elif "kimi-k2-thinking" in model_name.lower():
|
elif is_instream_thinking_model(model_name):
|
||||||
stream_processor = in_stream_thought_processor
|
stream_processor = in_stream_thought_processor
|
||||||
elif is_qwen_style_reasoning_model(model_name, api_base_url):
|
elif is_qwen_style_reasoning_model(model_name, api_base_url):
|
||||||
stream_processor = in_stream_thought_processor
|
stream_processor = in_stream_thought_processor
|
||||||
@@ -343,7 +343,7 @@ async def chat_completion_with_backoff(
|
|||||||
else:
|
else:
|
||||||
updated_messages.append(message)
|
updated_messages.append(message)
|
||||||
formatted_messages = updated_messages
|
formatted_messages = updated_messages
|
||||||
elif "kimi-k2-thinking" in model_name.lower():
|
elif is_instream_thinking_model(model_name):
|
||||||
stream_processor = ain_stream_thought_processor
|
stream_processor = ain_stream_thought_processor
|
||||||
elif is_qwen_style_reasoning_model(model_name, api_base_url):
|
elif is_qwen_style_reasoning_model(model_name, api_base_url):
|
||||||
stream_processor = ain_stream_thought_processor
|
stream_processor = ain_stream_thought_processor
|
||||||
@@ -909,6 +909,14 @@ def is_groq_api(api_base_url: str | None = None) -> bool:
|
|||||||
return api_base_url is not None and api_base_url.startswith("https://api.groq.com")
|
return api_base_url is not None and api_base_url.startswith("https://api.groq.com")
|
||||||
|
|
||||||
|
|
||||||
|
def is_instream_thinking_model(model_name: str) -> bool:
|
||||||
|
"""
|
||||||
|
Check if the model uses in-stream thinking style, i.e., <think>...</think> in output
|
||||||
|
"""
|
||||||
|
instream_thinking_model = ["kimi-k2-thinking", "minimax-m2"]
|
||||||
|
return any(prefix in model_name.lower() for prefix in instream_thinking_model)
|
||||||
|
|
||||||
|
|
||||||
def is_qwen_style_reasoning_model(model_name: str, api_base_url: str | None = None) -> bool:
|
def is_qwen_style_reasoning_model(model_name: str, api_base_url: str | None = None) -> bool:
|
||||||
"""
|
"""
|
||||||
Check if the model is a Qwen style reasoning model
|
Check if the model is a Qwen style reasoning model
|
||||||
|
|||||||
Reference in New Issue
Block a user