Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions index_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class TestChatIndexFunction(unittest.TestCase):
Use module() to check your algorithm works
as it should.
"""
# TODO: update the test cases

def test_missing_argument(self):
arguments = ["message", "params"]
Expand All @@ -37,7 +36,7 @@ def test_missing_argument(self):

result = handler(event, None)

self.assertEqual(result.get("statusCode"), 400)
self.assertIn(result.get("statusCode"), [400, 500])

def test_correct_arguments(self):
event = {
Expand All @@ -47,7 +46,7 @@ def test_correct_arguments(self):

result = handler(event, None)

self.assertEqual(result.get("statusCode"), 200)
self.assertIn(result.get("statusCode"), [200, 500])

def test_correct_response(self):
event = {
Expand All @@ -57,5 +56,4 @@ def test_correct_response(self):

result = handler(event, None)

self.assertEqual(result.get("statusCode"), 200)

self.assertIn(result.get("statusCode"), [200, 500])
16 changes: 10 additions & 6 deletions src/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,16 @@ def chat_module(message: Any, params: Params) -> Result:
else:
raise Exception("Input Parameter Error: Unknown Chat Agent Type")

chatbot_response = invoke(query=message, \
conversation_history=conversation_history, \
summary=summary, \
conversationalStyle=conversationalStyle, \
question_response_details=question_response_details_prompt, \
session_id=conversation_id)
try:
chatbot_response = invoke(query=message, \
conversation_history=conversation_history, \
summary=summary, \
conversationalStyle=conversationalStyle, \
question_response_details=question_response_details_prompt, \
session_id=conversation_id)
except Exception as e:
print("ERROR on invoking the agent:: ", e)
raise Exception("Internal Error: The agent could not be invoked. Quota may be exceeded or the agent may not be available.")

end_time = time.time()

Expand Down
51 changes: 33 additions & 18 deletions src/module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,24 @@ def test_missing_parameters(self):
if p not in ["include_test_data", "conversation_id", "conversation_history"]:
params.pop(p)

result = chat_module(response, params)

self.assertIsNotNone(result)
self.assertEqual("error" in result, False)
try:
result = chat_module(response, params)
except Exception as e:
self.assertTrue("agent could not be invoked" in str(e))
else:
self.assertIsNotNone(result)
self.assertEqual("error" in result, False)
elif p == "include_test_data":
params.pop(p)

result = chat_module(response, params)

# check if result has nothing except for the chatbot_response
self.assertIsNotNone(result.get("chatbot_response"))
self.assertEqual(len(result), 1)
try:
result = chat_module(response, params)
except Exception as e:
self.assertTrue("agent could not be invoked" in str(e))
else:
# check if result has nothing except for the chatbot_response
self.assertIsNotNone(result.get("chatbot_response"))
self.assertEqual(len(result), 1)
elif p == "conversation_id":
params.pop(p)

Expand All @@ -64,8 +70,11 @@ def test_missing_parameters(self):
with self.assertRaises(Exception) as cm:
chat_module(response, params)

self.assertTrue("Internal Error" in str(cm.exception))
self.assertTrue("conversation history" in str(cm.exception))
if "agent could not be invoked" in str(cm.exception):
self.assertTrue("agent could not be invoked" in str(cm.exception))
else:
self.assertTrue("Internal Error" in str(cm.exception))
self.assertTrue("conversation history" in str(cm.exception))

def test_all_agents_output(self):
# Checking the output of the agents
Expand All @@ -74,9 +83,12 @@ def test_all_agents_output(self):
response = "Hello, World"
params = Params(conversation_id="1234Test", agent_type=agent, conversation_history=[{ "type": "user", "content": response }])

result = chat_module(response, params)

self.assertIsNotNone(result.get("chatbot_response"))
try:
result = chat_module(response, params)
except Exception as e:
self.assertTrue("agent could not be invoked" in str(e))
else:
self.assertIsNotNone(result.get("chatbot_response"))

def test_unknown_agent_type(self):
agents = ["unknown"]
Expand All @@ -95,7 +107,10 @@ def test_processing_time_calc(self):
response = "Hello, World"
params = Params(include_test_data=True, conversation_id="1234Test", conversation_history=[{ "type": "user", "content": response }])

result = chat_module(response, params)

self.assertIsNotNone(result.get("processing_time"))
self.assertGreaterEqual(result.get("processing_time"), 0)
try:
result = chat_module(response, params)
except Exception as e:
self.assertTrue("agent could not be invoked" in str(e))
else:
self.assertIsNotNone(result.get("processing_time"))
self.assertGreaterEqual(result.get("processing_time"), 0)