diff --git a/dev_gpt/options/generate/pm/pm.py b/dev_gpt/options/generate/pm/pm.py index 95a2ef7..2c98628 100644 --- a/dev_gpt/options/generate/pm/pm.py +++ b/dev_gpt/options/generate/pm/pm.py @@ -1,13 +1,14 @@ from dev_gpt.apis import gpt from dev_gpt.apis.gpt import ask_gpt from dev_gpt.options.generate.chains.auto_refine_description import auto_refine_description +from dev_gpt.options.generate.chains.get_user_input_if_needed import get_user_input_if_needed 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, json_parser, self_healing_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.templates_user import generate_used_tools_prompt from dev_gpt.options.generate.ui import get_random_employee @@ -61,18 +62,29 @@ Description of the microservice: question_gen='Generate a question that requests for an example file url.', extension_name='Input Example', ) + used_tools = self.get_used_tools(microservice_description) microservice_description += self.user_input_extension_if_needed( { 'Microservice description': microservice_description, }, - condition_question='''\ -Besides interacting with the Google Custom Search and GPT-3.5 Turbo APIs, does the microservice make requests to any other APIs?''', - question_gen='Generate a question that asks for the endpoint of the external API and an example of a request and response when interacting with the external API.', + condition_question=f'''{ + (f"Other than interacting with {' and '.join(used_tools)}, does the microservice interface with any additional external APIs?") + if used_tools else "Based on the microservice description, does the microservice interface with external APIs" + }''', + question_gen='Generate a question that asks for the endpoint of the API and an example of a request and response when interacting with the API.', extension_name='Example of API usage', - post_transformation_fn=translation(from_format='api instruction', to_format='python code snippet raw without formatting') + post_transformation_fn=translation(from_format='api instruction', + to_format='python code snippet raw without formatting') ) return microservice_description, test_description + def get_used_tools(self, microservice_description): + return ask_gpt( + generate_used_tools_prompt, + self_healing_json_parser, + microservice_description=microservice_description + ) + def user_input_extension_if_needed( self, context, @@ -103,8 +115,6 @@ Microservice description: {microservice_description} ```''' - - generate_test_assertion_prompt = client_description + ''' Request json schema: ``` @@ -121,6 +131,7 @@ Note: the generated description must be less than 30 words long. Example: "Input for func is a base64 encoded image. The test asserts that the output of func is of type 'str'".''' + # def get_nlp_fns(self, microservice_description): # return ask_gpt( # get_nlp_fns_prompt, @@ -167,6 +178,7 @@ def construct_sub_task_tree(self, microservice_description): 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( # description=sub_task_description, @@ -257,7 +269,6 @@ def construct_sub_task_tree(self, microservice_description): # print('Sorry, I can not handle this feedback. Please formulate it more precisely.') - # better_description_prompt = client_description + ''' # Update the description of the Microservice to make it more precise without adding or removing information.''' diff --git a/dev_gpt/options/generate/templates_user.py b/dev_gpt/options/generate/templates_user.py index 59f80bd..a708748 100644 --- a/dev_gpt/options/generate/templates_user.py +++ b/dev_gpt/options/generate/templates_user.py @@ -547,3 +547,20 @@ Note that prompt.json must only contain one question. {custom_suffix} ''' ) + +generate_used_tools_prompt = '''\ +Microservice description: +{microservice_description} + +Question: +Respond with a list as JSON idicating which of the APIs [google_custom_search, gpt_3_5_turbo] are mentioned in the description. +Example 1: +["google_custom_search", "gpt_3_5_turbo"] +Example 2: +["google_custom_search"] +Example 3: +["gpt_3_5_turbo"] +Example 4: +[] +''' + diff --git a/test/unit/test_yes_no_question.py b/test/unit/test_yes_no_question.py index 716ee92..6c62fe1 100644 --- a/test/unit/test_yes_no_question.py +++ b/test/unit/test_yes_no_question.py @@ -17,7 +17,7 @@ The summary is returned as a string. \ The microservice uses the Yahoo Finance API to fetch the stock data and Python libraries to calculate the average closing price and generate the summary. \ The request parameter is "stock_symbol" and the response parameter is "summary". ``` -''', 'Besides interacting with the Google Custom Search and GPT-3.5 Turbo APIs, does the microservice make requests to any other APIs?' +''', 'Based on the microservice description, does the microservice interface with APIs?' ) def test_answer_yes_no_question_2(tmpdir):