File size: 2,594 Bytes
4d50781
 
 
 
0189767
4d50781
37050e9
4d50781
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0189767
4d50781
 
 
 
 
 
 
 
 
 
 
0189767
4d50781
 
 
 
 
 
 
 
 
 
 
 
 
0189767
4d50781
0189767
 
 
 
 
 
 
 
 
4d50781
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{
 "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
}