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,18 +31,32 @@ def post_validate_code(code: Code):
def post_validate_prompt(prompt: ValidatePromptRequest):
try:
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:
try:
template_field = TemplateField(
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)
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:
logger.exception(exc)
raise HTTPException(status_code=500, detail=str(exc)) from exc
return PromptValidationResponse(
input_variables=input_variables,
frontend_node=prompt.frontend_node,

View file

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

View file

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

View file

@ -830,10 +830,16 @@ export function groupByFamily(data, baseClasses) {
Object.keys(data).map((d) => {
Object.keys(data[d]).map((n) => {
if (
data[d][n].base_classes.some((r) => baseClasses.split("\n").includes(r))
) {
arrOfParent.push(d);
try {
if (
data[d][n].base_classes.some((r) =>
baseClasses.split("\n").includes(r)
)
) {
arrOfParent.push(d);
}
} catch (e) {
console.log(e);
}
});
});
@ -844,16 +850,20 @@ export function groupByFamily(data, baseClasses) {
Object.keys(data).map((d) => {
Object.keys(data[d]).map((n) => {
baseClasses.split("\n").forEach((tol) => {
data[d][n].base_classes.forEach((data) => {
if (tol == data) {
arrOfType.push({
family: d,
type: data,
});
}
try {
baseClasses.split("\n").forEach((tol) => {
data[d][n].base_classes.forEach((data) => {
if (tol == data) {
arrOfType.push({
family: d,
type: data,
});
}
});
});
});
} catch (e) {
console.log(e);
}
});
});