🔥 refactor(endpoints.py): rename client_id to flow_id in create_upload_file endpoint
✨ feat(endpoints.py): add UploadFileResponse schema to standardize upload file response
The client_id parameter in the create_upload_file endpoint has been renamed to flow_id to improve semantics. The UploadFileResponse schema has been added to standardize the response of the create_upload_file endpoint. The response now includes the flowId and file_path fields.
This commit is contained in:
parent
c26ecd3bda
commit
57f322a0e6
3 changed files with 17 additions and 4 deletions
|
|
@ -8,6 +8,7 @@ from fastapi import APIRouter, Depends, HTTPException, UploadFile
|
|||
from langflow.api.v1.schemas import (
|
||||
PredictRequest,
|
||||
PredictResponse,
|
||||
UploadFileResponse,
|
||||
)
|
||||
|
||||
from langflow.interface.types import build_langchain_types_dict
|
||||
|
|
@ -57,13 +58,16 @@ async def predict_flow(
|
|||
raise HTTPException(status_code=500, detail=str(e)) from e
|
||||
|
||||
|
||||
@router.post("/upload/{client_id}", response_model=dict, status_code=201)
|
||||
async def create_upload_file(file: UploadFile, client_id: str):
|
||||
@router.post("/upload/{flow_id}", response_model=UploadFileResponse, status_code=201)
|
||||
async def create_upload_file(file: UploadFile, flow_id: str):
|
||||
# Cache file
|
||||
try:
|
||||
file_path = save_uploaded_file(file.file, file_name=client_id)
|
||||
file_path = save_uploaded_file(file.file, file_name=flow_id)
|
||||
|
||||
return {"file_path": file_path}
|
||||
return UploadFileResponse(
|
||||
flowId=flow_id,
|
||||
file_path=file_path,
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.error(f"Error saving file: {exc}")
|
||||
raise HTTPException(status_code=500, detail=str(exc)) from exc
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
from langflow.database.models.flow import FlowCreate, FlowRead
|
||||
from pydantic import BaseModel, Field, validator
|
||||
|
|
@ -101,3 +102,10 @@ class InitResponse(BaseModel):
|
|||
|
||||
class BuiltResponse(BaseModel):
|
||||
built: bool
|
||||
|
||||
|
||||
class UploadFileResponse(BaseModel):
|
||||
"""Upload file response schema."""
|
||||
|
||||
flowId: str
|
||||
file_path: Path
|
||||
|
|
|
|||
|
|
@ -49,4 +49,5 @@ export type InitTypeAPI = {
|
|||
|
||||
export type UploadFileTypeAPI = {
|
||||
file_path: string;
|
||||
flowId: string;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue