Merge branch 'db' of personal:logspace-ai/langflow into db

This commit is contained in:
anovazzi1 2023-06-16 17:52:43 -03:00
commit 20b19967da
7 changed files with 55 additions and 13 deletions

View file

@ -6,7 +6,7 @@ from multiprocess import Process, cpu_count # type: ignore
import platform
from pathlib import Path
from typing import Optional
import socket
from rich.panel import Panel
from rich import box
from rich import print as rprint
@ -168,9 +168,13 @@ def serve(
)
webapp_process.start()
status_code = 0
# check if port is being used
if is_port_in_use(port, host):
port = get_free_port(port)
while status_code != 200:
try:
status_code = httpx.get(f"http://{host}:{port}").status_code
status_code = httpx.get(f"http://{host}:{port}/health").status_code
except Exception:
time.sleep(1)
@ -179,7 +183,7 @@ def serve(
webbrowser.open(f"http://{host}:{port}")
def setup_static_files(app: FastAPI, static_files_dir: str):
def setup_static_files(app: FastAPI, static_files_dir: Path):
"""
Setup the static files directory.
@ -194,6 +198,36 @@ def setup_static_files(app: FastAPI, static_files_dir: str):
)
def is_port_in_use(port, host="localhost"):
"""
Check if a port is in use.
Args:
port (int): The port number to check.
host (str): The host to check the port on. Defaults to 'localhost'.
Returns:
bool: True if the port is in use, False otherwise.
"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
return s.connect_ex((host, port)) == 0
def get_free_port(port):
"""
Given a used port, find a free port.
Args:
port (int): The port number to check.
Returns:
int: A free port number.
"""
while is_port_in_use(port):
port += 1
return port
def print_banner(host, port):
# console = Console()

View file

@ -6,9 +6,10 @@ from fastapi.middleware.cors import CORSMiddleware
from langflow.api import router
from langflow.database.base import create_db_and_tables
from pathlib import Path
def create_app(static_path: str = "static"):
def create_app(static_path: Path = Path("src/frontend")):
"""Create the FastAPI app and include the router."""
app = FastAPI()

View file

@ -48,7 +48,7 @@ export default function BuildTrigger({
if(!allNodesValid) {
setErrorData({
title: "Oops! Looks like you missed something",
list: ["Check nodes and retry. Hover over 🔴 node for status."],
list: ["Check components and retry. Hover over component status icon 🔴 to inspect."],
});
}
} catch (error) {

View file

@ -66,7 +66,7 @@ export const getPythonApiCode = (flow: FlowType): string => {
BASE_API_URL = "${window.location.protocol}//${
window.location.host
}/ap1/v1/predict"
}/api/v1/predict"
FLOW_ID = "${flowId}"
# You can tweak the flow by adding a tweaks dictionary
# e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}}

View file

@ -124,7 +124,7 @@ export default function ExtraSidebar() {
type="text"
name="search"
id="search"
placeholder="Search Nodes"
placeholder="Search"
className={
INPUT_STYLE +
"w-full border-1 dark:border-slate-600 dark:border-0.5 dark:ring-0 focus-visible:dark:ring-0 focus-visible:dark:ring-offset-1 rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50"

View file

@ -16,7 +16,7 @@ export default function HomePage() {
<div className="w-full flex justify-between py-12 pb-2 px-6">
<span className="text-2xl flex items-center justify-center gap-2 font-semibold">
<Home className="w-6" />
My Projects
My Collection
</span>
<div className="flex gap-2">
<Button
@ -51,8 +51,7 @@ export default function HomePage() {
</div>
</div>
<span className="flex pb-14 px-6 text-muted-foreground w-[60%]">
Manage your personal projects. Download or upload your complete project
collection.
Manage your personal projects. Download or upload your collection.
</span>
<div className="w-full p-4 grid gap-4 md:grid-cols-2 lg:grid-cols-4">
{flows.map((flow, idx) => (

View file

@ -119,8 +119,13 @@ def test_read_flow(client: TestClient, json_flow: str):
def test_update_flow(client: TestClient, json_flow: str):
flow = json.loads(json_flow)
data = flow["data"]
flow = FlowCreate(name="Test Flow", description="description", data=data)
response = client.post("api/v1/flows/", json=flow.dict())
response = client.post(
"api/v1/flows/",
json=flow.dict()
)
flow_id = response.json()["id"]
updated_flow = FlowUpdate(
name="Updated Flow",
@ -128,11 +133,14 @@ def test_update_flow(client: TestClient, json_flow: str):
data=data,
)
response = client.patch(
f"api/v1/flows/{flow_id}", json=updated_flow.dict())
f"api/v1/flows/{flow_id}",
json=updated_flow.dict()
)
assert response.status_code == 200
assert response.json()["name"] == updated_flow.name
assert response.json()["description"] == updated_flow.description
assert response.json()["data"] == updated_flow.data
# assert response.json()["data"] == updated_flow.data
def test_delete_flow(client: TestClient, json_flow: str):