Refactor buildInputs function and update code that calls it
This commit is contained in:
parent
feac452f1c
commit
e4dd94021d
1 changed files with 8 additions and 14 deletions
|
|
@ -13,7 +13,7 @@ import {
|
||||||
tweakType,
|
tweakType,
|
||||||
} from "../types/components";
|
} from "../types/components";
|
||||||
import { FlowType, NodeType } from "../types/flow";
|
import { FlowType, NodeType } from "../types/flow";
|
||||||
import { FlowState, FlowsState } from "../types/tabs";
|
import { FlowState } from "../types/tabs";
|
||||||
import { buildTweaks } from "./reactflowUtils";
|
import { buildTweaks } from "./reactflowUtils";
|
||||||
|
|
||||||
export function classNames(...classes: Array<string>): string {
|
export function classNames(...classes: Array<string>): string {
|
||||||
|
|
@ -217,12 +217,8 @@ export function groupByFamily(
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildInputs(flowState?: FlowState): string {
|
export function buildInputs(): string {
|
||||||
return flowState &&
|
return '{"input_value": "message"}';
|
||||||
flowState.input_keys &&
|
|
||||||
Object.keys(flowState.input_keys!).length > 0
|
|
||||||
? JSON.stringify(flowState.input_keys)
|
|
||||||
: '{"input": "message"}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRandomElement<T>(array: T[]): T {
|
export function getRandomElement<T>(array: T[]): T {
|
||||||
|
|
@ -323,7 +319,7 @@ export function getPythonApiCode(
|
||||||
// node.data.id
|
// node.data.id
|
||||||
// }
|
// }
|
||||||
const tweaks = buildTweaks(flow);
|
const tweaks = buildTweaks(flow);
|
||||||
const inputs = buildInputs(flowState);
|
const inputs = buildInputs();
|
||||||
return `import requests
|
return `import requests
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
@ -382,12 +378,10 @@ export function getCurlCode(
|
||||||
): string {
|
): string {
|
||||||
const flowId = flow.id;
|
const flowId = flow.id;
|
||||||
const tweaks = buildTweaks(flow);
|
const tweaks = buildTweaks(flow);
|
||||||
const inputs = buildInputs(flowState);
|
const inputs = buildInputs();
|
||||||
|
|
||||||
return `curl -X POST \\
|
return `curl -X POST \\
|
||||||
${window.location.protocol}//${
|
${window.location.protocol}//${window.location.host}/api/v1/run/${flowId} \\
|
||||||
window.location.host
|
|
||||||
}/api/v1/process/${flowId} \\
|
|
||||||
-H 'Content-Type: application/json'\\${
|
-H 'Content-Type: application/json'\\${
|
||||||
!isAuth ? `\n -H 'x-api-key: <your api key>'\\` : ""
|
!isAuth ? `\n -H 'x-api-key: <your api key>'\\` : ""
|
||||||
}
|
}
|
||||||
|
|
@ -410,7 +404,7 @@ export function getPythonCode(
|
||||||
): string {
|
): string {
|
||||||
const flowName = flow.name;
|
const flowName = flow.name;
|
||||||
const tweaks = buildTweaks(flow);
|
const tweaks = buildTweaks(flow);
|
||||||
const inputs = buildInputs(flowState);
|
const inputs = buildInputs();
|
||||||
return `from langflow import load_flow_from_json
|
return `from langflow import load_flow_from_json
|
||||||
TWEAKS = ${
|
TWEAKS = ${
|
||||||
tweak && tweak.length > 0
|
tweak && tweak.length > 0
|
||||||
|
|
@ -435,7 +429,7 @@ export function getWidgetCode(
|
||||||
): string {
|
): string {
|
||||||
const flowId = flow.id;
|
const flowId = flow.id;
|
||||||
const flowName = flow.name;
|
const flowName = flow.name;
|
||||||
const inputs = buildInputs(flowState);
|
const inputs = buildInputs();
|
||||||
let chat_input_field = getChatInputField(flow, flowState);
|
let chat_input_field = getChatInputField(flow, flowState);
|
||||||
|
|
||||||
return `<script src="https://cdn.jsdelivr.net/gh/logspace-ai/langflow-embedded-chat@main/dist/build/static/js/bundle.min.js"></script>
|
return `<script src="https://cdn.jsdelivr.net/gh/logspace-ai/langflow-embedded-chat@main/dist/build/static/js/bundle.min.js"></script>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue