From 2b4186a4f89ee9ba9299d0d33e986eb746159653 Mon Sep 17 00:00:00 2001 From: Nicholas Albion Date: Wed, 20 Sep 2023 23:15:37 +1000 Subject: [PATCH] test_chat_completion_Architect passes --- pilot/test_main_e2e.py | 4 ++-- pilot/utils/llm_connection.py | 6 ++---- pilot/utils/test_llm_connection.py | 32 ++++++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/pilot/test_main_e2e.py b/pilot/test_main_e2e.py index beeba9e..4df59d5 100644 --- a/pilot/test_main_e2e.py +++ b/pilot/test_main_e2e.py @@ -4,7 +4,7 @@ from unittest.mock import patch from dotenv import load_dotenv load_dotenv() -from database.database import create_tables, drop_tables +from database.database import create_tables from helpers.Project import Project from .main import init, get_custom_print @@ -40,7 +40,7 @@ class MockQuestionary(): elif self.state == 'DONE': answer = 'DONE' else: # if self.state == 'project_description': - answer = next(self.answers) + answer = next(self.answers, '') print('User:', answer) return answer diff --git a/pilot/utils/llm_connection.py b/pilot/utils/llm_connection.py index cf00ef1..624ad78 100644 --- a/pilot/utils/llm_connection.py +++ b/pilot/utils/llm_connection.py @@ -14,7 +14,8 @@ from logger.logger import logger from helpers.exceptions.TokenLimitError import TokenLimitError from utils.utils import fix_json - +model = os.getenv('MODEL_NAME') +endpoint = os.getenv('ENDPOINT') def get_tokens_in_messages(messages: List[str]) -> int: @@ -22,9 +23,6 @@ def get_tokens_in_messages(messages: List[str]) -> int: tokenized_messages = [tokenizer.encode(message['content']) for message in messages] return sum(len(tokens) for tokens in tokenized_messages) -#get endpoint and model name from .ENV file -model = os.getenv('MODEL_NAME') -endpoint = os.getenv('ENDPOINT') def num_tokens_from_functions(functions, model=model): """Return the number of tokens used by a list of functions.""" diff --git a/pilot/utils/test_llm_connection.py b/pilot/utils/test_llm_connection.py index 38e16af..93cdc5d 100644 --- a/pilot/utils/test_llm_connection.py +++ b/pilot/utils/test_llm_connection.py @@ -1,9 +1,11 @@ +import builtins from dotenv import load_dotenv from const.function_calls import ARCHITECTURE from helpers.AgentConvo import AgentConvo from helpers.Project import Project from helpers.agents.Architect import Architect from .llm_connection import create_gpt_chat_completion +from main import get_custom_print load_dotenv() @@ -11,7 +13,8 @@ project = Project({'app_id': 'test-app'}, current_step='test') class TestLlmConnection: - """Test the LLM connection class.""" + def setup_method(self): + builtins.print, ipc_client_instance = get_custom_print({}) def test_chat_completion_Architect(self): """Test the chat completion method.""" @@ -21,10 +24,27 @@ class TestLlmConnection: convo.construct_and_add_message_from_prompt('architecture/technologies.prompt', { 'name': 'Test App', - 'prompt': 'A web-based chat app', + 'prompt': ''' + The project involves the development of a web-based chat application named "Test_App". + In this application, users can send direct messages to each other. + However, it does not include a group chat functionality. + Multimedia messaging, such as the exchange of images and videos, is not a requirement for this application. + No clear instructions were given for the inclusion of user profile customization features like profile + picture and status updates, as well as a feature for chat history. The project must be developed strictly + as a monolithic application, regardless of any other suggested methods. + The project's specifications are subject to the project manager's discretion, implying a need for + solution-oriented decision-making in areas where precise instructions were not provided.''', 'app_type': 'web app', 'user_stories': [ - 'As a user I want to be able view messages sent and received' + 'User will be able to send direct messages to another user.', + 'User will receive direct messages from other users.', + 'User will view the sent and received messages in a conversation view.', + 'User will select a user to send a direct message.', + 'User will be able to search for users to send direct messages to.', + 'Users can view the online status of other users.', + 'User will be able to log into the application using their credentials.', + 'User will be able to logout from the Test_App.', + 'User will be able to register a new account on Test_App.', ] }) @@ -34,9 +54,13 @@ class TestLlmConnection: # When response = create_gpt_chat_completion(messages, '', function_calls=ARCHITECTURE) # Then + # You are and experienced software architect... + # You are working in a software development agency... + assert len(convo.messages) == 2 assert response is not None assert len(response) > 0 - # assert response != prompt + technologies: list[str] = response['function_calls']['arguments']['technologies'] + assert 'Node.js' in technologies def _create_convo(self, agent):