Merge branch 'db' of personal:logspace-ai/langflow into db
This commit is contained in:
commit
8fd94f0298
11 changed files with 76 additions and 101 deletions
|
|
@ -12,10 +12,11 @@ from langflow.api.v1.schemas import BuiltResponse, InitResponse
|
|||
from langflow.chat.manager import ChatManager
|
||||
from langflow.graph.graph.base import Graph
|
||||
from langflow.utils.logger import logger
|
||||
from cachetools import LRUCache
|
||||
|
||||
router = APIRouter(tags=["Chat"])
|
||||
chat_manager = ChatManager()
|
||||
flow_data_store = {}
|
||||
flow_data_store = LRUCache(maxsize=10)
|
||||
|
||||
|
||||
@router.websocket("/chat/{client_id}")
|
||||
|
|
@ -38,7 +39,8 @@ async def init_build(graph_data: dict):
|
|||
|
||||
try:
|
||||
flow_id = graph_data.get("id")
|
||||
|
||||
if flow_id is None:
|
||||
raise ValueError("No ID provided")
|
||||
flow_data_store[flow_id] = graph_data
|
||||
|
||||
return InitResponse(flowId=flow_id)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ from langflow.processing.process import process_graph_cached, process_tweaks
|
|||
from langflow.utils.logger import logger
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from fastapi.security import HTTPBearer
|
||||
|
||||
from langflow.api.v1.schemas import (
|
||||
PredictRequest,
|
||||
|
|
@ -17,20 +16,6 @@ from sqlmodel import Session
|
|||
# build router
|
||||
router = APIRouter(tags=["Base"])
|
||||
|
||||
security = HTTPBearer()
|
||||
|
||||
|
||||
def get_flow_from_token(
|
||||
bearer: HTTPBearer = Depends(security), session: Session = Depends(get_session)
|
||||
) -> str:
|
||||
# Extract the token, which is the flow_id in this case
|
||||
flow_id = bearer.credentials
|
||||
# Check if the flow_id exists in the database
|
||||
flow = session.get(Flow, flow_id)
|
||||
if flow is None:
|
||||
raise HTTPException(status_code=401, detail="Invalid token")
|
||||
return flow
|
||||
|
||||
|
||||
@router.get("/all")
|
||||
def get_all():
|
||||
|
|
@ -51,6 +36,9 @@ async def predict_flow(
|
|||
flow = session.get(Flow, flow_id)
|
||||
if flow is None:
|
||||
raise ValueError(f"Flow {flow_id} not found")
|
||||
|
||||
if flow.data is None:
|
||||
raise ValueError(f"Flow {flow_id} has no data")
|
||||
graph_data = flow.data
|
||||
if predict_request.tweaks:
|
||||
graph_data = process_tweaks(graph_data, predict_request.tweaks)
|
||||
|
|
|
|||
|
|
@ -252,7 +252,11 @@ class VectorStoreRouterAgent(CustomAgentExecutor):
|
|||
):
|
||||
"""Construct a vector store router agent from an LLM and tools."""
|
||||
|
||||
tools = vectorstoreroutertoolkit.get_tools()
|
||||
tools = (
|
||||
vectorstoreroutertoolkit
|
||||
if isinstance(vectorstoreroutertoolkit, list)
|
||||
else vectorstoreroutertoolkit.get_tools()
|
||||
)
|
||||
prompt = ZeroShotAgent.create_prompt(tools, prefix=VECTORSTORE_ROUTER_PREFIX)
|
||||
llm_chain = LLMChain(
|
||||
llm=llm,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import os
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import FileResponse
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
|
@ -20,7 +22,11 @@ def create_app(static_path: str = "static"):
|
|||
|
||||
@app.exception_handler(404)
|
||||
async def custom_404_handler(request, __):
|
||||
return FileResponse(f"{static_path}/index.html")
|
||||
path = f"{static_path}/index.html"
|
||||
|
||||
if not os.path.isfile(path):
|
||||
raise RuntimeError(f"File at path {path} does not exist.")
|
||||
return FileResponse(path)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ def load_flow_from_json(path: str, build=True):
|
|||
return graph
|
||||
|
||||
|
||||
def process_tweaks(graph_data: dict, tweaks: dict):
|
||||
def process_tweaks(graph_data: Dict, tweaks: Dict):
|
||||
"""This function is used to tweak the graph data using the node id and the tweaks dict"""
|
||||
# the tweaks dict is a dict of dicts
|
||||
# the key is the node id and the value is a dict of the tweaks
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue