Merge branch 'form_io' of github.com:logspace-ai/langflow into form_io

This commit is contained in:
Lucas Oliveira 2023-06-27 20:58:11 -03:00
commit e1efeb6b33
4 changed files with 42 additions and 15 deletions

View file

@ -31,14 +31,28 @@ def post_validate_code(code: Code):
def post_validate_prompt(prompt: ValidatePromptRequest): def post_validate_prompt(prompt: ValidatePromptRequest):
try: try:
input_variables = validate_prompt(prompt.template) input_variables = validate_prompt(prompt.template)
# Reinitialize custom_fields
old_custom_fields = prompt.frontend_node.custom_fields.copy()
prompt.frontend_node.custom_fields = []
# Add new variables to the template
for variable in input_variables: for variable in input_variables:
try: try:
template_field = TemplateField( template_field = TemplateField(
name=variable, field_type="str", show=True, advanced=False name=variable, field_type="str", show=True, advanced=False
) )
prompt.frontend_node.template[variable] = template_field.dict() prompt.frontend_node.template[variable] = template_field.to_dict()
prompt.frontend_node.custom_fields.append(variable) prompt.frontend_node.custom_fields.append(variable)
except Exception as exc:
logger.exception(exc)
raise HTTPException(status_code=500, detail=str(exc)) from exc
# Remove variables that are not in the template anymore
for variable in old_custom_fields:
if variable not in input_variables:
try:
prompt.frontend_node.template.pop(variable, None)
except Exception as exc: except Exception as exc:
logger.exception(exc) logger.exception(exc)
raise HTTPException(status_code=500, detail=str(exc)) from exc raise HTTPException(status_code=500, detail=str(exc)) from exc

View file

@ -260,6 +260,9 @@ export default function ParameterComponent({
</div> </div>
) : left === true && type === "prompt" ? ( ) : left === true && type === "prompt" ? (
<PromptAreaComponent <PromptAreaComponent
setNodeClass={(nodeClass) => {
data.node = nodeClass;
}}
nodeClass={data.node} nodeClass={data.node}
disabled={disabled} disabled={disabled}
value={data.node.template[name].value ?? ""} value={data.node.template[name].value ?? ""}

View file

@ -7,8 +7,8 @@ import { INPUT_STYLE } from "../../constants";
import { ExternalLink } from "lucide-react"; import { ExternalLink } from "lucide-react";
export default function PromptAreaComponent({ export default function PromptAreaComponent({
nodeClass,
setNodeClass, setNodeClass,
nodeClass,
value, value,
onChange, onChange,
disabled, disabled,

View file

@ -830,11 +830,17 @@ export function groupByFamily(data, baseClasses) {
Object.keys(data).map((d) => { Object.keys(data).map((d) => {
Object.keys(data[d]).map((n) => { Object.keys(data[d]).map((n) => {
try {
if ( if (
data[d][n].base_classes.some((r) => baseClasses.split("\n").includes(r)) data[d][n].base_classes.some((r) =>
baseClasses.split("\n").includes(r)
)
) { ) {
arrOfParent.push(d); arrOfParent.push(d);
} }
} catch (e) {
console.log(e);
}
}); });
}); });
@ -844,6 +850,7 @@ export function groupByFamily(data, baseClasses) {
Object.keys(data).map((d) => { Object.keys(data).map((d) => {
Object.keys(data[d]).map((n) => { Object.keys(data[d]).map((n) => {
try {
baseClasses.split("\n").forEach((tol) => { baseClasses.split("\n").forEach((tol) => {
data[d][n].base_classes.forEach((data) => { data[d][n].base_classes.forEach((data) => {
if (tol == data) { if (tol == data) {
@ -854,6 +861,9 @@ export function groupByFamily(data, baseClasses) {
} }
}); });
}); });
} catch (e) {
console.log(e);
}
}); });
}); });