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:
Edwin Jose 2025-06-24 01:59:14 -05:00 • committed by GitHub
commit f4bbfd030b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 48 additions and 114 deletions

View file

@ -19,6 +19,7 @@ class ModelProvidersDict(TypedDict):
prefix: str prefix: str
component_class: LCModelComponent component_class: LCModelComponent
icon: str icon: str
is_active: bool
def get_filtered_inputs(component_class): def get_filtered_inputs(component_class):
@ -186,6 +187,7 @@ try:
"prefix": "", "prefix": "",
"component_class": OpenAIModelComponent(), "component_class": OpenAIModelComponent(),
"icon": OpenAIModelComponent.icon, "icon": OpenAIModelComponent.icon,
"is_active": True,
} }
except ImportError: except ImportError:
pass pass
@ -198,6 +200,7 @@ try:
"prefix": "", "prefix": "",
"component_class": AzureChatOpenAIComponent(), "component_class": AzureChatOpenAIComponent(),
"icon": AzureChatOpenAIComponent.icon, "icon": AzureChatOpenAIComponent.icon,
"is_active": False,
} }
except ImportError: except ImportError:
pass pass
@ -210,6 +213,7 @@ try:
"prefix": "", "prefix": "",
"component_class": GroqModel(), "component_class": GroqModel(),
"icon": GroqModel.icon, "icon": GroqModel.icon,
"is_active": True,
} }
except ImportError: except ImportError:
pass pass
@ -222,6 +226,7 @@ try:
"prefix": "", "prefix": "",
"component_class": AnthropicModelComponent(), "component_class": AnthropicModelComponent(),
"icon": AnthropicModelComponent.icon, "icon": AnthropicModelComponent.icon,
"is_active": True,
} }
except ImportError: except ImportError:
pass pass
@ -234,6 +239,7 @@ try:
"prefix": "", "prefix": "",
"component_class": NVIDIAModelComponent(), "component_class": NVIDIAModelComponent(),
"icon": NVIDIAModelComponent.icon, "icon": NVIDIAModelComponent.icon,
"is_active": False,
} }
except ImportError: except ImportError:
pass pass
@ -246,6 +252,7 @@ try:
"prefix": "", "prefix": "",
"component_class": AmazonBedrockComponent(), "component_class": AmazonBedrockComponent(),
"icon": AmazonBedrockComponent.icon, "icon": AmazonBedrockComponent.icon,
"is_active": False,
} }
except ImportError: except ImportError:
pass pass
@ -258,6 +265,7 @@ try:
"prefix": "", "prefix": "",
"component_class": GoogleGenerativeAIComponent(), "component_class": GoogleGenerativeAIComponent(),
"icon": GoogleGenerativeAIComponent.icon, "icon": GoogleGenerativeAIComponent.icon,
"is_active": True,
} }
except ImportError: except ImportError:
pass pass
@ -270,17 +278,20 @@ try:
"prefix": "", "prefix": "",
"component_class": SambaNovaComponent(), "component_class": SambaNovaComponent(),
"icon": SambaNovaComponent.icon, "icon": SambaNovaComponent.icon,
"is_active": False,
} }
except ImportError: except ImportError:
pass pass
MODEL_PROVIDERS = list(MODEL_PROVIDERS_DICT.keys()) # Expose only active providers ----------------------------------------------
ALL_PROVIDER_FIELDS: list[str] = [field for provider in MODEL_PROVIDERS_DICT.values() for field in provider["fields"]] 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"] MODEL_DYNAMIC_UPDATE_FIELDS = ["api_key", "model", "tool_model_enabled", "base_url", "model_name"]
MODELS_METADATA = {name: {"icon": prov["icon"]} for name, prov in ACTIVE_MODEL_PROVIDERS_DICT.items()}
MODELS_METADATA = {
key: {"icon": MODEL_PROVIDERS_DICT[key]["icon"] if key in MODEL_PROVIDERS_DICT else None}
for key in MODEL_PROVIDERS_DICT
}

View file

@ -5,6 +5,7 @@ from langflow.base.agents.events import ExceptionWithMessageError
from langflow.base.models.model_input_constants import ( from langflow.base.models.model_input_constants import (
ALL_PROVIDER_FIELDS, ALL_PROVIDER_FIELDS,
MODEL_DYNAMIC_UPDATE_FIELDS, MODEL_DYNAMIC_UPDATE_FIELDS,
MODEL_PROVIDERS,
MODEL_PROVIDERS_DICT, MODEL_PROVIDERS_DICT,
MODELS_METADATA, MODELS_METADATA,
) )
@ -40,11 +41,11 @@ class AgentComponent(ToolCallingAgentComponent):
name="agent_llm", name="agent_llm",
display_name="Model Provider", display_name="Model Provider",
info="The provider of the language model that the agent will use to generate responses.", 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", value="OpenAI",
real_time_refresh=True, real_time_refresh=True,
input_types=[], 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"], *MODEL_PROVIDERS_DICT["OpenAI"]["inputs"],
MultilineInput( MultilineInput(
@ -221,7 +222,7 @@ class AgentComponent(ToolCallingAgentComponent):
custom_component = DropdownInput( custom_component = DropdownInput(
name="agent_llm", name="agent_llm",
display_name="Language Model", display_name="Language Model",
options=[*sorted(MODEL_PROVIDERS_DICT.keys()), "Custom"], options=[*sorted(MODEL_PROVIDERS), "Custom"],
value="Custom", value="Custom",
real_time_refresh=True, real_time_refresh=True,
input_types=["LanguageModel"], 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

View file

@ -4,7 +4,9 @@ from uuid import uuid4
import pytest import pytest
from langflow.base.models.anthropic_constants import ANTHROPIC_MODELS 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 ( from langflow.base.models.openai_constants import (
OPENAI_MODEL_NAMES, OPENAI_MODEL_NAMES,
OPENAI_REASONING_MODEL_NAMES, OPENAI_REASONING_MODEL_NAMES,
@ -64,7 +66,7 @@ class TestAgentComponent(ComponentTestBaseWithoutClient):
assert updated_config["agent_llm"]["value"] == "OpenAI" assert updated_config["agent_llm"]["value"] == "OpenAI"
assert isinstance(updated_config["agent_llm"]["options"], list) assert isinstance(updated_config["agent_llm"]["options"], list)
assert len(updated_config["agent_llm"]["options"]) > 0 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 "Custom" in updated_config["agent_llm"]["options"]
# Verify model_name field is populated for OpenAI # Verify model_name field is populated for OpenAI
@ -82,7 +84,7 @@ class TestAgentComponent(ComponentTestBaseWithoutClient):
assert updated_config["agent_llm"]["value"] == "Anthropic" assert updated_config["agent_llm"]["value"] == "Anthropic"
assert isinstance(updated_config["agent_llm"]["options"], list) assert isinstance(updated_config["agent_llm"]["options"], list)
assert len(updated_config["agent_llm"]["options"]) > 0 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 "Anthropic" in updated_config["agent_llm"]["options"]
assert updated_config["agent_llm"]["input_types"] == [] assert updated_config["agent_llm"]["input_types"] == []
options = updated_config["model_name"]["options"] options = updated_config["model_name"]["options"]
@ -94,7 +96,7 @@ class TestAgentComponent(ComponentTestBaseWithoutClient):
assert updated_config["agent_llm"]["value"] == "Custom" assert updated_config["agent_llm"]["value"] == "Custom"
assert isinstance(updated_config["agent_llm"]["options"], list) assert isinstance(updated_config["agent_llm"]["options"], list)
assert len(updated_config["agent_llm"]["options"]) > 0 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 "Custom" in updated_config["agent_llm"]["options"]
assert updated_config["agent_llm"]["input_types"] == ["LanguageModel"] assert updated_config["agent_llm"]["input_types"] == ["LanguageModel"]