From 28320e1067c980ef5b9fabcca0466857b8042487 Mon Sep 17 00:00:00 2001 From: Terry Yin Date: Fri, 29 Nov 2024 12:00:55 +0800 Subject: [PATCH] assistant is not saving any money --- .../AiAssistant/ai_assistant_thread.py | 26 ++++++++++++++++ .../ai_exploratory_test_assistant.py | 30 ++++++++----------- whatDoesThisButtonDo/exploratory_test.py | 7 +++-- 3 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 whatDoesThisButtonDo/AiAssistant/ai_assistant_thread.py diff --git a/whatDoesThisButtonDo/AiAssistant/ai_assistant_thread.py b/whatDoesThisButtonDo/AiAssistant/ai_assistant_thread.py new file mode 100644 index 0000000..f91793d --- /dev/null +++ b/whatDoesThisButtonDo/AiAssistant/ai_assistant_thread.py @@ -0,0 +1,26 @@ +from .openai_client import OpenAIClient +from .get_next_action_command import GetNextActionCommand + +class AIAssistantThread: + def __init__(self, test_oracles, api_key: str, model: str): + self.openai_client = OpenAIClient( + test_oracles=test_oracles, + api_key=api_key, + model=model + ) + + def get_next_action(self, possible_actions, sut_state): + """ + Get the AI's choice for the next action to take + + Args: + possible_actions: List of possible actions with their descriptions + sut_state: Current state of the system under test + + Returns: + dict: Contains 'action' name and 'parameters' for the chosen action, + or None to indicate testing should stop + """ + command = GetNextActionCommand(self.openai_client, possible_actions) + response = command.execute() + return response \ No newline at end of file diff --git a/whatDoesThisButtonDo/AiAssistant/ai_exploratory_test_assistant.py b/whatDoesThisButtonDo/AiAssistant/ai_exploratory_test_assistant.py index 93031ef..66592bc 100644 --- a/whatDoesThisButtonDo/AiAssistant/ai_exploratory_test_assistant.py +++ b/whatDoesThisButtonDo/AiAssistant/ai_exploratory_test_assistant.py @@ -1,26 +1,20 @@ -from .openai_client import OpenAIClient -from .get_next_action_command import GetNextActionCommand class AIExploratoryTestAssistant: def __init__(self, test_oracles, api_key: str, model: str): - self.openai_client = OpenAIClient( - test_oracles=test_oracles, - api_key=api_key, - model=model - ) + self.test_oracles = test_oracles + self.api_key = api_key + self.model = model - def get_next_action(self, possible_actions, sut_state): + def create_thread(self): """ - Get the AI's choice for the next action to take + Creates a new AI assistant thread for handling test interactions - Args: - possible_actions: List of possible actions with their descriptions - sut_state: Current state of the system under test - Returns: - dict: Contains 'action' name and 'parameters' for the chosen action, - or None to indicate testing should stop + AIAssistantThread: A new thread instance for test execution """ - command = GetNextActionCommand(self.openai_client, possible_actions) - response = command.execute() - return response \ No newline at end of file + from .ai_assistant_thread import AIAssistantThread + return AIAssistantThread( + test_oracles=self.test_oracles, + api_key=self.api_key, + model=self.model + ) \ No newline at end of file diff --git a/whatDoesThisButtonDo/exploratory_test.py b/whatDoesThisButtonDo/exploratory_test.py index 6751f5d..96b08a6 100644 --- a/whatDoesThisButtonDo/exploratory_test.py +++ b/whatDoesThisButtonDo/exploratory_test.py @@ -29,12 +29,15 @@ def execute(self) -> None: Executes the exploratory testing process """ try: + # Create an AI assistant thread for this test execution + ai_thread = self.ai_assistant.create_thread() + possible_next_actions = self.testable_sandbox.start() current_state = {"status": "started"} while possible_next_actions: - # Get AI's chosen action and parameters - action_choice = self.ai_assistant.get_next_action( + # Get AI's chosen action and parameters using the thread + action_choice = ai_thread.get_next_action( possible_next_actions, current_state )