{ "cells": [ { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "from chatbot_multiagent import submitUserMessage\n", "import random\n", "from math import inf\n", "\n", "def QA_sample_test(quesion_test:list[str], num_samples:int=inf):\n", " \n", " # Ensure there are at least 5 lines in the list\n", " num_samples = min(10, len(quesion_test))\n", " sample_quesion = random.sample(quesion_test, num_samples)\n", " \n", " result = []\n", " for quesion in sample_quesion:\n", " try:\n", " answer = submitUserMessage(quesion)\n", " result.append({'quesion': quesion, 'answer': answer}) \n", " except Exception as e:\n", " result.append({'quesion': quesion, 'error': e}) \n", " \n", " return result " ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "with open('./testsets/user_question_testsets.txt', 'r') as file:\n", " quesion_test = file.readlines() \n", "\n", "results = QA_sample_test(quesion_test, num_samples=15)" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Results saved to testsets/QA.txt\n" ] } ], "source": [ "file_path = 'testsets/QA.txt'\n", "\n", "# Open the file in write mode\n", "with open(file_path, 'w') as file:\n", " # Iterate over each dictionary in the list\n", " for result in results:\n", " # Iterate over each key-value pair in the dictionary\n", " for key, value in result.items():\n", " # Write each key-value pair to the file\n", " file.write(f\"{key}: \\n\\t{str(value).strip()}\\n\")\n", " # Add a blank line between dictionaries\n", " file.write(\"\\n\\n\")\n", " file.write(\"-\"*200+\"\\n\")\n", "\n", "print(f\"Results saved to {file_path}\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" } }, "nbformat": 4, "nbformat_minor": 2 }