File size: 60,027 Bytes
7ec15fa
 
 
 
 
 
 
 
 
 
 
96bffa5
193fd89
 
7ec15fa
96bffa5
7ec15fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
7ec15fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
7ec15fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
7ec15fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
7ec15fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
7ec15fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
7ec15fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
7ec15fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
7ec15fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
7ec15fa
 
 
 
 
 
 
0e4b9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
0e4b9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
0e4b9fc
 
 
 
 
 
 
7ec15fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
7ec15fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
7ec15fa
 
 
 
 
 
0e4b9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
0e4b9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
0e4b9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
0e4b9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
0e4b9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
0e4b9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
0e4b9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
0e4b9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
0e4b9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
0e4b9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
0e4b9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
0e4b9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
0e4b9fc
 
 
 
 
 
4851b42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
4851b42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
4851b42
 
 
 
 
 
0e4b9fc
7ec15fa
 
 
 
 
 
4823730
7ec15fa
 
 
0e4b9fc
7ec15fa
0e4b9fc
7ec15fa
 
 
 
 
4823730
7ec15fa
 
 
0e4b9fc
7ec15fa
0e4b9fc
7ec15fa
 
 
 
 
4823730
7ec15fa
 
 
0e4b9fc
7ec15fa
 
 
 
 
 
4823730
7ec15fa
 
 
0e4b9fc
7ec15fa
 
 
 
 
 
4823730
7ec15fa
 
 
0e4b9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4851b42
 
 
 
 
 
 
 
 
 
 
96bffa5
 
 
193fd89
96bffa5
7ec15fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
7ec15fa
 
 
 
 
 
 
 
 
 
 
193fd89
7ec15fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193fd89
 
 
7ec15fa
 
ffb6b49
7ec15fa
 
 
 
193fd89
7ec15fa
 
 
 
 
 
 
96bffa5
193fd89
7ec15fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
import streamlit as st
from langchain.agents import AgentType, initialize_agent
from langchain_community.chat_models import ChatOpenAI
from langchain.schema import SystemMessage
from langchain.prompts import MessagesPlaceholder
from typing import Dict, Any
from langchain.memory import ConversationBufferMemory
from langchain.agents import initialize_agent, Tool
import requests
from datetime import datetime
import os
#TODO aggiungre la frequenza per tutti i test, 
import uuid


API_O = os.environ.get("OPENAI_API_KEY")
class CustomMemory(ConversationBufferMemory):
    def _get_input_output(self, inputs: Dict[str, Any], outputs: Dict[str, Any]) -> tuple:
        input_str = inputs.get("input", "")
        chat_history = inputs.get("chat_history", [])
        input_str = f"Human: {input_str}\nChat History: {chat_history}\n"
        output_str = outputs.get("result", "")
        return input_str, output_str


def get_chat_completion(user_message, content):
    # Define the API endpoint
    url = "https://api.openai.com/v1/chat/completions"

    # Define the headers
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {API_O}"
    }

    # Define the data payload
    data = {
        "model": "gpt-4-1106-preview",
        "messages": [
            {
                "role": "system",
                "content": content
            },
            {
                "role": "user",
                "content": user_message
            }
        ]
    }
    # Send the request
    response = requests.post(url, headers=headers, json=data)
    # Return the JSON response
    return str(response.json()["choices"][0]["message"]["content"]).lower()


def video_streaming_Test(prompt):
    test_name = "video_streaming_test"
    content_one_time_test = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt the Start_Date is present, No if is missing. IF 'null' is in the input , the answer is NO. ACCEPTED ANSWER : YES / NO."
    content_multiple_tests = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt, both  Number_of_tests, Start_Date are present, No if even only one is missing.IF 'null' is in the input , the answer is NO. THERE CAN BE MORE IN THE PROMPT, YOU DON'T HAVE TO CAARE ABOUT IT. ACCEPTED ANSWER : YES / NO."

    if "One time test" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_one_time_test)
        if "yes" in str(response).lower():
            print(prompt)
            return f"1. run the new_chat tool, 2. report to the user in json format: test started successfully: {{test_name: {test_name}, type of test : selected_type_of_test, Start_Date: selected_start_date}}"
        else:
            return "There are some infomration needed missing, information needed: Start_Date "

    elif "Periodic test" in prompt or "Driving Mode" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_multiple_tests)
        if "yes" in str(response).lower():
            print(prompt)
            return f"1. run the new_chat tool, 2. report to the user in json format: test started successfully: {{test_name: {test_name}, type of test : selected_type_of_test,  Number_of_tests: selected_number_of_tests, Start_Date: selected_start_date}}"
        else:
            return "There are some infomration needed missing, information needed: Number_of_tests, Start_Date "
    else:
        return "seems like the user did not specify the type of test: Possible choiches: 1.One time test, 2.Periodic test, 3.Driving Mode "


def wifi_test(prompt):
    test_name = "wifi_test"

    content_one_time_test = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt the Start_Date is present, No if is missing. IF 'null' is in the input , the answer is NO. ACCEPTED ANSWER : YES / NO."
    content_multiple_tests = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt, both  Number_of_tests, Start_Date are present, No if even only one is missing.IF 'null' is in the input , the answer is NO. THERE CAN BE MORE IN THE PROMPT, YOU DON'T HAVE TO CAARE ABOUT IT. ACCEPTED ANSWER : YES / NO."
    if "One time test" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_one_time_test)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test, Start_Date: selected_start_date}}"
        else:
            return "There are some infomration needed missing, information needed: Start_Date "
    elif "Periodic test" in prompt or "Driving Mode" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_multiple_tests)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test,  Number_of_tests: selected_number_of_tests, Start_Date: selected_start_date}}"
        else:
            return "There are some infomration needed missing, information needed: Number_of_tests, Start_Date "
    else:
        return "seems like the user did not specify the type of test: Possible choiches: 1.One time test, 2.Periodic test, 3.Driving Mode "


def iot_test(prompt):
    test_name = "iot_test"

    content_one_time_test = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt all the following are present: 1: Start_Date, 2: Mqtt broker address, 3: Quality of Service (QoS), 4: Mqtt Message Count; No if even only one is missing. IF 'null' is in the input , the answer is NO. ACCEPTED ANSWER : YES / NO."
    content_multiple_tests = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt, all the following are present: 1: Number_of_tests, 2: Start_Date, 3: Mqtt broker address, 4: Quality of Service (QoS), 5: Mqtt Message Count; are present, No if even only one is missing.IF 'null' is in the input , the answer is NO. THERE CAN BE MORE IN THE PROMPT, YOU DON'T HAVE TO CARE ABOUT IT, . ACCEPTED ANSWER : YES / NO."
    if "One time test" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_one_time_test)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test, Start_Date: selected_start_date, Mqtt broker address: selected_Mqtt_broker_address, Quality of Service (QoS): selected_Quality_of_Service, Mqtt Message Count: selected_Mqtt_Message_Count }}"
        else:
            return "There are some infomration needed missing, information needed: 1: Start_Date, 2: Mqtt broker address, 3: Quality of Service (QoS), 4: Mqtt Message Count "

    elif "Periodic test" in prompt or "Driving Mode" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_multiple_tests)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test, Number_of_tests: selected_number_of_tests,  Start_Date: selected_start_date, Mqtt broker address: selected_Mqtt_broker_address, Quality of Service (QoS): selected_Quality_of_Service, Mqtt Message Count}}"
        else:
            return "There are some infomration needed missing, information needed: 1: Number_of_tests, 2: Start_Date, 3: Mqtt broker address, 4: Quality of Service (QoS), 5: Mqtt Message "
    else:
        return "seems like the user did not specify the type of test: Possible choiches: 1.One time test, 2.Periodic test, 3.Driving Mode "


def online_gaming_test(prompt):
    test_name = "online_gaming_test"

    content_one_time_test = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt both the Start_Date and the predefined_gaming_servers are present, No if even only one is missing. IF 'null' is in the input , the answer is NO. ACCEPTED ANSWER : YES / NO."
    content_multiple_tests = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt, all the following  Number_of_tests, Start_Date, predefined_gaming_servers are present, No if even only one is missing.IF 'null' is in the input , the answer is NO. THERE CAN BE MORE IN THE PROMPT, YOU DON'T HAVE TO CAARE ABOUT IT. ACCEPTED ANSWER : YES / NO."
    if "One time test" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_one_time_test)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test, Start_Date: selected_start_date, game_servers: predefined_gaming_servers}}"
        else:
            return "There are some infomration needed missing, information needed: Start_Date, predefined_gaming_servers "
    elif "Periodic test" in prompt or "Driving Mode" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_multiple_tests)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test,  Number_of_tests: selected_number_of_tests, Start_Date: selected_start_date, game_servers: predefined_gaming_servers}}"

        else:
            return "There are some infomration needed missing, information needed: Number_of_tests, Start_Date, predefined_gaming_servers "
    else:
        return "seems like the user did not specify the type of test: Possible choiches: 1.One time test, 2.Periodic test, 3.Driving Mode "


def youtube_streaming_test(prompt):
    test_name = "youtube_streaming_test"
    content_one_time_test = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt both the Start_Date and the video_quality are present, No if even only one is missing. IF 'null' is in the input , the answer is NO. ACCEPTED ANSWER : YES / NO."
    content_multiple_tests = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt, all the following Number_of_tests, Start_Date, video_quality are present, No if even only one is missing.IF 'null' is in the input , the answer is NO. THERE CAN BE MORE IN THE PROMPT, YOU DON'T HAVE TO CAARE ABOUT IT. ACCEPTED ANSWER : YES / NO."
    if "One time test" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_one_time_test)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test, Start_Date: selected_start_date, video_quality: selected_video_quality}}"
        else:
            return "There are some infomration needed missing, information needed: video_quality ,Start_Date"
    elif "Periodic test" in prompt or "Driving Mode" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_multiple_tests)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test,  Number_of_tests: selected_number_of_tests, Start_Date: selected_start_date, video_quality: selected_video_quality}}"

        else:
            return "There are some infomration needed missing, information needed: Number_of_tests, Start_Date, video_quality "
    else:
        return "seems like the user did not specify the type of test: Possible choiches: 1.One time test, 2.Periodic test, 3.Driving Mode "


def ping_test(prompt):
    test_name = "ping_test"
    content_one_time_test = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt all the following: host_or_ip, ping_count, Start_Date are  present, No if even only one is missing. IF 'null' is in the input , the answer is NO. ACCEPTED ANSWER : YES / NO."
    content_multiple_tests = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt, all the following: host_or_ip, ping_count, Number_of_tests, Start_Date are present, No if even only one is missing.IF 'null' is in the input , the answer is NO. THERE CAN BE MORE IN THE PROMPT, YOU DON'T HAVE TO CAARE ABOUT IT. ACCEPTED ANSWER : YES / NO."
    if "One time test" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_one_time_test)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test, Start_Date: selected_start_date,host_or_ip: selected_host_or_ip, ping_count: selected_ping_count  }}"
        else:
            return "There are some infomration needed missing, information needed: Start_Date ,host_or_ip, ping_count"
    elif "Periodic test" in prompt or "Driving Mode" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_multiple_tests)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test,  Number_of_tests: selected_number_of_tests, Start_Date: selected_start_date,host_or_ip: selected_host_or_ip, ping_count: selected_ping_count }}"
        else:
            return "There are some infomration needed missing, information needed: Number_of_tests, Start_Date, host_or_ip ping_count"
    else:
        return "seems like the user did not specify the type of test: Possible choiches: 1.One time test, 2.Periodic test, 3.Driving Mode "


def speed_test(prompt):
    test_name = "speed_test"
    content_one_time_test = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt both the Start_Date and the Speed_type are present, No if even only one is missing. IF 'null' is in the input , the answer is NO. ACCEPTED ANSWER : YES / NO."
    content_multiple_tests = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt, all the following Number_of_tests, Start_Date, Speed_type are present, No if even only one is missing.IF 'null' is in the input , the answer is NO. THERE CAN BE MORE IN THE PROMPT, YOU DON'T HAVE TO CAARE ABOUT IT. ACCEPTED ANSWER : YES / NO."
    if "One time test" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_one_time_test)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test, Start_Date: selected_start_date, Speed_type: selected_Speed_type}}"
        else:
            return "There are some infomration needed missing, information needed: Start_Date, Speed_type "
    elif "Periodic test" in prompt or "Driving Mode" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_multiple_tests)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test,  Number_of_tests: selected_number_of_tests, Start_Date: selected_start_date, Speed_type: selected_Speed_type}}"

        else:
            return "There are some infomration needed missing, information needed: Number_of_tests, Start_Date, Speed_type"
    else:
        return "seems like the user did not specify the type of test: Possible choiches: 1.One time test, 2.Periodic test, 3.Driving Mode "


def web_browsing_test(prompt):
    test_name = "web_browsing_test"
    content_one_time_test = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt , all the following Start_Date and the Host_list are present, No if even only one is missing. IF 'null' is in the input( except for the mail, can be null ) , the answer is NO. ACCEPTED ANSWER : YES / NO."
    content_multiple_tests = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt, all the following Number_of_tests, Start_Date, Host_list are present, No if even only one is missing.IF 'null' is in the input (except for the mail, can be null ) , the answer is NO. THERE CAN BE MORE IN THE PROMPT, YOU DON'T HAVE TO CAARE ABOUT IT. ACCEPTED ANSWER : YES / NO."
    if "One time test" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_one_time_test)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test, Start_Date: selected_start_date, Host_list: selected_Host_list}}"
        else:
            return "There are some infomration needed missing, information needed: Start_Date, Host_list"
    elif "Periodic test" in prompt or "Driving Mode" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_multiple_tests)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test,  Number_of_tests: selected_number_of_tests, Start_Date: selected_start_date, Host_list: selected_Host_list}}"

        else:
            return "There are some infomration needed missing, information needed: Number_of_tests, Start_Date, Host_list"
    else:
        return "seems like the user did not specify the type of test: Possible choiches: 1.One time test, 2.Periodic test, 3.Driving Mode "


def call_receive_test(prompt):
    test_name = "call_receive_test"
    content_one_time_test = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt the Start_Date is present, No if is missing. IF 'null' is in the input , the answer is NO. ACCEPTED ANSWER : YES / NO."
    content_multiple_tests = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt, both  Number_of_tests, Start_Date are present, No if even only one is missing.IF 'null' is in the input , the answer is NO. THERE CAN BE MORE IN THE PROMPT, YOU DON'T HAVE TO CAARE ABOUT IT. ACCEPTED ANSWER : YES / NO."
    if "One time test" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_one_time_test)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test, Start_Date: selected_start_date}}"
        else:
            return "There are some infomration needed missing, information needed: Start_Date "

    elif "Periodic test" in prompt or "Driving Mode" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_multiple_tests)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test,  Number_of_tests: selected_number_of_tests, Start_Date: selected_start_date}}"
        else:
            return "There are some infomration needed missing, information needed: Number_of_tests, Start_Date "
    else:
        return "seems like the user did not specify the type of test: Possible choiches: 1.One time test, 2.Periodic test, 3.Driving Mode "


def sms_receive_test(prompt):
    test_name = "sms_receive_test"
    content_one_time_test = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt the Start_Date is present, No if is missing. IF 'null' is in the input , the answer is NO. ACCEPTED ANSWER : YES / NO."
    content_multiple_tests = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt, both  Number_of_tests, Start_Date are present, No if even only one is missing.IF 'null' is in the input , the answer is NO. THERE CAN BE MORE IN THE PROMPT, YOU DON'T HAVE TO CAARE ABOUT IT. ACCEPTED ANSWER : YES / NO."
    if "One time test" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_one_time_test)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test, Start_Date: selected_start_date}}"
        else:
            return "There are some infomration needed missing, information needed: Start_Date "

    elif "Periodic test" in prompt or "Driving Mode" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_multiple_tests)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test,  Number_of_tests: selected_number_of_tests, Start_Date: selected_start_date}}"
        else:
            return "There are some infomration needed missing, information needed: Number_of_tests, Start_Date "
    else:
        return "seems like the user did not specify the type of test: Possible choiches: 1.One time test, 2.Periodic test, 3.Driving Mode "



def voice_call_test(prompt):
    test_name = "voice_call_test"
    content_one_time_test = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt , all the following Start_Date and the Phone_number are present, No if even only one is missing. IF 'null' is in the input( except for the mail, can be null ) , the answer is NO. ACCEPTED ANSWER : YES / NO."
    content_multiple_tests = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt, all the following Number_of_tests, Start_Date, Phone_number are present, No if even only one is missing.IF 'null' is in the input (except for the mail, can be null ) , the answer is NO. THERE CAN BE MORE IN THE PROMPT, YOU DON'T HAVE TO CAARE ABOUT IT. ACCEPTED ANSWER : YES / NO."
    if "One time test" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_one_time_test)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test, Start_Date: selected_start_date, Phone_number: selected_Phone_number}}"
        else:
            return "There are some infomration needed missing, information needed: Start_Date, Phone_number"
    elif "Periodic test" in prompt or "Driving Mode" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_multiple_tests)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test,  Number_of_tests: selected_number_of_tests, Start_Date: selected_start_date, Phone_number: selected_Phone_number}}"

        else:
            return "There are some infomration needed missing, information needed: Number_of_tests, Start_Date, Phone_number"
    else:
        return "seems like the user did not specify the type of test: Possible choiches: 1.One time test, 2.Periodic test, 3.Driving Mode "

    #TODO add optionals inputs 


def sms_send_test(prompt):
    test_name = "sms_send_test"
    content_one_time_test = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt , all the following Start_Date, phone_number, sms_message, are present, No if even only one is missing. IF 'null' is in the input( except for the email, can be null ) , the answer is NO. ACCEPTED ANSWER : YES / NO."
    content_multiple_tests = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt, all the following Number_of_tests, Start_Date, phone_number, sms_message, are present, No if even only one is missing. IF 'null' is in the input (except for the email, can be null ) , the answer is NO. THERE CAN BE MORE IN THE PROMPT, YOU DON'T HAVE TO CAARE ABOUT IT. ACCEPTED ANSWER : YES / NO."
    if "One time test" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_one_time_test)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test, Start_Date: selected_start_date, phone_number: selected_phone_number, sms_message: selected_sms_message}}"
        else:
            return "There are some infomration needed missing, information needed: Start_Date, phone_number, sms_message"
    elif "Periodic test" in prompt or "Driving Mode" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_multiple_tests)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test,  Number_of_tests: selected_number_of_tests, Start_Date: selected_start_date, phone_number: selected_phone_number, sms_message: selected_sms_message}}"

        else:
            return "There are some infomration needed missing, information needed: Number_of_tests, Start_Date, phone_number, sms_message"
    else:
        return "seems like the user did not specify the type of test: Possible choiches: 1.One time test, 2.Periodic test, 3.Driving Mode "

def service_mode_tests(prompt):
    test_name = "service_mode_tests"
    content_one_time_test = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt the Start_Date is present, No if is missing. IF 'null' is in the input , the answer is NO. ACCEPTED ANSWER : YES / NO."
    content_multiple_tests = "you only answer in shematic format,possibile asnwer are YES, NO. YES if in the prompt, both  Number_of_tests, Start_Date are present, No if even only one is missing.IF 'null' is in the input , the answer is NO. THERE CAN BE MORE IN THE PROMPT, YOU DON'T HAVE TO CAARE ABOUT IT. ACCEPTED ANSWER : YES / NO."

    if "One time test" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_one_time_test)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test, Start_Date: selected_start_date}}"
        else:
            return "There are some infomration needed missing, information needed: Start_Date "

    elif "Periodic test" in prompt or "Driving Mode" in prompt:
        if "now" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("now", formatted_date)
        elif "today" in prompt:
            now = datetime.now()
            formatted_date = str(now.strftime("%d/%m/%Y"))
            prompt = prompt.replace("today", formatted_date)

        response = get_chat_completion(prompt, content_multiple_tests)
        if "yes" in str(response).lower():
            print(prompt)
            return "1. run the new_chat tool, 2. report to the user in json format: test started successfully:  {{test_name: {test_name}, type of test : selected_type_of_test,  Number_of_tests: selected_number_of_tests, Start_Date: selected_start_date}}"
        else:
            return "There are some infomration needed missing, information needed: Number_of_tests, Start_Date "
    else:
        return "seems like the user did not specify the type of test: Possible choiches: 1.One time test, 2.Periodic test, 3.Driving Mode "



tools = [
    Tool(
        name="video_streaming_Test",
        func=lambda prompt: video_streaming_Test(prompt),
        description="""Use when the user wants to do a video_streaming_Test, 
                        start the tool IF AND ONLY IF  you have ALL the information needed.
                        There are three options for this test, 
                        1: One time test. Information Needed : (Start_Date : str[dd/mm/yy].)
                        2: Periodic test. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy].)
                        3: Driving Mode. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy].)
                        So first of all you have to understand which tetst does the user wants to do.ask DIRECTLLY the user which test options they want to perform, don't try to guess it. Then you have to find the informaton needed for that test.Users alway forget something, if you are missing some info, just pass none.In the field date,IF AND ONLY IF users says now or today, just pass now or today. NEVER CREATE INPUT IF NOT WRITTEN BY THE USER. IN THE INPUT PASS THE INFORMATION IN JSON FORMAT. IN THE INPUR PASS THE SPECIFIED TET TYPE, ask if missing test_type:(One time test/Periodic test/Driving Mode)"""
    ),

    Tool(
        name="wifi_test",
        func=lambda prompt: wifi_test(prompt),
        description="""Use when the user wants to do a wifi_test, 
                        start the tool IF AND ONLY IF  you have ALL the information needed.
                        There are three options for this test, 
                        1: One time test. Information Needed : (Start_Date : str[dd/mm/yy].)
                        2: Periodic test. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy].)
                        3: Driving Mode. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy].)
                        So first of all you have to understand which tetst does the user wants to do.ask DIRECTLLY the user which test options they want to perform, don't try to guess it. Then you have to find the informaton needed for that test.Users alway forget something, if you are missing some info, just pass none.In the field date,IF AND ONLY IF users says now or today, just pass now or today. NEVER CREATE INPUT IF NOT WRITTEN BY THE USER. IN THE INPUT PASS THE INFORMATION IN JSON FORMAT. IN THE INPUR PASS THE SPECIFIED TET TYPE, ask if missing test_type:(One time test/Periodic test/Driving Mode)"""
    ),

    Tool(
        name="iot_test",
        func=lambda prompt: iot_test(prompt),
        description="""Use when the user wants to do a iot_test, 
                        start the tool IF AND ONLY IF  you have ALL the information needed.
                        There are three options for this , 
                        1: One time test. Information Needed : (Start_Date : str[dd/mm/yy], Mqtt broker address: str, Quality of Service (QoS): int[default:0], Mqtt Message Count: int[default:200] )
                        2: Periodic test. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy], Mqtt broker address: str, Quality of Service (QoS): int[default:0], Mqtt Message Count: int[default:200] )
                        3: Driving Mode. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy] Mqtt broker address: str, Quality of Service (QoS): int[default:0], Mqtt Message Count: int[default:200] )
                        So first of all you have to understand which tetst does the user wants to do. ask DIRECTLLY the user which test options they want to perform, don't try to guess it. Then you have to find the informaton needed for that test.Users alway forget something, if you are missing some info, just pass none.In the field date,IF AND ONLY IF users says now or today, just pass now or today. NEVER CREATE INPUT IF NOT WRITTEN BY THE USER. IN THE INPUT PASS THE INFORMATION IN JSON FORMAT. IN THE INPUR PASS THE SPECIFIED TET TYPE, ask if missing test_type:(One time test/Periodic test/Driving Mode)"""
    ),
    Tool(
        name="online_gaming_test",
        func=lambda prompt: online_gaming_test(prompt),
        description="""Use when the user wants to do a online_gaming_test, 
                        start the tool IF AND ONLY IF  you have ALL the information needed.
                        There are three options for this test, 
                        1: One time test. Information Needed : (Start_Date : str[dd/mm/yy], predefined_gaming_servers: str[options: FORTNITE/PUBG])
                        2: Periodic test. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy], predefined_gaming_servers: str[options: FORTNITE/PUBG])
                        3: Driving Mode. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy] predefined_gaming_servers: str[options: FORTNITE/PUBG])
                        So first of all you have to understand which tetst does the user wants to do. ask DIRECTLLY the user which test options they want to perform, don't try to guess it. Then you have to find the informaton needed for that test.Users alway forget something, if you are missing some info, just pass none.In the field date,IF AND ONLY IF users says now or today, just pass now or today. NEVER CREATE INPUT IF NOT WRITTEN BY THE USER. IN THE INPUT PASS THE INFORMATION IN JSON FORMAT. IN THE INPUR PASS THE SPECIFIED TET TYPE, ask if missing test_type:(One time test/Periodic test/Driving Mode)"""
    ),
    Tool(
        name="ping_test",
        func=lambda prompt: ping_test(prompt),
        description="""Use when the user wants to do a ping_test, 
                        start the tool IF AND ONLY IF  you have ALL the information needed.
                        There are three options for this test,  ask DIRECTLLY the user which one of the following test options they want to perform, don't try to guess it.
                        1: One time test. Information Needed : (Start_Date : str[dd/mm/yy], host_or_ip: str/int, ping_count: int[predefined: 5])
                        2: Periodic test. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy], host_or_ip: str/int, ping_count: int[predefined: 5])
                        3: Driving Mode. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy], host_or_ip: str/int, ping_count: int[predefined: 5])
                        So first of all you have to understand which tetst does the user wants to do. ask DIRECTLLY the user which test options they want to perform, don't try to guess it. Then you have to find the informaton needed for that test.Users alway forget something, if you are missing some info, just pass none.In the field date,IF AND ONLY IF users says now or today, just pass now or today. NEVER CREATE INPUT IF NOT WRITTEN BY THE USER. IN THE INPUT PASS THE INFORMATION IN JSON FORMAT. IN THE INPUR PASS THE SPECIFIED TET TYPE, ask if missing test_type:(One time test/Periodic test/Driving Mode)"""
    ),
    Tool(
        name="youtube_streaming_test",
        func=lambda prompt: youtube_streaming_test(prompt),
        description="""Use when the user wants to do a youtube_streaming_test, 
                        start the tool IF AND ONLY IF  you have ALL the information needed.
                        There are three options for this test, 
                        1: One time test. Information Needed : (Start_Date : str[dd/mm/yy], video_quality: int[options: 480/720/1080])
                        2: Periodic test. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy], video_quality: int[options: 480/720/1080])
                        3: Driving Mode. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy], video_quality: int[options: 480/720/1080])
                        So first of all you have to understand which tetst does the user wants to do. ask DIRECTLLY the user which test options they want to perform, don't try to guess it. Then you have to find the informaton needed for that test.Users alway forget something, if you are missing some info, just pass none.In the field date,IF AND ONLY IF users says now or today, just pass now or today. NEVER CREATE INPUT IF NOT WRITTEN BY THE USER. IN THE INPUT PASS THE INFORMATION IN JSON FORMAT. IN THE INPUR PASS THE SPECIFIED TET TYPE, ask if missing test_type:(One time test/Periodic test/Driving Mode)"""
    ),
    Tool(
        name="speed_test",
        func=lambda prompt: speed_test(prompt),
        description="""Use when the user wants to do a speed_test, 
                        start the tool IF AND ONLY IF  you have ALL the information needed.
                        There are three options for this test, 
                        1: One time test. Information Needed : (Start_Date : str[dd/mm/yy], Speed_type: str[options: Fast/Ookla, ask directy the user for it])
                        2: Periodic test. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy], Speed_type: str[options: Fast/Ookla, ask directy the user for it])
                        3: Driving Mode. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy], Speed_type: str[options: Fast/Ookla, ask directy the user for it])
                        So first of all you have to understand which tetst does the user wants to do. ask DIRECTLLY the user which test options they want to perform, don't try to guess it. Then you have to find the informaton needed for that test.Users alway forget something, if you are missing some info, just pass none.In the field date, If and onyl if users says now or today, just pass now or today. NEVER CREATE INPUT IF NOT WRITTEN BY THE USER. IN THE INPUT PASS THE INFORMATION IN JSON FORMAT. IN THE INPUR PASS THE SPECIFIED TET TYPE, ask if missing test_type:(One time test/Periodic test/Driving Mode)"""
    ),
    Tool(
        name="web_browsing_test",
        func=lambda prompt: web_browsing_test(prompt),
        description="""Use when the user wants to do a web_browsing_test, 
                        start the tool IF AND ONLY IF  you have ALL the information needed.
                        There are three options for this test, 
                        1: One time test. Information Needed : (Start_Date : str[dd/mm/yy], Host_list: list, recover_email: str[optional])
                        2: Periodic test. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy], Host_list: list, recover_email: str[optional]
                        3: Driving Mode. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy], Host_list: list, recover_email: str[optional]
                        So first of all you have to understand which tetst does the user wants to do. ask DIRECTLLY the user which test options they want to perform, don't try to guess it. Then you have to find the informaton needed for that test.Users alway forget something, if you are missing some info, just pass none.In the field date,IF AND ONLY IF users says now or today, just pass now or today. NEVER CREATE INPUT IF NOT WRITTEN BY THE USER. IN THE INPUT PASS THE INFORMATION IN JSON FORMAT. IN THE INPUR PASS THE SPECIFIED TET TYPE, ask if missing test_type:(One time test/Periodic test/Driving Mode)"""
    ),
    Tool(
        name="call_receive_test",
        func=lambda prompt: call_receive_test(prompt),
        description="""Use when the user wants to do a call_receive_test, 
                        start the tool IF AND ONLY IF  you have ALL the information needed.
                        There are three options for this test, 
                        1: One time test. Information Needed : (Start_Date : str[dd/mm/yy].)
                        2: Periodic test. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy].)
                        3: Driving Mode. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy].)
                        So first of all you have to understand which tetst does the user wants to do.ask DIRECTLLY the user which test options they want to perform, don't try to guess it. Then you have to find the informaton needed for that test.Users alway forget something, if you are missing some info, just pass none.In the field date,IF AND ONLY IF users says now or today, just pass now or today. NEVER CREATE INPUT IF NOT WRITTEN BY THE USER. IN THE INPUT PASS THE INFORMATION IN JSON FORMAT. IN THE INPUR PASS THE SPECIFIED TET TYPE, ask if missing test_type:(One time test/Periodic test/Driving Mode)"""
    ),
    Tool(
        name="sms_receive_test",
        func=lambda prompt: sms_receive_test(prompt),
        description="""Use when the user wants to do a sms_receive_test, 
                        start the tool IF AND ONLY IF  you have ALL the information needed.
                        There are three options for this test, 
                        1: One time test. Information Needed : (Start_Date : str[dd/mm/yy].)
                        2: Periodic test. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy].)
                        3: Driving Mode. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy].)
                        So first of all you have to understand which tetst does the user wants to do.ask DIRECTLLY the user which test options they want to perform, don't try to guess it. Then you have to find the informaton needed for that test.Users alway forget something, if you are missing some info, just pass none.In the field date,IF AND ONLY IF users says now or today, just pass now or today. NEVER CREATE INPUT IF NOT WRITTEN BY THE USER. IN THE INPUT PASS THE INFORMATION IN JSON FORMAT. IN THE INPUR PASS THE SPECIFIED TET TYPE, ask if missing test_type:(One time test/Periodic test/Driving Mode)"""
    ),
    Tool(
        name="voice_call_test",
        func=lambda prompt: voice_call_test(prompt),
        description="""Use when the user wants to do a voice_call_test, 
                        start the tool IF AND ONLY IF  you have ALL the information needed.
                        There are three options for this test, 
                        1: One time test. Information Needed : (Start_Date : str[dd/mm/yy]. Phone_number: int)
                        2: Periodic test. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy]. Phone_number: int)
                        3: Driving Mode. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy]. Phone_number: int)
                        So first of all you have to understand which tetst does the user wants to do.ask DIRECTLLY the user which test options they want to perform, don't try to guess it. Then you have to find the informaton needed for that test.Users alway forget something, if you are missing some info, just pass none.In the field date,IF AND ONLY IF users says now or today, just pass now or today. NEVER CREATE INPUT IF NOT WRITTEN BY THE USER. IN THE INPUT PASS THE INFORMATION IN JSON FORMAT. IN THE INPUR PASS THE SPECIFIED TET TYPE, ask if missing test_type:(One time test/Periodic test/Driving Mode)"""
    ),
    Tool(
        name="sms_send_test",
        func=lambda prompt: sms_send_test(prompt),
        description="""Use when the user wants to do a sms_send_test, 
                        start the tool IF AND ONLY IF  you have ALL the information needed.
                        There are three options for this test, 
                        1: One time test. Information Needed : (Start_Date : str[dd/mm/yy], phone_number: int, sms_message: str, recover_email: str[optional)
                        2: Periodic test. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy], Host_list: list, phone_number: int, sms_message: str, recover_email: str[optional]
                        3: Driving Mode. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy], Host_list: list, phone_number: int, sms_message: str, recover_email: str[optional]
                        So first of all you have to understand which tetst does the user wants to do. ask DIRECTLLY the user which test options they want to perform, don't try to guess it. Then you have to find the informaton needed for that test.Users alway forget something, if you are missing some info, just pass none.In the field date,IF AND ONLY IF users says now or today, just pass now or today. NEVER CREATE INPUT IF NOT WRITTEN BY THE USER. IN THE INPUT PASS THE INFORMATION IN JSON FORMAT. IN THE INPUR PASS THE SPECIFIED TET TYPE, ask if missing test_type:(One time test/Periodic test/Driving Mode)"""
    ),
        Tool(
        name="service_mode_tests",
        func=lambda prompt: service_mode_tests(prompt),
        description="""Use when the user wants to do a service_mode_tests, 
                        start the tool IF AND ONLY IF  you have ALL the information needed.
                        There are three options for this test, 
                        1: One time test. Information Needed : (Start_Date : str[dd/mm/yy].)
                        2: Periodic test. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy].)
                        3: Driving Mode. Information Needed : (Number_of_tests : int, Start_Date : str[dd/mm/yy].)
                        So first of all you have to understand which tetst does the user wants to do.ask DIRECTLLY the user which test options they want to perform, don't try to guess it. Then you have to find the informaton needed for that test.Users alway forget something, if you are missing some info, just pass none.In the field date,IF AND ONLY IF users says now or today, just pass now or today. NEVER CREATE INPUT IF NOT WRITTEN BY THE USER. IN THE INPUT PASS THE INFORMATION IN JSON FORMAT. IN THE INPUR PASS THE SPECIFIED TET TYPE, ask if missing test_type:(One time test/Periodic test/Driving Mode)"""
    ),
        Tool(
            name="new_chat",
            func=lambda prompt: new_chat(),
            description="use this tool always when the agent made to finish a succesfull action, when the chain is finished, this tool is used to clear the chat and to create a new one. Use whrn the agent decides to use the new_chat tool"
        )
]

# Set Streamlit page configuration
st.set_page_config(page_title="🧠MemoryBot🤖", layout="centered")

hide_st_style = """
            <style>
            #MainMenu {visibility: hidden;}
            footer {visibility: hidden;}
            header {visibility: hidden;}
            </style>
            """
st.markdown(hide_st_style, unsafe_allow_html=True)

# Initialize session states
if "generated" not in st.session_state:
    st.session_state["generated"] = []
if "past" not in st.session_state:
    st.session_state["past"] = []
if "input" not in st.session_state:
    st.session_state["input"] = ""
if "stored_session" not in st.session_state:
    st.session_state["stored_session"] = []

# Define tool to get user input


def get_text():
    """
    Get the user input text.

    Returns:
        (str): The text entered by the user
    """
    input_text = st.text_input(
        "You: ",
        st.session_state.get("user_input", ""),  # Retrieve user input from new key
        key="input",
        placeholder="Enter a command or query here...",
        label_visibility="hidden",
    )
    return input_text


def new_chat():
    """
    Clears session state and starts a new chat.
    """
    save = []
    for i in range(len(st.session_state["generated"]) - 1, -1, -1):
        save.append("User:" + st.session_state["past"][i])
        save.append("Bot:" + st.session_state["generated"][i])
    st.session_state["stored_session"].append(save)
    st.session_state["generated"] = []
    st.session_state["past"] = []
    st.session_state["user_input"] = ""  # Clear user input
    st.session_state["bot_response"] = ""  # Clear bot response



st.sidebar.image("./assets/logo.png")

st.title("🧠 Memory Bot 🤖")
st.markdown(
    """ 
        > :black[**A Chatbot that remembers**     Made By - Bridge2e]
        """
)

# Ask the user to enter their OpenAI API key

# Session state storage would be ideal
if API_O:
    MODEL= "gpt-4-1106-preview"

    # Load the tools
    # Initialize the memory object
    memory = CustomMemory()
    # Initialize the agent with the memory object
    agent = initialize_agent(
        tools,
        ChatOpenAI(temperature=0, model_name=MODEL, openai_api_key=API_O),
        agent=AgentType.CONVERSATIONAL_REACT_DESCRIPTION,
        memory=memory,
        verbose=True,
    )

# Add a button to start a new chat
st.sidebar.button("New Chat", on_click=new_chat, type="primary")

# Get the user input
user_input = get_text()

# Generate the output using the agent and the user input, and add the input/output to the session
if user_input:
    with st.spinner("Processing..."):
        output = agent.run(
            input=user_input, chat_history=st.session_state.past)
    st.session_state.past.append(user_input)
    st.session_state.generated.append(output)

download_str = []
# Display the conversation history using an expander, and allow the user to download it
with st.expander("Conversation", expanded=True):
    for i in range(len(st.session_state["generated"]) - 1, -1, -1):
        st.info(st.session_state["past"][i], icon="🧐")
        st.success(st.session_state["generated"][i], icon="🤖")
        download_str.append(st.session_state["past"][i])
        download_str.append(st.session_state["generated"][i])

    # Can throw error - requires fix
    # download_str = "\n".join(download_str)
    # if download_str:
    #    st.download_button("Download", download_str)

# Display stored conversation sessions in the sidebar
for i, sublist in enumerate(st.session_state.stored_session):
    with st.sidebar.expander(label=f"Conversation-Session:{i}"):
        st.write(sublist)

# Allow the user to clear all stored conversation sessions
if st.session_state.stored_session:
    if st.sidebar.checkbox("Clear-all"):
        del st.session_state.stored_session

with st.sidebar:
    st.markdown("---")