mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-22 06:18:14 +00:00
Fix langchain-google-genai integration by stripping 'models/' prefix
Fixes #3702 When using langchain-google-genai with CrewAI, the model name would include a 'models/' prefix (e.g., 'models/gemini/gemini-pro') which is added by Google's API internally. However, LiteLLM does not recognize this format, causing a 'LLM Provider NOT provided' error. This fix strips the 'models/' prefix from model names when extracting them from langchain model objects, ensuring compatibility with LiteLLM while maintaining backward compatibility with models that don't have this prefix. Changes: - Modified create_llm() in llm_utils.py to strip 'models/' prefix - Added comprehensive tests covering various scenarios: - Model with 'models/' prefix in model attribute - Model with 'models/' prefix in model_name attribute - Model without prefix (no change) - Case-sensitive prefix handling (only lowercase 'models/' is stripped) Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -41,6 +41,10 @@ def create_llm(
|
||||
or getattr(llm_value, "deployment_name", None)
|
||||
or str(llm_value)
|
||||
)
|
||||
|
||||
if isinstance(model, str) and model.startswith("models/"):
|
||||
model = model[len("models/"):]
|
||||
|
||||
temperature: float | None = getattr(llm_value, "temperature", None)
|
||||
max_tokens: int | None = getattr(llm_value, "max_tokens", None)
|
||||
logprobs: int | None = getattr(llm_value, "logprobs", None)
|
||||
|
||||
Reference in New Issue
Block a user