Refactor: Make changes to api_key only show up in codetabs when authenticated
This commit is contained in:
parent
b1ef10e79b
commit
ac67fff000
3 changed files with 21 additions and 14 deletions
|
|
@ -30,7 +30,7 @@ class AuthSettings(BaseSettings):
|
||||||
|
|
||||||
# If AUTO_LOGIN = True
|
# If AUTO_LOGIN = True
|
||||||
# > The application does not request login and logs in automatically as a super user.
|
# > The application does not request login and logs in automatically as a super user.
|
||||||
AUTO_LOGIN: bool = False
|
AUTO_LOGIN: bool = True
|
||||||
FIRST_SUPERUSER: str = "langflow"
|
FIRST_SUPERUSER: str = "langflow"
|
||||||
FIRST_SUPERUSER_PASSWORD: str = "langflow"
|
FIRST_SUPERUSER_PASSWORD: str = "langflow"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import {
|
||||||
tabsArray,
|
tabsArray,
|
||||||
} from "../../utils/utils";
|
} from "../../utils/utils";
|
||||||
import BaseModal from "../baseModal";
|
import BaseModal from "../baseModal";
|
||||||
|
import { AuthContext } from "../../contexts/authContext";
|
||||||
|
|
||||||
const ApiModal = forwardRef(
|
const ApiModal = forwardRef(
|
||||||
(
|
(
|
||||||
|
|
@ -39,15 +40,16 @@ const ApiModal = forwardRef(
|
||||||
},
|
},
|
||||||
ref
|
ref
|
||||||
) => {
|
) => {
|
||||||
|
const { autoLogin } = useContext(AuthContext);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [activeTab, setActiveTab] = useState("0");
|
const [activeTab, setActiveTab] = useState("0");
|
||||||
const tweak = useRef<tweakType>([]);
|
const tweak = useRef<tweakType>([]);
|
||||||
const tweaksList = useRef<string[]>([]);
|
const tweaksList = useRef<string[]>([]);
|
||||||
const { setTweak, getTweak, tabsState } = useContext(TabsContext);
|
const { setTweak, getTweak, tabsState } = useContext(TabsContext);
|
||||||
const pythonApiCode = getPythonApiCode(flow, tweak.current, tabsState);
|
const pythonApiCode = getPythonApiCode(flow, autoLogin, tweak.current, tabsState);
|
||||||
const curl_code = getCurlCode(flow, tweak.current, tabsState);
|
const curl_code = getCurlCode(flow, autoLogin, tweak.current, tabsState);
|
||||||
const pythonCode = getPythonCode(flow, tweak.current, tabsState);
|
const pythonCode = getPythonCode(flow, tweak.current, tabsState);
|
||||||
const widgetCode = getWidgetCode(flow, tabsState);
|
const widgetCode = getWidgetCode(flow, autoLogin, tabsState);
|
||||||
const tweaksCode = buildTweaks(flow);
|
const tweaksCode = buildTweaks(flow);
|
||||||
const codesArray = [
|
const codesArray = [
|
||||||
curl_code,
|
curl_code,
|
||||||
|
|
@ -150,10 +152,10 @@ const ApiModal = forwardRef(
|
||||||
tweak.current.push(newTweak);
|
tweak.current.push(newTweak);
|
||||||
}
|
}
|
||||||
|
|
||||||
const pythonApiCode = getPythonApiCode(flow, tweak.current, tabsState);
|
const pythonApiCode = getPythonApiCode(flow, autoLogin ,tweak.current, tabsState);
|
||||||
const curl_code = getCurlCode(flow, tweak.current, tabsState);
|
const curl_code = getCurlCode(flow, autoLogin, tweak.current, tabsState);
|
||||||
const pythonCode = getPythonCode(flow, tweak.current, tabsState);
|
const pythonCode = getPythonCode(flow, tweak.current, tabsState);
|
||||||
const widgetCode = getWidgetCode(flow, tabsState);
|
const widgetCode = getWidgetCode(flow, autoLogin,tabsState);
|
||||||
|
|
||||||
tabs![0].code = curl_code;
|
tabs![0].code = curl_code;
|
||||||
tabs![1].code = pythonApiCode;
|
tabs![1].code = pythonApiCode;
|
||||||
|
|
|
||||||
|
|
@ -299,6 +299,7 @@ export function getChatInputField(flow: FlowType, tabsState?: TabsState) {
|
||||||
*/
|
*/
|
||||||
export function getPythonApiCode(
|
export function getPythonApiCode(
|
||||||
flow: FlowType,
|
flow: FlowType,
|
||||||
|
isAuth: boolean,
|
||||||
tweak?: any[],
|
tweak?: any[],
|
||||||
tabsState?: TabsState
|
tabsState?: TabsState
|
||||||
): string {
|
): string {
|
||||||
|
|
@ -325,7 +326,7 @@ TWEAKS = ${
|
||||||
: JSON.stringify(tweaks, null, 2)
|
: JSON.stringify(tweaks, null, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None) -> dict:
|
def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None${!isAuth ? `, apiKey: str` : ""}) -> dict:
|
||||||
"""
|
"""
|
||||||
Run a flow with a given message and optional tweaks.
|
Run a flow with a given message and optional tweaks.
|
||||||
|
|
||||||
|
|
@ -336,7 +337,7 @@ def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None) -> dict:
|
||||||
"""
|
"""
|
||||||
api_url = f"{BASE_API_URL}/{flow_id}"
|
api_url = f"{BASE_API_URL}/{flow_id}"
|
||||||
|
|
||||||
payload = {"inputs": inputs}
|
payload = {"inputs": inputs${!isAuth ? `, "api_key": apiKey` : ""}}
|
||||||
|
|
||||||
if tweaks:
|
if tweaks:
|
||||||
payload["tweaks"] = tweaks
|
payload["tweaks"] = tweaks
|
||||||
|
|
@ -346,7 +347,8 @@ def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None) -> dict:
|
||||||
|
|
||||||
# Setup any tweaks you want to apply to the flow
|
# Setup any tweaks you want to apply to the flow
|
||||||
inputs = ${inputs}
|
inputs = ${inputs}
|
||||||
print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS))`;
|
${!isAuth ? `api_key = "..."` : ""}
|
||||||
|
print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS${!isAuth ? `, api_key` : ""}))`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -356,6 +358,7 @@ print(run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS))`;
|
||||||
*/
|
*/
|
||||||
export function getCurlCode(
|
export function getCurlCode(
|
||||||
flow: FlowType,
|
flow: FlowType,
|
||||||
|
isAuth: boolean,
|
||||||
tweak?: any[],
|
tweak?: any[],
|
||||||
tabsState?: TabsState
|
tabsState?: TabsState
|
||||||
): string {
|
): string {
|
||||||
|
|
@ -368,7 +371,7 @@ export function getCurlCode(
|
||||||
window.location.host
|
window.location.host
|
||||||
}/api/v1/process/${flowId} \\
|
}/api/v1/process/${flowId} \\
|
||||||
-H 'Content-Type: application/json' \\
|
-H 'Content-Type: application/json' \\
|
||||||
-d '{"inputs": ${inputs},"api_key": "...", "tweaks": ${
|
-d '{"inputs": ${inputs},${!isAuth ? ` "api_key": "...", ` : " "}"tweaks": ${
|
||||||
tweak && tweak.length > 0
|
tweak && tweak.length > 0
|
||||||
? buildTweakObject(tweak)
|
? buildTweakObject(tweak)
|
||||||
: JSON.stringify(tweaks, null, 2)
|
: JSON.stringify(tweaks, null, 2)
|
||||||
|
|
@ -405,7 +408,7 @@ flow(inputs)`;
|
||||||
* @param {string} flow - The current flow.
|
* @param {string} flow - The current flow.
|
||||||
* @returns {string} - The widget code
|
* @returns {string} - The widget code
|
||||||
*/
|
*/
|
||||||
export function getWidgetCode(flow: FlowType, tabsState?: TabsState): string {
|
export function getWidgetCode(flow: FlowType, isAuth: boolean, tabsState?: TabsState): string {
|
||||||
const flowId = flow.id;
|
const flowId = flow.id;
|
||||||
const flowName = flow.name;
|
const flowName = flow.name;
|
||||||
const inputs = buildInputs(tabsState!, flow.id);
|
const inputs = buildInputs(tabsState!, flow.id);
|
||||||
|
|
@ -425,8 +428,10 @@ chat_input_field: Input key that you want the chat to send the user message with
|
||||||
chat_input_field="${chat_input_field}"
|
chat_input_field="${chat_input_field}"
|
||||||
`
|
`
|
||||||
: ""
|
: ""
|
||||||
}host_url="http://localhost:7860"
|
}host_url="http://localhost:7860"${(!isAuth ? `
|
||||||
api_key="..."
|
api_key="..."`
|
||||||
|
: "")}
|
||||||
|
|
||||||
></langflow-chat>`;
|
></langflow-chat>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue