Update APIRequest and ExtractDataFromRecord components
This commit is contained in:
parent
f53a08ba7a
commit
0c153e659f
2 changed files with 36 additions and 5 deletions
|
|
@ -14,7 +14,7 @@ class APIRequest(CustomComponent):
|
|||
output_types: list[str] = ["Record"]
|
||||
documentation: str = "https://docs.langflow.org/components/utilities#api-request"
|
||||
field_config = {
|
||||
"url": {"display_name": "URL", "info": "The URL to make the request to."},
|
||||
"urls": {"display_name": "URLs", "info": "The URLs to make the request to."},
|
||||
"method": {
|
||||
"display_name": "Method",
|
||||
"info": "The HTTP method to use.",
|
||||
|
|
@ -116,4 +116,5 @@ class APIRequest(CustomComponent):
|
|||
for u, rec in zip(urls, bodies)
|
||||
]
|
||||
)
|
||||
self.status = results
|
||||
return results
|
||||
|
|
|
|||
|
|
@ -9,9 +9,39 @@ class ExtractKeyFromRecordComponent(CustomComponent):
|
|||
|
||||
field_config = {
|
||||
"record": {"display_name": "Record"},
|
||||
"keys": {
|
||||
"display_name": "Keys",
|
||||
"info": "The keys to extract from the record.",
|
||||
"input_types": [],
|
||||
},
|
||||
"silent_error": {
|
||||
"display_name": "Silent Errors",
|
||||
"info": "If True, errors will not be raised.",
|
||||
"advanced": True,
|
||||
},
|
||||
}
|
||||
|
||||
def build(self, record: Record, key: str, silent_error: bool = True) -> dict:
|
||||
data = getattr(record, key)
|
||||
self.status = data
|
||||
return data
|
||||
def build(
|
||||
self, record: Record, keys: list[str], silent_error: bool = True
|
||||
) -> Record:
|
||||
"""
|
||||
Extracts the keys from a record.
|
||||
|
||||
Args:
|
||||
record (Record): The record from which to extract the keys.
|
||||
keys (list[str]): The keys to extract from the record.
|
||||
silent_error (bool): If True, errors will not be raised.
|
||||
|
||||
Returns:
|
||||
dict: The extracted keys.
|
||||
"""
|
||||
extracted_keys = {}
|
||||
for key in keys:
|
||||
try:
|
||||
extracted_keys[key] = getattr(record, key)
|
||||
except AttributeError:
|
||||
if not silent_error:
|
||||
raise KeyError(f"The key '{key}' does not exist in the record.")
|
||||
return_record = Record(data=extracted_keys)
|
||||
self.status = return_record
|
||||
return return_record
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue