Merge branch 'zustand/io/migration' into new_project_modal
This commit is contained in:
commit
97b574272f
4 changed files with 45 additions and 42 deletions
|
|
@ -1,8 +1,7 @@
|
|||
import asyncio
|
||||
from typing import List, Optional, Union
|
||||
import httpx
|
||||
from typing import List, Optional
|
||||
|
||||
import requests
|
||||
import httpx
|
||||
|
||||
from langflow import CustomComponent
|
||||
from langflow.schema import Record
|
||||
|
|
@ -42,7 +41,7 @@ class APIRequest(CustomComponent):
|
|||
|
||||
async def make_request(
|
||||
self,
|
||||
session: requests.Session,
|
||||
client: httpx.AsyncClient,
|
||||
method: str,
|
||||
url: str,
|
||||
headers: Optional[dict] = None,
|
||||
|
|
@ -55,23 +54,22 @@ class APIRequest(CustomComponent):
|
|||
|
||||
data = record.text if record else None
|
||||
try:
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.request(
|
||||
method, url, headers=headers, content=data, timeout=timeout
|
||||
)
|
||||
try:
|
||||
response_json = response.json()
|
||||
result = orjson_dumps(response_json, indent_2=False)
|
||||
except Exception:
|
||||
result = response.text
|
||||
return Record(
|
||||
text=result,
|
||||
data={
|
||||
"source": url,
|
||||
"headers": headers,
|
||||
"status_code": response.status_code,
|
||||
},
|
||||
)
|
||||
response = await client.request(
|
||||
method, url, headers=headers, content=data, timeout=timeout
|
||||
)
|
||||
try:
|
||||
response_json = response.json()
|
||||
result = orjson_dumps(response_json, indent_2=False)
|
||||
except Exception:
|
||||
result = response.text
|
||||
return Record(
|
||||
text=result,
|
||||
data={
|
||||
"source": url,
|
||||
"headers": headers,
|
||||
"status_code": response.status_code,
|
||||
},
|
||||
)
|
||||
except httpx.TimeoutException:
|
||||
return Record(
|
||||
text="Request Timed Out",
|
||||
|
|
@ -88,7 +86,7 @@ class APIRequest(CustomComponent):
|
|||
method: str,
|
||||
url: List[str],
|
||||
headers: Optional[dict] = None,
|
||||
record: Optional[Union[Record, List[Record]]] = None,
|
||||
record: Optional[Record] = None,
|
||||
timeout: int = 5,
|
||||
) -> List[Record]:
|
||||
if headers is None:
|
||||
|
|
@ -99,11 +97,11 @@ class APIRequest(CustomComponent):
|
|||
if isinstance(record, list)
|
||||
else [record] if record else [None] * len(urls)
|
||||
)
|
||||
|
||||
results = await asyncio.gather(
|
||||
*[
|
||||
self.make_request(method, u, headers, doc, timeout)
|
||||
for u, doc in zip(urls, records)
|
||||
]
|
||||
)
|
||||
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)
|
||||
]
|
||||
)
|
||||
return results
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
):
|
||||
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 = config.model_dump() if isinstance(config, BaseModel) else config
|
||||
field_name, field_type, field_value, field_required = get_field_properties(
|
||||
|
|
|
|||
|
|
@ -727,4 +727,14 @@ export const STATUS_BUILD = "Build to validate status.";
|
|||
export const STATUS_BUILDING = "Building...";
|
||||
export const SAVED_HOVER = "Last saved at ";
|
||||
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",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,17 +1,10 @@
|
|||
import { PRIORITY_SIDEBAR_ORDER } from "../../../../constants/constants";
|
||||
|
||||
export function sortKeys(a: string, b: string) {
|
||||
// Define the order of specific keys
|
||||
const order = [
|
||||
"saved_components",
|
||||
"inputs",
|
||||
"outputs",
|
||||
"prompts",
|
||||
"data",
|
||||
"prompts",
|
||||
"models",
|
||||
"helpers",
|
||||
];
|
||||
const indexA = order.indexOf(a.toLowerCase());
|
||||
const indexB = order.indexOf(b.toLowerCase());
|
||||
|
||||
const indexA = PRIORITY_SIDEBAR_ORDER.indexOf(a.toLowerCase());
|
||||
const indexB = PRIORITY_SIDEBAR_ORDER.indexOf(b.toLowerCase());
|
||||
|
||||
// Check if both keys are in the predefined order
|
||||
if (indexA !== -1 && indexB !== -1) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue