diff --git a/src/backend/base/langflow/base/agents/crewai/crew.py b/src/backend/base/langflow/base/agents/crewai/crew.py index 29bd1fc7f..7e97ce534 100644 --- a/src/backend/base/langflow/base/agents/crewai/crew.py +++ b/src/backend/base/langflow/base/agents/crewai/crew.py @@ -62,11 +62,13 @@ def convert_llm(llm: Any, excluded_keys=None) -> LLM: if isinstance(llm, LLM): return llm - # Check if we should use model_name or model - if hasattr(llm, "model_name"): + # Check if we should use model_name model, or something else + if hasattr(llm, "model_name") and llm.model_name: model_name = llm.model_name - elif hasattr(llm, "model"): + elif hasattr(llm, "model") and llm.model: model_name = llm.model + elif hasattr(llm, "deployment_name") and llm.deployment_name: + model_name = llm.deployment_name else: msg = "Could not find model name in the LLM object" raise ValueError(msg) @@ -74,13 +76,17 @@ def convert_llm(llm: Any, excluded_keys=None) -> LLM: # Normalize to the LLM model name # Remove langchain_ prefix if present provider = llm.get_lc_namespace()[0] + api_base = None if provider.startswith("langchain_"): provider = provider[10:] model_name = f"{provider}/{model_name}" + elif hasattr(llm, "azure_endpoint"): + api_base = llm.azure_endpoint + model_name = f"azure/{model_name}" # Retrieve the API Key from the LLM if excluded_keys is None: - excluded_keys = {"model", "model_name", "_type", "api_key"} + excluded_keys = {"model", "model_name", "_type", "api_key", "azure_deployment"} # Find the API key in the LLM api_key = _find_api_key(llm) @@ -89,6 +95,7 @@ def convert_llm(llm: Any, excluded_keys=None) -> LLM: return LLM( model=model_name, api_key=api_key, + api_base=api_base, **{k: v for k, v in llm.dict().items() if k not in excluded_keys}, )