From 2514f72635e7bc35a54556a080085099f78178d2 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 30 Nov 2023 09:59:24 -0800 Subject: [PATCH 1/3] Implement Submind test base class for testing CBF subminds Add common Chatbot test resources --- neon_minerva/chatbots/__init__.py | 18 ++++++ neon_minerva/chatbots/test_constants.py | 74 ++++++++++++++++++++++ neon_minerva/chatbots/util.py | 31 +++++++++ neon_minerva/tests/chatbot_v1_test_base.py | 46 ++++++++++++++ requirements/chatbots.txt | 2 + 5 files changed, 171 insertions(+) create mode 100644 neon_minerva/chatbots/__init__.py create mode 100644 neon_minerva/chatbots/test_constants.py create mode 100644 neon_minerva/chatbots/util.py create mode 100644 neon_minerva/tests/chatbot_v1_test_base.py create mode 100644 requirements/chatbots.txt diff --git a/neon_minerva/chatbots/__init__.py b/neon_minerva/chatbots/__init__.py new file mode 100644 index 0000000..158a323 --- /dev/null +++ b/neon_minerva/chatbots/__init__.py @@ -0,0 +1,18 @@ +# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System +# +# Copyright 2008-2023 Neongecko.com Inc. | All Rights Reserved +# +# Notice of License - Duplicating this Notice of License near the start of any file containing +# a derivative of this software is a condition of license for this software. +# Friendly Licensing: +# No charge, open source royalty free use of the Neon AI software source and object is offered for +# educational users, noncommercial enthusiasts, Public Benefit Corporations (and LLCs) and +# Social Purpose Corporations (and LLCs). Developers can contact developers@neon.ai +# For commercial licensing, distribution of derivative works or redistribution please contact licenses@neon.ai +# Distributed on an "AS IS” basis without warranties or conditions of any kind, either express or implied. +# Trademarks of Neongecko: Neon AI(TM), Neon Assist (TM), Neon Communicator(TM), Klat(TM) +# Authors: Guy Daniels, Daniel McKnight, Regina Bloomstine, Elon Gasper, Richard Leeds +# +# Specialized conversational reconveyance options from Conversation Processing Intelligence Corp. +# US Patents 2008-2023: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924 +# China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending diff --git a/neon_minerva/chatbots/test_constants.py b/neon_minerva/chatbots/test_constants.py new file mode 100644 index 0000000..073b046 --- /dev/null +++ b/neon_minerva/chatbots/test_constants.py @@ -0,0 +1,74 @@ +# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System +# +# Copyright 2008-2023 Neongecko.com Inc. | All Rights Reserved +# +# Notice of License - Duplicating this Notice of License near the start of any file containing +# a derivative of this software is a condition of license for this software. +# Friendly Licensing: +# No charge, open source royalty free use of the Neon AI software source and object is offered for +# educational users, noncommercial enthusiasts, Public Benefit Corporations (and LLCs) and +# Social Purpose Corporations (and LLCs). Developers can contact developers@neon.ai +# For commercial licensing, distribution of derivative works or redistribution please contact licenses@neon.ai +# Distributed on an "AS IS” basis without warranties or conditions of any kind, either express or implied. +# Trademarks of Neongecko: Neon AI(TM), Neon Assist (TM), Neon Communicator(TM), Klat(TM) +# Authors: Guy Daniels, Daniel McKnight, Regina Bloomstine, Elon Gasper, Richard Leeds +# +# Specialized conversational reconveyance options from Conversation Processing Intelligence Corp. +# US Patents 2008-2023: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924 +# China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending + +PROMPT = "hello!" + +RESPONSES = {"Ned": "Hi, I'm Ned. How are you, testrunner?", + "Eliza": "Hello... I'm glad you could drop by today.", + "terry": "Hey", + "Ima": "I am ready to talk", + "wolfram": "Hello, human", + "kbot": "hello!", + "alice": "Hi there!", + "abstain": ""} + +VOTES_BY_USER = { + '1prompt1': { + 'bot1': [], + 'bot2': ['bot1'], + 'bot3': [], + 'bot4': [], + 'abstain': ['bot2', 'bot3', 'bot4'] + }, + '2prompt2': { + 'bot1': [], + 'bot2': [], + 'bot4': [], + 'abstain': ['bot1', 'bot2', 'bot4'] + }, + '3prompt3': { + 'bot1': [], + 'bot2': ['bot1'], + 'bot3': [], + 'bot4': [], + 'abstain': ['bot2', 'bot3', 'bot4'] + } +} + +SELECTIONS = { + 'bot1': [('prompt1', 'bot2'), ('prompt2', 'abstain'), ('prompt3', 'bot2')], + 'bot2': [('prompt1', 'abstain'), ('prompt2', 'abstain'), ('prompt3', 'abstain')], + 'bot3': [('prompt1', 'abstain'), ('prompt3', 'abstain')], + 'bot4': [('prompt1', 'abstain'), ('prompt2', 'abstain'), ('prompt3', 'abstain')] +} + +SELECTION_HISTORY = ['bot2', 'bot2', 'bot2'] + +PARTICIPANT_HISTORY = [(), # element 0 is expected to be an empty tuple + ('bot1', 'bot2', 'bot3', 'bot4'), + ('bot1', 'bot2', 'bot3', 'bot4')] + +# ContextKeeper constants +RECENT_USERS = [f"user{number}" for number in range(20)] +RECENT_SHOUTS = [ + "Who is the president of Ukraine?", + "Who is the president of the US?", + "What is the distance between them?", + "When was he born?" +] diff --git a/neon_minerva/chatbots/util.py b/neon_minerva/chatbots/util.py new file mode 100644 index 0000000..6104de6 --- /dev/null +++ b/neon_minerva/chatbots/util.py @@ -0,0 +1,31 @@ +# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System +# +# Copyright 2008-2023 Neongecko.com Inc. | All Rights Reserved +# +# Notice of License - Duplicating this Notice of License near the start of any file containing +# a derivative of this software is a condition of license for this software. +# Friendly Licensing: +# No charge, open source royalty free use of the Neon AI software source and object is offered for +# educational users, noncommercial enthusiasts, Public Benefit Corporations (and LLCs) and +# Social Purpose Corporations (and LLCs). Developers can contact developers@neon.ai +# For commercial licensing, distribution of derivative works or redistribution please contact licenses@neon.ai +# Distributed on an "AS IS” basis without warranties or conditions of any kind, either express or implied. +# Trademarks of Neongecko: Neon AI(TM), Neon Assist (TM), Neon Communicator(TM), Klat(TM) +# Authors: Guy Daniels, Daniel McKnight, Regina Bloomstine, Elon Gasper, Richard Leeds +# +# Specialized conversational reconveyance options from Conversation Processing Intelligence Corp. +# US Patents 2008-2023: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924 +# China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending +import pkg_resources + + +def load_chatbot(name: str): + try: + from importlib_metadata import entry_points + bot_entrypoints = entry_points(group="neon.plugin.chatbot") + except ImportError: + bot_entrypoints = pkg_resources.iter_entry_points("neon.plugin.chatbot") + + for bot in bot_entrypoints: + if bot.name == name: + return bot.load() diff --git a/neon_minerva/tests/chatbot_v1_test_base.py b/neon_minerva/tests/chatbot_v1_test_base.py new file mode 100644 index 0000000..ac5c936 --- /dev/null +++ b/neon_minerva/tests/chatbot_v1_test_base.py @@ -0,0 +1,46 @@ +# NEON AI (TM) SOFTWARE, Software Development Kit & Application Development System +# +# Copyright 2008-2023 Neongecko.com Inc. | All Rights Reserved +# +# Notice of License - Duplicating this Notice of License near the start of any file containing +# a derivative of this software is a condition of license for this software. +# Friendly Licensing: +# No charge, open source royalty free use of the Neon AI software source and object is offered for +# educational users, noncommercial enthusiasts, Public Benefit Corporations (and LLCs) and +# Social Purpose Corporations (and LLCs). Developers can contact developers@neon.ai +# For commercial licensing, distribution of derivative works or redistribution please contact licenses@neon.ai +# Distributed on an "AS IS” basis without warranties or conditions of any kind, either express or implied. +# Trademarks of Neongecko: Neon AI(TM), Neon Assist (TM), Neon Communicator(TM), Klat(TM) +# Authors: Guy Daniels, Daniel McKnight, Regina Bloomstine, Elon Gasper, Richard Leeds +# +# Specialized conversational reconveyance options from Conversation Processing Intelligence Corp. +# US Patents 2008-2023: US7424516, US20140161250, US20140177813, US8638908, US8068604, US8553852, US10530923, US10530924 +# China Patent: CN102017585 - Europe Patent: EU2156652 - Patents Pending + + +import unittest + +from os import getenv +from time import sleep +from chatbot_core.utils import clean_up_bot +from klat_connector import start_socket +from klat_connector.mach_server import MachKlatServer +from neon_minerva.chatbots.util import load_chatbot + + +class TestSubmind(unittest.TestCase): + # Determine submind to test + submind_entrypoint = getenv("TEST_BOT_ENTRYPOINT") + bot_class = load_chatbot(submind_entrypoint) + # Initialize a server for testing + server = MachKlatServer() + sleep(1) + socket = start_socket("0.0.0.0") + # Initialize a submind instance + submind = bot_class(socket, "Private", "testrunner", "testpassword", + on_server=False) + + @classmethod + def tearDownClass(cls) -> None: + clean_up_bot(cls.submind) + cls.server.shutdown_server() diff --git a/requirements/chatbots.txt b/requirements/chatbots.txt new file mode 100644 index 0000000..0724fe8 --- /dev/null +++ b/requirements/chatbots.txt @@ -0,0 +1,2 @@ +klat-connector +neon-chatbot-core \ No newline at end of file From 76ee6301e12e5c6876572c9e036c23858f1f7f9d Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 30 Nov 2023 10:06:33 -0800 Subject: [PATCH 2/3] Add Chatbot extra deps to setup.py --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 52304e5..dd1e47b 100644 --- a/setup.py +++ b/setup.py @@ -74,6 +74,7 @@ def get_requirements(requirements_filename: str): ], python_requires='>=3.6', install_requires=get_requirements("requirements.txt"), + extras_require={"chatbots": get_requirements("chatbots.txt")}, entry_points={ 'console_scripts': ['minerva=neon_minerva.cli:neon_minerva_cli'] } From c47e4389bd4821a04d16151cf54d330bb53b8a43 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 30 Nov 2023 11:14:33 -0800 Subject: [PATCH 3/3] Refactor so submind may be defined after test case import --- neon_minerva/tests/chatbot_v1_test_base.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/neon_minerva/tests/chatbot_v1_test_base.py b/neon_minerva/tests/chatbot_v1_test_base.py index ac5c936..a7a8bcf 100644 --- a/neon_minerva/tests/chatbot_v1_test_base.py +++ b/neon_minerva/tests/chatbot_v1_test_base.py @@ -29,16 +29,20 @@ class TestSubmind(unittest.TestCase): - # Determine submind to test - submind_entrypoint = getenv("TEST_BOT_ENTRYPOINT") - bot_class = load_chatbot(submind_entrypoint) # Initialize a server for testing server = MachKlatServer() sleep(1) socket = start_socket("0.0.0.0") - # Initialize a submind instance - submind = bot_class(socket, "Private", "testrunner", "testpassword", - on_server=False) + submind = None + + @classmethod + def setUpClass(cls) -> None: + # Determine submind to test + submind_entrypoint = getenv("TEST_BOT_ENTRYPOINT") + bot_class = load_chatbot(submind_entrypoint) + # Initialize a submind instance + cls.submind = bot_class(cls.socket, "Private", "testrunner", + "testpassword", on_server=False) @classmethod def tearDownClass(cls) -> None: