mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-08-10 08:21:54 +00:00
fix: avoid double-prefixing instructor model strings
With LiteLLM models now carrying a real `provider` while `model` keeps its `provider/name` form, `InternalInstructor` was building `groq/groq/...` for `instructor.from_provider`. Skip the prefix when the model string is already qualified.
This commit is contained in:
@@ -105,7 +105,12 @@ class InternalInstructor(Generic[T]):
|
||||
if value is not None:
|
||||
extra_kwargs[attr] = value
|
||||
|
||||
return instructor.from_provider(f"{provider}/{model_string}", **extra_kwargs)
|
||||
qualified_model = (
|
||||
model_string
|
||||
if not provider or model_string.startswith(f"{provider}/")
|
||||
else f"{provider}/{model_string}"
|
||||
)
|
||||
return instructor.from_provider(qualified_model, **extra_kwargs)
|
||||
|
||||
def _extract_provider(self) -> str:
|
||||
"""Extract provider from LLM model name.
|
||||
|
||||
@@ -1004,3 +1004,21 @@ def test_internal_instructor_omits_unset_base_url_and_api_key() -> None:
|
||||
InternalInstructor(content="x", model=SimpleModel, llm=mock_llm)
|
||||
|
||||
mock_from_provider.assert_called_once_with("openai/gpt-4o")
|
||||
|
||||
|
||||
def test_internal_instructor_does_not_double_prefix_qualified_models() -> None:
|
||||
from crewai.utilities.internal_instructor import InternalInstructor
|
||||
|
||||
mock_llm = Mock()
|
||||
mock_llm.is_litellm = False
|
||||
mock_llm.model = "groq/llama-3.3-70b"
|
||||
mock_llm.provider = "groq"
|
||||
mock_llm.base_url = None
|
||||
mock_llm.api_key = None
|
||||
|
||||
with patch("instructor.from_provider") as mock_from_provider:
|
||||
mock_from_provider.return_value = Mock()
|
||||
|
||||
InternalInstructor(content="x", model=SimpleModel, llm=mock_llm)
|
||||
|
||||
mock_from_provider.assert_called_once_with("groq/llama-3.3-70b")
|
||||
|
||||
Reference in New Issue
Block a user