chore: Update Python API code to use optional typing and fix formatting
This commit is contained in:
parent
273df44963
commit
5dce2cddef
2 changed files with 43 additions and 43 deletions
|
|
@ -8,19 +8,19 @@
|
||||||
export default function getPythonApiCode(
|
export default function getPythonApiCode(
|
||||||
flowId: string,
|
flowId: string,
|
||||||
isAuth: boolean,
|
isAuth: boolean,
|
||||||
tweaksBuildedObject,
|
tweaksBuildedObject
|
||||||
): string {
|
): string {
|
||||||
const tweaksObject = tweaksBuildedObject[0];
|
const tweaksObject = tweaksBuildedObject[0];
|
||||||
return `import requests
|
return `import requests
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
BASE_API_URL = "${window.location.protocol}//${window.location.host}/api/v1/run"
|
BASE_API_URL = "${window.location.protocol}//${window.location.host}/api/v1/run"
|
||||||
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 = ${JSON.stringify(tweaksObject, null, 2)}
|
TWEAKS = ${JSON.stringify(tweaksObject, null, 2)}
|
||||||
|
|
||||||
def run_flow(message: str,
|
def run_flow(message: str,
|
||||||
flow_id: str,
|
flow_id: str,
|
||||||
output_type: str = "chat",
|
output_type: str = "chat",
|
||||||
input_type: str = "chat",
|
input_type: str = "chat",
|
||||||
|
|
@ -49,10 +49,10 @@ export default function getPythonApiCode(
|
||||||
response = requests.post(api_url, json=payload, headers=headers)
|
response = requests.post(api_url, json=payload, headers=headers)
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
# Setup any tweaks you want to apply to the flow
|
# Setup any tweaks you want to apply to the flow
|
||||||
message = "message"
|
message = "message"
|
||||||
${!isAuth ? `api_key = "<your api key>"` : ""}
|
${!isAuth ? `api_key = "<your api key>"` : ""}
|
||||||
print(run_flow(message=message, flow_id=FLOW_ID, tweaks=TWEAKS${
|
print(run_flow(message=message, flow_id=FLOW_ID, tweaks=TWEAKS${
|
||||||
!isAuth ? `, api_key=api_key` : ""
|
!isAuth ? `, api_key=api_key` : ""
|
||||||
}))`;
|
}))`;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,14 @@
|
||||||
*/
|
*/
|
||||||
export default function getPythonCode(
|
export default function getPythonCode(
|
||||||
flowName: string,
|
flowName: string,
|
||||||
tweaksBuildedObject,
|
tweaksBuildedObject
|
||||||
): string {
|
): string {
|
||||||
const tweaksObject = tweaksBuildedObject[0];
|
const tweaksObject = tweaksBuildedObject[0];
|
||||||
|
|
||||||
return `from langflow.load import run_flow_from_json
|
return `from langflow.load import run_flow_from_json
|
||||||
TWEAKS = ${JSON.stringify(tweaksObject, null, 2)}
|
TWEAKS = ${JSON.stringify(tweaksObject, null, 2)}
|
||||||
|
|
||||||
result = run_flow_from_json(flow="${flowName}.json",
|
result = run_flow_from_json(flow="${flowName}.json",
|
||||||
input_value="message",
|
input_value="message",
|
||||||
fallback_to_env_vars=True, # False by default
|
fallback_to_env_vars=True, # False by default
|
||||||
tweaks=TWEAKS)`;
|
tweaks=TWEAKS)`;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue