Merge branch 'dev' of https://github.com/langflow-ai/langflow into dev
This commit is contained in:
commit
26fd9d5312
7 changed files with 31 additions and 38 deletions
|
|
@ -205,17 +205,12 @@ async def build_and_cache_graph_from_db(
|
||||||
flow_id: str,
|
flow_id: str,
|
||||||
session: Session,
|
session: Session,
|
||||||
chat_service: "ChatService",
|
chat_service: "ChatService",
|
||||||
graph: Optional[Graph] = None,
|
|
||||||
):
|
):
|
||||||
"""Build and cache the graph."""
|
"""Build and cache the graph."""
|
||||||
flow: Optional[Flow] = session.get(Flow, flow_id)
|
flow: Optional[Flow] = session.get(Flow, flow_id)
|
||||||
if not flow or not flow.data:
|
if not flow or not flow.data:
|
||||||
raise ValueError("Invalid flow ID")
|
raise ValueError("Invalid flow ID")
|
||||||
other_graph = Graph.from_payload(flow.data, flow_id)
|
graph = Graph.from_payload(flow.data, flow_id)
|
||||||
if graph is None:
|
|
||||||
graph = other_graph
|
|
||||||
else:
|
|
||||||
graph = graph.update(other_graph)
|
|
||||||
await chat_service.set_cache(flow_id, graph)
|
await chat_service.set_cache(flow_id, graph)
|
||||||
return graph
|
return graph
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,13 +79,8 @@ async def retrieve_vertices_order(
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# First, we need to check if the flow_id is in the cache
|
# First, we need to check if the flow_id is in the cache
|
||||||
graph = None
|
|
||||||
if not data:
|
if not data:
|
||||||
if cache := await chat_service.get_cache(flow_id):
|
graph = await build_and_cache_graph_from_db(flow_id=flow_id, session=session, chat_service=chat_service)
|
||||||
graph = cache.get("result")
|
|
||||||
graph = await build_and_cache_graph_from_db(
|
|
||||||
flow_id=flow_id, session=session, chat_service=chat_service, graph=graph
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
graph = await build_and_cache_graph_from_data(
|
graph = await build_and_cache_graph_from_data(
|
||||||
flow_id=flow_id, graph_data=data.model_dump(), chat_service=chat_service
|
flow_id=flow_id, graph_data=data.model_dump(), chat_service=chat_service
|
||||||
|
|
|
||||||
|
|
@ -98,9 +98,9 @@ class APIRequest(CustomComponent):
|
||||||
timeout: int = 5,
|
timeout: int = 5,
|
||||||
) -> List[Record]:
|
) -> List[Record]:
|
||||||
if headers is None:
|
if headers is None:
|
||||||
headers = {}
|
headers_dict = {}
|
||||||
else:
|
else:
|
||||||
headers = headers.data
|
headers_dict = headers.data
|
||||||
|
|
||||||
bodies = []
|
bodies = []
|
||||||
if body:
|
if body:
|
||||||
|
|
@ -114,7 +114,7 @@ class APIRequest(CustomComponent):
|
||||||
bodies += [None] * (len(urls) - len(bodies)) # type: ignore
|
bodies += [None] * (len(urls) - len(bodies)) # type: ignore
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
results = await asyncio.gather(
|
results = await asyncio.gather(
|
||||||
*[self.make_request(client, method, u, headers, rec, timeout) for u, rec in zip(urls, bodies)]
|
*[self.make_request(client, method, u, headers_dict, rec, timeout) for u, rec in zip(urls, bodies)]
|
||||||
)
|
)
|
||||||
self.status = results
|
self.status = results
|
||||||
return results
|
return results
|
||||||
|
|
|
||||||
|
|
@ -445,9 +445,16 @@ class Graph:
|
||||||
vertex = self.get_vertex(vertex_id)
|
vertex = self.get_vertex(vertex_id)
|
||||||
vertex.set_state(state)
|
vertex.set_state(state)
|
||||||
|
|
||||||
def mark_branch(self, vertex_id: str, state: str):
|
def mark_branch(self, vertex_id: str, state: str, visited: Optional[set] = None):
|
||||||
"""Marks a branch of the graph."""
|
"""Marks a branch of the graph."""
|
||||||
|
if visited is None:
|
||||||
|
visited = set()
|
||||||
|
visited.add(vertex_id)
|
||||||
|
if vertex_id in visited:
|
||||||
|
return
|
||||||
|
|
||||||
self.mark_vertex(vertex_id, state)
|
self.mark_vertex(vertex_id, state)
|
||||||
|
|
||||||
for child_id in self.parent_child_map[vertex_id]:
|
for child_id in self.parent_child_map[vertex_id]:
|
||||||
self.mark_branch(child_id, state)
|
self.mark_branch(child_id, state)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ def get_id_from_search_string(search_string: str) -> Optional[str]:
|
||||||
Returns:
|
Returns:
|
||||||
Optional[str]: The extracted ID, or None if no ID is found.
|
Optional[str]: The extracted ID, or None if no ID is found.
|
||||||
"""
|
"""
|
||||||
possible_id = search_string
|
possible_id: Optional[str] = search_string
|
||||||
if "www.langflow.store/store/" in search_string:
|
if "www.langflow.store/store/" in search_string:
|
||||||
possible_id = search_string.split("/")[-1]
|
possible_id = search_string.split("/")[-1]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,33 +116,29 @@ export async function buildVertices({
|
||||||
nodes,
|
nodes,
|
||||||
edges,
|
edges,
|
||||||
}: BuildVerticesParams) {
|
}: BuildVerticesParams) {
|
||||||
let verticesBuild = useFlowStore.getState().verticesBuild;
|
|
||||||
// if startNodeId and stopNodeId are provided
|
// if startNodeId and stopNodeId are provided
|
||||||
// something is wrong
|
// something is wrong
|
||||||
if (startNodeId && stopNodeId) {
|
if (startNodeId && stopNodeId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let verticesOrderResponse = await updateVerticesOrder(
|
||||||
|
flowId,
|
||||||
|
startNodeId,
|
||||||
|
stopNodeId,
|
||||||
|
nodes,
|
||||||
|
edges
|
||||||
|
);
|
||||||
|
if (onValidateNodes) {
|
||||||
|
try {
|
||||||
|
onValidateNodes(verticesOrderResponse.verticesToRun);
|
||||||
|
} catch (e) {
|
||||||
|
useFlowStore.getState().setIsBuilding(false);
|
||||||
|
|
||||||
if (!verticesBuild || startNodeId || stopNodeId) {
|
return;
|
||||||
let verticesOrderResponse = await updateVerticesOrder(
|
|
||||||
flowId,
|
|
||||||
startNodeId,
|
|
||||||
stopNodeId,
|
|
||||||
nodes,
|
|
||||||
edges
|
|
||||||
);
|
|
||||||
if (onValidateNodes) {
|
|
||||||
try {
|
|
||||||
onValidateNodes(verticesOrderResponse.verticesToRun);
|
|
||||||
} catch (e) {
|
|
||||||
useFlowStore.getState().setIsBuilding(false);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (onGetOrderSuccess) onGetOrderSuccess();
|
|
||||||
verticesBuild = useFlowStore.getState().verticesBuild;
|
|
||||||
}
|
}
|
||||||
|
if (onGetOrderSuccess) onGetOrderSuccess();
|
||||||
|
let verticesBuild = useFlowStore.getState().verticesBuild;
|
||||||
|
|
||||||
const verticesIds = verticesBuild?.verticesIds!;
|
const verticesIds = verticesBuild?.verticesIds!;
|
||||||
const verticesLayers = verticesBuild?.verticesLayers!;
|
const verticesLayers = verticesBuild?.verticesLayers!;
|
||||||
|
|
|
||||||
|
|
@ -393,13 +393,13 @@ def test_various_prompts(client, prompt, expected_input_variables):
|
||||||
|
|
||||||
|
|
||||||
def test_get_vertices_flow_not_found(client, logged_in_headers):
|
def test_get_vertices_flow_not_found(client, logged_in_headers):
|
||||||
response = client.get("/api/v1/build/nonexistent_id/vertices", headers=logged_in_headers)
|
response = client.post("/api/v1/build/nonexistent_id/vertices", headers=logged_in_headers)
|
||||||
assert response.status_code == 500 # Or whatever status code you've set for invalid ID
|
assert response.status_code == 500 # Or whatever status code you've set for invalid ID
|
||||||
|
|
||||||
|
|
||||||
def test_get_vertices(client, added_flow_with_prompt_and_history, logged_in_headers):
|
def test_get_vertices(client, added_flow_with_prompt_and_history, logged_in_headers):
|
||||||
flow_id = added_flow_with_prompt_and_history["id"]
|
flow_id = added_flow_with_prompt_and_history["id"]
|
||||||
response = client.get(f"/api/v1/build/{flow_id}/vertices", headers=logged_in_headers)
|
response = client.post(f"/api/v1/build/{flow_id}/vertices", headers=logged_in_headers)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert "ids" in response.json()
|
assert "ids" in response.json()
|
||||||
# The response should contain the list in this order
|
# The response should contain the list in this order
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue