feat: add is_active flag to model providers and update provider filtering (#8588)
* update model constants * [autofix.ci] apply automated fixes * update model input constants to reuse the filtered data * Update test_agent_component.py * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
aeebbd3bfc
commit
f4bbfd030b
18 changed files with 48 additions and 114 deletions
|
|
@ -19,6 +19,7 @@ class ModelProvidersDict(TypedDict):
|
|||
prefix: str
|
||||
component_class: LCModelComponent
|
||||
icon: str
|
||||
is_active: bool
|
||||
|
||||
|
||||
def get_filtered_inputs(component_class):
|
||||
|
|
@ -186,6 +187,7 @@ try:
|
|||
"prefix": "",
|
||||
"component_class": OpenAIModelComponent(),
|
||||
"icon": OpenAIModelComponent.icon,
|
||||
"is_active": True,
|
||||
}
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
@ -198,6 +200,7 @@ try:
|
|||
"prefix": "",
|
||||
"component_class": AzureChatOpenAIComponent(),
|
||||
"icon": AzureChatOpenAIComponent.icon,
|
||||
"is_active": False,
|
||||
}
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
@ -210,6 +213,7 @@ try:
|
|||
"prefix": "",
|
||||
"component_class": GroqModel(),
|
||||
"icon": GroqModel.icon,
|
||||
"is_active": True,
|
||||
}
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
@ -222,6 +226,7 @@ try:
|
|||
"prefix": "",
|
||||
"component_class": AnthropicModelComponent(),
|
||||
"icon": AnthropicModelComponent.icon,
|
||||
"is_active": True,
|
||||
}
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
@ -234,6 +239,7 @@ try:
|
|||
"prefix": "",
|
||||
"component_class": NVIDIAModelComponent(),
|
||||
"icon": NVIDIAModelComponent.icon,
|
||||
"is_active": False,
|
||||
}
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
@ -246,6 +252,7 @@ try:
|
|||
"prefix": "",
|
||||
"component_class": AmazonBedrockComponent(),
|
||||
"icon": AmazonBedrockComponent.icon,
|
||||
"is_active": False,
|
||||
}
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
@ -258,6 +265,7 @@ try:
|
|||
"prefix": "",
|
||||
"component_class": GoogleGenerativeAIComponent(),
|
||||
"icon": GoogleGenerativeAIComponent.icon,
|
||||
"is_active": True,
|
||||
}
|
||||
except ImportError:
|
||||
pass
|
||||
|
|
@ -270,17 +278,20 @@ try:
|
|||
"prefix": "",
|
||||
"component_class": SambaNovaComponent(),
|
||||
"icon": SambaNovaComponent.icon,
|
||||
"is_active": False,
|
||||
}
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
MODEL_PROVIDERS = list(MODEL_PROVIDERS_DICT.keys())
|
||||
ALL_PROVIDER_FIELDS: list[str] = [field for provider in MODEL_PROVIDERS_DICT.values() for field in provider["fields"]]
|
||||
# Expose only active providers ----------------------------------------------
|
||||
ACTIVE_MODEL_PROVIDERS_DICT: dict[str, ModelProvidersDict] = {
|
||||
name: prov for name, prov in MODEL_PROVIDERS_DICT.items() if prov.get("is_active", True)
|
||||
}
|
||||
|
||||
MODEL_PROVIDERS: list[str] = list(ACTIVE_MODEL_PROVIDERS_DICT.keys())
|
||||
|
||||
ALL_PROVIDER_FIELDS: list[str] = [field for prov in ACTIVE_MODEL_PROVIDERS_DICT.values() for field in prov["fields"]]
|
||||
|
||||
MODEL_DYNAMIC_UPDATE_FIELDS = ["api_key", "model", "tool_model_enabled", "base_url", "model_name"]
|
||||
|
||||
|
||||
MODELS_METADATA = {
|
||||
key: {"icon": MODEL_PROVIDERS_DICT[key]["icon"] if key in MODEL_PROVIDERS_DICT else None}
|
||||
for key in MODEL_PROVIDERS_DICT
|
||||
}
|
||||
MODELS_METADATA = {name: {"icon": prov["icon"]} for name, prov in ACTIVE_MODEL_PROVIDERS_DICT.items()}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from langflow.base.agents.events import ExceptionWithMessageError
|
|||
from langflow.base.models.model_input_constants import (
|
||||
ALL_PROVIDER_FIELDS,
|
||||
MODEL_DYNAMIC_UPDATE_FIELDS,
|
||||
MODEL_PROVIDERS,
|
||||
MODEL_PROVIDERS_DICT,
|
||||
MODELS_METADATA,
|
||||
)
|
||||
|
|
@ -40,11 +41,11 @@ class AgentComponent(ToolCallingAgentComponent):
|
|||
name="agent_llm",
|
||||
display_name="Model Provider",
|
||||
info="The provider of the language model that the agent will use to generate responses.",
|
||||
options=[*sorted(MODEL_PROVIDERS_DICT.keys()), "Custom"],
|
||||
options=[*sorted(MODEL_PROVIDERS), "Custom"],
|
||||
value="OpenAI",
|
||||
real_time_refresh=True,
|
||||
input_types=[],
|
||||
options_metadata=[MODELS_METADATA[key] for key in sorted(MODELS_METADATA.keys())] + [{"icon": "brain"}],
|
||||
options_metadata=[MODELS_METADATA[key] for key in sorted(MODEL_PROVIDERS)] + [{"icon": "brain"}],
|
||||
),
|
||||
*MODEL_PROVIDERS_DICT["OpenAI"]["inputs"],
|
||||
MultilineInput(
|
||||
|
|
@ -221,7 +222,7 @@ class AgentComponent(ToolCallingAgentComponent):
|
|||
custom_component = DropdownInput(
|
||||
name="agent_llm",
|
||||
display_name="Language Model",
|
||||
options=[*sorted(MODEL_PROVIDERS_DICT.keys()), "Custom"],
|
||||
options=[*sorted(MODEL_PROVIDERS), "Custom"],
|
||||
value="Custom",
|
||||
real_time_refresh=True,
|
||||
input_types=["LanguageModel"],
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -4,7 +4,9 @@ from uuid import uuid4
|
|||
|
||||
import pytest
|
||||
from langflow.base.models.anthropic_constants import ANTHROPIC_MODELS
|
||||
from langflow.base.models.model_input_constants import MODEL_PROVIDERS_DICT
|
||||
from langflow.base.models.model_input_constants import (
|
||||
MODEL_PROVIDERS,
|
||||
)
|
||||
from langflow.base.models.openai_constants import (
|
||||
OPENAI_MODEL_NAMES,
|
||||
OPENAI_REASONING_MODEL_NAMES,
|
||||
|
|
@ -64,7 +66,7 @@ class TestAgentComponent(ComponentTestBaseWithoutClient):
|
|||
assert updated_config["agent_llm"]["value"] == "OpenAI"
|
||||
assert isinstance(updated_config["agent_llm"]["options"], list)
|
||||
assert len(updated_config["agent_llm"]["options"]) > 0
|
||||
assert all(provider in updated_config["agent_llm"]["options"] for provider in MODEL_PROVIDERS_DICT)
|
||||
assert all(provider in updated_config["agent_llm"]["options"] for provider in MODEL_PROVIDERS)
|
||||
assert "Custom" in updated_config["agent_llm"]["options"]
|
||||
|
||||
# Verify model_name field is populated for OpenAI
|
||||
|
|
@ -82,7 +84,7 @@ class TestAgentComponent(ComponentTestBaseWithoutClient):
|
|||
assert updated_config["agent_llm"]["value"] == "Anthropic"
|
||||
assert isinstance(updated_config["agent_llm"]["options"], list)
|
||||
assert len(updated_config["agent_llm"]["options"]) > 0
|
||||
assert all(provider in updated_config["agent_llm"]["options"] for provider in MODEL_PROVIDERS_DICT)
|
||||
assert all(provider in updated_config["agent_llm"]["options"] for provider in MODEL_PROVIDERS)
|
||||
assert "Anthropic" in updated_config["agent_llm"]["options"]
|
||||
assert updated_config["agent_llm"]["input_types"] == []
|
||||
options = updated_config["model_name"]["options"]
|
||||
|
|
@ -94,7 +96,7 @@ class TestAgentComponent(ComponentTestBaseWithoutClient):
|
|||
assert updated_config["agent_llm"]["value"] == "Custom"
|
||||
assert isinstance(updated_config["agent_llm"]["options"], list)
|
||||
assert len(updated_config["agent_llm"]["options"]) > 0
|
||||
assert all(provider in updated_config["agent_llm"]["options"] for provider in MODEL_PROVIDERS_DICT)
|
||||
assert all(provider in updated_config["agent_llm"]["options"] for provider in MODEL_PROVIDERS)
|
||||
assert "Custom" in updated_config["agent_llm"]["options"]
|
||||
assert updated_config["agent_llm"]["input_types"] == ["LanguageModel"]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue