From d023e9fd55342095ffac4690696e5487e8a7b220 Mon Sep 17 00:00:00 2001 From: "manuel.carbonell@kantar.com" Date: Thu, 22 Feb 2024 17:39:10 +0000 Subject: [PATCH] update multiscript prompt format --- sgpt/handlers/multiscript_handler.py | 3 --- sgpt/role.py | 11 ++++++++-- sgpt/utils.py | 32 +++++++++++----------------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/sgpt/handlers/multiscript_handler.py b/sgpt/handlers/multiscript_handler.py index e1874bc2..afff272b 100644 --- a/sgpt/handlers/multiscript_handler.py +++ b/sgpt/handlers/multiscript_handler.py @@ -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, diff --git a/sgpt/role.py b/sgpt/role.py index 4b82c1d8..de74d2b8 100644 --- a/sgpt/role.py +++ b/sgpt/role.py @@ -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. diff --git a/sgpt/utils.py b/sgpt/utils.py index c2faa761..5d060a92 100644 --- a/sgpt/utils.py +++ b/sgpt/utils.py @@ -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: """