From 2727b936e83525097a26d4ef54480edc2dbd218e Mon Sep 17 00:00:00 2001 From: alimosaed Date: Fri, 22 Nov 2024 15:42:38 -0500 Subject: [PATCH] fix: resolve lint issues --- .../_app/pyproject.toml | 2 +- .../solace/quick_start/README.md | 1 - .../solace/quick_start/deploy_core.py | 10 +++++--- .../solace/quick_start/deploy_workflow.py | 24 ++++++++++--------- .../quick_start/interaction_concurrent.py | 6 +++-- .../quick_start/interaction_multi_flows.py | 6 +++-- .../solace/quick_start/interaction_simple.py | 6 ++--- 7 files changed, 32 insertions(+), 23 deletions(-) diff --git a/examples/message-queue-integrations/_app/pyproject.toml b/examples/message-queue-integrations/_app/pyproject.toml index 653daf99..3fbf66a5 100644 --- a/examples/message-queue-integrations/_app/pyproject.toml +++ b/examples/message-queue-integrations/_app/pyproject.toml @@ -14,4 +14,4 @@ python = "^3.10" llama-index-llms-openai = "^0.2.1" llama-index-embeddings-openai = "^0.2.4" llama-index-agent-openai = "^0.3.0" -llama-deploy = {version = "^0.2.1", extras = ["awssqs", "rabbitmq", "kafka", "redis", "solace"]} +llama-deploy = {version = "^0.3.0", extras = ["awssqs", "rabbitmq", "kafka", "redis", "solace"]} diff --git a/examples/message-queue-integrations/solace/quick_start/README.md b/examples/message-queue-integrations/solace/quick_start/README.md index 50cc059a..743dbc55 100644 --- a/examples/message-queue-integrations/solace/quick_start/README.md +++ b/examples/message-queue-integrations/solace/quick_start/README.md @@ -45,4 +45,3 @@ python -m examples.message-queue-integrations.solace.quick_start.interaction_con ``` bash python -m examples.message-queue-integrations.solace.quick_start.interaction_multi_flows ``` - diff --git a/examples/message-queue-integrations/solace/quick_start/deploy_core.py b/examples/message-queue-integrations/solace/quick_start/deploy_core.py index 681ef6f9..5bb7b072 100644 --- a/examples/message-queue-integrations/solace/quick_start/deploy_core.py +++ b/examples/message-queue-integrations/solace/quick_start/deploy_core.py @@ -6,21 +6,25 @@ SolaceMessageQueueConfig, ) + def load_env(): # Load environment variables from .env.solace file - dotenv_path = find_dotenv('.env.solace') + dotenv_path = find_dotenv(".env.solace") if not dotenv_path: - raise FileNotFoundError('.env.solace file not found') - + raise FileNotFoundError(".env.solace file not found") + load_dotenv(dotenv_path) + async def main(): await deploy_core( control_plane_config=ControlPlaneConfig(), message_queue_config=SolaceMessageQueueConfig(), ) + if __name__ == "__main__": import asyncio + load_env() asyncio.run(main()) diff --git a/examples/message-queue-integrations/solace/quick_start/deploy_workflow.py b/examples/message-queue-integrations/solace/quick_start/deploy_workflow.py index f999eb0a..b11c70a0 100644 --- a/examples/message-queue-integrations/solace/quick_start/deploy_workflow.py +++ b/examples/message-queue-integrations/solace/quick_start/deploy_workflow.py @@ -15,9 +15,11 @@ step, ) + class ProgressEvent(Event): progress: str + # create a dummy workflow class PingWorkflow(Workflow): @step() @@ -28,12 +30,11 @@ async def run_step(self, ctx: Context, ev: StartEvent) -> StopEvent: # stream events as steps run current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") - ctx.write_event_to_stream( - ProgressEvent(progress=f"{current_time}: Ping Ping!") - ) + ctx.write_event_to_stream(ProgressEvent(progress=f"{current_time}: Ping Ping!")) return StopEvent(result=result) - + + # create a dummy workflow class HelloWorkflow(Workflow): @step() @@ -43,20 +44,20 @@ async def run_step(self, ctx: Context, ev: StartEvent) -> StopEvent: result = arg1 + "_result" # stream events as steps run - ctx.write_event_to_stream( - ProgressEvent(progress="Hello!") - ) + ctx.write_event_to_stream(ProgressEvent(progress="Hello!")) return StopEvent(result=result) + def load_env(): # Load environment variables from .env.solace file - dotenv_path = find_dotenv('.env.solace') + dotenv_path = find_dotenv(".env.solace") if not dotenv_path: - raise FileNotFoundError('.env.solace file not found') - + raise FileNotFoundError(".env.solace file not found") + load_dotenv(dotenv_path) + async def main(): flow1 = deploy_workflow( workflow=PingWorkflow(), @@ -77,6 +78,7 @@ async def main(): # Run both tasks concurrently await asyncio.gather(flow1, flow2) + if __name__ == "__main__": load_env() - asyncio.run(main()) \ No newline at end of file + asyncio.run(main()) diff --git a/examples/message-queue-integrations/solace/quick_start/interaction_concurrent.py b/examples/message-queue-integrations/solace/quick_start/interaction_concurrent.py index afdfcfa7..f1ecc054 100644 --- a/examples/message-queue-integrations/solace/quick_start/interaction_concurrent.py +++ b/examples/message-queue-integrations/solace/quick_start/interaction_concurrent.py @@ -7,6 +7,7 @@ # Points to deployed control plane client = LlamaDeployClient(ControlPlaneConfig()) + def run_workflow(workflow_name: str): """Function to run the workflow in a separate thread.""" # Create a session @@ -18,9 +19,10 @@ def run_workflow(workflow_name: str): print(f"task_id for {workflow_name}:", task_id) for event in session.get_task_result_stream(task_id): print(f"task result for {workflow_name}:", event) - + print(f"Done with {workflow_name}") + # Create and start threads for each workflow threads = [] for _ in range(ITERATION_COUNT): @@ -30,4 +32,4 @@ def run_workflow(workflow_name: str): # Optionally, wait for all threads to complete for thread in threads: - thread.join() \ No newline at end of file + thread.join() diff --git a/examples/message-queue-integrations/solace/quick_start/interaction_multi_flows.py b/examples/message-queue-integrations/solace/quick_start/interaction_multi_flows.py index ab3f00cc..03478427 100644 --- a/examples/message-queue-integrations/solace/quick_start/interaction_multi_flows.py +++ b/examples/message-queue-integrations/solace/quick_start/interaction_multi_flows.py @@ -7,6 +7,7 @@ # Points to deployed control plane client = LlamaDeployClient(ControlPlaneConfig()) + def run_workflow(workflow_name: str): """Function to run the workflow in a separate thread.""" # Create a session @@ -18,9 +19,10 @@ def run_workflow(workflow_name: str): print(f"task_id for {workflow_name}:", task_id) for event in session.get_task_result_stream(task_id): print(f"task result for {workflow_name}:", event) - + print(f"Done with {workflow_name}") + # Flows flows = ["ping_workflow", "hello_workflow"] @@ -34,4 +36,4 @@ def run_workflow(workflow_name: str): # Optionally, wait for all threads to complete for thread in threads: - thread.join() \ No newline at end of file + thread.join() diff --git a/examples/message-queue-integrations/solace/quick_start/interaction_simple.py b/examples/message-queue-integrations/solace/quick_start/interaction_simple.py index ef17266c..463ee964 100644 --- a/examples/message-queue-integrations/solace/quick_start/interaction_simple.py +++ b/examples/message-queue-integrations/solace/quick_start/interaction_simple.py @@ -19,7 +19,7 @@ print("task_id:", task_id) for event in session.get_task_result_stream(task_id): print("task result:", event) - + time.sleep(SLEEP_TIME) - -print("Done") \ No newline at end of file + +print("Done")