-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix component as a tool #4166
fix component as a tool #4166
Conversation
src/backend/base/langflow/custom/custom_component/custom_component.py
Outdated
Show resolved
Hide resolved
self._previous_value = self.value | ||
return self | ||
|
||
def __deepcopy__(self, memo): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why this was necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deepcopy was creating issues due to recursion.
Hence overriding that to prevent that issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems potentially very risky, regarding mutable attributes. You're only copying mutable attributes from the BoolInput
. However, BaseInputMixin
(and the others) also contain mutable attributes.
Future devs that add mutable attributes to these mixins won't know that they need to also update BoolInput
, else they risk sharing state between instances.
Let's sync up later and see if there are any alternatives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a fix for deepcopy (it was missing passing memo
to the inner deepcopy calls). It is in main already.
4458645
to
05b48d0
Compare
@@ -71,7 +72,9 @@ def ensure_url(self, string: str) -> str: | |||
return string | |||
|
|||
def fetch_content(self) -> list[Data]: | |||
urls = [self.ensure_url(url.strip()) for url in self.urls if url.strip()] | |||
# check if the urls are list or not | |||
urls_list = [self.urls] if isinstance(self.urls, str) else self.urls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If self.urls
is None
, does the below behavior still work? Or do we need to add an explicit None
check and return an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Jordan. I'd say a check could be useful to catch unexpected errors. This should never happen but will help us avoid regression.
@@ -17,6 +17,7 @@ | |||
from langflow.helpers.custom import format_type | |||
from langflow.schema.artifact import get_artifact_type, post_process_raw | |||
from langflow.schema.data import Data | |||
from langflow.schema.dotdict import dotdict # noqa: TCH001 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you run into an issue putting this in a TYPE_CHECKING
block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to typechecking block
self._previous_value = self.value | ||
return self | ||
|
||
def __deepcopy__(self, memo): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems potentially very risky, regarding mutable attributes. You're only copying mutable attributes from the BoolInput
. However, BaseInputMixin
(and the others) also contain mutable attributes.
Future devs that add mutable attributes to these mixins won't know that they need to also update BoolInput
, else they risk sharing state between instances.
Let's sync up later and see if there are any alternatives.
self._previous_value = self.value | ||
return self | ||
|
||
def __deepcopy__(self, memo): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a fix for deepcopy (it was missing passing memo
to the inner deepcopy calls). It is in main already.
@@ -71,7 +72,9 @@ def ensure_url(self, string: str) -> str: | |||
return string | |||
|
|||
def fetch_content(self) -> list[Data]: | |||
urls = [self.ensure_url(url.strip()) for url in self.urls if url.strip()] | |||
# check if the urls are list or not | |||
urls_list = [self.urls] if isinstance(self.urls, str) else self.urls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Jordan. I'd say a check could be useful to catch unexpected errors. This should never happen but will help us avoid regression.
added class variable is_tool that enable the component to be tool. added basic bool input to turn on/off as tool. TOdO to solve But the toggle doesnt update is_tool as true or changes the output.
…efinition - Changed the definition of 'value' to use Field for default value assignment. - Updated 'onChange' to use Field with exclude and repr options. - Ensured that the model configuration allows for assignment validation and arbitrary types. - Added a model validator to check for value changes and trigger the onChange callback.
Tool calling agent may provide a URL component with text data instead of list data. Hence, this is being fixed.
shall update once the Dynamic function is available and utilise the build config to make the update.
2d62b1a
to
61bc7ef
Compare
moved todict to type checking block
This PR is Set to draft: |
added class variable is_tool that enable the component to be tool. added basic bool input to turn on/off as tool.
TODO to solve But the toggle doesnt update is_tool as true or changes the output.