diff --git a/src/frontend/src/modals/apiModal/views/index.tsx b/src/frontend/src/modals/apiModal/views/index.tsx
index 7c24ededa..a5cc47721 100644
--- a/src/frontend/src/modals/apiModal/views/index.tsx
+++ b/src/frontend/src/modals/apiModal/views/index.tsx
@@ -37,17 +37,12 @@ const ApiModal = forwardRef(
flow: FlowType;
children: ReactNode;
},
- ref
+ ref,
) => {
- let tweak = useTweaksStore((state) => state.tweak);
+ const tweak = useTweaksStore((state) => state.tweak);
const addTweaks = useTweaksStore((state) => state.setTweak);
const setTweaksList = useTweaksStore((state) => state.setTweaksList);
const tweaksList = useTweaksStore((state) => state.tweaksList);
- // ! Workdaround to fix the issue with the tweak object being an array
- // TODO: Fix the issue with the tweak object being an array
- if (Array.isArray(tweak) && tweak.length === 1) {
- tweak = tweak[0];
- }
const [activeTweaks, setActiveTweaks] = useState(false);
const { autoLogin } = useContext(AuthContext);
@@ -113,7 +108,7 @@ const ApiModal = forwardRef(
buildTweakObject(
nodeId,
element.data.node.template[templateField].value,
- element.data.node.template[templateField]
+ element.data.node.template[templateField],
);
}
});
@@ -130,7 +125,7 @@ const ApiModal = forwardRef(
async function buildTweakObject(
tw: string,
changes: string | string[] | boolean | number | Object[] | Object,
- template: TemplateVariableType
+ template: TemplateVariableType,
) {
changes = getChangesType(changes, template);
@@ -167,12 +162,6 @@ const ApiModal = forwardRef(
}
const addCodes = (cloneTweak) => {
- // if cloneTweak is an array and it's lenght is 1, then it's a single tweak
- // so just get the first element
- if (Array.isArray(cloneTweak) && cloneTweak.length === 1) {
- cloneTweak = cloneTweak[0];
- }
-
const pythonApiCode = getPythonApiCode(flow?.id, autoLogin, cloneTweak);
const curl_code = getCurlCode(flow?.id, autoLogin, cloneTweak);
const pythonCode = getPythonCode(flow?.name, cloneTweak);
@@ -217,7 +206,7 @@ const ApiModal = forwardRef(
);
- }
+ },
);
export default ApiModal;
diff --git a/src/frontend/src/utils/utils.ts b/src/frontend/src/utils/utils.ts
index 2ef264c98..b3a6e50f3 100644
--- a/src/frontend/src/utils/utils.ts
+++ b/src/frontend/src/utils/utils.ts
@@ -60,7 +60,7 @@ export function normalCaseToSnakeCase(str: string): string {
export function toTitleCase(
str: string | undefined,
- isNodeField?: boolean
+ isNodeField?: boolean,
): string {
if (!str) return "";
let result = str
@@ -69,7 +69,7 @@ export function toTitleCase(
if (isNodeField) return word;
if (index === 0) {
return checkUpperWords(
- word[0].toUpperCase() + word.slice(1).toLowerCase()
+ word[0].toUpperCase() + word.slice(1).toLowerCase(),
);
}
return checkUpperWords(word.toLowerCase());
@@ -82,7 +82,7 @@ export function toTitleCase(
if (isNodeField) return word;
if (index === 0) {
return checkUpperWords(
- word[0].toUpperCase() + word.slice(1).toLowerCase()
+ word[0].toUpperCase() + word.slice(1).toLowerCase(),
);
}
return checkUpperWords(word.toLowerCase());
@@ -122,7 +122,7 @@ export function groupByFamily(
data: APIDataType,
baseClasses: string,
left: boolean,
- flow?: NodeType[]
+ flow?: NodeType[],
): groupedObjType[] {
const baseClassesSet = new Set(baseClasses.split("\n"));
let arrOfPossibleInputs: Array<{
@@ -148,7 +148,7 @@ export function groupByFamily(
baseClassesSet.has(template.type)) ||
(template.input_types &&
template.input_types.some((inputType) =>
- baseClassesSet.has(inputType)
+ baseClassesSet.has(inputType),
)))
);
};
@@ -168,7 +168,7 @@ export function groupByFamily(
hasBaseClassInBaseClasses:
foundNode?.hasBaseClassInBaseClasses ||
nodeData.node!.base_classes.some((baseClass) =>
- baseClassesSet.has(baseClass)
+ baseClassesSet.has(baseClass),
), //seta como anterior ou verifica se o node tem base class
displayName: nodeData.node?.display_name,
});
@@ -185,10 +185,10 @@ export function groupByFamily(
if (!foundNode) {
foundNode = {
hasBaseClassInTemplate: Object.values(node!.template).some(
- checkBaseClass
+ checkBaseClass,
),
hasBaseClassInBaseClasses: node!.base_classes.some((baseClass) =>
- baseClassesSet.has(baseClass)
+ baseClassesSet.has(baseClass),
),
displayName: node?.display_name,
};
@@ -245,7 +245,7 @@ export function getRandomDescription(): string {
export function getRandomName(
retry: number = 0,
noSpace: boolean = false,
- maxRetries: number = 3
+ maxRetries: number = 3,
): string {
const left: string[] = ADJECTIVES;
const right: string[] = NOUNS;
@@ -324,8 +324,9 @@ export function getChatInputField(flowState?: FlowState) {
export function getPythonApiCode(
flowId: string,
isAuth: boolean,
- tweaksBuildedObject
+ tweaksBuildedObject,
): string {
+ const tweaksObject = tweaksBuildedObject[0];
return `import requests
from typing import Optional
@@ -333,7 +334,7 @@ BASE_API_URL = "${window.location.protocol}//${window.location.host}/api/v1/run"
FLOW_ID = "${flowId}"
# You can tweak the flow by adding a tweaks dictionary
# e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}}
-TWEAKS = ${JSON.stringify(tweaksBuildedObject, null, 2)}
+TWEAKS = ${JSON.stringify(tweaksObject, null, 2)}
def run_flow(message: str,
flow_id: str,
@@ -381,8 +382,10 @@ print(run_flow(message=message, flow_id=FLOW_ID, tweaks=TWEAKS${
export function getCurlCode(
flowId: string,
isAuth: boolean,
- tweaksBuildedObject
+ tweaksBuildedObject,
): string {
+ const tweaksObject = tweaksBuildedObject[0];
+
return `curl -X POST \\
${window.location.protocol}//${
window.location.host
@@ -393,7 +396,7 @@ export function getCurlCode(
-d '{"input_value": "message",
"output_type": "chat",
"input_type": "chat",
- "tweaks": ${JSON.stringify(tweaksBuildedObject, null, 2)}'
+ "tweaks": ${JSON.stringify(tweaksObject, null, 2)}'
`;
}
@@ -421,8 +424,10 @@ export function getOutputIds(flow) {
* @returns {string} - The python code
*/
export function getPythonCode(flowName: string, tweaksBuildedObject): string {
+ const tweaksObject = tweaksBuildedObject[0];
+
return `from langflow.load import run_flow_from_json
-TWEAKS = ${JSON.stringify(tweaksBuildedObject, null, 2)}
+TWEAKS = ${JSON.stringify(tweaksObject, null, 2)}
result = run_flow_from_json(flow="${flowName}.json",
input_value="message",
@@ -438,7 +443,7 @@ result = run_flow_from_json(flow="${flowName}.json",
export function getWidgetCode(
flowId: string,
flowName: string,
- isAuth: boolean
+ isAuth: boolean,
): string {
return `
@@ -563,7 +568,7 @@ export function checkLocalStorageKey(key: string): boolean {
export function IncrementObjectKey(
object: object,
- key: string
+ key: string,
): { newKey: string; increment: number } {
let count = 1;
const type = removeCountFromString(key);
@@ -635,7 +640,7 @@ export function getSetFromObject(obj: object, key?: string): Set {
export function getFieldTitle(
template: APITemplateType,
- templateField: string
+ templateField: string,
): string {
return template[templateField].display_name
? template[templateField].display_name!