Upload run_replanning.py
Browse files- run_replanning.py +65 -0
run_replanning.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
import hydra
|
| 4 |
+
|
| 5 |
+
from flows.backends.api_info import ApiInfo
|
| 6 |
+
from flows.messages import InputMessage
|
| 7 |
+
from flows.utils.general_helpers import read_yaml_file
|
| 8 |
+
|
| 9 |
+
from flows import logging
|
| 10 |
+
from flows.flow_cache import CACHING_PARAMETERS, clear_cache
|
| 11 |
+
|
| 12 |
+
CACHING_PARAMETERS.do_caching = False # Set to True in order to disable caching
|
| 13 |
+
# clear_cache() # Uncomment this line to clear the cache
|
| 14 |
+
|
| 15 |
+
logging.set_verbosity_debug()
|
| 16 |
+
logging.auto_set_dir()
|
| 17 |
+
|
| 18 |
+
dependencies = [
|
| 19 |
+
{"url": "Tachi67/ReplanningFlowModule", "revision": "main"},
|
| 20 |
+
{"url": "Tachi67/PlanGeneratorFlowModule", "revision": "main"},
|
| 21 |
+
{"url": "Tachi67/InteractivePlanGenFlowModule", "revision": "main"},
|
| 22 |
+
{"url": "Tachi67/PlanWriterFlowModule", "revision": "main"},
|
| 23 |
+
{"url": "Tachi67/PlanFileEditFlowModule", "revision": "main"},
|
| 24 |
+
{"url": "Tachi67/ParseFeedbackFlowModule", "revision": "main"},
|
| 25 |
+
{"url": "aiflows/HumanStandardInputFlowModule", "revision": "5683a922372c5fa90be9f6447d6662d8d80341fc"}
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
from flows import flow_verse
|
| 29 |
+
|
| 30 |
+
flow_verse.sync_dependencies(dependencies)
|
| 31 |
+
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
# ~~~ make sure to set the openai api key in the envs ~~~
|
| 34 |
+
key = os.getenv("OPENAI_API_KEY")
|
| 35 |
+
api_information = [ApiInfo(backend_used="openai", api_key=os.getenv("OPENAI_API_KEY"))]
|
| 36 |
+
path_to_output_file = None
|
| 37 |
+
|
| 38 |
+
# ~~~ setting api information into config ~~~
|
| 39 |
+
current_dir = os.getcwd()
|
| 40 |
+
cfg_path = os.path.join(current_dir, "ReplanningFlow.yaml")
|
| 41 |
+
cfg = read_yaml_file(cfg_path)
|
| 42 |
+
cfg["subflows_config"]["Controller"]["backend"]["api_infos"] = api_information
|
| 43 |
+
cfg["subflows_config"]["Executor"]["subflows_config"]["write_plan"]["subflows_config"]["PlanGenerator"]["backend"]["api_infos"] = api_information
|
| 44 |
+
|
| 45 |
+
# ~~~ instantiating the flow and input data ~~~
|
| 46 |
+
ReplanningFlow = hydra.utils.instantiate(cfg, _recursive_=False, _convert_="partial")
|
| 47 |
+
|
| 48 |
+
# ~~~ creating the plan file location (of the upper level flow e.g. ExtLib)
|
| 49 |
+
plan_file_location = os.path.join(current_dir, "ExtLib_plan.txt")
|
| 50 |
+
with open(plan_file_location, 'w') as file:
|
| 51 |
+
pass
|
| 52 |
+
|
| 53 |
+
input_data = {
|
| 54 |
+
"goal": "data source OpenWeatherMap is deprecated",
|
| 55 |
+
"plan": "1. Write a function that fetches today's weather at Lausanne from OpenWeatherMap. \n 2. Write a funtion that prints the fetched data in a formatted way.",
|
| 56 |
+
"plan_file_location": plan_file_location
|
| 57 |
+
}
|
| 58 |
+
input_message = InputMessage.build(
|
| 59 |
+
data_dict=input_data,
|
| 60 |
+
src_flow="Launcher",
|
| 61 |
+
dst_flow=ReplanningFlow.name
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
# ~~~ calling the flow ~~~
|
| 65 |
+
output_message = ReplanningFlow(input_message)
|