mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-24 01:22:23 +08:00
refactor: Standardize model name extraction with helper function and tests (#11352)
* add valitador to agent model * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) * [autofix.ci] apply automated fixes (attempt 3/3) * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
b89bd76e22
commit
ed675ea478
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
File diff suppressed because one or more lines are too long
@ -1226,7 +1226,7 @@
|
||||
},
|
||||
"Agent": {
|
||||
"versions": {
|
||||
"0.3.0": "bdc309bc2d2a"
|
||||
"0.3.0": "b60d28d2784f"
|
||||
}
|
||||
},
|
||||
"EmbeddingModel": {
|
||||
|
||||
@ -1,6 +1,17 @@
|
||||
from lfx.custom.custom_component.component import Component
|
||||
|
||||
|
||||
def _extract_model_name(value):
|
||||
"""Extract model name from ModelInput format (list of dicts with 'name' key)."""
|
||||
if isinstance(value, str):
|
||||
return value
|
||||
if isinstance(value, list) and value and isinstance(value[0], dict):
|
||||
return value[0].get("name")
|
||||
if isinstance(value, dict):
|
||||
return value.get("name")
|
||||
return None
|
||||
|
||||
|
||||
class ChatComponent(Component):
|
||||
display_name = "Chat Component"
|
||||
description = "Use as base for chat components."
|
||||
@ -15,7 +26,11 @@ class ChatComponent(Component):
|
||||
icon = component.icon
|
||||
possible_attributes = ["model_name", "model_id", "model"]
|
||||
for attribute in possible_attributes:
|
||||
if hasattr(component, attribute) and getattr(component, attribute):
|
||||
return getattr(component, attribute), icon, source, component.get_id()
|
||||
if hasattr(component, attribute):
|
||||
attr_value = getattr(component, attribute)
|
||||
if attr_value:
|
||||
model_name = _extract_model_name(attr_value)
|
||||
if model_name:
|
||||
return model_name, icon, source, component.get_id()
|
||||
return source, icon, component.display_name, component.get_id()
|
||||
return None, None, None, None
|
||||
|
||||
@ -451,7 +451,6 @@ class AgentComponent(ToolCallingAgentComponent):
|
||||
|
||||
# Iterate over all providers in the MODEL_PROVIDERS_DICT
|
||||
if field_name == "model":
|
||||
self.log(str(field_value))
|
||||
# Update input types for all fields
|
||||
build_config = self.update_input_types(build_config)
|
||||
|
||||
|
||||
0
src/lfx/tests/unit/base/io/__init__.py
Normal file
0
src/lfx/tests/unit/base/io/__init__.py
Normal file
29
src/lfx/tests/unit/base/io/test_chat.py
Normal file
29
src/lfx/tests/unit/base/io/test_chat.py
Normal file
@ -0,0 +1,29 @@
|
||||
from lfx.base.io.chat import _extract_model_name
|
||||
|
||||
|
||||
class TestExtractModelName:
|
||||
def test_should_return_string_when_input_is_string(self):
|
||||
assert _extract_model_name("gpt-4o-mini") == "gpt-4o-mini"
|
||||
|
||||
def test_should_return_name_when_input_is_model_input_list(self):
|
||||
model_input = [{"name": "gpt-4o-mini", "icon": "OpenAI", "provider": "OpenAI"}]
|
||||
assert _extract_model_name(model_input) == "gpt-4o-mini"
|
||||
|
||||
def test_should_return_name_when_input_is_dict(self):
|
||||
model_dict = {"name": "claude-3", "provider": "Anthropic"}
|
||||
assert _extract_model_name(model_dict) == "claude-3"
|
||||
|
||||
def test_should_return_none_when_input_is_empty_list(self):
|
||||
assert _extract_model_name([]) is None
|
||||
|
||||
def test_should_return_none_when_input_is_none(self):
|
||||
assert _extract_model_name(None) is None
|
||||
|
||||
def test_should_return_none_when_list_has_no_name_key(self):
|
||||
assert _extract_model_name([{"provider": "OpenAI"}]) is None
|
||||
|
||||
def test_should_return_none_when_dict_has_no_name_key(self):
|
||||
assert _extract_model_name({"provider": "OpenAI"}) is None
|
||||
|
||||
def test_should_return_none_when_input_is_integer(self):
|
||||
assert _extract_model_name(123) is None
|
||||
Reference in New Issue
Block a user