🔧 chore(chat.py): remove unused imports and variables to improve code readability and maintainability
🐛 fix(chat.py): fix error handling in build_vertex function to correctly handle exceptions and improve error reporting
This commit is contained in:
parent
3bb3ca7f3a
commit
67f826b43f
1 changed files with 4 additions and 10 deletions
|
|
@ -3,7 +3,6 @@ from typing import Optional
|
||||||
|
|
||||||
from fastapi import (
|
from fastapi import (
|
||||||
APIRouter,
|
APIRouter,
|
||||||
Body,
|
|
||||||
Depends,
|
Depends,
|
||||||
HTTPException,
|
HTTPException,
|
||||||
WebSocket,
|
WebSocket,
|
||||||
|
|
@ -26,7 +25,6 @@ from langflow.api.v1.schemas import (
|
||||||
VerticesOrderResponse,
|
VerticesOrderResponse,
|
||||||
)
|
)
|
||||||
from langflow.graph.graph.base import Graph
|
from langflow.graph.graph.base import Graph
|
||||||
from langflow.processing.process import process_tweaks_on_graph
|
|
||||||
from langflow.services.auth.utils import (
|
from langflow.services.auth.utils import (
|
||||||
get_current_active_user,
|
get_current_active_user,
|
||||||
get_current_user_for_websocket,
|
get_current_user_for_websocket,
|
||||||
|
|
@ -318,11 +316,10 @@ async def build_vertex(
|
||||||
vertex_id: str,
|
vertex_id: str,
|
||||||
chat_service: "ChatService" = Depends(get_chat_service),
|
chat_service: "ChatService" = Depends(get_chat_service),
|
||||||
current_user=Depends(get_current_active_user),
|
current_user=Depends(get_current_active_user),
|
||||||
tweaks: dict = Body(None),
|
|
||||||
inputs: dict = Body(None),
|
|
||||||
):
|
):
|
||||||
"""Build a vertex instead of the entire graph."""
|
"""Build a vertex instead of the entire graph."""
|
||||||
try:
|
try:
|
||||||
|
start_time = time.perf_counter()
|
||||||
cache = chat_service.get_cache(flow_id)
|
cache = chat_service.get_cache(flow_id)
|
||||||
if not cache:
|
if not cache:
|
||||||
# If there's no cache
|
# If there's no cache
|
||||||
|
|
@ -336,11 +333,8 @@ async def build_vertex(
|
||||||
graph = cache.get("result")
|
graph = cache.get("result")
|
||||||
result_dict = {}
|
result_dict = {}
|
||||||
duration = ""
|
duration = ""
|
||||||
start_time = time.perf_counter()
|
|
||||||
if tweaks:
|
vertex = graph.get_vertex(vertex_id)
|
||||||
graph = process_tweaks_on_graph(graph, tweaks)
|
|
||||||
if not (vertex := graph.get_vertex(vertex_id)):
|
|
||||||
raise ValueError(f"Invalid vertex {vertex_id}")
|
|
||||||
try:
|
try:
|
||||||
if not vertex.pinned or not vertex._built:
|
if not vertex.pinned or not vertex._built:
|
||||||
await vertex.build(user_id=current_user.id)
|
await vertex.build(user_id=current_user.id)
|
||||||
|
|
@ -368,7 +362,7 @@ async def build_vertex(
|
||||||
raise ValueError(f"No result found for vertex {vertex_id}")
|
raise ValueError(f"No result found for vertex {vertex_id}")
|
||||||
chat_service.set_cache(flow_id, graph)
|
chat_service.set_cache(flow_id, graph)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
params = str(exc)
|
params = repr(exc)
|
||||||
valid = False
|
valid = False
|
||||||
result_dict = ResultDict(results={})
|
result_dict = ResultDict(results={})
|
||||||
artifacts = {}
|
artifacts = {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue