🐛 fix(endpoints.py): make inputs and tweaks optional in process_flow endpoint

🐛 fix(process.py): make inputs optional in process_graph_cached function
The inputs and tweaks parameters in the process_flow endpoint are now optional, which allows for more flexibility in the API. The inputs parameter in the process_graph_cached function is now optional, which prevents a ValueError from being raised when a Chain object is processed without inputs.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-23 08:40:43 -03:00
commit 508c66cbaa
2 changed files with 4 additions and 2 deletions

View file

@ -27,7 +27,7 @@ def get_all():
@router.post("/process/{flow_id}", response_model=ProcessResponse) @router.post("/process/{flow_id}", response_model=ProcessResponse)
async def process_flow( async def process_flow(
flow_id: str, flow_id: str,
inputs: dict, inputs: Optional[dict] = None,
tweaks: Optional[dict] = None, tweaks: Optional[dict] = None,
session: Session = Depends(get_session), session: Session = Depends(get_session),
): ):

View file

@ -82,7 +82,7 @@ def get_input_str_if_only_one_input(inputs: dict) -> Optional[str]:
return list(inputs.values())[0] if len(inputs) == 1 else None return list(inputs.values())[0] if len(inputs) == 1 else None
def process_graph_cached(data_graph: Dict[str, Any], inputs: dict): def process_graph_cached(data_graph: Dict[str, Any], inputs: Optional[dict] = None):
""" """
Process graph by extracting input variables and replacing ZeroShotPrompt Process graph by extracting input variables and replacing ZeroShotPrompt
with PromptTemplate,then run the graph and return the result and thought. with PromptTemplate,then run the graph and return the result and thought.
@ -99,6 +99,8 @@ def process_graph_cached(data_graph: Dict[str, Any], inputs: dict):
# Generate result and thought # Generate result and thought
if isinstance(langchain_object, Chain): if isinstance(langchain_object, Chain):
if inputs is None:
raise ValueError("Inputs must be provided for a Chain")
logger.debug("Generating result and thought") logger.debug("Generating result and thought")
result = get_result_and_thought(langchain_object, inputs) result = get_result_and_thought(langchain_object, inputs)
logger.debug("Generated result and thought") logger.debug("Generated result and thought")