Upload 5 files
Browse files- PlanFileEditAtomicFlow.py +94 -0
- PlanFileEditAtomicFlow.yaml +10 -0
- README.md +33 -3
- __init__.py +1 -0
- pip_requirements.txt +15 -0
PlanFileEditAtomicFlow.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Any
|
| 2 |
+
from aiflows.base_flows.atomic import AtomicFlow
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class PlanFileEditAtomicFlow(AtomicFlow):
|
| 7 |
+
"""This class is used to write plan to a temp code file, with commented instructions to give information
|
| 8 |
+
to the user.
|
| 9 |
+
|
| 10 |
+
*Input Interface*:
|
| 11 |
+
- `plan`: str
|
| 12 |
+
- `plan_file_location`: str
|
| 13 |
+
|
| 14 |
+
*Output Interface*:
|
| 15 |
+
- `plan_editor_output`: str
|
| 16 |
+
- `temp_plan_file_location`: str
|
| 17 |
+
"""
|
| 18 |
+
def _generate_content(self, plan_file_location, plan_str) -> str:
|
| 19 |
+
content = (
|
| 20 |
+
"The below plan will be written to " +
|
| 21 |
+
plan_file_location + "\n"
|
| 22 |
+
"Edit the plan directly or provide your thoughts down below if you have any suggestions.\n"
|
| 23 |
+
"When you are done editing plan and providing feedback, save file and close the current VSCode session to continue.\n"
|
| 24 |
+
"###########\n"
|
| 25 |
+
"Plan:\n" +
|
| 26 |
+
plan_str +
|
| 27 |
+
"\n############\n"
|
| 28 |
+
"Thoughts:"
|
| 29 |
+
)
|
| 30 |
+
return content
|
| 31 |
+
|
| 32 |
+
def _generate_temp_file_location(self, plan_file_location):
|
| 33 |
+
directory = os.path.dirname(plan_file_location)
|
| 34 |
+
ret = os.path.join(directory, 'temp_plan.txt')
|
| 35 |
+
return ret
|
| 36 |
+
|
| 37 |
+
def _write_plan_content_to_file(self, file_location, content: str):
|
| 38 |
+
try:
|
| 39 |
+
with open(file_location, "w") as file:
|
| 40 |
+
file.write(content)
|
| 41 |
+
|
| 42 |
+
return True, f"Plan written to {file_location}", file_location
|
| 43 |
+
|
| 44 |
+
except Exception as e:
|
| 45 |
+
return False, str(e), file_location
|
| 46 |
+
|
| 47 |
+
def _check_input(self, input_data: Dict[str, Any]):
|
| 48 |
+
assert any(item in input_data for item in ["plan", "new_plan"]), "plan or new_plan is not passed to PlanFileEditAtomicFlow"
|
| 49 |
+
assert "plan_file_location" in input_data, "plan_file_location not passed to PlanFileEditAtomicFlow"
|
| 50 |
+
plan_file_loc = input_data["plan_file_location"]
|
| 51 |
+
assert os.path.exists(plan_file_loc), f"{plan_file_loc} does not exist"
|
| 52 |
+
assert os.path.isfile(plan_file_loc), f"{plan_file_loc} is not a file"
|
| 53 |
+
|
| 54 |
+
def _generate_input_to_writer(self, input_data: Dict[str, Any]):
|
| 55 |
+
"""
|
| 56 |
+
sometimes the plan generator will return an arrary of indexed plans, like
|
| 57 |
+
[
|
| 58 |
+
"1. Extend the code library with a function named 'import_libraries'. This function should import necessary libraries for the task...",
|
| 59 |
+
"2. Extend the code library with a function named 'fetch_stock_prices'. This function should take two inputs: 'company_code' and 'duration'...",
|
| 60 |
+
"3. Investigate the issue with importing the 'fetch_stock_prices' function from the library..."
|
| 61 |
+
]
|
| 62 |
+
In this case we need to prase this format accorrdingly.
|
| 63 |
+
"""
|
| 64 |
+
|
| 65 |
+
plan = input_data['plan'] if "plan" in input_data else input_data['new_plan']
|
| 66 |
+
if isinstance(plan, str):
|
| 67 |
+
plan_str = plan
|
| 68 |
+
elif isinstance(plan, list):
|
| 69 |
+
plan_str = "\n".join(plan)
|
| 70 |
+
else:
|
| 71 |
+
raise TypeError("plan is neither a string nor a list")
|
| 72 |
+
plan_file_location = input_data["plan_file_location"]
|
| 73 |
+
content_to_write = self._generate_content(plan_file_location, plan_str)
|
| 74 |
+
file_location_to_write = self._generate_temp_file_location(plan_file_location)
|
| 75 |
+
return content_to_write, file_location_to_write
|
| 76 |
+
|
| 77 |
+
def run(
|
| 78 |
+
self,
|
| 79 |
+
input_data: Dict[str, Any]
|
| 80 |
+
):
|
| 81 |
+
self._check_input(input_data)
|
| 82 |
+
|
| 83 |
+
# ~~~ Getting input data to the file editor ~~~
|
| 84 |
+
content_to_write, file_location_to_write = self._generate_input_to_writer(input_data)
|
| 85 |
+
|
| 86 |
+
# ~~~ Calling the writer function ~~~
|
| 87 |
+
result, plan_editor_output, temp_file_location = self._write_plan_content_to_file(
|
| 88 |
+
file_location_to_write, content_to_write)
|
| 89 |
+
|
| 90 |
+
# ~~~ Generating return variables ~~~
|
| 91 |
+
response = {}
|
| 92 |
+
response["plan_editor_output"] = plan_editor_output
|
| 93 |
+
response["temp_plan_file_location"] = temp_file_location
|
| 94 |
+
return response
|
PlanFileEditAtomicFlow.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: "PlanFileEditAtomicFlow"
|
| 2 |
+
description: "A flow that writes plan to a temp file"
|
| 3 |
+
|
| 4 |
+
input_interface:
|
| 5 |
+
- "plan"
|
| 6 |
+
- "plan_file_location"
|
| 7 |
+
|
| 8 |
+
output_interface:
|
| 9 |
+
- "plan_editor_output"
|
| 10 |
+
- "temp_plan_file_location"
|
README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Table of Contents
|
| 2 |
+
|
| 3 |
+
* [PlanFileEditAtomicFlow](#PlanFileEditAtomicFlow)
|
| 4 |
+
* [PlanFileEditAtomicFlow](#PlanFileEditAtomicFlow.PlanFileEditAtomicFlow)
|
| 5 |
+
* [\_\_init\_\_](#__init__)
|
| 6 |
+
|
| 7 |
+
<a id="PlanFileEditAtomicFlow"></a>
|
| 8 |
+
|
| 9 |
+
# PlanFileEditAtomicFlow
|
| 10 |
+
|
| 11 |
+
<a id="PlanFileEditAtomicFlow.PlanFileEditAtomicFlow"></a>
|
| 12 |
+
|
| 13 |
+
## PlanFileEditAtomicFlow Objects
|
| 14 |
+
|
| 15 |
+
```python
|
| 16 |
+
class PlanFileEditAtomicFlow(AtomicFlow)
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
This class is used to write plan to a temp code file, with commented instructions to give information
|
| 20 |
+
to the user.
|
| 21 |
+
|
| 22 |
+
*Input Interface*:
|
| 23 |
+
- `plan`: str
|
| 24 |
+
- `plan_file_location`: str
|
| 25 |
+
|
| 26 |
+
*Output Interface*:
|
| 27 |
+
- `plan_editor_output`: str
|
| 28 |
+
- `temp_plan_file_location`: str
|
| 29 |
+
|
| 30 |
+
<a id="__init__"></a>
|
| 31 |
+
|
| 32 |
+
# \_\_init\_\_
|
| 33 |
+
|
__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from .PlanFileEditAtomicFlow import PlanFileEditAtomicFlow
|
pip_requirements.txt
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
colorama==0.4.6
|
| 2 |
+
pytest==7.3.1
|
| 3 |
+
pytest-cov==4.1.0
|
| 4 |
+
hydra-core==1.3.2
|
| 5 |
+
hydra-colorlog==1.1.0
|
| 6 |
+
wrapt-timeout-decorator==1.3.12.2
|
| 7 |
+
diskcache==5.6.1
|
| 8 |
+
openai==1.0.0
|
| 9 |
+
huggingface_hub==0.19.4
|
| 10 |
+
jsonlines==3.1.0
|
| 11 |
+
jinja2==3.1.2
|
| 12 |
+
mock==5.0.2
|
| 13 |
+
rich==12.6.0
|
| 14 |
+
litellm==1.0.0
|
| 15 |
+
aiflows
|