mirror of
https://github.com/aljazceru/dev-gpt.git
synced 2025-12-20 23:24:20 +01:00
docs: fix documentation
This commit is contained in:
@@ -82,7 +82,7 @@ class _GPTConversation:
|
|||||||
self.messages.append(chat_message)
|
self.messages.append(chat_message)
|
||||||
if os.environ['VERBOSE'].lower() == 'true':
|
if os.environ['VERBOSE'].lower() == 'true':
|
||||||
print_colored('user', prompt, 'blue')
|
print_colored('user', prompt, 'blue')
|
||||||
print_colored('assistant', '', 'green', end='')
|
print_colored('assistant', '', 'green', end='')
|
||||||
response = self._chat([self.system_message] + self.messages)
|
response = self._chat([self.system_message] + self.messages)
|
||||||
if os.environ['VERBOSE'].lower() == 'true':
|
if os.environ['VERBOSE'].lower() == 'true':
|
||||||
print()
|
print()
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ def main(ctx):
|
|||||||
@click.option('--description', required=True, help='Description of the microservice.')
|
@click.option('--description', required=True, help='Description of the microservice.')
|
||||||
@click.option('--test', required=True, help='Test scenario for the microservice.')
|
@click.option('--test', required=True, help='Test scenario for the microservice.')
|
||||||
@click.option('--model', default='gpt-4', help='GPT model to use (default: gpt-4).')
|
@click.option('--model', default='gpt-4', help='GPT model to use (default: gpt-4).')
|
||||||
@click.option('--verbose', default=False, is_flag=True, help='Verbose mode.')
|
@click.option('--verbose', default=False, is_flag=True, help='Verbose mode.') # only for development
|
||||||
@path_param
|
@path_param
|
||||||
def generate(
|
def generate(
|
||||||
description,
|
description,
|
||||||
@@ -67,8 +67,8 @@ def generate(
|
|||||||
generator = Generator(description, test, model=model)
|
generator = Generator(description, test, model=model)
|
||||||
with get_openai_callback() as cb:
|
with get_openai_callback() as cb:
|
||||||
generator.generate(path)
|
generator.generate(path)
|
||||||
print(f"Prompt/Completion/Total Tokens: {cb.prompt_tokens}/{cb.completion_tokens}/{cb.total_tokens}")
|
# print(f"Prompt/Completion/Total Tokens: {cb.prompt_tokens}/{cb.completion_tokens}/{cb.total_tokens}")
|
||||||
print(f"Total Cost on OpenAI (USD): ${cb.total_cost}")
|
# print(f"Total Cost on OpenAI (USD): ${cb.total_cost}")
|
||||||
|
|
||||||
@main.command()
|
@main.command()
|
||||||
@path_param
|
@path_param
|
||||||
|
|||||||
@@ -52,6 +52,26 @@ metas:
|
|||||||
all_microservice_files_string += f'**{file_name}**\n```{tag}\n{file_name_to_content[file_name]}\n```\n\n'
|
all_microservice_files_string += f'**{file_name}**\n```{tag}\n{file_name_to_content[file_name]}\n```\n\n'
|
||||||
return all_microservice_files_string.strip()
|
return all_microservice_files_string.strip()
|
||||||
|
|
||||||
|
|
||||||
|
def generate_and_persist_file(self, section_title, template, destination_folder, file_name, **kwargs):
|
||||||
|
print_colored('', f'\n############# {section_title} #############', 'blue')
|
||||||
|
conversation = self.gpt_session.get_conversation()
|
||||||
|
kwargs = {k: v for k, v in kwargs.items() if k in template.input_variables}
|
||||||
|
content_raw = conversation.chat(
|
||||||
|
template.format(
|
||||||
|
file_name=file_name,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
)
|
||||||
|
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 = self.extract_content_from_result(
|
||||||
|
content_raw, file_name, match_single_block=True
|
||||||
|
)
|
||||||
|
persist_file(content, os.path.join(destination_folder, file_name))
|
||||||
|
return content_raw
|
||||||
|
|
||||||
def generate_microservice(
|
def generate_microservice(
|
||||||
self,
|
self,
|
||||||
path,
|
path,
|
||||||
@@ -62,84 +82,58 @@ metas:
|
|||||||
MICROSERVICE_FOLDER_v1 = get_microservice_path(path, microservice_name, packages, num_approach, 1)
|
MICROSERVICE_FOLDER_v1 = get_microservice_path(path, microservice_name, packages, num_approach, 1)
|
||||||
os.makedirs(MICROSERVICE_FOLDER_v1)
|
os.makedirs(MICROSERVICE_FOLDER_v1)
|
||||||
|
|
||||||
print_colored('', '\n############# Microservice #############', 'blue')
|
microservice_content = self.generate_and_persist_file(
|
||||||
conversation = self.gpt_session.get_conversation()
|
'Microservice',
|
||||||
microservice_content_raw = conversation.chat(
|
template_generate_executor,
|
||||||
template_generate_executor.format(
|
MICROSERVICE_FOLDER_v1,
|
||||||
microservice_name=microservice_name,
|
microservice_name=microservice_name,
|
||||||
microservice_description=self.task_description,
|
microservice_description=self.task_description,
|
||||||
test=self.test_description,
|
test_description=self.test_description,
|
||||||
packages=packages,
|
packages=packages,
|
||||||
file_name_purpose=EXECUTOR_FILE_NAME,
|
file_name_purpose=EXECUTOR_FILE_NAME,
|
||||||
tag_name=EXECUTOR_FILE_TAG,
|
tag_name=EXECUTOR_FILE_TAG,
|
||||||
file_name=EXECUTOR_FILE_NAME,
|
file_name=EXECUTOR_FILE_NAME,
|
||||||
)
|
|
||||||
)
|
|
||||||
microservice_content = self.extract_content_from_result(
|
|
||||||
microservice_content_raw, 'microservice.py', match_single_block=True
|
|
||||||
)
|
|
||||||
if microservice_content == '':
|
|
||||||
microservice_content_raw = conversation.chat('You must add the executor code.')
|
|
||||||
microservice_content = self.extract_content_from_result(
|
|
||||||
microservice_content_raw, 'microservice.py', match_single_block=True
|
|
||||||
)
|
|
||||||
persist_file(microservice_content, os.path.join(MICROSERVICE_FOLDER_v1, 'microservice.py'))
|
|
||||||
|
|
||||||
print_colored('', '\n############# Test Microservice #############', 'blue')
|
|
||||||
conversation = self.gpt_session.get_conversation()
|
|
||||||
test_microservice_content_raw = conversation.chat(
|
|
||||||
template_generate_test.format(
|
|
||||||
code_files_wrapped=self.files_to_string({'microservice.py': microservice_content}),
|
|
||||||
microservice_name=microservice_name,
|
|
||||||
test_description=self.test_description,
|
|
||||||
file_name_purpose=TEST_EXECUTOR_FILE_NAME,
|
|
||||||
tag_name=TEST_EXECUTOR_FILE_TAG,
|
|
||||||
file_name=TEST_EXECUTOR_FILE_NAME,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
test_microservice_content = self.extract_content_from_result(
|
|
||||||
test_microservice_content_raw, 'microservice.py', match_single_block=True
|
|
||||||
)
|
|
||||||
persist_file(test_microservice_content, os.path.join(MICROSERVICE_FOLDER_v1, 'test_microservice.py'))
|
|
||||||
|
|
||||||
print_colored('', '\n############# Requirements #############', 'blue')
|
|
||||||
requirements_path = os.path.join(MICROSERVICE_FOLDER_v1, 'requirements.txt')
|
|
||||||
conversation = self.gpt_session.get_conversation()
|
|
||||||
requirements_content_raw = conversation.chat(
|
|
||||||
template_generate_requirements.format(
|
|
||||||
code_files_wrapped=self.files_to_string(
|
|
||||||
{'microservice.py': microservice_content, 'test_microservice.py': test_microservice_content}
|
|
||||||
),
|
|
||||||
file_name_purpose=REQUIREMENTS_FILE_NAME,
|
|
||||||
file_name=REQUIREMENTS_FILE_NAME,
|
|
||||||
tag_name=REQUIREMENTS_FILE_TAG,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
requirements_content = self.extract_content_from_result(requirements_content_raw, 'requirements.txt',
|
test_microservice_content = self.generate_and_persist_file(
|
||||||
match_single_block=True)
|
'Test Microservice',
|
||||||
persist_file(requirements_content, requirements_path)
|
template_generate_test,
|
||||||
|
MICROSERVICE_FOLDER_v1,
|
||||||
|
code_files_wrapped=self.files_to_string({'microservice.py': microservice_content}),
|
||||||
|
microservice_name=microservice_name,
|
||||||
|
microservice_description=self.task_description,
|
||||||
|
test_description=self.test_description,
|
||||||
|
file_name_purpose=TEST_EXECUTOR_FILE_NAME,
|
||||||
|
tag_name=TEST_EXECUTOR_FILE_TAG,
|
||||||
|
file_name=TEST_EXECUTOR_FILE_NAME,
|
||||||
|
)
|
||||||
|
|
||||||
print_colored('', '\n############# Dockerfile #############', 'blue')
|
requirements_content = self.generate_and_persist_file(
|
||||||
conversation = self.gpt_session.get_conversation()
|
'Requirements',
|
||||||
dockerfile_content_raw = conversation.chat(
|
template_generate_requirements,
|
||||||
template_generate_dockerfile.format(
|
MICROSERVICE_FOLDER_v1,
|
||||||
code_files_wrapped=self.files_to_string(
|
code_files_wrapped=self.files_to_string({
|
||||||
{
|
'microservice.py': microservice_content,
|
||||||
'microservice.py': microservice_content,
|
'test_microservice.py': test_microservice_content
|
||||||
'test_microservice.py': test_microservice_content,
|
}),
|
||||||
'requirements.txt': requirements_content,
|
file_name_purpose=REQUIREMENTS_FILE_NAME,
|
||||||
}
|
file_name=REQUIREMENTS_FILE_NAME,
|
||||||
),
|
tag_name=REQUIREMENTS_FILE_TAG,
|
||||||
file_name_purpose=DOCKER_FILE_NAME,
|
|
||||||
file_name=DOCKER_FILE_NAME,
|
|
||||||
tag_name=DOCKER_FILE_TAG,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
dockerfile_content = self.extract_content_from_result(
|
|
||||||
dockerfile_content_raw, 'Dockerfile', match_single_block=True
|
self.generate_and_persist_file(
|
||||||
|
'Dockerfile',
|
||||||
|
template_generate_dockerfile,
|
||||||
|
MICROSERVICE_FOLDER_v1,
|
||||||
|
code_files_wrapped=self.files_to_string({
|
||||||
|
'microservice.py': microservice_content,
|
||||||
|
'test_microservice.py': test_microservice_content,
|
||||||
|
'requirements.txt': requirements_content
|
||||||
|
}),
|
||||||
|
file_name_purpose=DOCKER_FILE_NAME,
|
||||||
|
file_name=DOCKER_FILE_NAME,
|
||||||
|
tag_name=DOCKER_FILE_TAG,
|
||||||
)
|
)
|
||||||
persist_file(dockerfile_content, os.path.join(MICROSERVICE_FOLDER_v1, 'Dockerfile'))
|
|
||||||
|
|
||||||
self.write_config_yml(microservice_name, MICROSERVICE_FOLDER_v1)
|
self.write_config_yml(microservice_name, MICROSERVICE_FOLDER_v1)
|
||||||
print('\nFirst version of the microservice generated. Start iterating on it to make the tests pass...')
|
print('\nFirst version of the microservice generated. Start iterating on it to make the tests pass...')
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ template_generate_executor = PromptTemplate.from_template(
|
|||||||
|
|
||||||
Write the executor called '{microservice_name}'. The name is very important to keep.
|
Write the executor called '{microservice_name}'. The name is very important to keep.
|
||||||
It matches the following description: '{microservice_description}'.
|
It matches the following description: '{microservice_description}'.
|
||||||
It will be tested with the following scenario: '{test}'.
|
It will be tested with the following scenario: '{test_description}'.
|
||||||
For the implementation use the following package: '{packages}'.
|
For the implementation use the following package: '{packages}'.
|
||||||
|
|
||||||
Obey the following rules:
|
Obey the following rules:
|
||||||
@@ -101,7 +101,7 @@ Your approach:
|
|||||||
1. Identify the core challenge when implementing the executor.
|
1. Identify the core challenge when implementing the executor.
|
||||||
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.
|
4. Write the code for the executor. Don't write code for the test.
|
||||||
''' + '\n' + template_code_wrapping_string
|
''' + '\n' + template_code_wrapping_string
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -264,6 +264,7 @@ template_generate_playground = PromptTemplate.from_template(
|
|||||||
Create a playground for the executor {microservice_name} using streamlit.
|
Create a playground for the executor {microservice_name} using streamlit.
|
||||||
The playground must look like it was made by a professional designer.
|
The playground must look like it was made by a professional designer.
|
||||||
All the ui elements are well thought out to make them visually appealing and easy to use.
|
All the ui elements are well thought out to make them visually appealing and easy to use.
|
||||||
|
The playground contains emojis that fit the theme of the playground.
|
||||||
This is an example how you can connect to the executor assuming the document (d) is already defined:
|
This is an example how you can connect to the executor assuming the document (d) is already defined:
|
||||||
```
|
```
|
||||||
from jina import Client, Document, DocumentArray
|
from jina import Client, Document, DocumentArray
|
||||||
|
|||||||
Reference in New Issue
Block a user