From 9958ce76fd387af8761734dc0be3bb576a7ded09 Mon Sep 17 00:00:00 2001 From: Rodrigo Nader Date: Wed, 6 Mar 2024 00:50:27 -0300 Subject: [PATCH] Refactor APIRequest class to use 'body' instead of 'record' parameter --- .../langflow/components/helpers/APIRequest.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/backend/langflow/components/helpers/APIRequest.py b/src/backend/langflow/components/helpers/APIRequest.py index 4d9f3ce9c..75abe4e94 100644 --- a/src/backend/langflow/components/helpers/APIRequest.py +++ b/src/backend/langflow/components/helpers/APIRequest.py @@ -27,9 +27,9 @@ class APIRequest(CustomComponent): "display_name": "Headers", "info": "The headers to send with the request.", }, - "record": { - "display_name": "Record", - "info": "The record to send with the request (for POST, PATCH, PUT).", + "body": { + "display_name": "Body", + "info": "The body to send with the request (for POST, PATCH, PUT).", }, "timeout": { "display_name": "Timeout", @@ -45,14 +45,14 @@ class APIRequest(CustomComponent): method: str, url: str, headers: Optional[dict] = None, - record: Optional[Record] = None, + body: Optional[dict] = None, timeout: int = 5, ) -> Record: method = method.upper() if method not in ["GET", "POST", "PATCH", "PUT"]: raise ValueError(f"Unsupported method: {method}") - data = record.data if record else None + data = body if body else None try: response = await client.request( method, url, headers=headers, content=data, timeout=timeout @@ -86,22 +86,22 @@ class APIRequest(CustomComponent): method: str, url: List[str], headers: Optional[dict] = None, - record: Optional[Record] = None, + body: Optional[dict] = None, timeout: int = 5, ) -> List[Record]: if headers is None: headers = {} urls = url if isinstance(url, list) else [url] - records = ( - record - if isinstance(record, list) - else [record] if record else [None] * len(urls) + bodies = ( + body + if isinstance(body, list) + else [body] if body else [None] * len(urls) ) async with httpx.AsyncClient() as client: results = await asyncio.gather( *[ self.make_request(client, method, u, headers, rec, timeout) - for u, rec in zip(urls, records) + for u, rec in zip(urls, bodies) ] ) return results