diff --git a/README.md b/README.md index a5bf2a5..b3a6b89 100644 --- a/README.md +++ b/README.md @@ -72,8 +72,8 @@ you need to set the GOOGLE_API_KEY and GOOGLE_CSE_ID environment variables. More information can be found [here](https://developers.google.com/custom-search/v1/overview). ```bash dev-gpt configure --openai_api_key -dev-gpt configure --google_api_key (optional if you want to use google search) -dev-gpt configure --google_cse_id (optional if you want to use google search) +dev-gpt configure --google_api_key (optional if you want to use google custom search) +dev-gpt configure --google_cse_id (optional if you want to use google custom search) ``` If you set the environment variable `OPENAI_API_KEY`, the configuration step can be skipped. diff --git a/dev_gpt/options/generate/chains/auto_refine_description.py b/dev_gpt/options/generate/chains/auto_refine_description.py index abaf289..7d1b264 100644 --- a/dev_gpt/options/generate/chains/auto_refine_description.py +++ b/dev_gpt/options/generate/chains/auto_refine_description.py @@ -39,10 +39,10 @@ Note: the output must be a list of tasks the Microservice has to perform. Note: you must uses the following tools if necessary: {get_available_tools()} Example for the description: "return an image representing the current weather for a given location." \ -when the tools gpt-3.5-turbo and google-search are available: +when the tools gpt_3_5_turbo and google_custom_search are available: 1. get the current weather information from the https://openweathermap.org/ API -2. generate a Google search query to find the image matching the weather information and the location by using gpt-3.5-turbo (a) -3. find the image by using the Google search API (b) +2. generate a Google search query to find the image matching the weather information and the location by using gpt_3_5_turbo (a) +3. find the image by using the google_custom_search (b) 4. return the image as a base64 encoded string''' generate_request_schema_prompt = '''{context_string} @@ -59,5 +59,5 @@ Write an updated microservice description by incorporating information about the Note: You must not mention any details about algorithms or the technical implementation. Note: You must not mention that there is a request and response JSON schema Note: You must not use any formatting like triple backticks. -Note: If Google Custom Search or gpt-3.5-turbo is mentioned in the description, then you must mention them in the updated description as well. -Note: If an external API besides Google Custom Search and gpt-3.5-turbo is mentioned in the description, then you must mention the API in the updated description as well.''' +Note: If google_custom_search or gpt_3_5_turbo is mentioned in the description, then you must mention them in the updated description as well. +Note: If an external API besides google_custom_search and gpt_3_5_turbo is mentioned in the description, then you must mention the API in the updated description as well.''' diff --git a/dev_gpt/options/generate/generator.py b/dev_gpt/options/generate/generator.py index e7835d1..22fcc81 100644 --- a/dev_gpt/options/generate/generator.py +++ b/dev_gpt/options/generate/generator.py @@ -523,15 +523,19 @@ pytest file_name_s=['strategies.json'], description=self.microservice_specification.task )['strategies.json'] - packages_list = [[pkg.strip().lower() for pkg in packages] for packages in json.loads(packages_json_string)] - packages_list = [[self.replace_with_tool_if_possible(pkg) for pkg in packages] for packages in - packages_list] - - packages_list = self.filter_packages_list(packages_list) - packages_list = self.remove_duplicates_from_packages_list(packages_list) - packages_list = packages_list[:NUM_IMPLEMENTATION_STRATEGIES] + packages_list = self.process_packages_json_string(packages_json_string) return packages_list + @staticmethod + def process_packages_json_string(packages_json_string): + packages_list = [[pkg.strip().lower().replace('-', '_') for pkg in packages] for packages in json.loads(packages_json_string)] + packages_list = [[Generator.replace_with_tool_if_possible(pkg) for pkg in packages] for packages in + packages_list] + + packages_list = Generator.filter_packages_list(packages_list) + packages_list = Generator.remove_duplicates_from_packages_list(packages_list) + packages_list = packages_list[:NUM_IMPLEMENTATION_STRATEGIES] + return packages_list def generate(self): os.makedirs(self.microservice_root_path) @@ -592,6 +596,7 @@ You can now run or deploy your microservice: and ( # all packages must be on pypi or it is gpt_3_5_turbo is_package_on_pypi(package) or package == 'gpt_3_5_turbo' + or package == 'google_custom_search' ) ] for packages in packages_list ] diff --git a/dev_gpt/options/generate/pm/pm.py b/dev_gpt/options/generate/pm/pm.py index 3c5a525..17468cb 100644 --- a/dev_gpt/options/generate/pm/pm.py +++ b/dev_gpt/options/generate/pm/pm.py @@ -66,7 +66,7 @@ Description of the microservice: 'Microservice description': microservice_description, }, condition_question='''\ -Does the microservice send requests to an API beside the Google Custom Search API and gpt-3.5-turbo?''', +Does the microservice send requests to an API beside the google_custom_search and gpt_3_5_turbo?''', 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.', extension_name='Example of API usage', post_transformation_fn=translation(from_format='api instruction', to_format='python code snippet raw without formatting') diff --git a/dev_gpt/options/generate/tools/tools.py b/dev_gpt/options/generate/tools/tools.py index a658372..8d447d3 100644 --- a/dev_gpt/options/generate/tools/tools.py +++ b/dev_gpt/options/generate/tools/tools.py @@ -2,8 +2,8 @@ import os def get_available_tools(): - tools = ['gpt-3.5-turbo (for any kind of text processing like summarization, paraphrasing, etc.)'] + tools = ['gpt_3_5_turbo (for any kind of text processing like summarization, paraphrasing, etc.)'] if os.environ.get('GOOGLE_API_KEY') and os.environ.get('GOOGLE_CSE_ID'): - tools.append('Google Custom Search') + tools.append('google_custom_search (for retrieving images or textual information from google') chars = 'abcdefghijklmnopqrstuvwxyz' return '\n'.join([f'{char}) {tool}' for tool, char in zip(tools, chars)]) \ No newline at end of file diff --git a/test/unit/test_packages.py b/test/unit/test_packages.py new file mode 100644 index 0000000..73a3cd0 --- /dev/null +++ b/test/unit/test_packages.py @@ -0,0 +1,20 @@ +from dev_gpt.options.generate.generator import Generator + +def test_package_parsing(): + packages_json_string = '''\ + [ + ["PyPDF2", "gpt_3_5_turbo"], + ["pdfminer.six", "gpt_3_5_turbo"], + ["tika", "gpt_3_5_turbo"], + [], + ["gpt_3_5_turbo"] + ]''' + + parsed_packages = Generator.process_packages_json_string(packages_json_string) + for parsed, expected in zip(parsed_packages, [ + ['pypdf2', 'gpt_3_5_turbo'], + ['pdfminer.six', 'gpt_3_5_turbo'], + [], + ['gpt_3_5_turbo'], + ]): + assert set(parsed) == set(expected) \ No newline at end of file