mirror of
https://github.com/aljazceru/dev-gpt.git
synced 2025-12-23 16:44:20 +01:00
feat: enhance package generation (#34)
* feat: enhance package generation * fix: exclude unnecessary packages * fix: using custom gpt with gpt turbo * fix: fix curl command * fix: fix usage of gpt * fix: fix typo * refactor: refactor package creation flow for
This commit is contained in:
@@ -2,17 +2,19 @@ import os
|
||||
import random
|
||||
import re
|
||||
import shutil
|
||||
from typing import List
|
||||
|
||||
from src.apis import gpt
|
||||
from src.apis.jina_cloud import process_error_message, push_executor
|
||||
from src.constants import FILE_AND_TAG_PAIRS, NUM_IMPLEMENTATION_STRATEGIES, MAX_DEBUGGING_ITERATIONS, \
|
||||
PROBLEMATIC_PACKAGES, EXECUTOR_FILE_NAME, EXECUTOR_FILE_TAG, TEST_EXECUTOR_FILE_NAME, TEST_EXECUTOR_FILE_TAG, \
|
||||
REQUIREMENTS_FILE_NAME, REQUIREMENTS_FILE_TAG, DOCKER_FILE_NAME, DOCKER_FILE_TAG
|
||||
from src.options.generate.templates_user import template_generate_microservice_name, template_generate_possible_packages, \
|
||||
REQUIREMENTS_FILE_NAME, REQUIREMENTS_FILE_TAG, DOCKER_FILE_NAME, DOCKER_FILE_TAG, UNNECESSARY_PACKAGES
|
||||
from src.options.generate.templates_user import template_generate_microservice_name, \
|
||||
template_generate_possible_packages, \
|
||||
template_solve_code_issue, \
|
||||
template_solve_dependency_issue, template_is_dependency_issue, template_generate_playground, \
|
||||
template_generate_executor, template_generate_test, template_generate_requirements, template_generate_dockerfile, \
|
||||
template_chain_of_thought, template_summarize_error
|
||||
template_chain_of_thought, template_summarize_error, template_generate_possible_packages_output_format_string
|
||||
from src.utils.io import persist_file, get_all_microservice_files_with_content, get_microservice_path
|
||||
from src.utils.string_tools import print_colored
|
||||
|
||||
@@ -54,9 +56,9 @@ metas:
|
||||
return all_microservice_files_string.strip()
|
||||
|
||||
|
||||
def generate_and_persist_file(self, section_title, template, destination_folder, file_name, **template_kwargs):
|
||||
def generate_and_persist_file(self, section_title, template, destination_folder=None, file_name=None, system_definition_examples: List[str] = ['gpt', 'executor', 'docarray', 'client'], **template_kwargs):
|
||||
print_colored('', f'\n\n############# {section_title} #############', 'blue')
|
||||
conversation = self.gpt_session.get_conversation()
|
||||
conversation = self.gpt_session.get_conversation(system_definition_examples=system_definition_examples)
|
||||
template_kwargs = {k: v for k, v in template_kwargs.items() if k in template.input_variables}
|
||||
content_raw = conversation.chat(
|
||||
template.format(
|
||||
@@ -66,11 +68,12 @@ metas:
|
||||
)
|
||||
content = self.extract_content_from_result(content_raw, file_name, match_single_block=True)
|
||||
if content == '':
|
||||
content_raw = conversation.chat(f'You must add the {file_name} code.')
|
||||
content_raw = conversation.chat(f'You must add the content for {file_name}.')
|
||||
content = self.extract_content_from_result(
|
||||
content_raw, file_name, match_single_block=True
|
||||
)
|
||||
persist_file(content, os.path.join(destination_folder, file_name))
|
||||
if destination_folder:
|
||||
persist_file(content, os.path.join(destination_folder, file_name))
|
||||
return content
|
||||
|
||||
def generate_microservice(
|
||||
@@ -258,11 +261,15 @@ metas:
|
||||
|
||||
def get_possible_packages(self):
|
||||
print_colored('', '\n\n############# What packages to use? #############', 'blue')
|
||||
conversation = self.gpt_session.get_conversation()
|
||||
packages_raw = conversation.chat(
|
||||
template_generate_possible_packages.format(description=self.task_description)
|
||||
packages_csv_string = self.generate_and_persist_file(
|
||||
'packages to use',
|
||||
template_generate_possible_packages,
|
||||
None,
|
||||
file_name='packages.csv',
|
||||
system_definition_examples=['gpt'],
|
||||
description=self.task_description
|
||||
|
||||
)
|
||||
packages_csv_string = self.extract_content_from_result(packages_raw, 'packages.csv')
|
||||
packages_list = [[pkg.strip() for pkg in packages_string.split(',')] for packages_string in packages_csv_string.split('\n')]
|
||||
packages_list = packages_list[:NUM_IMPLEMENTATION_STRATEGIES]
|
||||
return packages_list
|
||||
@@ -274,6 +281,9 @@ metas:
|
||||
packages_list = [
|
||||
packages for packages in packages_list if len(set(packages).intersection(set(PROBLEMATIC_PACKAGES))) == 0
|
||||
]
|
||||
packages_list = [
|
||||
[package for package in packages if package not in UNNECESSARY_PACKAGES] for packages in packages_list
|
||||
]
|
||||
for num_approach, packages in enumerate(packages_list):
|
||||
try:
|
||||
self.generate_microservice(microservice_path, microservice_name, packages, num_approach)
|
||||
|
||||
Reference in New Issue
Block a user