Skip to content

Instantly share code, notes, and snippets.

@ogabrielluiz
Created June 19, 2023 15:19
Show Gist options
  • Save ogabrielluiz/7fae719bf0e4c4d8f239d6e0dd2c627f to your computer and use it in GitHub Desktop.
Save ogabrielluiz/7fae719bf0e4c4d8f239d6e0dd2c627f to your computer and use it in GitHub Desktop.
Test to check if the same flow can be run by multiple people passing their own API keys.
import requests
BASE_API_URL = "http://localhost:3000/api/v1/predict"
FLOW_ID = "864c4f98-2e59-468b-8e13-79cd8da07468" # replace with yours
# You can tweak the flow by adding a tweaks dictionary
# e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}}
TWEAKS = {"ChatOpenAI-g4jEr": {}, "ConversationChain-UidfJ": {}} # replace with yours
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["tweaks"] = tweaks
response = requests.post(api_url, json=payload)
return response.json()
# Replate these with your own API keys
openai_api_keys = [
"sk-DX",
"sk-A",
"sk-8",
]
names = ["Gabriel", "Samuel", "Bob"]
for key, name in zip(openai_api_keys, names):
TWEAKS["ChatOpenAI-g4jEr"] = {"openai_api_key": key} # replace with yours
r1 = run_flow(f"Hello, my name is {name}", FLOW_ID, TWEAKS)
print(r1["result"], "\n")
for key, name in zip(openai_api_keys, names):
TWEAKS["ChatOpenAI-g4jEr"] = {"openai_api_key": key} # replace with yours
r2 = run_flow("What is my name?", FLOW_ID, TWEAKS)
assert name in r2["result"]
print(r2["result"], "\n")
print(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment