🔎 feat: search fix web search

This commit is contained in:
Florian Hönicke
2023-05-19 15:10:15 +02:00
parent 513ce588fe
commit 328eee7f18
4 changed files with 136 additions and 132 deletions

View File

@@ -23,7 +23,7 @@ from dev_gpt.options.generate.templates_user import template_generate_microservi
template_generate_possible_packages, \ template_generate_possible_packages, \
template_implement_solution_code_issue, \ template_implement_solution_code_issue, \
template_solve_pip_dependency_issue, template_is_dependency_issue, template_generate_playground, \ 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_chain_of_thought, template_summarize_error, \
template_solve_apt_get_dependency_issue, \ template_solve_apt_get_dependency_issue, \
template_suggest_solutions_code_issue, template_was_error_seen_before, \ 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: 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')) 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( microservice_content = self.generate_and_persist_file(
section_title='Microservice', 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, microservice_description=self.microservice_specification.task,
test_description=self.microservice_specification.test, test_description=self.microservice_specification.test,
packages=packages, packages=packages,

View File

@@ -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.translation import translation
from dev_gpt.options.generate.chains.user_confirmation_feedback_loop import user_feedback_loop 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.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.prompt_factory import make_prompt_friendly
from dev_gpt.options.generate.ui import get_random_employee from dev_gpt.options.generate.ui import get_random_employee
@@ -35,9 +36,9 @@ Description of the microservice:
def refine(self, microservice_description): def refine(self, microservice_description):
microservice_description, test_description = self.refine_description(microservice_description) microservice_description, test_description = self.refine_description(microservice_description)
return microservice_description, test_description # sub_task_tree = construct_sub_task_tree(microservice_description)
# sub_task_tree = self.construct_sub_task_tree(microservice_description)
# return sub_task_tree # return sub_task_tree
return microservice_description, test_description
def refine_description(self, microservice_description): def refine_description(self, microservice_description):
context = {'microservice_description': microservice_description} context = {'microservice_description': microservice_description}
@@ -128,44 +129,44 @@ Example:
# microservice_description=microservice_description # microservice_description=microservice_description
# ) # )
# #
# def construct_sub_task_tree(self, 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 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( # nlp_fns = self.get_nlp_fns(
# # microservice_description # microservice_description
# # ) # )
#
# sub_task_tree_dict = ask_gpt( sub_task_tree_dict = ask_gpt(
# construct_sub_task_tree_prompt, json_parser, construct_sub_task_tree_prompt, json_parser,
# microservice_description=microservice_description, microservice_description=microservice_description,
# # nlp_fns=nlp_fns # nlp_fns=nlp_fns
# ) )
# reflections = ask_gpt( reflections = ask_gpt(
# sub_task_tree_reflections_prompt, identity_parser, sub_task_tree_reflections_prompt, identity_parser,
# microservice_description=microservice_description, microservice_description=microservice_description,
# # nlp_fns=nlp_fns, # nlp_fns=nlp_fns,
# sub_task_tree=sub_task_tree_dict, sub_task_tree=sub_task_tree_dict,
# ) )
# solutions = ask_gpt( solutions = ask_gpt(
# sub_task_tree_solutions_prompt, identity_parser, sub_task_tree_solutions_prompt, identity_parser,
# # nlp_fns=nlp_fns, # nlp_fns=nlp_fns,
# microservice_description=microservice_description, sub_task_tree=sub_task_tree_dict, microservice_description=microservice_description, sub_task_tree=sub_task_tree_dict,
# reflections=reflections, reflections=reflections,
# ) )
# sub_task_tree_updated = ask_gpt( sub_task_tree_updated = ask_gpt(
# sub_task_tree_update_prompt, sub_task_tree_update_prompt,
# json_parser, json_parser,
# microservice_description=microservice_description, microservice_description=microservice_description,
# # nlp_fns=nlp_fns, # nlp_fns=nlp_fns,
# sub_task_tree=sub_task_tree_dict, solutions=solutions sub_task_tree=sub_task_tree_dict, solutions=solutions
# ) )
# # for task_dict in self.iterate_over_sub_tasks(sub_task_tree_updated): # for task_dict in self.iterate_over_sub_tasks(sub_task_tree_updated):
# # task_dict.update(self.get_additional_task_info(task_dict['task'])) # task_dict.update(self.get_additional_task_info(task_dict['task']))
#
# sub_task_tree = TaskTree.parse_obj(sub_task_tree_updated) sub_task_tree = TaskTree.parse_obj(sub_task_tree_updated)
# return sub_task_tree return sub_task_tree
# def get_additional_task_info(self, sub_task_description): # def get_additional_task_info(self, sub_task_description):
# additional_info_dict = self.get_additional_infos( # 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 unknown.
# Note: You must ignore facts that are unclear.''' # Note: You must ignore facts that are unclear.'''
# construct_sub_task_tree_prompt = client_description + ''' 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. 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: Example:
# Input: "Input: list of integers, Output: Audio file of short story where each number is mentioned exactly once." Input: "Input: list of integers, Output: Audio file of short story where each number is mentioned exactly once."
# Output: 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.", "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:", "python_fn_signature": "def generate_integer_story_audio(numbers: List[int]) -> str:",
# "sub_fns": [ "sub_fns": [
# {{ {{
# "description": "Generate sentence from integer.", "description": "Generate sentence from integer.",
# "python_fn_signature": "def generate_sentence_from_integer(number: int) -> int:", "python_fn_signature": "def generate_sentence_from_integer(number: int) -> int:",
# "sub_fns": [] "sub_fns": []
# }}, }},
# {{ {{
# "description": "Convert the story into an audio file.", "description": "Convert the story into an audio file.",
# "python_fn_signature": "def convert_story_to_audio(story: str) -> bytes:", "python_fn_signature": "def convert_story_to_audio(story: str) -> bytes:",
# "sub_fns": [] "sub_fns": []
# }} }}
# ] ]
# }} }}
#
# 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 + ''' Note: you must only output the json string - nothing else.
# Sub task tree: Note: you must pretty print the json string.'''
# ```
# {sub_task_tree} sub_task_tree_reflections_prompt = client_description + '''
# ``` 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}
# sub_task_tree_solutions_prompt = client_description + ''' ```
# 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} sub_task_tree_solutions_prompt = client_description + '''
# ``` Sub task tree:
# Reflections: ```
# ``` {sub_task_tree}
# {reflections} ```
# ``` Reflections:
# For each constructive criticism, write a solution (5 words) that address the criticism.''' ```
# {reflections}
# sub_task_tree_update_prompt = client_description + ''' ```
# Sub task tree: For each constructive criticism, write a solution (5 words) that address the criticism.'''
# ```
# {sub_task_tree} sub_task_tree_update_prompt = client_description + '''
# ``` Sub task tree:
# Solutions: ```
# ``` {sub_task_tree}
# {solutions} ```
# ``` Solutions:
# Update the sub task tree by applying the solutions. (pretty print the json string)''' ```
# {solutions}
# ask_questions_prompt = client_description + ''' ```
# Request json schema: Update the sub task tree by applying the solutions. (pretty print the json string)'''
# ```
# {request_schema} ask_questions_prompt = client_description + '''
# ``` Request json schema:
# Response json schema: ```
# ``` {request_schema}
# {response_schema} ```
# ``` Response json schema:
# Ask the user up to 5 unique detailed questions (5 words) about the microservice description that are not yet answered. ```
# ''' {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 + ''' # answer_questions_prompt = client_description + '''
# Request json schema: # Request json schema:

View File

@@ -1,22 +1,22 @@
# from typing import Dict, List, Union, Optional from typing import Dict, List, Union, Optional
# from pydantic import BaseModel, Field from pydantic import BaseModel, Field
#
# class JSONSchema(BaseModel): class JSONSchema(BaseModel):
# type: str type: str
# format: Union[str, None] = None format: Union[str, None] = None
# items: Union['JSONSchema', None] = None items: Union['JSONSchema', None] = None
# properties: Dict[str, 'JSONSchema'] = Field(default_factory=dict) properties: Dict[str, 'JSONSchema'] = Field(default_factory=dict)
# additionalProperties: Union[bool, 'JSONSchema'] = True additionalProperties: Union[bool, 'JSONSchema'] = True
# required: List[str] = Field(default_factory=list) required: List[str] = Field(default_factory=list)
#
# class Config: class Config:
# arbitrary_types_allowed = True arbitrary_types_allowed = True
#
# class TaskTree(BaseModel): class TaskTree(BaseModel):
# description: Optional[str] description: Optional[str]
# python_fn_signature: str python_fn_signature: str
# sub_fns: List['TaskTree'] sub_fns: List['TaskTree']
#
# JSONSchema.update_forward_refs() JSONSchema.update_forward_refs()
# TaskTree.update_forward_refs() TaskTree.update_forward_refs()
# #

View File

@@ -126,7 +126,8 @@ image_url_list = search_images('<search term>', 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''' general_guidelines_string + f'''
Write a python function which receives as \ Write a python function which receives as \
@@ -151,10 +152,10 @@ Your approach:
2. Think about solutions for these challenges. 2. Think about solutions for these challenges.
3. Decide for one of the solutions. 3. Decide for one of the solutions.
4. Write the code for the function. Don't write code for the test. 4. Write the code for the function. Don't write code for the test.
{gpt_35_turbo_usage_string} {gpt_35_turbo_usage_string if is_using_gpt_3_5_turbo else ''}
{google_custom_search_usage_string} {google_custom_search_usage_string if is_using_google_custom_search else ''}
{template_code_wrapping_string}''' {template_code_wrapping_string}'''
) )
template_generate_test = PromptTemplate.from_template( template_generate_test = PromptTemplate.from_template(