Skip to content

Commit

Permalink
Merge pull request #344 from Pythagora-io/main
Browse files Browse the repository at this point in the history
merge main to development
  • Loading branch information
LeonOstrez authored Dec 7, 2023
2 parents a074b60 + eb0ec2f commit 0bdf8f0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pilot/helpers/Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,31 @@ def get_files(self, files):
files_with_content.append(file_data)
return files_with_content

def find_input_required_lines(self, file_content):
"""
Parses the provided string (representing file content) and returns a list of tuples containing
the line number and line content for lines that contain the text 'INPUT_REQUIRED'.
:param file_content: The string content of the file.
:return: A list of tuples (line number, line content).
"""
lines_with_input_required = []
lines = file_content.split('\n')

for line_number, line in enumerate(lines, start=1):
if 'INPUT_REQUIRED' in line:
lines_with_input_required.append((line_number, line.strip()))

return lines_with_input_required

def save_file(self, data):
"""
Save a file.
Args:
data: { name: 'hello.py', path: 'path/to/hello.py', content: 'print("Hello!")' }
"""

name = data['name'] if 'name' in data and data['name'] != '' else os.path.basename(data['path'])
path = data['path'] if 'path' in data else name

Expand All @@ -248,6 +266,18 @@ def save_file(self, data):
update={'name': name, 'path': path, 'full_path': full_path})
.execute())

if not self.skip_steps:
inputs_required = self.find_input_required_lines(data['content'])
for line_number, line_content in inputs_required:
user_input = ''
print(color_yellow_bold(f'Input required on line {line_number}:\n{line_content}') + '\n')
while user_input.lower() not in ['y']:
user_input = styled_text(
self,
f'Please open the file {data["path"]} on the line {line_number} and add the required input. Once you\'re done, type "y" to continue.',
ignore_user_input_count=True
)

def get_full_file_path(self, file_path: str, file_name: str) -> Tuple[str, str]:
"""
Combine file path and name into a full file path.
Expand Down
3 changes: 3 additions & 0 deletions pilot/prompts/development/parse_task.prompt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Ok, now, take your previous message and convert it to actionable items. An item might be a code change or a command run. When you need to change code, make sure that you put the entire content of the file in the value of `content` key even though you will likely copy and paste the most of the previous message. The commands must be able to run on a {{ os }} machine.

**IMPORTANT**
Within the file modifications, anything needs to be written by the user, add the comment in the same line as the code that starts with `// INPUT_REQUIRED {input_description}` where `input_description` is a description of what needs to be added here by the user. Finally, you can save the modified files on the disk by calling `save_files` function.

**IMPORTANT**
When you want to add a comment that tells the user to add the previous implementation at that place, make sure that the comment starts with `[OLD CODE]` and add a description of what old code should be inserted here. For example, `[OLD CODE] Login route`.

Expand Down

0 comments on commit 0bdf8f0

Please sign in to comment.