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:
parent
7dce8cd499
commit
b2a3166a2c
1 changed files with 11 additions and 4 deletions
|
|
@ -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},
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue