Refactor caching and result set up
This commit is contained in:
parent
aebab3f7e3
commit
80815e0526
1 changed files with 5 additions and 21 deletions
|
|
@ -11,7 +11,11 @@ from fastapi import (
|
||||||
status,
|
status,
|
||||||
)
|
)
|
||||||
from fastapi.responses import StreamingResponse
|
from fastapi.responses import StreamingResponse
|
||||||
from langflow.api.utils import build_input_keys_response, format_elapsed_time
|
from langflow.api.utils import (
|
||||||
|
build_and_cache_graph,
|
||||||
|
build_input_keys_response,
|
||||||
|
format_elapsed_time,
|
||||||
|
)
|
||||||
from langflow.api.v1.schemas import (
|
from langflow.api.v1.schemas import (
|
||||||
BuildStatus,
|
BuildStatus,
|
||||||
BuiltResponse,
|
BuiltResponse,
|
||||||
|
|
@ -30,7 +34,6 @@ from langflow.services.auth.utils import (
|
||||||
from langflow.services.cache.service import BaseCacheService
|
from langflow.services.cache.service import BaseCacheService
|
||||||
from langflow.services.cache.utils import update_build_status
|
from langflow.services.cache.utils import update_build_status
|
||||||
from langflow.services.chat.service import ChatService
|
from langflow.services.chat.service import ChatService
|
||||||
from langflow.services.database.models.flow import Flow
|
|
||||||
from langflow.services.deps import get_cache_service, get_chat_service, get_session
|
from langflow.services.deps import get_cache_service, get_chat_service, get_session
|
||||||
from langflow.services.monitor.utils import log_vertex_build
|
from langflow.services.monitor.utils import log_vertex_build
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
@ -274,25 +277,6 @@ async def try_running_celery_task(vertex, user_id):
|
||||||
return vertex
|
return vertex
|
||||||
|
|
||||||
|
|
||||||
def build_and_cache_graph(
|
|
||||||
flow_id: str,
|
|
||||||
session: Session,
|
|
||||||
chat_service: "ChatService",
|
|
||||||
graph: Optional[Graph] = None,
|
|
||||||
):
|
|
||||||
"""Build and cache the graph."""
|
|
||||||
flow: Flow = session.get(Flow, flow_id)
|
|
||||||
if not flow or not flow.data:
|
|
||||||
raise ValueError("Invalid flow ID")
|
|
||||||
other_graph = Graph.from_payload(flow.data)
|
|
||||||
if graph is None:
|
|
||||||
graph = other_graph
|
|
||||||
else:
|
|
||||||
graph = graph.update(other_graph)
|
|
||||||
chat_service.set_cache(flow_id, graph)
|
|
||||||
return graph
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/build/{flow_id}/vertices", response_model=VerticesOrderResponse)
|
@router.get("/build/{flow_id}/vertices", response_model=VerticesOrderResponse)
|
||||||
async def get_vertices(
|
async def get_vertices(
|
||||||
flow_id: str,
|
flow_id: str,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue