refactor: Update output names in TextInput, TextOutput, RecordsOutput, ChatInput, and ChatOutput
The output names in the TextInput, TextOutput, RecordsOutput, ChatInput, and ChatOutput components have been updated to use more descriptive names. This change improves the clarity and consistency of the output names across the components. Note: The commit message has been generated based on the provided code changes and recent commits.
This commit is contained in:
parent
41b0660dfd
commit
5121fb10e5
10 changed files with 32 additions and 18 deletions
|
|
@ -43,8 +43,8 @@ class TextOperatorComponent(Component):
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
outputs = [
|
outputs = [
|
||||||
Output(name="True Result", method="result_response"),
|
Output(display_name="True Result", name="true_result", method="result_response"),
|
||||||
Output(name="False Result", method="result_response"),
|
Output(display_name="False Result", name="false_result", method="result_response"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def true_response(self) -> Union[Text, Record]:
|
def true_response(self) -> Union[Text, Record]:
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,8 @@ class ChatInput(ChatComponent):
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
outputs = [
|
outputs = [
|
||||||
Output(name="Message", method="text_response"),
|
Output(display_name="Message", name="message", method="text_response"),
|
||||||
Output(name="Record", method="record_response"),
|
Output(display_name="Record", name="record", method="record_response"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def text_response(self) -> Text:
|
def text_response(self) -> Text:
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ class TextInput(TextComponent):
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
outputs = [
|
outputs = [
|
||||||
Output(name="Text", method="text_response"),
|
Output(display_name="Text", name="text", method="text_response"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def text_response(self) -> Text:
|
def text_response(self) -> Text:
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,8 @@ class ChatOutput(ChatComponent):
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
outputs = [
|
outputs = [
|
||||||
Output(name="Message", method="text_response"),
|
Output(display_name="Message", name="message", method="text_response"),
|
||||||
Output(name="Record", method="record_response"),
|
Output(display_name="Record", name="record", method="record_response"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def text_response(self) -> Text:
|
def text_response(self) -> Text:
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ class RecordsOutput(Component):
|
||||||
Input(name="input_value", type=Record, display_name="Record Input"),
|
Input(name="input_value", type=Record, display_name="Record Input"),
|
||||||
]
|
]
|
||||||
outputs = [
|
outputs = [
|
||||||
Output(name="Record", method="record_response"),
|
Output(display_name="Record", name="record", method="record_response"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def record_response(self) -> Record:
|
def record_response(self) -> Record:
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ class TextOutput(TextComponent):
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
outputs = [
|
outputs = [
|
||||||
Output(name="Text", method="text_response"),
|
Output(display_name="Text", name="text", method="text_response"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def text_response(self) -> Text:
|
def text_response(self) -> Text:
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,8 @@ class Component(CustomComponent):
|
||||||
|
|
||||||
def _set_outputs(self, outputs: List[dict]):
|
def _set_outputs(self, outputs: List[dict]):
|
||||||
self.outputs = [Output(**output) for output in outputs]
|
self.outputs = [Output(**output) for output in outputs]
|
||||||
|
for output in self.outputs:
|
||||||
|
setattr(self, output.name, output)
|
||||||
|
|
||||||
async def build_results(self, vertex: "Vertex"):
|
async def build_results(self, vertex: "Vertex"):
|
||||||
_results = {}
|
_results = {}
|
||||||
|
|
@ -69,14 +71,13 @@ class Component(CustomComponent):
|
||||||
for output in self.outputs:
|
for output in self.outputs:
|
||||||
# Build the output if it's connected to some other vertex
|
# Build the output if it's connected to some other vertex
|
||||||
# or if it's not connected to any vertex
|
# or if it's not connected to any vertex
|
||||||
self.output = output
|
if not vertex.outgoing_edges or output.display_name in vertex.edges_source_names:
|
||||||
if not vertex.outgoing_edges or output.name in vertex.edges_source_names:
|
|
||||||
method: Callable | Awaitable = getattr(self, output.method)
|
method: Callable | Awaitable = getattr(self, output.method)
|
||||||
result = method()
|
result = method()
|
||||||
# If the method is asynchronous, we need to await it
|
# If the method is asynchronous, we need to await it
|
||||||
if inspect.iscoroutinefunction(method):
|
if inspect.iscoroutinefunction(method):
|
||||||
result = await result
|
result = await result
|
||||||
_results[output.name] = result
|
_results[output.display_name] = result
|
||||||
self._results = _results
|
self._results = _results
|
||||||
return _results
|
return _results
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,10 @@ class Output(BaseModel):
|
||||||
selected: Optional[str] = Field(default=None, serialization_alias="selected")
|
selected: Optional[str] = Field(default=None, serialization_alias="selected")
|
||||||
"""The selected output type for the field."""
|
"""The selected output type for the field."""
|
||||||
|
|
||||||
name: str = Field(default="", serialization_alias="name")
|
display_name: Optional[str] = Field(default=None, serialization_alias="name")
|
||||||
|
"""The display name of the field."""
|
||||||
|
|
||||||
|
name: str = Field(default=None, serialization_alias="name")
|
||||||
"""The name of the field."""
|
"""The name of the field."""
|
||||||
|
|
||||||
method: Optional[str] = Field(default=None, serialization_alias="method")
|
method: Optional[str] = Field(default=None, serialization_alias="method")
|
||||||
|
|
@ -168,3 +171,12 @@ class Output(BaseModel):
|
||||||
def set_selected(self):
|
def set_selected(self):
|
||||||
if not self.selected:
|
if not self.selected:
|
||||||
self.selected = self.types[0]
|
self.selected = self.types[0]
|
||||||
|
|
||||||
|
@field_validator("display_name", mode="before")
|
||||||
|
def validate_display_name(cls, v, info):
|
||||||
|
if not v:
|
||||||
|
if info.data.get("name"):
|
||||||
|
return info.data["name"]
|
||||||
|
else:
|
||||||
|
raise ValueError("If display_name is not set, name must be set")
|
||||||
|
return v
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ class MultipleOutputsComponent(Component):
|
||||||
Input(display_name="Number", name="number", field_type=int),
|
Input(display_name="Number", name="number", field_type=int),
|
||||||
]
|
]
|
||||||
outputs = [
|
outputs = [
|
||||||
Output(name="Certain Output", method="certain_output"),
|
Output(display_name="Certain Output", name="certain_output", method="certain_output"),
|
||||||
Output(name="Other Output", method="other_output"),
|
Output(display_name="Other Output", name="other_output", method="other_output"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def certain_output(self) -> str:
|
def certain_output(self) -> str:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
from random import randint
|
||||||
|
|
||||||
from langflow.custom import Component
|
from langflow.custom import Component
|
||||||
from langflow.template.field.base import Input, Output
|
from langflow.template.field.base import Input, Output
|
||||||
from random import randint
|
|
||||||
|
|
||||||
|
|
||||||
class MultipleOutputsComponent(Component):
|
class MultipleOutputsComponent(Component):
|
||||||
|
|
@ -9,8 +10,8 @@ class MultipleOutputsComponent(Component):
|
||||||
Input(display_name="Number", name="number", field_type=int),
|
Input(display_name="Number", name="number", field_type=int),
|
||||||
]
|
]
|
||||||
outputs = [
|
outputs = [
|
||||||
Output(name="Certain Output", method="certain_output"),
|
Output(display_name="Certain Output", name="certain_output", method="certain_output"),
|
||||||
Output(name="Other Output", method="other_output"),
|
Output(display_name="Other Output", name="other_output", method="other_output"),
|
||||||
]
|
]
|
||||||
|
|
||||||
def certain_output(self) -> int:
|
def certain_output(self) -> int:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue