🐛 fix(endpoints.py): change predict_flow function signature to include flow_id and session dependencies
✨ feat(endpoints.py): add flow_id parameter to predict_flow function to allow for running a flow by ID The predict_flow function now includes a flow_id parameter and a session dependency to allow for running a flow by ID. The flow object is retrieved from the session using the flow_id parameter. If the flow is not found, a ValueError is raised. 🔨 refactor(constants.tsx): change API_URL constant to BASE_API_URL and add flow_id parameter to run_flow function The API_URL constant has been renamed to BASE_API_URL to better reflect its purpose. The run_flow function now includes a flow_id parameter to allow for running a flow by ID. The flow_id parameter is used to construct the API URL.
This commit is contained in:
parent
b2598165a6
commit
7817c64591
2 changed files with 24 additions and 15 deletions
|
|
@ -52,28 +52,33 @@ export const TEXT_DIALOG_SUBTITLE = "Edit you text.";
|
|||
export const getPythonApiCode = (flowId: string): string => {
|
||||
return `import requests
|
||||
|
||||
FLOW_ID = "${flowId}"
|
||||
API_URL = f"${window.location.protocol}//${window.location.host}/predict"
|
||||
BASE_API_URL = "${window.location.protocol}//${window.location.host}/predict"
|
||||
|
||||
def run_flow(message, tweaks=None):
|
||||
def run_flow(message: str, flow_id: str, tweaks: dict = None) -> dict:
|
||||
"""
|
||||
Run a flow with a given message and optional tweaks.
|
||||
|
||||
:param message: The message to send to the flow
|
||||
:param flow_id: The ID of the flow to run
|
||||
:param tweaks: Optional tweaks to customize the flow
|
||||
:return: The JSON response from the flow
|
||||
"""
|
||||
api_url = f"{BASE_API_URL}/{flow_id}"
|
||||
|
||||
payload = {"message": message}
|
||||
|
||||
if tweaks:
|
||||
payload = {'message': message, 'tweaks': tweaks}
|
||||
else:
|
||||
payload = {'message': message}
|
||||
payload["tweaks"] = tweaks
|
||||
|
||||
headers = {'Authorization':
|
||||
f'Bearer {FLOW_ID}',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
response = requests.post(API_URL, json=payload)
|
||||
response = requests.post(api_url, json=payload)
|
||||
return response.json()
|
||||
|
||||
# Setup any tweaks you want to apply to the flow
|
||||
tweaks = {} # {"nodeId": {"key": "value"}, "nodeId2": {"key": "value"}}
|
||||
|
||||
print(run_flow("Your message", tweaks=tweaks))`;
|
||||
FLOW_ID = "${flowId}"
|
||||
|
||||
print(run_flow("Your message", flow_id=FLOW_ID, tweaks=tweaks))`;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue