feat: Update field types in prompt and formatter modules

This commit updates the field types in the `prompt.py` and `formatter/base.py` modules. The `DefaultPromptField` class in `prompt.py` now inherits from `InputField` instead of `TemplateField`. Similarly, the `format` method in the `FieldFormatter` class in `formatter/base.py` now accepts an `InputField` parameter instead of a `TemplateField` parameter. These changes ensure consistency and improve the accuracy of the code.
This commit is contained in:
ogabrielluiz 2024-05-30 16:46:45 -03:00
commit 5c818f0b60
22 changed files with 1275 additions and 371 deletions

View file

@ -1,7 +1,7 @@
import random
from langflow.custom import CustomComponent
from langflow.field_typing import TemplateField
from langflow.field_typing import InputField
class TestComponent(CustomComponent):
@ -11,7 +11,7 @@ class TestComponent(CustomComponent):
return [f"Random {random.randint(1, 100)}" for _ in range(5)]
def build_config(self):
return {"param": TemplateField(display_name="Param", options=self.refresh_values)}
return {"param": InputField(display_name="Param", options=self.refresh_values)}
def build(self, param: int):
return param

View file

@ -1,16 +1,17 @@
import pytest
from langflow.template.field.base import TemplateField
from langflow.template.field.base import InputField
from langflow.template.frontend_node.base import FrontendNode
from langflow.template.template.base import Template
@pytest.fixture
def sample_template_field() -> TemplateField:
return TemplateField(name="test_field", field_type="str")
def sample_template_field() -> InputField:
return InputField(name="test_field", field_type="str")
@pytest.fixture
def sample_template(sample_template_field: TemplateField) -> Template:
def sample_template(sample_template_field: InputField) -> Template:
return Template(type_name="test_template", fields=[sample_template_field])
@ -24,7 +25,7 @@ def sample_frontend_node(sample_template: Template) -> FrontendNode:
)
def test_template_field_defaults(sample_template_field: TemplateField):
def test_template_field_defaults(sample_template_field: InputField):
assert sample_template_field.field_type == "str"
assert sample_template_field.required is False
assert sample_template_field.placeholder == ""
@ -38,7 +39,7 @@ def test_template_field_defaults(sample_template_field: TemplateField):
assert sample_template_field.name == "test_field"
def test_template_to_dict(sample_template: Template, sample_template_field: TemplateField):
def test_template_to_dict(sample_template: Template, sample_template_field: InputField):
template_dict = sample_template.to_dict()
assert template_dict["_type"] == "test_template"
assert len(template_dict) == 2 # _type and test_field