fix: Handle the special case Azure Deployment params (#5676)

* fix: Handle the special case Azure deployment params

* Update crew.py
This commit is contained in:
Eric Hare 2025-01-16 09:45:45 -08:00 • committed by GitHub
commit b2a3166a2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -62,11 +62,13 @@ def convert_llm(llm: Any, excluded_keys=None) -> LLM:
if isinstance(llm, LLM): if isinstance(llm, LLM):
return llm return llm
# Check if we should use model_name or model # Check if we should use model_name model, or something else
if hasattr(llm, "model_name"): if hasattr(llm, "model_name") and llm.model_name:
model_name = llm.model_name model_name = llm.model_name
elif hasattr(llm, "model"): elif hasattr(llm, "model") and llm.model:
model_name = llm.model model_name = llm.model
elif hasattr(llm, "deployment_name") and llm.deployment_name:
model_name = llm.deployment_name
else: else:
msg = "Could not find model name in the LLM object" msg = "Could not find model name in the LLM object"
raise ValueError(msg) raise ValueError(msg)
@ -74,13 +76,17 @@ def convert_llm(llm: Any, excluded_keys=None) -> LLM:
# Normalize to the LLM model name # Normalize to the LLM model name
# Remove langchain_ prefix if present # Remove langchain_ prefix if present
provider = llm.get_lc_namespace()[0] provider = llm.get_lc_namespace()[0]
api_base = None
if provider.startswith("langchain_"): if provider.startswith("langchain_"):
provider = provider[10:] provider = provider[10:]
model_name = f"{provider}/{model_name}" 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 # Retrieve the API Key from the LLM
if excluded_keys is None: 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 # Find the API key in the LLM
api_key = _find_api_key(llm) api_key = _find_api_key(llm)
@ -89,6 +95,7 @@ def convert_llm(llm: Any, excluded_keys=None) -> LLM:
return LLM( return LLM(
model=model_name, model=model_name,
api_key=api_key, api_key=api_key,
api_base=api_base,
**{k: v for k, v in llm.dict().items() if k not in excluded_keys}, **{k: v for k, v in llm.dict().items() if k not in excluded_keys},
) )