From 328eee7f18b2acc45d8d3e7fee6cd49f59596269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Ho=CC=88nicke?= Date: Fri, 19 May 2023 15:10:15 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8E=20feat:=20search=20fix=20web=20sea?= =?UTF-8?q?rch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dev_gpt/options/generate/generator.py | 6 +- dev_gpt/options/generate/pm/pm.py | 211 +++++++++--------- .../options/generate/pm/task_tree_schema.py | 42 ++-- dev_gpt/options/generate/templates_user.py | 9 +- 4 files changed, 136 insertions(+), 132 deletions(-) diff --git a/dev_gpt/options/generate/generator.py b/dev_gpt/options/generate/generator.py index b28d648..661cdce 100644 --- a/dev_gpt/options/generate/generator.py +++ b/dev_gpt/options/generate/generator.py @@ -23,7 +23,7 @@ from dev_gpt.options.generate.templates_user import template_generate_microservi template_generate_possible_packages, \ template_implement_solution_code_issue, \ template_solve_pip_dependency_issue, template_is_dependency_issue, template_generate_playground, \ - template_generate_function, template_generate_test, template_generate_requirements, \ + template_generate_function_constructor, template_generate_test, template_generate_requirements, \ template_chain_of_thought, template_summarize_error, \ template_solve_apt_get_dependency_issue, \ template_suggest_solutions_code_issue, template_was_error_seen_before, \ @@ -197,9 +197,11 @@ metas: with open(os.path.join(os.path.dirname(__file__), 'static_files', 'microservice', 'apis.py'), 'r', encoding='utf-8') as f: persist_file(f.read(), os.path.join(self.cur_microservice_path, 'apis.py')) + is_using_gpt_3_5_turbo = 'gpt-3-5-turbo' in packages + is_using_google_custom_search = 'google-custom-search' in packages microservice_content = self.generate_and_persist_file( section_title='Microservice', - template=template_generate_function, + template=template_generate_function_constructor(is_using_gpt_3_5_turbo, is_using_google_custom_search), microservice_description=self.microservice_specification.task, test_description=self.microservice_specification.test, packages=packages, diff --git a/dev_gpt/options/generate/pm/pm.py b/dev_gpt/options/generate/pm/pm.py index 2156fac..83a3d98 100644 --- a/dev_gpt/options/generate/pm/pm.py +++ b/dev_gpt/options/generate/pm/pm.py @@ -5,7 +5,8 @@ from dev_gpt.options.generate.chains.question_answering import is_question_true from dev_gpt.options.generate.chains.translation import translation from dev_gpt.options.generate.chains.user_confirmation_feedback_loop import user_feedback_loop from dev_gpt.options.generate.chains.get_user_input_if_needed import get_user_input_if_needed -from dev_gpt.options.generate.parser import identity_parser +from dev_gpt.options.generate.parser import identity_parser, json_parser +from dev_gpt.options.generate.pm.task_tree_schema import TaskTree from dev_gpt.options.generate.prompt_factory import make_prompt_friendly from dev_gpt.options.generate.ui import get_random_employee @@ -35,9 +36,9 @@ Description of the microservice: def refine(self, microservice_description): microservice_description, test_description = self.refine_description(microservice_description) - return microservice_description, test_description - # sub_task_tree = self.construct_sub_task_tree(microservice_description) + # sub_task_tree = construct_sub_task_tree(microservice_description) # return sub_task_tree + return microservice_description, test_description def refine_description(self, microservice_description): context = {'microservice_description': microservice_description} @@ -128,44 +129,44 @@ Example: # microservice_description=microservice_description # ) # -# def construct_sub_task_tree(self, microservice_description): -# """ -# takes a microservice description and recursively constructs a tree of sub-tasks that need to be done to implement the microservice -# """ -# # -# # nlp_fns = self.get_nlp_fns( -# # microservice_description -# # ) -# -# sub_task_tree_dict = ask_gpt( -# construct_sub_task_tree_prompt, json_parser, -# microservice_description=microservice_description, -# # nlp_fns=nlp_fns -# ) -# reflections = ask_gpt( -# sub_task_tree_reflections_prompt, identity_parser, -# microservice_description=microservice_description, -# # nlp_fns=nlp_fns, -# sub_task_tree=sub_task_tree_dict, -# ) -# solutions = ask_gpt( -# sub_task_tree_solutions_prompt, identity_parser, -# # nlp_fns=nlp_fns, -# microservice_description=microservice_description, sub_task_tree=sub_task_tree_dict, -# reflections=reflections, -# ) -# sub_task_tree_updated = ask_gpt( -# sub_task_tree_update_prompt, -# json_parser, -# microservice_description=microservice_description, -# # nlp_fns=nlp_fns, -# sub_task_tree=sub_task_tree_dict, solutions=solutions -# ) -# # for task_dict in self.iterate_over_sub_tasks(sub_task_tree_updated): -# # task_dict.update(self.get_additional_task_info(task_dict['task'])) -# -# sub_task_tree = TaskTree.parse_obj(sub_task_tree_updated) -# return sub_task_tree +def construct_sub_task_tree(self, microservice_description): + """ + takes a microservice description and recursively constructs a tree of sub-tasks that need to be done to implement the microservice + """ + # + # nlp_fns = self.get_nlp_fns( + # microservice_description + # ) + + sub_task_tree_dict = ask_gpt( + construct_sub_task_tree_prompt, json_parser, + microservice_description=microservice_description, + # nlp_fns=nlp_fns + ) + reflections = ask_gpt( + sub_task_tree_reflections_prompt, identity_parser, + microservice_description=microservice_description, + # nlp_fns=nlp_fns, + sub_task_tree=sub_task_tree_dict, + ) + solutions = ask_gpt( + sub_task_tree_solutions_prompt, identity_parser, + # nlp_fns=nlp_fns, + microservice_description=microservice_description, sub_task_tree=sub_task_tree_dict, + reflections=reflections, + ) + sub_task_tree_updated = ask_gpt( + sub_task_tree_update_prompt, + json_parser, + microservice_description=microservice_description, + # nlp_fns=nlp_fns, + sub_task_tree=sub_task_tree_dict, solutions=solutions + ) + # for task_dict in self.iterate_over_sub_tasks(sub_task_tree_updated): + # task_dict.update(self.get_additional_task_info(task_dict['task'])) + + sub_task_tree = TaskTree.parse_obj(sub_task_tree_updated) + return sub_task_tree # def get_additional_task_info(self, sub_task_description): # additional_info_dict = self.get_additional_infos( @@ -281,71 +282,71 @@ Example: # Note: You must ignore facts that are unknown. # Note: You must ignore facts that are unclear.''' -# construct_sub_task_tree_prompt = client_description + ''' -# Recursively constructs a tree of functions that need to be implemented for the endpoint_function that retrieves a json string and returns a json string. -# Example: -# Input: "Input: list of integers, Output: Audio file of short story where each number is mentioned exactly once." -# Output: -# {{ -# "description": "Create an audio file containing a short story in which each integer from the provided list is seamlessly incorporated, ensuring that every integer is mentioned exactly once.", -# "python_fn_signature": "def generate_integer_story_audio(numbers: List[int]) -> str:", -# "sub_fns": [ -# {{ -# "description": "Generate sentence from integer.", -# "python_fn_signature": "def generate_sentence_from_integer(number: int) -> int:", -# "sub_fns": [] -# }}, -# {{ -# "description": "Convert the story into an audio file.", -# "python_fn_signature": "def convert_story_to_audio(story: str) -> bytes:", -# "sub_fns": [] -# }} -# ] -# }} -# -# Note: you must only output the json string - nothing else. -# Note: you must pretty print the json string.''' +construct_sub_task_tree_prompt = client_description + ''' +Recursively constructs a tree of functions that need to be implemented for the endpoint_function that retrieves a json string and returns a json string. +Example: +Input: "Input: list of integers, Output: Audio file of short story where each number is mentioned exactly once." +Output: +{{ + "description": "Create an audio file containing a short story in which each integer from the provided list is seamlessly incorporated, ensuring that every integer is mentioned exactly once.", + "python_fn_signature": "def generate_integer_story_audio(numbers: List[int]) -> str:", + "sub_fns": [ + {{ + "description": "Generate sentence from integer.", + "python_fn_signature": "def generate_sentence_from_integer(number: int) -> int:", + "sub_fns": [] + }}, + {{ + "description": "Convert the story into an audio file.", + "python_fn_signature": "def convert_story_to_audio(story: str) -> bytes:", + "sub_fns": [] + }} + ] +}} -# sub_task_tree_reflections_prompt = client_description + ''' -# Sub task tree: -# ``` -# {sub_task_tree} -# ``` -# Write down 3 arguments why the sub task tree might not perfectly represents the information mentioned in the microservice description. (5 words per argument)''' -# -# sub_task_tree_solutions_prompt = client_description + ''' -# Sub task tree: -# ``` -# {sub_task_tree} -# ``` -# Reflections: -# ``` -# {reflections} -# ``` -# For each constructive criticism, write a solution (5 words) that address the criticism.''' -# -# sub_task_tree_update_prompt = client_description + ''' -# Sub task tree: -# ``` -# {sub_task_tree} -# ``` -# Solutions: -# ``` -# {solutions} -# ``` -# Update the sub task tree by applying the solutions. (pretty print the json string)''' -# -# ask_questions_prompt = client_description + ''' -# Request json schema: -# ``` -# {request_schema} -# ``` -# Response json schema: -# ``` -# {response_schema} -# ``` -# Ask the user up to 5 unique detailed questions (5 words) about the microservice description that are not yet answered. -# ''' +Note: you must only output the json string - nothing else. +Note: you must pretty print the json string.''' + +sub_task_tree_reflections_prompt = client_description + ''' +Sub task tree: +``` +{sub_task_tree} +``` +Write down 3 arguments why the sub task tree might not perfectly represents the information mentioned in the microservice description. (5 words per argument)''' + +sub_task_tree_solutions_prompt = client_description + ''' +Sub task tree: +``` +{sub_task_tree} +``` +Reflections: +``` +{reflections} +``` +For each constructive criticism, write a solution (5 words) that address the criticism.''' + +sub_task_tree_update_prompt = client_description + ''' +Sub task tree: +``` +{sub_task_tree} +``` +Solutions: +``` +{solutions} +``` +Update the sub task tree by applying the solutions. (pretty print the json string)''' + +ask_questions_prompt = client_description + ''' +Request json schema: +``` +{request_schema} +``` +Response json schema: +``` +{response_schema} +``` +Ask the user up to 5 unique detailed questions (5 words) about the microservice description that are not yet answered. +''' # answer_questions_prompt = client_description + ''' # Request json schema: diff --git a/dev_gpt/options/generate/pm/task_tree_schema.py b/dev_gpt/options/generate/pm/task_tree_schema.py index 41035fc..39f3518 100644 --- a/dev_gpt/options/generate/pm/task_tree_schema.py +++ b/dev_gpt/options/generate/pm/task_tree_schema.py @@ -1,22 +1,22 @@ -# from typing import Dict, List, Union, Optional -# from pydantic import BaseModel, Field -# -# class JSONSchema(BaseModel): -# type: str -# format: Union[str, None] = None -# items: Union['JSONSchema', None] = None -# properties: Dict[str, 'JSONSchema'] = Field(default_factory=dict) -# additionalProperties: Union[bool, 'JSONSchema'] = True -# required: List[str] = Field(default_factory=list) -# -# class Config: -# arbitrary_types_allowed = True -# -# class TaskTree(BaseModel): -# description: Optional[str] -# python_fn_signature: str -# sub_fns: List['TaskTree'] -# -# JSONSchema.update_forward_refs() -# TaskTree.update_forward_refs() +from typing import Dict, List, Union, Optional +from pydantic import BaseModel, Field + +class JSONSchema(BaseModel): + type: str + format: Union[str, None] = None + items: Union['JSONSchema', None] = None + properties: Dict[str, 'JSONSchema'] = Field(default_factory=dict) + additionalProperties: Union[bool, 'JSONSchema'] = True + required: List[str] = Field(default_factory=list) + + class Config: + arbitrary_types_allowed = True + +class TaskTree(BaseModel): + description: Optional[str] + python_fn_signature: str + sub_fns: List['TaskTree'] + +JSONSchema.update_forward_refs() +TaskTree.update_forward_refs() # diff --git a/dev_gpt/options/generate/templates_user.py b/dev_gpt/options/generate/templates_user.py index aa70f4d..5b0dd66 100644 --- a/dev_gpt/options/generate/templates_user.py +++ b/dev_gpt/options/generate/templates_user.py @@ -126,7 +126,8 @@ image_url_list = search_images('', top_n=10) ``` """ -template_generate_function = PromptTemplate.from_template( +def template_generate_function_constructor(is_using_gpt_3_5_turbo, is_using_google_custom_search): + return PromptTemplate.from_template( general_guidelines_string + f''' Write a python function which receives as \ @@ -151,10 +152,10 @@ Your approach: 2. Think about solutions for these challenges. 3. Decide for one of the solutions. 4. Write the code for the function. Don't write code for the test. -{gpt_35_turbo_usage_string} -{google_custom_search_usage_string} +{gpt_35_turbo_usage_string if is_using_gpt_3_5_turbo else ''} +{google_custom_search_usage_string if is_using_google_custom_search else ''} {template_code_wrapping_string}''' -) + ) template_generate_test = PromptTemplate.from_template(