🔀 refactor(endpoints.py): rename predict_flow endpoint to process_flow and update its functionality

🔀 refactor(constants.tsx): update BASE_API_URL to reflect the changes in the predict_flow endpoint name
The predict_flow endpoint has been renamed to process_flow to better reflect its functionality. The inputs are now passed as a dictionary instead of a PredictRequest object. The tweaks parameter is now optional and is passed as a dictionary. The response model has been updated to reflect the changes in the response. The BASE_API_URL constant in constants.tsx has been updated to reflect the changes in the endpoint name.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-22 18:57:17 -03:00
commit 176738987b
2 changed files with 14 additions and 14 deletions

View file

@ -1,3 +1,4 @@
from typing import Optional
from langflow.cache.utils import save_uploaded_file
from langflow.database.models.flow import Flow
from langflow.processing.process import process_graph_cached, process_tweaks
@ -6,8 +7,7 @@ from langflow.utils.logger import logger
from fastapi import APIRouter, Depends, HTTPException, UploadFile
from langflow.api.v1.schemas import (
PredictRequest,
PredictResponse,
ProcessResponse,
UploadFileResponse,
)
@ -24,14 +24,15 @@ def get_all():
return build_langchain_types_dict()
@router.post("/predict/{flow_id}", response_model=PredictResponse)
async def predict_flow(
predict_request: PredictRequest,
@router.post("/process/{flow_id}", response_model=ProcessResponse)
async def process_flow(
flow_id: str,
inputs: dict,
tweaks: Optional[dict] = None,
session: Session = Depends(get_session),
):
"""
Endpoint to process a message using the flow passed in the bearer token.
Endpoint to process an input with a given flow_id.
"""
try:
@ -42,15 +43,14 @@ async def predict_flow(
if flow.data is None:
raise ValueError(f"Flow {flow_id} has no data")
graph_data = flow.data
if predict_request.tweaks:
if tweaks:
try:
graph_data = process_tweaks(graph_data, predict_request.tweaks)
graph_data = process_tweaks(graph_data, tweaks)
except Exception as exc:
logger.error(f"Error processing tweaks: {exc}")
response = process_graph_cached(graph_data, predict_request.message)
return PredictResponse(
result=response.get("result", ""),
intermediate_steps=response.get("thought", ""),
response = process_graph_cached(graph_data, inputs)
return ProcessResponse(
result=response,
)
except Exception as e:
# Log stack trace

View file

@ -66,7 +66,7 @@ export const getPythonApiCode = (flow: FlowType): string => {
BASE_API_URL = "${window.location.protocol}//${
window.location.host
}/api/v1/predict"
}/api/v1/process"
FLOW_ID = "${flowId}"
# You can tweak the flow by adding a tweaks dictionary
# e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}}
@ -106,7 +106,7 @@ export const getCurlCode = (flow: FlowType): string => {
return `curl -X POST \\
${window.location.protocol}//${
window.location.host
}/api/v1/predict/${flowId} \\
}/api/v1/process/${flowId} \\
-H 'Content-Type: application/json' \\
-d '{"message": "Your message", "tweaks": ${JSON.stringify(
tweaks,