Skip to content

Commit 998fe95

Browse files
Merge pull request #714 from haesleinhuepf/other_files
Work with other files in generated code using correct relative paths
2 parents 7a1bf29 + 4b5aaa9 commit 998fe95

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/git_bob/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.22.1"
1+
__version__ = "0.23.0"
22

33

44
__all__ = (

src/git_bob/_ai_github_utilities.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,21 +310,35 @@ def create_or_modify_file(repository, issue, filename, branch_name, issue_summar
310310
if is_ignored(filename, repository, branch_name):
311311
raise ValueError(f"Access to {filename} is restricted by .gitbobignore")
312312

313+
more_instructions = ""
313314
created_files = {}
314315
for attempt in range(number_of_attempts):
315316
an_error_happened = False
316317

317318
created_files = {}
318319
original_ipynb_file_content = None
320+
temp = filename.split("/")
321+
working_directory = "/".join(temp[:-1])
322+
if len(working_directory) > 0:
323+
working_directory = working_directory + "/"
324+
325+
all_files = """
326+
## Other files in the repository
327+
328+
You are in working directory {working_directory}. When you are writing code that accesses other files, make sure to use the correct relative file-paths.
329+
These are all files in the repository:
330+
""" + "* " + "\n* ".join(Config.git_utilities.list_repository_files(repository, branch_name=branch_name))
319331

320332
format_specific_instructions = ""
321333
if any([filename.endswith(f) for f in image_file_endings]):
322334
print(f"Cannot create or modify image files like {filename}.")
323335
return created_files
324336
elif filename.endswith('.py'):
325337
format_specific_instructions = " When writing new functions, use numpy-style docstrings."
326-
elif filename.endswith('.ipynb'):
338+
more_instructions = all_files
339+
if filename.endswith('.ipynb'):
327340
format_specific_instructions = " In the notebook file, write short code snippets in code cells and avoid long code blocks. Make sure everything is done step-by-step and we can inspect intermediate results. Add explanatory markdown cells in front of every code cell. The notebook has NO cell outputs! Make sure that there is code that saves results such as plots, images or dataframes, e.g. as .png or .csv files. Numpy images have to be converted to np.uint8 before saving as .png. Plots must be saved to disk before the cell ends or it is shown. The notebook must be executable from top to bottom without errors. Return the notebook in JSON format!"
341+
more_instructions = all_files
328342
elif filename.endswith('.docx'):
329343
format_specific_instructions = " Write the document in simple markdown format."
330344
elif filename.endswith('.mp3'):
@@ -370,6 +384,7 @@ def create_or_modify_file(repository, issue, filename, branch_name, issue_summar
370384
Modify the file "{filename}" to solve the issue #{issue}. {format_specific_instructions}
371385
If the discussion is long, some stuff might be already done. In that case, focus on what was said at the very end in the discussion.
372386
Keep your modifications absolutely minimal.
387+
{more_instructions}
373388
374389
That's the file "{filename}" content you will find in the file:
375390
```
@@ -385,6 +400,7 @@ def create_or_modify_file(repository, issue, filename, branch_name, issue_summar
385400
print(filename, "will be created")
386401
file_content_instruction = f"""
387402
Create the file "{filename}" to solve the issue #{issue}. {format_specific_instructions}
403+
{more_instructions}
388404
389405
## Your task
390406
Generate content for the file "{filename}" to solve the issue above.
@@ -406,7 +422,10 @@ def create_or_modify_file(repository, issue, filename, branch_name, issue_summar
406422
407423
Respond ONLY the content of the file and afterwards a single line summarizing the changes you made (without mentioning the issue).
408424
"""
425+
print("Prompt:", prompt)
426+
409427
print("Prompting for new file content...")
428+
410429
response = prompt_function(prompt)
411430

412431
new_content, commit_message = split_content_and_summary(response)

0 commit comments

Comments
 (0)