From b7ab52229192382572495ff7fbd8b4beffa6a15c Mon Sep 17 00:00:00 2001 From: Andrei Fajardo Date: Thu, 12 Sep 2024 11:46:32 -0400 Subject: [PATCH] use nested workflow for human in the loop --- .../workflows/government_essentials.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/snowflake_cybersyn_demo/workflows/government_essentials.py b/snowflake_cybersyn_demo/workflows/government_essentials.py index 43488f9..033359d 100644 --- a/snowflake_cybersyn_demo/workflows/government_essentials.py +++ b/snowflake_cybersyn_demo/workflows/government_essentials.py @@ -10,6 +10,7 @@ from llama_index.llms.openai import OpenAI import snowflake_cybersyn_demo.workflows._db as db +from snowflake_cybersyn_demo.workflows.human_input import HumanInputWorkflow class StatisticsLookupEvent(Event): @@ -34,14 +35,18 @@ async def retrieve_candidates_from_db( return StatisticsLookupEvent(statistic_variables=stats_vars, city=city) @step - async def human_input(self, ev: StatisticsLookupEvent) -> HumanInputEvent: + async def human_input( + self, + ev: StatisticsLookupEvent, + human_input_workflow: HumanInputWorkflow, + ) -> HumanInputEvent: stats_vars = "\n".join(ev.statistic_variables) human_prompt = ( "List of statistic variables that exist in the database are provided below." f"{stats_vars}" "\n\nPlease select one.:\n\n" ) - human_input = input(human_prompt) + human_input = await human_input_workflow.run(prompt=human_prompt) # use llm to clean up selection llm = OpenAI("gpt-4o") @@ -77,6 +82,7 @@ async def get_time_series_data(self, ev: HumanInputEvent) -> StopEvent: # Local Testing async def _test_workflow() -> None: w = GovtEssentialsStatisticsWorkflow(timeout=None, verbose=False) + w.add_workflows(human_input_workflow=HumanInputWorkflow()) result = await w.run(city="New York") print(str(result))