🐛 fix(codeAreaComponent): update initial state of myValue to handle non-string values properly
🐛 fix(constants.tsx): refactor getCurlCode and getPythonCode to use buildTweakObject function for generating tweak object 🐛 fix(ApiModal): update logic for opening accordions based on tweak.current length and closeEdit value
This commit is contained in:
parent
7c777bf692
commit
fdb998688a
3 changed files with 38 additions and 14 deletions
|
|
@ -12,7 +12,7 @@ export default function CodeAreaComponent({
|
||||||
disabled,
|
disabled,
|
||||||
editNode = false,
|
editNode = false,
|
||||||
}: TextAreaComponentType) {
|
}: TextAreaComponentType) {
|
||||||
const [myValue, setMyValue] = useState(value);
|
const [myValue, setMyValue] = useState(typeof value == "string" ? value : JSON.stringify(value));
|
||||||
const { openPopUp } = useContext(PopUpContext);
|
const { openPopUp } = useContext(PopUpContext);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
|
|
@ -22,7 +22,7 @@ export default function CodeAreaComponent({
|
||||||
}, [disabled, onChange]);
|
}, [disabled, onChange]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setMyValue(value);
|
setMyValue(typeof value == "string" ? value : JSON.stringify(value));
|
||||||
}, [value]);
|
}, [value]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ FLOW_ID = "${flowId}"
|
||||||
# You can tweak the flow by adding a tweaks dictionary
|
# You can tweak the flow by adding a tweaks dictionary
|
||||||
# e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}}
|
# e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}}
|
||||||
TWEAKS = ${
|
TWEAKS = ${
|
||||||
tweak && tweak.length > 0 ? JSON.stringify(tweak, null, 2).replace(/\\/g, '') : JSON.stringify(tweaks, null, 2)
|
tweak && tweak.length > 0 ? buildTweakObject(tweak): JSON.stringify(tweaks, null, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
def run_flow(message: str, flow_id: str, tweaks: dict = None) -> dict:
|
def run_flow(message: str, flow_id: str, tweaks: dict = None) -> dict:
|
||||||
|
|
@ -111,7 +111,7 @@ export const getCurlCode = (flow: FlowType, tweak?): string => {
|
||||||
}/api/v1/process/${flowId} \\
|
}/api/v1/process/${flowId} \\
|
||||||
-H 'Content-Type: application/json' \\
|
-H 'Content-Type: application/json' \\
|
||||||
-d '{"inputs": {"input": message}, "tweaks": ${
|
-d '{"inputs": {"input": message}, "tweaks": ${
|
||||||
tweak && tweak.length > 0 ? JSON.stringify(tweak, null, 2).replace(/\\/g, '') : JSON.stringify(tweaks, null, 2)
|
tweak && tweak.length > 0 ? buildTweakObject(tweak) : JSON.stringify(tweaks, null, 2)
|
||||||
}}'`;
|
}}'`;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
|
|
@ -124,13 +124,32 @@ export const getPythonCode = (flow: FlowType, tweak?): string => {
|
||||||
const tweaks = buildTweaks(flow);
|
const tweaks = buildTweaks(flow);
|
||||||
return `from langflow import load_flow_from_json
|
return `from langflow import load_flow_from_json
|
||||||
TWEAKS = ${
|
TWEAKS = ${
|
||||||
tweak && tweak.length > 0 ? JSON.stringify(tweak, null, 2).replace(/\\/g, '') : JSON.stringify(tweaks, null, 2)
|
tweak && tweak.length > 0 ? buildTweakObject(tweak) : JSON.stringify(tweaks, null, 2)
|
||||||
}
|
}
|
||||||
flow = load_flow_from_json("${flowName}.json", tweaks=TWEAKS)
|
flow = load_flow_from_json("${flowName}.json", tweaks=TWEAKS)
|
||||||
# Now you can use it like any chain
|
# Now you can use it like any chain
|
||||||
flow("Hey, have you heard of LangFlow?")`;
|
flow("Hey, have you heard of LangFlow?")`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function buildTweakObject(tweak){
|
||||||
|
tweak.forEach(el => {
|
||||||
|
Object.keys(el).forEach(key => {
|
||||||
|
for (let kp in el[key]) {
|
||||||
|
try{
|
||||||
|
el[key][kp] = JSON.parse(el[key][kp]);
|
||||||
|
console.log(el[key][kp]);
|
||||||
|
}
|
||||||
|
catch{}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const tweakString = JSON.stringify(tweak, null, 2);
|
||||||
|
console.log(tweakString);
|
||||||
|
|
||||||
|
return tweakString;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base text for subtitle of Import Dialog
|
* The base text for subtitle of Import Dialog
|
||||||
* @constant
|
* @constant
|
||||||
|
|
|
||||||
|
|
@ -103,9 +103,14 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (closeEdit !== "") {
|
if (closeEdit !== "") {
|
||||||
setActiveTab("3");
|
|
||||||
tweak.current = getTweak;
|
tweak.current = getTweak;
|
||||||
|
if(tweak.current.length > 0){
|
||||||
|
setActiveTab("3");
|
||||||
openAccordions();
|
openAccordions();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
startTweaks();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
startTweaks();
|
startTweaks();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue