Skip to content

Commit

Permalink
update multiscript prompt format
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-carbonell-kantar committed Feb 22, 2024
1 parent 971fe07 commit d023e9f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
3 changes: 0 additions & 3 deletions sgpt/handlers/multiscript_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ def handle(self,
prompt_with_scripts = prompt + "\n\n" + "\n\n".join(
f"File: {script[0]}\n\n{script[1]}" for script in script_list
)
import pdb
pdb.set_trace()
messages[-1]["content"] = prompt_with_scripts

generator = self.get_completion(
model=model,
temperature=temperature,
Expand Down
11 changes: 9 additions & 2 deletions sgpt/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@
For example if the prompt is "Hello world Python", you should return "print('Hello world')"."""


MULTISCRIPT_CODE_ROLE = """You are a Multi-Script Code Generator.
MULTISCRIPT_CODE_ROLE = """
You are provided with a prompt and a list of existing scripts with their content.
Your task is to generate output that lists the modified or newly created scripts along with their full content.
The output should be in dictionary format, where each file path is a key and its content is the corresponding value ias a string.
The output should be in the following format:
FILE:\tfilename1.py
#content of the first file
import ..
...
FILE:\tfilename2.py
# content of the second file
...
Provide only code in plain text format without Markdown formatting.
Do not include symbols such as ``` or ```python.
If there is a lack of details, provide the most logical solution.
Expand Down
32 changes: 12 additions & 20 deletions sgpt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,19 @@ def list_scripts_with_content(directory: str) -> List[Tuple[str, str]]:
return scripts

def parse_modifications(completion: str, script_list: List[Tuple[str, str]]) -> List[Tuple[str, str]]:
modifications = []
lines = completion.split('\n')
current_file = None
current_content = []
import pdb

modifications = json.loads(completion)
return modifications
'''
for line in lines:
if line.startswith('File: '):
if current_file is not None:
modifications.append((current_file, '\n'.join(current_content)))
current_content = []
current_file = line[len('File: '):].strip()
else:
current_content.append(line)
if current_file is not None:
modifications.append((current_file, '\n'.join(current_content)))
return modifications
'''
pdb.set_trace()
files_dict = {}
files = completion.split('FILE:')

for f in files:

file_name=f.split('\n')[0].strip()
if len(file_name)<4: continue
file_content ='\n'.join(f.split('\n')[1:]).strip()
files_dict[file_name]=file_content

return files_dict

def modify_or_create_scripts(modifications: List, directory: str) -> None:
"""
Expand Down

0 comments on commit d023e9f

Please sign in to comment.