mirror of
https://github.com/aljazceru/dev-gpt.git
synced 2025-12-29 03:14:21 +01:00
👩💼 feat: pm role more robust
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
from copy import deepcopy
|
||||
from time import sleep
|
||||
|
||||
from typing import List, Any
|
||||
@@ -49,6 +50,7 @@ class GPTSession:
|
||||
self.chars_generation_so_far = 0
|
||||
|
||||
def get_conversation(self, messages: List[BaseMessage] = [], print_stream: bool = True, print_costs: bool = True):
|
||||
messages = deepcopy(messages)
|
||||
return _GPTConversation(
|
||||
self.model_name, self.cost_callback, messages, print_stream, print_costs
|
||||
)
|
||||
|
||||
@@ -7,7 +7,7 @@ from typing import Callable, Union
|
||||
from typing import List, Text, Optional
|
||||
|
||||
from langchain import PromptTemplate
|
||||
from langchain.schema import SystemMessage, HumanMessage
|
||||
from langchain.schema import SystemMessage, HumanMessage, AIMessage
|
||||
from pydantic.dataclasses import dataclass
|
||||
|
||||
from src.apis import gpt
|
||||
@@ -327,6 +327,9 @@ metas:
|
||||
class MaxDebugTimeReachedException(BaseException):
|
||||
pass
|
||||
|
||||
class TaskRefinementException(BaseException):
|
||||
pass
|
||||
|
||||
def is_dependency_issue(self, summarized_error, dock_req_string: str, package_manager: str):
|
||||
# a few heuristics to quickly jump ahead
|
||||
if any([error_message in summarized_error for error_message in ['AttributeError', 'NameError', 'AssertionError']]):
|
||||
@@ -417,34 +420,42 @@ Test scenario:
|
||||
''')
|
||||
|
||||
def refine_task(self, pm):
|
||||
user_input = self.microservice_specification.task
|
||||
if not user_input:
|
||||
user_input = self.get_user_input(pm, 'What should your microservice do?')
|
||||
messages = [
|
||||
SystemMessage(content=system_task_introduction + system_task_iteration),
|
||||
]
|
||||
try:
|
||||
user_input = self.microservice_specification.task
|
||||
if not user_input:
|
||||
user_input = self.get_user_input(pm, 'What should your microservice do?')
|
||||
messages = [
|
||||
SystemMessage(content=system_task_introduction + system_task_iteration),
|
||||
]
|
||||
|
||||
while True:
|
||||
conversation = self.gpt_session.get_conversation(messages, print_stream=os.environ['VERBOSE'].lower() == 'true', print_costs=False)
|
||||
print('thinking...')
|
||||
agent_response_raw = conversation.chat(template_task_refinement.format(user_input=user_input), role='user')
|
||||
while True:
|
||||
conversation = self.gpt_session.get_conversation(messages, print_stream=os.environ['VERBOSE'].lower() == 'true', print_costs=False)
|
||||
print('thinking...')
|
||||
agent_response_raw = conversation.chat(template_task_refinement.format(user_input=user_input), role='user')
|
||||
|
||||
question = self.extract_content_from_result(agent_response_raw, 'prompt.txt', can_contain_code_block=False)
|
||||
task_final = self.extract_content_from_result(agent_response_raw, 'task-final.txt', can_contain_code_block=False)
|
||||
if task_final:
|
||||
self.microservice_specification.task = task_final
|
||||
break
|
||||
if question:
|
||||
messages.append(HumanMessage(content=user_input),)
|
||||
user_input = self.get_user_input(pm, question)
|
||||
messages.append(AIMessage(content=question))
|
||||
elif task_final:
|
||||
user_input = self.get_user_input(pm, agent_response_raw + '\n: ')
|
||||
else:
|
||||
raise self.TaskRefinementException()
|
||||
except self.TaskRefinementException as e:
|
||||
print_colored('', f'{pm.emoji} Could not refine the task. Please try again...', 'red')
|
||||
self.refine_task(pm)
|
||||
|
||||
question = self.extract_content_from_result(agent_response_raw, 'prompt.txt', can_contain_code_block=False)
|
||||
task_final = self.extract_content_from_result(agent_response_raw, 'task-final.txt', can_contain_code_block=False)
|
||||
if task_final:
|
||||
self.microservice_specification.task = task_final
|
||||
break
|
||||
if question:
|
||||
user_input = self.get_user_input(pm, question)
|
||||
messages.extend([HumanMessage(content=user_input)])
|
||||
else:
|
||||
user_input = self.get_user_input(pm, agent_response_raw + '\n: ')
|
||||
|
||||
def refine_test(self, pm):
|
||||
user_input = self.microservice_specification.task
|
||||
messages = [
|
||||
SystemMessage(content=system_task_introduction + system_test_iteration),
|
||||
]
|
||||
user_input = self.microservice_specification.task
|
||||
while True:
|
||||
conversation = self.gpt_session.get_conversation(messages, print_stream=os.environ['VERBOSE'].lower() == 'true', print_costs=False)
|
||||
print('thinking...')
|
||||
@@ -487,6 +498,7 @@ Test scenario:
|
||||
@staticmethod
|
||||
def get_user_input(employee, prompt_to_user):
|
||||
val = input(f'{employee.emoji}❓ {prompt_to_user}\nyou: ')
|
||||
print()
|
||||
while not val:
|
||||
val = input('you: ')
|
||||
return val
|
||||
|
||||
@@ -185,7 +185,7 @@ Please provide the input and output format.
|
||||
'''
|
||||
|
||||
system_test_iteration = f'''
|
||||
The client gives you a description of the microservice.
|
||||
The client gives you a description of the microservice (web service).
|
||||
Your task is to describe verbally a unit test for that microservice.
|
||||
There are two cases:
|
||||
a) The unit test requires an example file as input.
|
||||
|
||||
@@ -370,7 +370,7 @@ Either ask for clarification like this:
|
||||
<prompt to the client here>
|
||||
```
|
||||
|
||||
Or write the summarized description like this:
|
||||
Or write the summarized microservice description like this:
|
||||
**task-final.txt**
|
||||
```text
|
||||
<task here>
|
||||
|
||||
Reference in New Issue
Block a user