mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-07-19 01:23:20 +02:00
Improve reasoning detection (#4817)
* Improve reasoning detection * Address greptile comments * Fix mypy
This commit is contained in:
@ -264,7 +264,7 @@ class DefaultMultiLLM(LLM):
|
|||||||
):
|
):
|
||||||
self._timeout = timeout
|
self._timeout = timeout
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
if model_is_reasoning_model(model_name):
|
if model_is_reasoning_model(model_name, model_provider):
|
||||||
self._timeout = QA_TIMEOUT * 10 # Reasoning models are slow
|
self._timeout = QA_TIMEOUT * 10 # Reasoning models are slow
|
||||||
else:
|
else:
|
||||||
self._timeout = QA_TIMEOUT
|
self._timeout = QA_TIMEOUT
|
||||||
|
@ -663,12 +663,34 @@ def model_supports_image_input(model_name: str, model_provider: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def model_is_reasoning_model(model_name: str) -> bool:
|
def model_is_reasoning_model(model_name: str, model_provider: str) -> bool:
|
||||||
_REASONING_MODEL_NAMES = [
|
model_map = get_model_map()
|
||||||
"o1",
|
try:
|
||||||
"o1-mini",
|
model_obj = find_model_obj(
|
||||||
"o3-mini",
|
model_map,
|
||||||
"deepseek-reasoner",
|
model_provider,
|
||||||
"deepseek-r1",
|
model_name,
|
||||||
]
|
)
|
||||||
return model_name.lower() in _REASONING_MODEL_NAMES
|
if model_obj and "supports_reasoning" in model_obj:
|
||||||
|
return model_obj["supports_reasoning"]
|
||||||
|
|
||||||
|
# Fallback: try using litellm.supports_reasoning() for newer models
|
||||||
|
try:
|
||||||
|
logger.debug("Falling back to `litellm.supports_reasoning`")
|
||||||
|
full_model_name = (
|
||||||
|
f"{model_provider}/{model_name}"
|
||||||
|
if model_provider not in model_name
|
||||||
|
else model_name
|
||||||
|
)
|
||||||
|
return litellm.supports_reasoning(model=full_model_name)
|
||||||
|
except Exception:
|
||||||
|
logger.exception(
|
||||||
|
f"Failed to check if {model_provider}/{model_name} supports reasoning"
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
logger.exception(
|
||||||
|
f"Failed to get model object for {model_provider}/{model_name}"
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
33
backend/tests/unit/onyx/llm/test_model_is_reasoning.py
Normal file
33
backend/tests/unit/onyx/llm/test_model_is_reasoning.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
from onyx.llm.utils import model_is_reasoning_model
|
||||||
|
|
||||||
|
|
||||||
|
def test_model_is_reasoning_model() -> None:
|
||||||
|
"""Test that reasoning models are correctly identified and non-reasoning models are not"""
|
||||||
|
|
||||||
|
# Models that should be identified as reasoning models
|
||||||
|
reasoning_models = [
|
||||||
|
("o3", "openai"),
|
||||||
|
("o3-mini", "openai"),
|
||||||
|
("o4-mini", "openai"),
|
||||||
|
("deepseek-reasoner", "deepseek"),
|
||||||
|
("deepseek-r1", "openrouter/deepseek"),
|
||||||
|
("claude-sonnet-4-20250514", "anthropic"),
|
||||||
|
]
|
||||||
|
|
||||||
|
# Models that should NOT be identified as reasoning models
|
||||||
|
non_reasoning_models = [
|
||||||
|
("gpt-4o", "openai"),
|
||||||
|
("claude-3-5-sonnet-20240620", "anthropic"),
|
||||||
|
]
|
||||||
|
|
||||||
|
# Test reasoning models
|
||||||
|
for model_name, provider in reasoning_models:
|
||||||
|
assert (
|
||||||
|
model_is_reasoning_model(model_name, provider) is True
|
||||||
|
), f"Expected {provider}/{model_name} to be identified as a reasoning model"
|
||||||
|
|
||||||
|
# Test non-reasoning models
|
||||||
|
for model_name, provider in non_reasoning_models:
|
||||||
|
assert (
|
||||||
|
model_is_reasoning_model(model_name, provider) is False
|
||||||
|
), f"Expected {provider}/{model_name} to NOT be identified as a reasoning model"
|
Reference in New Issue
Block a user