merge fix

This commit is contained in:
cristhianzl 2024-02-20 19:55:16 -03:00
commit 103ab84bc3
9 changed files with 48 additions and 38 deletions

View file

@ -3,7 +3,6 @@ from typing import Optional
from fastapi import (
APIRouter,
Body,
Depends,
HTTPException,
WebSocket,
@ -26,7 +25,6 @@ from langflow.api.v1.schemas import (
VerticesOrderResponse,
)
from langflow.graph.graph.base import Graph
from langflow.processing.process import process_tweaks_on_graph
from langflow.services.auth.utils import (
get_current_active_user,
get_current_user_for_websocket,
@ -318,12 +316,11 @@ async def build_vertex(
vertex_id: str,
chat_service: "ChatService" = Depends(get_chat_service),
current_user=Depends(get_current_active_user),
tweaks: dict = Body(None),
inputs: dict = Body(None),
):
"""Build a vertex instead of the entire graph."""
start_time = time.perf_counter()
try:
start_time = time.perf_counter()
cache = chat_service.get_cache(flow_id)
if not cache:
# If there's no cache
@ -337,10 +334,8 @@ async def build_vertex(
graph = cache.get("result")
result_dict = {}
duration = ""
if tweaks:
graph = process_tweaks_on_graph(graph, tweaks)
if not (vertex := graph.get_vertex(vertex_id)):
raise ValueError(f"Invalid vertex {vertex_id}")
vertex = graph.get_vertex(vertex_id)
try:
if not vertex.pinned or not vertex._built:
await vertex.build(user_id=current_user.id)
@ -364,7 +359,7 @@ async def build_vertex(
raise ValueError(f"No result found for vertex {vertex_id}")
chat_service.set_cache(flow_id, graph)
except Exception as exc:
params = str(exc)
params = repr(exc)
valid = False
result_dict = ResultData(results={})
artifacts = {}

View file

@ -7,12 +7,8 @@ from langflow.graph.graph.constants import lazy_load_vertex_dict
from langflow.graph.graph.utils import process_flow
from langflow.graph.schema import InterfaceComponentTypes
from langflow.graph.vertex.base import Vertex
from langflow.graph.vertex.types import (
ChatVertex,
FileToolVertex,
LLMVertex,
ToolkitVertex,
)
from langflow.graph.vertex.types import (ChatVertex, FileToolVertex, LLMVertex,
ToolkitVertex)
from langflow.interface.tools.constants import FILE_TOOLS
from langflow.utils import payload
from loguru import logger
@ -216,7 +212,10 @@ class Graph:
def get_vertex(self, vertex_id: str) -> Union[None, Vertex]:
"""Returns a vertex by id."""
return self.vertex_map.get(vertex_id)
try:
return self.vertex_map.get(vertex_id)
except KeyError:
raise ValueError(f"Vertex {vertex_id} not found")
def get_vertex_edges(self, vertex_id: str) -> List[ContractEdge]:
"""Returns a list of edges for a given vertex."""

View file

@ -2,6 +2,7 @@ import ast
import json
from typing import Callable, Dict, List, Optional, Union
import yaml
from langchain_core.messages import AIMessage
from langflow.graph.utils import UnbuiltObject, flatten_list
from langflow.graph.vertex.base import StatefulVertex, StatelessVertex
@ -343,8 +344,11 @@ class ChatVertex(StatelessVertex):
return str(task.info)
else:
return f"Task {self.task_id} is not running"
if self.artifacts and "repr" in self.artifacts:
return self.artifacts["repr"] or super()._built_object_repr()
if self.artifacts:
# dump as a yaml string
yaml_str = yaml.dump(self.artifacts, default_flow_style=False)
return yaml_str
return super()._built_object_repr()
async def _run(self, *args, **kwargs):
if self.is_interface_component: