|
"""A simple script to run a Flow that can be used for development and debugging.""" |
|
|
|
import os |
|
|
|
import hydra |
|
|
|
import aiflows |
|
from aiflows.backends.api_info import ApiInfo |
|
from aiflows.utils.general_helpers import read_yaml_file, quick_load_api_keys |
|
|
|
from aiflows import logging |
|
from aiflows.flow_cache import CACHING_PARAMETERS, clear_cache |
|
|
|
from aiflows.utils import serving |
|
from aiflows.workers import run_dispatch_worker_thread |
|
from aiflows.messages import FlowMessage |
|
from aiflows.interfaces import KeyInterface |
|
from aiflows.utils.colink_utils import start_colink_server |
|
from aiflows.workers import run_dispatch_worker_thread |
|
|
|
CACHING_PARAMETERS.do_caching = False |
|
|
|
|
|
|
|
|
|
|
|
dependencies = [ |
|
{"url": "aiflows/VectorStoreFlowModule", "revision": os.getcwd()} |
|
] |
|
|
|
from aiflows import flow_verse |
|
flow_verse.sync_dependencies(dependencies) |
|
if __name__ == "__main__": |
|
|
|
|
|
|
|
cl = start_colink_server() |
|
|
|
|
|
|
|
root_dir = "." |
|
cfg_path = os.path.join(root_dir, "demo.yaml") |
|
cfg = read_yaml_file(cfg_path) |
|
|
|
|
|
|
|
api_information = [ApiInfo(backend_used="openai", |
|
api_key = os.getenv("OPENAI_API_KEY"))] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
quick_load_api_keys(cfg, api_information, key="api_infos") |
|
|
|
|
|
|
|
serving.serve_flow( |
|
cl = cl, |
|
flow_class_name="flow_modules.aiflows.VectorStoreFlowModule.ChromaDBFlow", |
|
flow_endpoint="ChromaDBFlow", |
|
) |
|
|
|
|
|
run_dispatch_worker_thread(cl) |
|
|
|
|
|
|
|
proxy_flow_cdb= serving.get_flow_instance( |
|
cl=cl, |
|
flow_endpoint="ChromaDBFlow", |
|
user_id="local", |
|
config_overrides = cfg["chroma_demo_flow"] |
|
) |
|
|
|
|
|
serving.serve_flow( |
|
cl = cl, |
|
flow_class_name="flow_modules.aiflows.VectorStoreFlowModule.VectorStoreFlow", |
|
flow_endpoint="VectorStoreFlow", |
|
) |
|
|
|
|
|
|
|
run_dispatch_worker_thread(cl) |
|
|
|
|
|
proxy_flow_vs= serving.get_flow_instance( |
|
cl=cl, |
|
flow_endpoint="VectorStoreFlow", |
|
user_id="local", |
|
config_overrides = cfg["vector_store_demo_flow"], |
|
) |
|
|
|
|
|
|
|
data_write = {"id": 1, "operation": "write", "content": "The Capital of Switzerland is Bern"} |
|
data_read1 = {"id": 1, "operation": "read", "content": "Switzerland"} |
|
data_read2 = {"id": 3, "operation": "read", "content": "What did the author do growing up?"} |
|
|
|
data = [data_read2,data_write,data_read1] |
|
|
|
futures = [] |
|
|
|
print("##########CHROMA DB DEMO###############") |
|
for dp in data: |
|
|
|
input_message = FlowMessage( |
|
data=data_write, |
|
) |
|
futures.append(proxy_flow_cdb.get_reply_future(input_message)) |
|
|
|
replies = [ft.get_data() for ft in futures] |
|
for dp,rp in zip(data, replies): |
|
print("~~~~~ Message Sent~~~~~") |
|
print(dp) |
|
print("~~~~~ Replies ~~~~~") |
|
print(rp) |
|
|
|
|
|
|
|
print("##########VECTOR STORE DEMO##############") |
|
for dp in data: |
|
|
|
input_message = FlowMessage( |
|
data=data_write, |
|
) |
|
futures.append(proxy_flow_vs.get_reply_future(input_message)) |
|
|
|
replies = [ft.get_data() for ft in futures] |
|
for dp,rp in zip(data, replies): |
|
print("~~~~~ Message Sent~~~~~") |
|
print(dp) |
|
print("~~~~~ Replies ~~~~~") |
|
print(rp) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|