From c417822eccdebe7622c4f968666683758d6110d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Ho=CC=88nicke?= Date: Fri, 28 Apr 2023 10:28:58 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=A9=E2=80=8D=F0=9F=92=BC=20feat:=20pm?= =?UTF-8?q?=20role=20cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/options/generate/generator.py | 80 ++++++++++-------------- src/options/generate/templates_system.py | 13 ++-- src/options/generate/templates_user.py | 8 +-- 3 files changed, 43 insertions(+), 58 deletions(-) diff --git a/src/options/generate/generator.py b/src/options/generate/generator.py index cff1f79..05d9306 100644 --- a/src/options/generate/generator.py +++ b/src/options/generate/generator.py @@ -24,7 +24,7 @@ from src.options.generate.templates_user import template_generate_microservice_n template_generate_apt_get_install, template_solve_apt_get_dependency_issue, \ template_is_dependency_issue, template_generate_playground, \ template_generate_executor, template_generate_test, template_generate_requirements, \ - template_chain_of_thought, template_summarize_error, template_task_refinement + template_chain_of_thought, template_summarize_error, template_refinement from src.options.generate.ui import get_random_employee from src.utils.io import persist_file, get_all_microservice_files_with_content, get_microservice_path from src.utils.string_tools import print_colored @@ -409,8 +409,20 @@ gptdeploy deploy --path {self.microservice_root_path} def refine_specification(self): pm = get_random_employee('pm') print(f'{pm.emoji}👋 Hi, I\'m {pm.name}, a PM at Jina AI. Gathering the requirements for our engineers.') - self.refine_task(pm) - self.refine_test(pm) + original_task = self.microservice_specification.task + while True: + try: + self.microservice_specification.test = None + if not original_task: + self.microservice_specification.task = self.get_user_input(pm, 'What should your microservice do?') + + self.refine_requirements(pm, system_task_iteration, 'task') + self.refine_requirements(pm, system_test_iteration, 'test') + break + except self.TaskRefinementException as e: + + print_colored('', f'{pm.emoji} Could not refine your requirements. Please try again...', 'red') + print(f''' {pm.emoji} 👍 Great, I will handover the following requirements to our engineers: Description of the microservice: @@ -419,61 +431,33 @@ Test scenario: {self.microservice_specification.test} ''') - def refine_task(self, pm): - try: - user_input = self.microservice_specification.task - if not user_input: - user_input = self.get_user_input(pm, 'What should your microservice do?') - messages = [ - SystemMessage(content=system_task_introduction + system_task_iteration), - ] - - while True: - conversation = self.gpt_session.get_conversation(messages, print_stream=os.environ['VERBOSE'].lower() == 'true', print_costs=False) - print('thinking...') - agent_response_raw = conversation.chat(template_task_refinement.format(user_input=user_input), role='user') - - question = self.extract_content_from_result(agent_response_raw, 'prompt.txt', can_contain_code_block=False) - task_final = self.extract_content_from_result(agent_response_raw, 'task-final.txt', can_contain_code_block=False) - if task_final: - self.microservice_specification.task = task_final - break - if question: - messages.append(HumanMessage(content=user_input),) - user_input = self.get_user_input(pm, question) - messages.append(AIMessage(content=question)) - elif task_final: - user_input = self.get_user_input(pm, agent_response_raw + '\n: ') - else: - raise self.TaskRefinementException() - except self.TaskRefinementException as e: - print_colored('', f'{pm.emoji} Could not refine the task. Please try again...', 'red') - self.refine_task(pm) - - - def refine_test(self, pm): + def refine_requirements(self, pm, template_init, refinement_type): user_input = self.microservice_specification.task messages = [ - SystemMessage(content=system_task_introduction + system_test_iteration), + SystemMessage(content=system_task_introduction + template_init), ] while True: conversation = self.gpt_session.get_conversation(messages, print_stream=os.environ['VERBOSE'].lower() == 'true', print_costs=False) print('thinking...') - agent_response_raw = conversation.chat(f'''**client-response.txt** -``` -{user_input} -``` -''', role='user') + agent_response_raw = conversation.chat( + template_refinement.format( + user_input=user_input, + _optional_test=' test' if refinement_type == 'test' else '' + ), + role='user' + ) + question = self.extract_content_from_result(agent_response_raw, 'prompt.txt', can_contain_code_block=False) - test_final = self.extract_content_from_result(agent_response_raw, 'test-final.txt', can_contain_code_block=False) - if test_final: - self.microservice_specification.test = test_final + final = self.extract_content_from_result(agent_response_raw, 'final.txt', can_contain_code_block=False) + if final: + setattr(self.microservice_specification, refinement_type, final) break - if question: + elif question: + messages.append(HumanMessage(content=user_input),) + messages.append(AIMessage(content=question)) user_input = self.get_user_input(pm, question) - messages.extend([HumanMessage(content=user_input)]) else: - user_input = self.get_user_input(pm, agent_response_raw + '\n: ') + raise self.TaskRefinementException() @staticmethod diff --git a/src/options/generate/templates_system.py b/src/options/generate/templates_system.py index beffbb8..cc27871 100644 --- a/src/options/generate/templates_system.py +++ b/src/options/generate/templates_system.py @@ -141,7 +141,7 @@ Otherwise you respond with the summarized description. The summarized description must contain all the information mentioned by the client. Your response must exactly match the following block code format (double asterisks for the file name and triple backticks for the file block): -**task-final.txt** +**final.txt** ```text ``` @@ -166,7 +166,7 @@ output: ✅ credentials: n/a database access: n/a -**task-final.txt** +**final.txt** ```text The user inserts a png and gets an svg as response. ``` @@ -190,6 +190,7 @@ Your task is to describe verbally a unit test for that microservice. There are two cases: a) The unit test requires an example file as input. In this case you must ask the client to provide the example file as URL. +You must not accept files that are not URLs. Your response must exactly match the following block code format (double asterisks for the file name and triple backticks for the file block): **prompt.txt** @@ -202,7 +203,7 @@ b) Any strings, ints, or bools can be used as input for the unit test. In this case you must describe the unit test verbally. Your response must exactly match the following block code format (double asterisks for the file name and triple backticks for the file block): -**test-final.txt** +**final.txt** ```text ``` @@ -216,7 +217,7 @@ Client: given a city, get the weather report for the next 5 days using OpenWeatherMap with the api key b6907d289e10d714a6e88b30761fae22 ``` PM: -**test-final.txt** +**final.txt** ```text The test takes the city "Berlin" as input and asserts that the weather report for the next 5 days exists in the response. ``` @@ -238,7 +239,7 @@ Client: https://aquasecurity.github.io/kube-bench/v0.6.5/images/kube-bench-logo-only.png ``` PM: -**test-final.txt** +**final.txt** ```text The test takes the png https://aquasecurity.github.io/kube-bench/v0.6.5/images/kube-bench-logo-only.png as input and asserts the output is an svg. ``` @@ -250,7 +251,7 @@ Client: The microservice takes nothing as input and returns the current time. ``` PM: -**test-final.txt** +**final.txt** ```text The test takes nothing as input and asserts that the output is a string. ``` diff --git a/src/options/generate/templates_user.py b/src/options/generate/templates_user.py index 850384d..9d3bbf9 100644 --- a/src/options/generate/templates_user.py +++ b/src/options/generate/templates_user.py @@ -358,7 +358,7 @@ The playground (app.py) must not import the executor. ) -template_task_refinement = PromptTemplate.from_template( +template_refinement = PromptTemplate.from_template( ''' **client response** ```text @@ -370,10 +370,10 @@ Either ask for clarification like this: ``` -Or write the summarized microservice description like this: -**task-final.txt** +Or write the summarized microservice{_optional_test} description like this: +**final.txt** ```text - + ``` ''' )