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 = """ """ 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("---")