fix(api): make frontend_node field optional in ValidatePromptRequest to allow for a tweak call without a frontend_node

fix(api): handle case where frontend_node is None in post_validate_prompt to avoid attempting to update a non-existent node
This commit is contained in:
anovazzi1 2023-08-29 22:03:54 -03:00
commit 8a772086e2
2 changed files with 11 additions and 3 deletions

View file

@ -1,3 +1,4 @@
from typing import Optional
from langflow.template.frontend_node.base import FrontendNode
from pydantic import BaseModel, validator
@ -20,7 +21,8 @@ class FrontendNodeRequest(FrontendNode):
class ValidatePromptRequest(BaseModel):
name: str
template: str
frontend_node: FrontendNodeRequest
#optional for tweak call
frontend_node: Optional[FrontendNodeRequest]
# Build ValidationResponse class for {"imports": {"errors": []}, "function": {"errors": []}}
@ -39,7 +41,8 @@ class CodeValidationResponse(BaseModel):
class PromptValidationResponse(BaseModel):
input_variables: list
frontend_node: FrontendNodeRequest
#object return for tweak call
frontend_node: FrontendNodeRequest | object
INVALID_CHARACTERS = {

View file

@ -31,7 +31,12 @@ def post_validate_code(code: Code):
def post_validate_prompt(prompt_request: ValidatePromptRequest):
try:
input_variables = validate_prompt(prompt_request.template)
# Check if frontend_node is None before proceeding to avoid attempting to update a non-existent node.
if prompt_request.frontend_node is None:
return PromptValidationResponse(
input_variables=input_variables,
frontend_node={},
)
old_custom_fields = get_old_custom_fields(prompt_request)
add_new_variables_to_template(input_variables, prompt_request)