Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(validate.py): extract build_graph function to langflow.inter… #204

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/backend/langflow/api/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
PromptValidationResponse,
validate_prompt,
)
from langflow.interface.run import build_graph
from langflow.utils.logger import logger
from langflow.utils.validate import validate_code

Expand All @@ -33,3 +34,20 @@ def post_validate_prompt(prompt: Prompt):
except Exception as e:
logger.exception(e)
raise HTTPException(status_code=500, detail=str(e)) from e


# validate node
@router.post("/node/{node_id}", status_code=200)
def post_validate_node(node_id: str, data: dict):
try:
# build graph
graph = build_graph(data)
# validate node
node = graph.get_node(node_id)
if node is not None:
_ = node.build()
return str(node.params)
raise Exception(f"Node {node_id} not found")
except Exception as e:
logger.exception(e)
raise HTTPException(status_code=500, detail=str(e)) from e
12 changes: 6 additions & 6 deletions src/backend/langflow/interface/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def build_langchain_object_with_caching(data_graph):
"""

logger.debug("Building langchain object")
graph = build_graph(data_graph)
return graph.build()


def build_graph(data_graph):
nodes = data_graph["nodes"]
# Add input variables
# nodes = payload.extract_input_variables(nodes)
# Nodes, edges and root node
edges = data_graph["edges"]
graph = Graph(nodes, edges)

return graph.build()
return Graph(nodes, edges)


def build_langchain_object(data_graph):
Expand Down
12 changes: 12 additions & 0 deletions src/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"reactflow": "^11.5.5",
"tailwindcss": "^3.2.6",
"typescript": "^4.9.5",
"use-debounce": "^9.0.4",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
Loading