fix formatting

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-09-26 15:24:49 -03:00
commit 553bf51a7f
3 changed files with 39 additions and 55 deletions

View file

@ -134,18 +134,18 @@ export type TooltipComponentType = {
children: ReactElement; children: ReactElement;
title: string | ReactElement; title: string | ReactElement;
placement?: placement?:
| "bottom-end" | "bottom-end"
| "bottom-start" | "bottom-start"
| "bottom" | "bottom"
| "left-end" | "left-end"
| "left-start" | "left-start"
| "left" | "left"
| "right-end" | "right-end"
| "right-start" | "right-start"
| "right" | "right"
| "top-end" | "top-end"
| "top-start" | "top-start"
| "top"; | "top";
}; };
export type ProgressBarType = { export type ProgressBarType = {

View file

@ -220,7 +220,8 @@ export function validateNode(
) )
) { ) {
errors.push( errors.push(
`${type} is missing ${template.display_name || toNormalCase(template[t].name) `${type} is missing ${
template.display_name || toNormalCase(template[t].name)
}.` }.`
); );
} else if ( } else if (
@ -233,12 +234,14 @@ export function validateNode(
) { ) {
if (hasDuplicateKeys(template[t].value)) if (hasDuplicateKeys(template[t].value))
errors.push( errors.push(
`${type} (${template.display_name || template[t].name `${type} (${
template.display_name || template[t].name
}) contains duplicate keys with the same values.` }) contains duplicate keys with the same values.`
); );
if (hasEmptyKey(template[t].value)) if (hasEmptyKey(template[t].value))
errors.push( errors.push(
`${type} (${template.display_name || template[t].name `${type} (${
template.display_name || template[t].name
}) field must not be empty.` }) field must not be empty.`
); );
} }
@ -336,7 +339,6 @@ export function convertArrayToObj(arrayOfObjects) {
return objConverted; return objConverted;
} }
export function hasDuplicateKeys(array) { export function hasDuplicateKeys(array) {
const keys = {}; const keys = {};
for (const obj of array) { for (const obj of array) {

View file

@ -186,13 +186,13 @@ export function groupByFamily(
return left return left
? arrOfPossibleOutputs.map((output) => ({ ? arrOfPossibleOutputs.map((output) => ({
family: output.category, family: output.category,
type: output.full ? "" : output.nodes.join(", "), type: output.full ? "" : output.nodes.join(", "),
})) }))
: arrOfPossibleInputs.map((input) => ({ : arrOfPossibleInputs.map((input) => ({
family: input.category, family: input.category,
type: input.full ? "" : input.nodes.join(", "), type: input.full ? "" : input.nodes.join(", "),
})); }));
} }
export function buildInputs(tabsState: TabsState, id: string): string { export function buildInputs(tabsState: TabsState, id: string): string {
@ -262,7 +262,7 @@ export function buildTweakObject(tweak: tweakType) {
for (let kp in el[key]) { for (let kp in el[key]) {
try { try {
el[key][kp] = JSON.parse(el[key][kp]); el[key][kp] = JSON.parse(el[key][kp]);
} catch { } } catch {}
} }
}); });
}); });
@ -314,24 +314,21 @@ export function getPythonApiCode(
return `import requests return `import requests
from typing import Optional from typing import Optional
BASE_API_URL = "${window.location.protocol}//${window.location.host BASE_API_URL = "${window.location.protocol}//${
}/api/v1/process" window.location.host
}/api/v1/process"
FLOW_ID = "${flowId}" 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 = ${tweak && tweak.length > 0 TWEAKS = ${
tweak && tweak.length > 0
? buildTweakObject(tweak) ? buildTweakObject(tweak)
: JSON.stringify(tweaks, null, 2) : JSON.stringify(tweaks, null, 2)
} }
<<<<<<< HEAD
def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None${!isAuth ? `, apiKey: str=""` : ""
}) -> dict:
=======
def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None${ def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None${
!isAuth ? `, api_key: Optional[str] = None` : "" !isAuth ? `, api_key: Optional[str] = None` : ""
}) -> dict: }) -> dict:
>>>>>>> 1773f3fda830988438e7f3e3aa40959f1df692f5
""" """
Run a flow with a given message and optional tweaks. Run a flow with a given message and optional tweaks.
@ -354,14 +351,9 @@ def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None${
# Setup any tweaks you want to apply to the flow # Setup any tweaks you want to apply to the flow
inputs = ${inputs} inputs = ${inputs}
${!isAuth ? `api_key = "<your api key>"` : ""} ${!isAuth ? `api_key = "<your api key>"` : ""}
<<<<<<< HEAD
print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS${!isAuth ? `, apiKey=api_key` : ""
}))`;
=======
print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS${ print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS${
!isAuth ? `, api_key=api_key` : "" !isAuth ? `, api_key=api_key` : ""
}))`; }))`;
>>>>>>> 1773f3fda830988438e7f3e3aa40959f1df692f5
} }
/** /**
@ -380,13 +372,6 @@ export function getCurlCode(
const inputs = buildInputs(tabsState!, flow.id); const inputs = buildInputs(tabsState!, flow.id);
return `curl -X POST \\ return `curl -X POST \\
<<<<<<< HEAD
${window.location.protocol}//${window.location.host
}/api/v1/process/${flowId} \\
-H 'Content-Type: application/json'\\
${!isAuth ? `-H 'api-key: <your api key>'\\` : ""}
-d '{"inputs": ${inputs}, "tweaks": ${tweak && tweak.length > 0
=======
${window.location.protocol}//${ ${window.location.protocol}//${
window.location.host window.location.host
}/api/v1/process/${flowId} \\ }/api/v1/process/${flowId} \\
@ -395,10 +380,9 @@ export function getCurlCode(
} }
-d '{"inputs": ${inputs}, "tweaks": ${ -d '{"inputs": ${inputs}, "tweaks": ${
tweak && tweak.length > 0 tweak && tweak.length > 0
>>>>>>> 1773f3fda830988438e7f3e3aa40959f1df692f5
? buildTweakObject(tweak) ? buildTweakObject(tweak)
: JSON.stringify(tweaks, null, 2) : JSON.stringify(tweaks, null, 2)
}}'`; }}'`;
} }
/** /**
@ -415,10 +399,11 @@ export function getPythonCode(
const tweaks = buildTweaks(flow); const tweaks = buildTweaks(flow);
const inputs = buildInputs(tabsState!, flow.id); const inputs = buildInputs(tabsState!, flow.id);
return `from langflow import load_flow_from_json return `from langflow import load_flow_from_json
TWEAKS = ${tweak && tweak.length > 0 TWEAKS = ${
tweak && tweak.length > 0
? buildTweakObject(tweak) ? buildTweakObject(tweak)
: JSON.stringify(tweaks, null, 2) : 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
inputs = ${inputs} inputs = ${inputs}
@ -448,22 +433,19 @@ chat_input_field: Input key that you want the chat to send the user message with
<langflow-chat <langflow-chat
window_title="${flowName}" window_title="${flowName}"
flow_id="${flowId}" flow_id="${flowId}"
${tabsState![flow.id] && tabsState![flow.id].formKeysData ${
tabsState![flow.id] && tabsState![flow.id].formKeysData
? `chat_inputs='${inputs}' ? `chat_inputs='${inputs}'
chat_input_field="${chat_input_field}" chat_input_field="${chat_input_field}"
` `
: "" : ""
}host_url="http://localhost:7860"${!isAuth }host_url="http://localhost:7860"${
!isAuth
? ` ? `
api_key="..."` api_key="..."`
: "" : ""
<<<<<<< HEAD
}
=======
} }
>>>>>>> 1773f3fda830988438e7f3e3aa40959f1df692f5
></langflow-chat>`; ></langflow-chat>`;
} }