Merge branch 'zustand/io/migration' into new_project_modal

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-03-05 21:48:40 -03:00
commit 97b574272f
4 changed files with 45 additions and 42 deletions

View file

@ -1,8 +1,7 @@
import asyncio import asyncio
from typing import List, Optional, Union from typing import List, Optional
import httpx
import requests import httpx
from langflow import CustomComponent from langflow import CustomComponent
from langflow.schema import Record from langflow.schema import Record
@ -42,7 +41,7 @@ class APIRequest(CustomComponent):
async def make_request( async def make_request(
self, self,
session: requests.Session, client: httpx.AsyncClient,
method: str, method: str,
url: str, url: str,
headers: Optional[dict] = None, headers: Optional[dict] = None,
@ -55,23 +54,22 @@ class APIRequest(CustomComponent):
data = record.text if record else None data = record.text if record else None
try: try:
async with httpx.AsyncClient() as client: response = await client.request(
response = await client.request( method, url, headers=headers, content=data, timeout=timeout
method, url, headers=headers, content=data, timeout=timeout )
) try:
try: response_json = response.json()
response_json = response.json() result = orjson_dumps(response_json, indent_2=False)
result = orjson_dumps(response_json, indent_2=False) except Exception:
except Exception: result = response.text
result = response.text return Record(
return Record( text=result,
text=result, data={
data={ "source": url,
"source": url, "headers": headers,
"headers": headers, "status_code": response.status_code,
"status_code": response.status_code, },
}, )
)
except httpx.TimeoutException: except httpx.TimeoutException:
return Record( return Record(
text="Request Timed Out", text="Request Timed Out",
@ -88,7 +86,7 @@ class APIRequest(CustomComponent):
method: str, method: str,
url: List[str], url: List[str],
headers: Optional[dict] = None, headers: Optional[dict] = None,
record: Optional[Union[Record, List[Record]]] = None, record: Optional[Record] = None,
timeout: int = 5, timeout: int = 5,
) -> List[Record]: ) -> List[Record]:
if headers is None: if headers is None:
@ -99,11 +97,11 @@ class APIRequest(CustomComponent):
if isinstance(record, list) if isinstance(record, list)
else [record] if record else [None] * len(urls) else [record] if record else [None] * len(urls)
) )
async with httpx.AsyncClient() as client:
results = await asyncio.gather( results = await asyncio.gather(
*[ *[
self.make_request(method, u, headers, doc, timeout) self.make_request(client, method, u, headers, rec, timeout)
for u, doc in zip(urls, records) for u, rec in zip(urls, records)
] ]
) )
return results return results

View file

@ -224,6 +224,8 @@ def add_extra_fields(frontend_node, field_config, function_args):
key in function_args_names for key in field_config.keys() key in function_args_names for key in field_config.keys()
): ):
for field_name, field_config in _field_config.copy().items(): for field_name, field_config in _field_config.copy().items():
if "name" not in field_config or field_name == "code":
continue
config = _field_config.get(field_name, {}) config = _field_config.get(field_name, {})
config = config.model_dump() if isinstance(config, BaseModel) else config config = config.model_dump() if isinstance(config, BaseModel) else config
field_name, field_type, field_value, field_required = get_field_properties( field_name, field_type, field_value, field_required = get_field_properties(

View file

@ -727,4 +727,14 @@ export const STATUS_BUILD = "Build to validate status.";
export const STATUS_BUILDING = "Building..."; export const STATUS_BUILDING = "Building...";
export const SAVED_HOVER = "Last saved at "; export const SAVED_HOVER = "Last saved at ";
export const RUN_TIMESTAMP_PREFIX = "Last Run: "; export const RUN_TIMESTAMP_PREFIX = "Last Run: ";
export const STARTER_FOLDER_NAME = "Starter Projects";
export const PRIORITY_SIDEBAR_ORDER = [
"saved_components",
"inputs",
"outputs",
"prompts",
"data",
"prompt",
"models",
"helpers",
];

View file

@ -1,17 +1,10 @@
import { PRIORITY_SIDEBAR_ORDER } from "../../../../constants/constants";
export function sortKeys(a: string, b: string) { export function sortKeys(a: string, b: string) {
// Define the order of specific keys // Define the order of specific keys
const order = [
"saved_components", const indexA = PRIORITY_SIDEBAR_ORDER.indexOf(a.toLowerCase());
"inputs", const indexB = PRIORITY_SIDEBAR_ORDER.indexOf(b.toLowerCase());
"outputs",
"prompts",
"data",
"prompts",
"models",
"helpers",
];
const indexA = order.indexOf(a.toLowerCase());
const indexB = order.indexOf(b.toLowerCase());
// Check if both keys are in the predefined order // Check if both keys are in the predefined order
if (indexA !== -1 && indexB !== -1) { if (indexA !== -1 && indexB !== -1) {