From d1c0ad9c8f9238b361d24c1635f18afaa961715f Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Thu, 16 May 2024 22:35:42 -0500 Subject: [PATCH 01/41] =?UTF-8?q?=F0=9F=A7=B9v0.1.5=20-=20fix=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 10 ++++++++-- rag_assistant/__init__.py | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 6a81dcd..4d37c7f 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -349,7 +349,11 @@ def setup_gradio_interface(self): tab_names=["chat", "retrieval", "documents"]) - def launch(self, share: bool = False, server_name: Optional[str] = None, favicon_path: Optional[str] = None): + def launch(self, + share: bool = False, + server_name: Optional[str] = None, + favicon_path: Optional[str] = None): + kwargs = {} kwargs.update({'share': share}) if server_name: @@ -401,8 +405,10 @@ def main(): if args.favicon_path: launch_kwargs.update({'favicon_path': args.favicon_path}) else: - launch_kwargs.update({'favicon_path': "./favicon-32x32.png"}) + launch_kwargs.update({'favicon_path': "favicon-32x32.png"}) + + assistant.initialize_agent() assistant.launch(**launch_kwargs) if __name__ == "__main__": diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index edf0a73..04ef018 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.3" +__version__ = "0.1.5" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant @@ -7,7 +7,7 @@ ## Installation ```bash -pip install rag_assistant==0.1.3 --user +pip install rag_assistant==0.1.5 --user ``` ## Execution From f1f282a01511bcf567ea97d80ee57a203e416dc4 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Thu, 16 May 2024 22:38:32 -0500 Subject: [PATCH 02/41] =?UTF-8?q?=F0=9F=A4=A6=20Fix=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index 9921323..04ef018 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -15,4 +15,3 @@ ! rag_assistant --api_key "YOUR API KEY" --db_path "E:\\swarmauri_github/prompt_responses.db" --system_context "You are a helpful assistant." ``` """ -s \ No newline at end of file From 7c9e14b1781c27d2f9e92648091e5f0ae6e3a2cc Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Thu, 16 May 2024 22:49:02 -0500 Subject: [PATCH 03/41] =?UTF-8?q?=E2=98=9D=EF=B8=8Fv0.1.6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 2 +- rag_assistant/__init__.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index cb71a99..4d37c7f 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -64,6 +64,7 @@ def __init__(self, self.document_table = [] self.long_term_memory_df = None self.last_recall_df = None + self.agent = self.initialize_agent() self.set_model(model_name) self.css = """ #chat-dialogue-container { @@ -78,7 +79,6 @@ def __init__(self, display: none !important; } """ - self.agent = self.initialize_agent() self.setup_gradio_interface() def initialize_agent(self): diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index 04ef018..4143ffc 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.5" +__version__ = "0.1.6" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant @@ -7,7 +7,7 @@ ## Installation ```bash -pip install rag_assistant==0.1.5 --user +pip install rag_assistant==0.1.6 --user ``` ## Execution From f5ee1b75f05cf09959f020c7c6ce11a085e4cea9 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Thu, 16 May 2024 23:15:50 -0500 Subject: [PATCH 04/41] =?UTF-8?q?=F0=9F=9A=AFrm=20v0.1.7=20-=20remove=20fa?= =?UTF-8?q?vicon=5Fpath=20arg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 20 +++++++++++--------- rag_assistant/__init__.py | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 4d37c7f..54f32d1 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -79,6 +79,7 @@ def __init__(self, display: none !important; } """ + self.favicon_path = "./favicon-32x32.png" self.setup_gradio_interface() def initialize_agent(self): @@ -351,15 +352,16 @@ def setup_gradio_interface(self): def launch(self, share: bool = False, - server_name: Optional[str] = None, - favicon_path: Optional[str] = None): + server_name: Optional[str] = None + #favicon_path: Optional[str] = None + ): kwargs = {} kwargs.update({'share': share}) if server_name: kwargs.update({'server_name': server_name}) - if favicon_path: - kwargs.update({'favicon_path': favicon_path}) + + kwargs.update({'favicon_path': self.favicon_path}) self.app.launch(**kwargs) @@ -373,7 +375,7 @@ def main(): parser.add_argument('-db_path', '--db_path', type=str, help='path to sqlite3 db', required=False) parser.add_argument('-share', '--share', type=bool, help='Deploy a live app on gradio', required=False) parser.add_argument('-server_name', '--server_name', type=str, help='Server name', required=False) - parser.add_argument('-favicon_path', '--favicon_path', type=str, help='Path of applicaton favicon', required=False) + #parser.add_argument('-favicon_path', '--favicon_path', type=str, help='Path of application favicon', required=False) args = parser.parse_args() @@ -402,10 +404,10 @@ def main(): launch_kwargs.update({'share': args.share}) if args.server_name: launch_kwargs.update({'server_name': args.server_name}) - if args.favicon_path: - launch_kwargs.update({'favicon_path': args.favicon_path}) - else: - launch_kwargs.update({'favicon_path': "favicon-32x32.png"}) + #if args.favicon_path: + #launch_kwargs.update({'favicon_path': args.favicon_path}) + #else: + #launch_kwargs.update({'favicon_path': "favicon-32x32.png"}) assistant.initialize_agent() diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index 4143ffc..b8fd9a3 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.6" +__version__ = "0.1.7" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant @@ -7,7 +7,7 @@ ## Installation ```bash -pip install rag_assistant==0.1.6 --user +pip install rag_assistant==0.1.7 --user ``` ## Execution From 7666e0a97a2abe86df7baca58c5e38f623e53024 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Thu, 16 May 2024 23:20:15 -0500 Subject: [PATCH 05/41] =?UTF-8?q?=E2=98=9D=EF=B8=8Fv0.1.8=20-=20move=20gra?= =?UTF-8?q?dio=5Finterface=20setup=20to=20assistant.launch()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 6 +++--- rag_assistant/__init__.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 54f32d1..2ac6a0e 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -80,7 +80,7 @@ def __init__(self, } """ self.favicon_path = "./favicon-32x32.png" - self.setup_gradio_interface() + def initialize_agent(self): VS = Doc2VecVectorStore() @@ -304,7 +304,7 @@ def setup_gradio_interface(self): value="openai_gpt-3.5-turbo", label="Model", info="Select openai model"), - gr.Textbox(label="System Context", value=self.system_context or "You are a helpful assistant"), + gr.Textbox(label="System Context", value = self.system_context), gr.Checkbox(label="Fixed Retrieval", value=True, interactive=True), gr.Slider(label="Top K", value=10, minimum=0, maximum=100, step=5, interactive=True), gr.Slider(label="Temperature", value=1, minimum=0.0, maximum=1, step=0.01, interactive=True), @@ -362,7 +362,7 @@ def launch(self, kwargs.update({'server_name': server_name}) kwargs.update({'favicon_path': self.favicon_path}) - + self.setup_gradio_interface() self.app.launch(**kwargs) diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index b8fd9a3..b628499 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.7" +__version__ = "0.1.8" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant @@ -7,7 +7,7 @@ ## Installation ```bash -pip install rag_assistant==0.1.7 --user +pip install rag_assistant==0.1.8 --user ``` ## Execution From 23a159bf1e3e0b9bca8192d2fec5b31c56ed9270 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 17 May 2024 15:52:28 -0500 Subject: [PATCH 06/41] =?UTF-8?q?=E2=98=9D=EF=B8=8F=20add=20support=20for?= =?UTF-8?q?=20gpt-3.5-turbo-16k-0613?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 1 + rag_assistant/__init__.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 2ac6a0e..7eeda9a 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -49,6 +49,7 @@ def __init__(self, 'mistral_mistral-large-latest', 'openai_gpt-3.5-turbo', 'openai_gpt-3.5-turbo-16k', + 'openai_gpt-3.5-turbo-16k-0613', 'openai_gpt-4-0125-preview', 'openai_gpt-4o', 'google_gemini-1.5-pro-latest', diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index b628499..a3f15d0 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.8" +__version__ = "0.1.9" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant @@ -7,7 +7,7 @@ ## Installation ```bash -pip install rag_assistant==0.1.8 --user +pip install rag_assistant==0.1.9 --user ``` ## Execution From 2704316c6f88aeb08cb970da244fad79446fccc2 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Mon, 20 May 2024 21:05:27 -0500 Subject: [PATCH 07/41] =?UTF-8?q?=F0=9F=A6=8B=20-=20v0.2.2.3=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/__init__.py | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index a3f15d0..c59783f 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.9" +__version__ = "0.1.10" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant @@ -7,7 +7,7 @@ ## Installation ```bash -pip install rag_assistant==0.1.9 --user +pip install rag_assistant==0.1.10 --user ``` ## Execution diff --git a/setup.py b/setup.py index 3571a82..fec349a 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ }, include_package_data=True, install_requires=['gradio', - 'swarmauri[full]==0.1.127'], + 'swarmauri[full]==0.2.3'], classifiers=[ 'License :: OSI Approved :: MIT License', 'Programming Language :: Python :: 3.10' From 8ee6593a564aa87ea58edfb22c46192f7dcc6cb7 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Tue, 21 May 2024 02:47:17 -0500 Subject: [PATCH 08/41] test --- rag_assistant/__init__.py | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index c59783f..e783cd9 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.10" +__version__ = "0.1.12" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant @@ -7,7 +7,7 @@ ## Installation ```bash -pip install rag_assistant==0.1.10 --user +pip install rag_assistant==0.1.12 --user ``` ## Execution diff --git a/setup.py b/setup.py index fec349a..c56f4d6 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ }, include_package_data=True, install_requires=['gradio', - 'swarmauri[full]==0.2.3'], + 'swarmauri[full]==0.2.5'], classifiers=[ 'License :: OSI Approved :: MIT License', 'Programming Language :: Python :: 3.10' From d9f0554e93da650f9d1179c3800671136ca94da7 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 19:24:29 -0500 Subject: [PATCH 09/41] =?UTF-8?q?=E2=98=9D=EF=B8=8Fv0.1.13.dev1=20-=20add?= =?UTF-8?q?=20toast=20fns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 13 ++++++++++++- rag_assistant/__init__.py | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 7eeda9a..f5aaaf5 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -26,6 +26,15 @@ AgentMessage) from swarmauri.standard.utils.load_documents_from_json import load_documents_from_json_file +def info_fn(msg): + gr.Info(msg) + +def error_fn(msg): + raise gr.Error(msg) + +def warning_fn(msg): + gr.Warning(msg) + class RagAssistant: def __init__(self, api_key: str = "", @@ -133,6 +142,7 @@ def load_and_filter_json(self, file_info): self.long_term_memory_df = self.preprocess_documents(documents) return self.long_term_memory_df except json.JSONDecodeError: + error_fn("Invalid JSON file. Please check the file and try again.") return "Invalid JSON file. Please check the file and try again." def preprocess_documents(self, documents): @@ -148,6 +158,7 @@ def preprocess_documents(self, documents): df = pd.DataFrame.from_dict(docs) return df except Exception as e: + error_fn("preprocess_documents failed: {e}") print(f"preprocess_documents: {e}") @@ -272,7 +283,7 @@ async def chatbot_function(self, return "", self.last_recall_df, history except Exception as e: - gr.Error(f"{e}") + error_fn(f"chatbot_function error: {e}") self.agent.conversation._history.pop(0) print(f"chatbot_function error: {e}") return "", [], history diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index e783cd9..dff4b45 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.12" +__version__ = "0.1.13.dev1" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From 69d2d19582de05cc631e403b81166af0a625358f Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 19:28:55 -0500 Subject: [PATCH 10/41] =?UTF-8?q?=E2=98=9D=EF=B8=8Fv0.1.13.dev2=20-=20add?= =?UTF-8?q?=20head=20back?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index f5aaaf5..79b5e0a 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -25,6 +25,7 @@ SystemMessage, AgentMessage) from swarmauri.standard.utils.load_documents_from_json import load_documents_from_json_file +head="""""" def info_fn(msg): gr.Info(msg) @@ -357,7 +358,7 @@ def setup_gradio_interface(self): self.load_button.click(self.load_and_filter_json, inputs=[self.file], outputs=self.data_frame) self.save_button.click(self.save_df, inputs=[self.data_frame]) - with gr.Blocks(css = self.css, title="Swarmauri Rag Agent") as self.app: + with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: gr.TabbedInterface(interface_list=[self.chat, self.retrieval_table, self.document_table], tab_names=["chat", "retrieval", "documents"]) From 5b7e79c05e4586f0b89754c9eebdbd9d9e76a505 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 19:47:18 -0500 Subject: [PATCH 11/41] =?UTF-8?q?=F0=9F=8C=8Bv0.1.13.dev3=20-=20add=20supp?= =?UTF-8?q?ort=20for=20hiding=20inputs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 39 +++++++++++++++++++++++++++++------ rag_assistant/__init__.py | 2 +- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 79b5e0a..70d32ca 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -91,6 +91,9 @@ def __init__(self, } """ self.favicon_path = "./favicon-32x32.png" + self._show_api_key = False + self._show_provider_model = False + self._show_system_context = False def initialize_agent(self): @@ -312,12 +315,13 @@ def setup_gradio_interface(self): with gr.Accordion("See Details", open=False): self.additional_inputs = [ - gr.Textbox(label="API Key", value=self.api_key or "Enter your API Key"), + gr.Textbox(label="API Key", value=self.api_key or "Enter your API Key", visible=self._show_api_key), gr.Dropdown(self.allowed_models, value="openai_gpt-3.5-turbo", label="Model", - info="Select openai model"), - gr.Textbox(label="System Context", value = self.system_context), + info="Select openai model", + visible=self._show_provider_model), + gr.Textbox(label="System Context", value = self.system_context, visible=self._show_system_context), gr.Checkbox(label="Fixed Retrieval", value=True, interactive=True), gr.Slider(label="Top K", value=10, minimum=0, maximum=100, step=5, interactive=True), gr.Slider(label="Temperature", value=1, minimum=0.0, maximum=1, step=0.01, interactive=True), @@ -365,8 +369,10 @@ def setup_gradio_interface(self): def launch(self, share: bool = False, - server_name: Optional[str] = None - #favicon_path: Optional[str] = None + server_name: Optional[str] = None, + show_api_key: False, + show_provider_model: False, + show_system_context: False ): kwargs = {} @@ -374,6 +380,10 @@ def launch(self, if server_name: kwargs.update({'server_name': server_name}) + self._show_api_key = show_api_key + self._show_provider_model = show_provider_model + self._show_system_context = show_system_context + kwargs.update({'favicon_path': self.favicon_path}) self.setup_gradio_interface() self.app.launch(**kwargs) @@ -383,10 +393,19 @@ def main(): import argparse parser = argparse.ArgumentParser(description="Swarmauri Developer Assistant Command Line Tool") parser.add_argument('-api_key', '--api_key', type=str, help='Your api key', required=True) + parser.add_argument('-show_api_key', '--show_api_key', + type=bool, help='Toggle displaying api key on app', default=False, required=False) + parser.add_argument('-provider_model', '--provider_model', type=str, help='Your provider model', required=False) + parser.add_argument('-show_provider_model', '--show_provider_model', + type=bool, help='Toggle displaying Provider Model on app', default=False, required=False) + parser.add_argument('-system_context', '--system_context', type=str, help='Assistants System Context', required=False) + parser.add_argument('-show_system_context', '--show_system_context', + type=bool, help='Toggle displaying System Context on app', default=False, required=False) + parser.add_argument('-db_path', '--db_path', type=str, help='path to sqlite3 db', required=False) - parser.add_argument('-share', '--share', type=bool, help='Deploy a live app on gradio', required=False) + parser.add_argument('-share', '--share', type=bool, help='Deploy a live app on gradio', default=False, required=False) parser.add_argument('-server_name', '--server_name', type=str, help='Server name', required=False) #parser.add_argument('-favicon_path', '--favicon_path', type=str, help='Path of application favicon', required=False) args = parser.parse_args() @@ -417,6 +436,14 @@ def main(): launch_kwargs.update({'share': args.share}) if args.server_name: launch_kwargs.update({'server_name': args.server_name}) + + if args.show_api_key: + launch_kwargs.update({'show_api_key': args.show_api_key}) + if args.show_provider_model: + launch_kwargs.update({'show_provider_model': args.show_provider_model}) + if args.show_system_context: + launch_kwargs.update({'show_system_context': args.show_system_context}) + #if args.favicon_path: #launch_kwargs.update({'favicon_path': args.favicon_path}) #else: diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index dff4b45..d71c436 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev1" +__version__ = "0.1.13.dev3" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From 9c10e08749ed9e77a421b9aa8e1840dc01077c10 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 19:56:10 -0500 Subject: [PATCH 12/41] =?UTF-8?q?=F0=9F=A4=A6=20v0.1.13.dev4=20-=20E999=20?= =?UTF-8?q?SyntaxError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 70d32ca..d7991fa 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -369,10 +369,10 @@ def setup_gradio_interface(self): def launch(self, share: bool = False, - server_name: Optional[str] = None, - show_api_key: False, - show_provider_model: False, - show_system_context: False + show_api_key: bool = False, + show_provider_model: bool = False, + show_system_context: bool = False, + server_name: Optional[str] = None ): kwargs = {} From 0f7363b47764a34ffc1c8fb0164a18a14cf9f2fe Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 20:18:31 -0500 Subject: [PATCH 13/41] =?UTF-8?q?=F0=9F=8C=8Bv0.1.13.dev5=20-=20add=20prod?= =?UTF-8?q?uction=20fields=20for=20documents-related=20ops?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 29 +++++++++++++++++++++++++---- rag_assistant/__init__.py | 2 +- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index d7991fa..8083539 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -94,7 +94,7 @@ def __init__(self, self._show_api_key = False self._show_provider_model = False self._show_system_context = False - + self._show_documents_tab = False def initialize_agent(self): VS = Doc2VecVectorStore() @@ -363,16 +363,21 @@ def setup_gradio_interface(self): self.save_button.click(self.save_df, inputs=[self.data_frame]) with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: - gr.TabbedInterface(interface_list=[self.chat, self.retrieval_table, self.document_table], + if self._show_documents_tab: + gr.TabbedInterface(interface_list=[self.chat, self.retrieval_table, self.document_table], tab_names=["chat", "retrieval", "documents"]) - + else: + gr.TabbedInterface(interface_list=[self.chat], tab_names=["chat"]) def launch(self, share: bool = False, + show_api_key: bool = False, show_provider_model: bool = False, show_system_context: bool = False, - server_name: Optional[str] = None + show_documents_tab: bool = False, + server_name: Optional[str] = None, + documents_file_path: Optional[str] = None, ): kwargs = {} @@ -383,9 +388,15 @@ def launch(self, self._show_api_key = show_api_key self._show_provider_model = show_provider_model self._show_system_context = show_system_context + self._show_documents_tab = show_documents_tab kwargs.update({'favicon_path': self.favicon_path}) self.setup_gradio_interface() + + if documents_file_path: + self.data_frame = self.load_and_filter_json(documents_file_path) + + self.app.launch(**kwargs) @@ -404,6 +415,10 @@ def main(): parser.add_argument('-show_system_context', '--show_system_context', type=bool, help='Toggle displaying System Context on app', default=False, required=False) + parser.add_argument('-documents_file_path', '--documents_file_path', type=str, help='Filepath of Documents JSON', required=False) + parser.add_argument('-show_documents_tab', '--show_documents_tab', + type=bool, help='Toggle displaying Document Tabs on app', default=False, required=False) + parser.add_argument('-db_path', '--db_path', type=str, help='path to sqlite3 db', required=False) parser.add_argument('-share', '--share', type=bool, help='Deploy a live app on gradio', default=False, required=False) parser.add_argument('-server_name', '--server_name', type=str, help='Server name', required=False) @@ -444,6 +459,12 @@ def main(): if args.show_system_context: launch_kwargs.update({'show_system_context': args.show_system_context}) + if args.documents_file_path: + launch_kwargs.update({'documents_file_path': args.documents_file_path}) + if args.show_documents_tab: + launch_kwargs.update({'show_documents_tab': args.show_documents_tab}) + + #if args.favicon_path: #launch_kwargs.update({'favicon_path': args.favicon_path}) #else: diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index d71c436..d8f41a2 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev3" +__version__ = "0.1.13.dev5" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From ea2ca959fef98a7a1cd23b35e36fc891311cd806 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 20:34:41 -0500 Subject: [PATCH 14/41] =?UTF-8?q?=F0=9F=8C=8Bv0.1.13.dev6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 14 ++++++++------ rag_assistant/__init__.py | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 8083539..369d686 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -135,12 +135,14 @@ def change_vectorizer(self, vectorizer: str): self.agent.vector_store = MLMVectorStore() else: self.agent.vector_store = TFIDFVectorStore() - - - def load_and_filter_json(self, file_info): + + def load_json_from_file_info(self, file_info): + return self._load_and_filter_json(file_info.name) + + def _load_and_filter_json(self, file_path): # Load JSON file using json library try: - documents = load_documents_from_json_file(file_info.name) + documents = load_documents_from_json_file(file_path) self.agent.vector_store.documents = [] self.agent.vector_store.add_documents(documents) self.long_term_memory_df = self.preprocess_documents(documents) @@ -359,7 +361,7 @@ def setup_gradio_interface(self): self.save_button = gr.Button("save") self.vectorizer.change(self.change_vectorizer, inputs=[self.vectorizer], outputs=self.data_frame) - self.load_button.click(self.load_and_filter_json, inputs=[self.file], outputs=self.data_frame) + self.load_button.click(self.load_json_from_file_info, inputs=[self.file], outputs=self.data_frame) self.save_button.click(self.save_df, inputs=[self.data_frame]) with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: @@ -394,7 +396,7 @@ def launch(self, self.setup_gradio_interface() if documents_file_path: - self.data_frame = self.load_and_filter_json(documents_file_path) + self.data_frame = self._load_and_filter_json(documents_file_path) self.app.launch(**kwargs) diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index d8f41a2..dbeb1e9 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev5" +__version__ = "0.1.13.dev6" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From 3e29bbe954502845c4816da150f735ecaa9b48c7 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 20:48:08 -0500 Subject: [PATCH 15/41] =?UTF-8?q?=F0=9F=90=9B=F0=9F=94=91KeyError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 10 +++++----- rag_assistant/__init__.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 369d686..ba324f0 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -148,7 +148,7 @@ def _load_and_filter_json(self, file_path): self.long_term_memory_df = self.preprocess_documents(documents) return self.long_term_memory_df except json.JSONDecodeError: - error_fn("Invalid JSON file. Please check the file and try again.") + #error_fn("Invalid JSON file. Please check the file and try again.") return "Invalid JSON file. Please check the file and try again." def preprocess_documents(self, documents): @@ -164,7 +164,7 @@ def preprocess_documents(self, documents): df = pd.DataFrame.from_dict(docs) return df except Exception as e: - error_fn("preprocess_documents failed: {e}") + #error_fn("preprocess_documents failed: {e}") print(f"preprocess_documents: {e}") @@ -289,7 +289,7 @@ async def chatbot_function(self, return "", self.last_recall_df, history except Exception as e: - error_fn(f"chatbot_function error: {e}") + #error_fn(f"chatbot_function error: {e}") self.agent.conversation._history.pop(0) print(f"chatbot_function error: {e}") return "", [], history @@ -395,8 +395,8 @@ def launch(self, kwargs.update({'favicon_path': self.favicon_path}) self.setup_gradio_interface() - if documents_file_path: - self.data_frame = self._load_and_filter_json(documents_file_path) + #if documents_file_path: + #self.data_frame = self._load_and_filter_json(documents_file_path) self.app.launch(**kwargs) diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index dbeb1e9..3c2d9e2 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev6" +__version__ = "0.1.13.dev7" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From f21f5478da8850cb9af66e52623894f470f357b8 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 21:13:38 -0500 Subject: [PATCH 16/41] =?UTF-8?q?=F0=9F=90=9B=20v0.1.13.dev8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 43 ++++++++++++++++++----------------- rag_assistant/__init__.py | 2 +- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index ba324f0..eec981c 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -41,7 +41,8 @@ def __init__(self, api_key: str = "", system_context: str = "You are a helpful assistant.", model_name = "openai_gpt-4o", - db_path='prompt_responses.db'): + db_path='prompt_responses.db', + document_file_path = Optional[str] = None): print('Initializing... this will take a moment.') self.system_context = system_context self.api_key = api_key @@ -95,7 +96,9 @@ def __init__(self, self._show_provider_model = False self._show_system_context = False self._show_documents_tab = False - + self._init_file_path = document_file_path + + def initialize_agent(self): VS = Doc2VecVectorStore() agent = RagAgent(name="Rag", @@ -135,20 +138,18 @@ def change_vectorizer(self, vectorizer: str): self.agent.vector_store = MLMVectorStore() else: self.agent.vector_store = TFIDFVectorStore() - - def load_json_from_file_info(self, file_info): - return self._load_and_filter_json(file_info.name) - - def _load_and_filter_json(self, file_path): + + + def load_and_filter_json(self, file_info): # Load JSON file using json library try: - documents = load_documents_from_json_file(file_path) + documents = load_documents_from_json_file(file_info.name) self.agent.vector_store.documents = [] self.agent.vector_store.add_documents(documents) self.long_term_memory_df = self.preprocess_documents(documents) return self.long_term_memory_df except json.JSONDecodeError: - #error_fn("Invalid JSON file. Please check the file and try again.") + error_fn("Invalid JSON file. Please check the file and try again.") return "Invalid JSON file. Please check the file and try again." def preprocess_documents(self, documents): @@ -164,7 +165,7 @@ def preprocess_documents(self, documents): df = pd.DataFrame.from_dict(docs) return df except Exception as e: - #error_fn("preprocess_documents failed: {e}") + error_fn("preprocess_documents failed: {e}") print(f"preprocess_documents: {e}") @@ -289,7 +290,7 @@ async def chatbot_function(self, return "", self.last_recall_df, history except Exception as e: - #error_fn(f"chatbot_function error: {e}") + error_fn(f"chatbot_function error: {e}") self.agent.conversation._history.pop(0) print(f"chatbot_function error: {e}") return "", [], history @@ -352,7 +353,7 @@ def setup_gradio_interface(self): with gr.Blocks(css = self.css) as self.document_table: with gr.Row(): - self.file = gr.File(label="Upload JSON File") + self.file = gr.File(label="Upload JSON File", value=self._init_file_path) self.vectorizer = gr.Dropdown(choices=["Doc2Vec", "TFIDF", "MLM"], value="Doc2Vec", label="Select vectorizer") self.load_button = gr.Button("load") with gr.Row(): @@ -361,7 +362,7 @@ def setup_gradio_interface(self): self.save_button = gr.Button("save") self.vectorizer.change(self.change_vectorizer, inputs=[self.vectorizer], outputs=self.data_frame) - self.load_button.click(self.load_json_from_file_info, inputs=[self.file], outputs=self.data_frame) + self.load_button.click(self.load_and_filter_json, inputs=[self.file], outputs=self.data_frame) self.save_button.click(self.save_df, inputs=[self.data_frame]) with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: @@ -382,22 +383,22 @@ def launch(self, documents_file_path: Optional[str] = None, ): - kwargs = {} - kwargs.update({'share': share}) - if server_name: - kwargs.update({'server_name': server_name}) + # Create interfaces self._show_api_key = show_api_key self._show_provider_model = show_provider_model self._show_system_context = show_system_context self._show_documents_tab = show_documents_tab - - kwargs.update({'favicon_path': self.favicon_path}) + self._init_file_path = documents_file_path self.setup_gradio_interface() - #if documents_file_path: - #self.data_frame = self._load_and_filter_json(documents_file_path) + # Deploy interfaces + kwargs = {} + kwargs.update({'share': share}) + if server_name: + kwargs.update({'server_name': server_name}) + kwargs.update({'favicon_path': self.favicon_path}) self.app.launch(**kwargs) diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index 3c2d9e2..f34bd50 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev7" +__version__ = "0.1.13.dev8" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From 7943093669d102b669bb3f11072a7d5db15f3ee4 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 21:15:00 -0500 Subject: [PATCH 17/41] Update RagAssistant.py --- rag_assistant/RagAssistant.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index eec981c..1712b61 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -41,8 +41,7 @@ def __init__(self, api_key: str = "", system_context: str = "You are a helpful assistant.", model_name = "openai_gpt-4o", - db_path='prompt_responses.db', - document_file_path = Optional[str] = None): + db_path='prompt_responses.db'): print('Initializing... this will take a moment.') self.system_context = system_context self.api_key = api_key From 2f47865563f8d7a7806c3ba6949985f18cf1b815 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 21:16:21 -0500 Subject: [PATCH 18/41] F821 --- rag_assistant/RagAssistant.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 1712b61..7f496e4 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -95,7 +95,7 @@ def __init__(self, self._show_provider_model = False self._show_system_context = False self._show_documents_tab = False - self._init_file_path = document_file_path + self._init_file_path = None def initialize_agent(self): From 0394d406257630d622439b6c090bbc75e230b327 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 21:32:19 -0500 Subject: [PATCH 19/41] Update RagAssistant.py --- rag_assistant/RagAssistant.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 7f496e4..1096e4e 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -148,7 +148,7 @@ def load_and_filter_json(self, file_info): self.long_term_memory_df = self.preprocess_documents(documents) return self.long_term_memory_df except json.JSONDecodeError: - error_fn("Invalid JSON file. Please check the file and try again.") + #error_fn("Invalid JSON file. Please check the file and try again.") return "Invalid JSON file. Please check the file and try again." def preprocess_documents(self, documents): @@ -164,7 +164,7 @@ def preprocess_documents(self, documents): df = pd.DataFrame.from_dict(docs) return df except Exception as e: - error_fn("preprocess_documents failed: {e}") + #error_fn("preprocess_documents failed: {e}") print(f"preprocess_documents: {e}") @@ -289,7 +289,7 @@ async def chatbot_function(self, return "", self.last_recall_df, history except Exception as e: - error_fn(f"chatbot_function error: {e}") + #error_fn(f"chatbot_function error: {e}") self.agent.conversation._history.pop(0) print(f"chatbot_function error: {e}") return "", [], history @@ -362,6 +362,7 @@ def setup_gradio_interface(self): self.vectorizer.change(self.change_vectorizer, inputs=[self.vectorizer], outputs=self.data_frame) self.load_button.click(self.load_and_filter_json, inputs=[self.file], outputs=self.data_frame) + self.file.select(self.load_and_filter_json, inputs=[self.file], outputs=self.data_frame) self.save_button.click(self.save_df, inputs=[self.data_frame]) with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: @@ -397,7 +398,7 @@ def launch(self, kwargs.update({'share': share}) if server_name: kwargs.update({'server_name': server_name}) - kwargs.update({'favicon_path': self.favicon_path}) + #kwargs.update({'favicon_path': self.favicon_path}) self.app.launch(**kwargs) @@ -463,6 +464,7 @@ def main(): if args.documents_file_path: launch_kwargs.update({'documents_file_path': args.documents_file_path}) + if args.show_documents_tab: launch_kwargs.update({'show_documents_tab': args.show_documents_tab}) From 4a2872d39288e8c70dc937e07b415f5a60319a99 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 21:34:42 -0500 Subject: [PATCH 20/41] v0.1.13.dev9 --- rag_assistant/RagAssistant.py | 2 ++ rag_assistant/__init__.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 1096e4e..43a62ea 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -423,9 +423,11 @@ def main(): type=bool, help='Toggle displaying Document Tabs on app', default=False, required=False) parser.add_argument('-db_path', '--db_path', type=str, help='path to sqlite3 db', required=False) + parser.add_argument('-share', '--share', type=bool, help='Deploy a live app on gradio', default=False, required=False) parser.add_argument('-server_name', '--server_name', type=str, help='Server name', required=False) #parser.add_argument('-favicon_path', '--favicon_path', type=str, help='Path of application favicon', required=False) + args = parser.parse_args() diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index f34bd50..7a637bc 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev8" +__version__ = "0.1.13.dev9" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From 7bc4cae5c591525a8dad6439fae3e76d1688b407 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 21:41:06 -0500 Subject: [PATCH 21/41] v0.1.13.dev10 --- rag_assistant/RagAssistant.py | 13 +++++++------ rag_assistant/__init__.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 43a62ea..e28fa61 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -366,11 +366,12 @@ def setup_gradio_interface(self): self.save_button.click(self.save_df, inputs=[self.data_frame]) with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: - if self._show_documents_tab: - gr.TabbedInterface(interface_list=[self.chat, self.retrieval_table, self.document_table], - tab_names=["chat", "retrieval", "documents"]) - else: - gr.TabbedInterface(interface_list=[self.chat], tab_names=["chat"]) + with gr.Tab("chat"): + self.chat.render() + with gr.Tab("retrieval", visible=self._show_documents_tab): + self.retrieval_table.render() + with gr.Tab("documents", visible=self._show_documents_tab): + self.document_table.render() def launch(self, share: bool = False, @@ -427,7 +428,7 @@ def main(): parser.add_argument('-share', '--share', type=bool, help='Deploy a live app on gradio', default=False, required=False) parser.add_argument('-server_name', '--server_name', type=str, help='Server name', required=False) #parser.add_argument('-favicon_path', '--favicon_path', type=str, help='Path of application favicon', required=False) - + args = parser.parse_args() diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index 7a637bc..f6d0469 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev9" +__version__ = "0.1.13.dev10" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From 6d31677971f864bf84b52c7efae2a32363ffd291 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 21:53:49 -0500 Subject: [PATCH 22/41] v0.1.13.dev11 --- rag_assistant/RagAssistant.py | 6 ++++-- rag_assistant/__init__.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index e28fa61..93ad362 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -362,11 +362,13 @@ def setup_gradio_interface(self): self.vectorizer.change(self.change_vectorizer, inputs=[self.vectorizer], outputs=self.data_frame) self.load_button.click(self.load_and_filter_json, inputs=[self.file], outputs=self.data_frame) - self.file.select(self.load_and_filter_json, inputs=[self.file], outputs=self.data_frame) + #self.file.select(self.load_and_filter_json, inputs=[self.file], outputs=self.data_frame) self.save_button.click(self.save_df, inputs=[self.data_frame]) with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: - with gr.Tab("chat"): + print(self._show_documents_tab, type(self._show_documents_tab)) + + with gr.Tab("chat", visible=True): self.chat.render() with gr.Tab("retrieval", visible=self._show_documents_tab): self.retrieval_table.render() diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index f6d0469..ed73cdf 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev10" +__version__ = "0.1.13.dev11" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From bbcac8f8a9ddc6305c8753dd7337176612061ac7 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 22:07:13 -0500 Subject: [PATCH 23/41] 0.1.13.dev12 --- rag_assistant/RagAssistant.py | 4 ++-- rag_assistant/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 93ad362..910208a 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -362,15 +362,15 @@ def setup_gradio_interface(self): self.vectorizer.change(self.change_vectorizer, inputs=[self.vectorizer], outputs=self.data_frame) self.load_button.click(self.load_and_filter_json, inputs=[self.file], outputs=self.data_frame) - #self.file.select(self.load_and_filter_json, inputs=[self.file], outputs=self.data_frame) self.save_button.click(self.save_df, inputs=[self.data_frame]) + self.data_frame.value = self.load_and_filter_json(self.file) with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: print(self._show_documents_tab, type(self._show_documents_tab)) with gr.Tab("chat", visible=True): self.chat.render() - with gr.Tab("retrieval", visible=self._show_documents_tab): + with gr.Tab("retrieval", visible=False): self.retrieval_table.render() with gr.Tab("documents", visible=self._show_documents_tab): self.document_table.render() diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index ed73cdf..98ab207 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev11" +__version__ = "0.1.13.dev12" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From d02f1b505e82417724b7bfffadb4b054f834875a Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 22:13:11 -0500 Subject: [PATCH 24/41] =?UTF-8?q?=F0=9F=90=9B=20v0.1.13.dev13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 4 ++-- rag_assistant/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 910208a..382c423 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -355,7 +355,7 @@ def setup_gradio_interface(self): self.file = gr.File(label="Upload JSON File", value=self._init_file_path) self.vectorizer = gr.Dropdown(choices=["Doc2Vec", "TFIDF", "MLM"], value="Doc2Vec", label="Select vectorizer") self.load_button = gr.Button("load") - with gr.Row(): + with gr.Row():c self.data_frame = gr.Dataframe(interactive=True, wrap=True, line_breaks=True, elem_id="document-table-container", height="700") with gr.Row(): self.save_button = gr.Button("save") @@ -370,7 +370,7 @@ def setup_gradio_interface(self): with gr.Tab("chat", visible=True): self.chat.render() - with gr.Tab("retrieval", visible=False): + with gr.Tab("retrieval", visible=self._show_documents_tab): self.retrieval_table.render() with gr.Tab("documents", visible=self._show_documents_tab): self.document_table.render() diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index 98ab207..f1d0f67 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev12" +__version__ = "0.1.13.dev13" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From fc7da29adba4505aebfc712127865b718f717062 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 22:17:40 -0500 Subject: [PATCH 25/41] =?UTF-8?q?=E2=98=9D=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 11 ++++++----- rag_assistant/__init__.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 382c423..2dddc73 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -139,10 +139,10 @@ def change_vectorizer(self, vectorizer: str): self.agent.vector_store = TFIDFVectorStore() - def load_and_filter_json(self, file_info): + def load_and_filter_json(self, filename): # Load JSON file using json library try: - documents = load_documents_from_json_file(file_info.name) + documents = load_documents_from_json_file(filename) self.agent.vector_store.documents = [] self.agent.vector_store.add_documents(documents) self.long_term_memory_df = self.preprocess_documents(documents) @@ -361,9 +361,10 @@ def setup_gradio_interface(self): self.save_button = gr.Button("save") self.vectorizer.change(self.change_vectorizer, inputs=[self.vectorizer], outputs=self.data_frame) - self.load_button.click(self.load_and_filter_json, inputs=[self.file], outputs=self.data_frame) + self.load_button.click(self.load_and_filter_json, inputs=[self.file.name], outputs=self.data_frame) self.save_button.click(self.save_df, inputs=[self.data_frame]) - self.data_frame.value = self.load_and_filter_json(self.file) + if self._init_file_path: + self.data_frame.value = self.load_and_filter_json(self.file.name) with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: print(self._show_documents_tab, type(self._show_documents_tab)) @@ -470,7 +471,7 @@ def main(): if args.documents_file_path: launch_kwargs.update({'documents_file_path': args.documents_file_path}) - if args.show_documents_tab: + if args.show_documents_tab == True: launch_kwargs.update({'show_documents_tab': args.show_documents_tab}) diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index f1d0f67..b135e08 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev13" +__version__ = "0.1.13.dev14" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From ed50083988631beb40875881f6c1e439432f2325 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 22:19:02 -0500 Subject: [PATCH 26/41] typo --- rag_assistant/RagAssistant.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 2dddc73..c3563eb 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -355,7 +355,7 @@ def setup_gradio_interface(self): self.file = gr.File(label="Upload JSON File", value=self._init_file_path) self.vectorizer = gr.Dropdown(choices=["Doc2Vec", "TFIDF", "MLM"], value="Doc2Vec", label="Select vectorizer") self.load_button = gr.Button("load") - with gr.Row():c + with gr.Row(): self.data_frame = gr.Dataframe(interactive=True, wrap=True, line_breaks=True, elem_id="document-table-container", height="700") with gr.Row(): self.save_button = gr.Button("save") From 0ea1c8181b470eeb579038383641ef3aefd022ac Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 22:30:20 -0500 Subject: [PATCH 27/41] v0.1.13.dev15 --- rag_assistant/RagAssistant.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index c3563eb..6a92d1b 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -137,9 +137,11 @@ def change_vectorizer(self, vectorizer: str): self.agent.vector_store = MLMVectorStore() else: self.agent.vector_store = TFIDFVectorStore() - - def load_and_filter_json(self, filename): + def load_json_from_file_info(self, file_info): + self._load_and_filter_json(file_info.name) + + def _load_and_filter_json(self, filename): # Load JSON file using json library try: documents = load_documents_from_json_file(filename) @@ -361,10 +363,10 @@ def setup_gradio_interface(self): self.save_button = gr.Button("save") self.vectorizer.change(self.change_vectorizer, inputs=[self.vectorizer], outputs=self.data_frame) - self.load_button.click(self.load_and_filter_json, inputs=[self.file.name], outputs=self.data_frame) + self.load_button.click(self.load_json_from_file_info, inputs=[self.file.name], outputs=self.data_frame) self.save_button.click(self.save_df, inputs=[self.data_frame]) if self._init_file_path: - self.data_frame.value = self.load_and_filter_json(self.file.name) + self.data_frame.value = self._load_and_filter_json(self.file.name) with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: print(self._show_documents_tab, type(self._show_documents_tab)) From 37ed500476c96a5ff12b42d36e2060137684fdc3 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 22:39:28 -0500 Subject: [PATCH 28/41] v0.1.13.dev16 --- rag_assistant/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index b135e08..20d245e 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev14" +__version__ = "0.1.13.dev16" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From d7545d0696179b445a31eb8583c1b2a3ec3c14f1 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 22:47:46 -0500 Subject: [PATCH 29/41] v0.1.13.dev17 --- rag_assistant/RagAssistant.py | 4 ++-- rag_assistant/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 6a92d1b..1731339 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -363,10 +363,10 @@ def setup_gradio_interface(self): self.save_button = gr.Button("save") self.vectorizer.change(self.change_vectorizer, inputs=[self.vectorizer], outputs=self.data_frame) - self.load_button.click(self.load_json_from_file_info, inputs=[self.file.name], outputs=self.data_frame) + self.load_button.click(self.load_json_from_file_info, inputs=[self.file], outputs=self.data_frame) self.save_button.click(self.save_df, inputs=[self.data_frame]) if self._init_file_path: - self.data_frame.value = self._load_and_filter_json(self.file.name) + self.data_frame.value = self._load_and_filter_json(self._init_file_path_) with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: print(self._show_documents_tab, type(self._show_documents_tab)) diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index 20d245e..f5ba728 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev16" +__version__ = "0.1.13.dev17" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From 29428c6a0d34e3831a69f58a6b7a621029b29a70 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 22:55:21 -0500 Subject: [PATCH 30/41] v0.1.13.dev18 --- rag_assistant/RagAssistant.py | 2 +- rag_assistant/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 1731339..87f8238 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -366,7 +366,7 @@ def setup_gradio_interface(self): self.load_button.click(self.load_json_from_file_info, inputs=[self.file], outputs=self.data_frame) self.save_button.click(self.save_df, inputs=[self.data_frame]) if self._init_file_path: - self.data_frame.value = self._load_and_filter_json(self._init_file_path_) + self.data_frame.value = self._load_and_filter_json(self._init_file_path) with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: print(self._show_documents_tab, type(self._show_documents_tab)) diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index f5ba728..a632de7 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev17" +__version__ = "0.1.13.dev18" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From effca60c3f498232068ce68b04b0e087a31ad49b Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 23:08:31 -0500 Subject: [PATCH 31/41] v0.1.13.dev19 --- rag_assistant/RagAssistant.py | 4 ++-- rag_assistant/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 87f8238..d2a6fdc 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -365,8 +365,8 @@ def setup_gradio_interface(self): self.vectorizer.change(self.change_vectorizer, inputs=[self.vectorizer], outputs=self.data_frame) self.load_button.click(self.load_json_from_file_info, inputs=[self.file], outputs=self.data_frame) self.save_button.click(self.save_df, inputs=[self.data_frame]) - if self._init_file_path: - self.data_frame.value = self._load_and_filter_json(self._init_file_path) + #if self._init_file_path: + #self.data_frame.value = self._load_and_filter_json(self._init_file_path) with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: print(self._show_documents_tab, type(self._show_documents_tab)) diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index a632de7..58cb194 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev18" +__version__ = "0.1.13.dev19" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From e30083387d385f436b6f8e2ced912db40c1d6788 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 23:24:55 -0500 Subject: [PATCH 32/41] v0.1.13.dev20 --- rag_assistant/RagAssistant.py | 6 ++++-- rag_assistant/__init__.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index d2a6fdc..0ab0d2d 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -365,8 +365,9 @@ def setup_gradio_interface(self): self.vectorizer.change(self.change_vectorizer, inputs=[self.vectorizer], outputs=self.data_frame) self.load_button.click(self.load_json_from_file_info, inputs=[self.file], outputs=self.data_frame) self.save_button.click(self.save_df, inputs=[self.data_frame]) - #if self._init_file_path: - #self.data_frame.value = self._load_and_filter_json(self._init_file_path) + print('self._init_file_path', self._init_file_path) + if self._init_file_path: + self.data_frame.value = self._load_and_filter_json(self._init_file_path) with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: print(self._show_documents_tab, type(self._show_documents_tab)) @@ -396,6 +397,7 @@ def launch(self, self._show_system_context = show_system_context self._show_documents_tab = show_documents_tab self._init_file_path = documents_file_path + print('self._init_file_path', self._init_file_path) self.setup_gradio_interface() diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index 58cb194..27a4aa4 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev19" +__version__ = "0.1.13.dev20" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From fc8c71c8af99b4309d3b5907bf95a7c7bb4c44de Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 23:38:01 -0500 Subject: [PATCH 33/41] v0.1.13.dev21 --- rag_assistant/RagAssistant.py | 13 +++++++++---- rag_assistant/__init__.py | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 0ab0d2d..df98d46 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -358,16 +358,20 @@ def setup_gradio_interface(self): self.vectorizer = gr.Dropdown(choices=["Doc2Vec", "TFIDF", "MLM"], value="Doc2Vec", label="Select vectorizer") self.load_button = gr.Button("load") with gr.Row(): - self.data_frame = gr.Dataframe(interactive=True, wrap=True, line_breaks=True, elem_id="document-table-container", height="700") + if self._init_file_path: + df = self._load_and_filter_json(self._init_file_path) + self.data_frame = gr.Dataframe(interactive=True, + wrap=True, + line_breaks=True, + elem_id="document-table-container", + height="700", + value=df) with gr.Row(): self.save_button = gr.Button("save") self.vectorizer.change(self.change_vectorizer, inputs=[self.vectorizer], outputs=self.data_frame) self.load_button.click(self.load_json_from_file_info, inputs=[self.file], outputs=self.data_frame) self.save_button.click(self.save_df, inputs=[self.data_frame]) - print('self._init_file_path', self._init_file_path) - if self._init_file_path: - self.data_frame.value = self._load_and_filter_json(self._init_file_path) with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: print(self._show_documents_tab, type(self._show_documents_tab)) @@ -398,6 +402,7 @@ def launch(self, self._show_documents_tab = show_documents_tab self._init_file_path = documents_file_path print('self._init_file_path', self._init_file_path) + self._load_and_filter_json(self._init_file_path) self.setup_gradio_interface() diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index 27a4aa4..01ef386 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev20" +__version__ = "0.1.13.dev21" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From 22b0158243e44fb23b039a9500a6a9fabb3a13f5 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 23:38:30 -0500 Subject: [PATCH 34/41] v0.1.13.dev22 --- rag_assistant/RagAssistant.py | 1 - rag_assistant/__init__.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index df98d46..1e2bb5d 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -402,7 +402,6 @@ def launch(self, self._show_documents_tab = show_documents_tab self._init_file_path = documents_file_path print('self._init_file_path', self._init_file_path) - self._load_and_filter_json(self._init_file_path) self.setup_gradio_interface() diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index 01ef386..c626d30 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev21" +__version__ = "0.1.13.dev22" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From a2843bf0e70edc438f7ef2be7044b25ed4eb07d0 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Fri, 31 May 2024 23:51:24 -0500 Subject: [PATCH 35/41] v0.1.13.dev23 - error toast --- rag_assistant/RagAssistant.py | 11 +++++------ rag_assistant/__init__.py | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 1e2bb5d..68739a0 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -150,7 +150,7 @@ def _load_and_filter_json(self, filename): self.long_term_memory_df = self.preprocess_documents(documents) return self.long_term_memory_df except json.JSONDecodeError: - #error_fn("Invalid JSON file. Please check the file and try again.") + error_fn("Invalid JSON file. Please check the file and try again.") return "Invalid JSON file. Please check the file and try again." def preprocess_documents(self, documents): @@ -166,7 +166,7 @@ def preprocess_documents(self, documents): df = pd.DataFrame.from_dict(docs) return df except Exception as e: - #error_fn("preprocess_documents failed: {e}") + error_fn("preprocess_documents failed: {e}") print(f"preprocess_documents: {e}") @@ -261,7 +261,7 @@ async def chatbot_function(self, # Set additional parameters self.api_key = api_key self.set_model(model_name) - #print(self.model, self.model.model_name, self.api_key) + # Set Conversation Size self.agent.system_context = system_context @@ -291,7 +291,7 @@ async def chatbot_function(self, return "", self.last_recall_df, history except Exception as e: - #error_fn(f"chatbot_function error: {e}") + error_fn(f"chatbot_function error: {e}") self.agent.conversation._history.pop(0) print(f"chatbot_function error: {e}") return "", [], history @@ -374,7 +374,7 @@ def setup_gradio_interface(self): self.save_button.click(self.save_df, inputs=[self.data_frame]) with gr.Blocks(css = self.css, title="Swarmauri Rag Agent", head=head) as self.app: - print(self._show_documents_tab, type(self._show_documents_tab)) + with gr.Tab("chat", visible=True): self.chat.render() @@ -401,7 +401,6 @@ def launch(self, self._show_system_context = show_system_context self._show_documents_tab = show_documents_tab self._init_file_path = documents_file_path - print('self._init_file_path', self._init_file_path) self.setup_gradio_interface() diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index c626d30..5cf761d 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.13.dev22" +__version__ = "0.1.14" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From c4bcb9082c71fe6d2a968d427f68444f2d05003b Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Sat, 1 Jun 2024 03:03:55 -0500 Subject: [PATCH 36/41] =?UTF-8?q?=F0=9F=90=9B=20v0.1.15.dev1=20-=20fix=20s?= =?UTF-8?q?et=5Fmodel=20from=20argparse=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 5 ++++- rag_assistant/__init__.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 68739a0..12f96ad 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -76,6 +76,7 @@ def __init__(self, self.long_term_memory_df = None self.last_recall_df = None self.agent = self.initialize_agent() + self.model_name = model_name self.set_model(model_name) self.css = """ #chat-dialogue-container { @@ -126,6 +127,8 @@ def set_model(self, provider_model_choice: str): self.model = AnthropicModel(api_key=self.api_key, model_name=model_name) self.agent.model = self.model + + self.model_name = provider_model_choice else: raise ValueError(f"Model name '{model_name}' is not supported. Choose from {self.allowed_models}") @@ -321,7 +324,7 @@ def setup_gradio_interface(self): self.additional_inputs = [ gr.Textbox(label="API Key", value=self.api_key or "Enter your API Key", visible=self._show_api_key), gr.Dropdown(self.allowed_models, - value="openai_gpt-3.5-turbo", + value=self.model_name, label="Model", info="Select openai model", visible=self._show_provider_model), diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index 5cf761d..7835ebd 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.14" +__version__ = "0.1.15.dev1" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From 38aa10bfb50a46dc1bcb899ab7eae0bfaec5c8aa Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Sat, 1 Jun 2024 03:18:15 -0500 Subject: [PATCH 37/41] =?UTF-8?q?=F0=9F=9A=A2v0.1.16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index 7835ebd..b5520eb 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.15.dev1" +__version__ = "0.1.16" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From 6b2b3caef727430e91b481d6d727b566d3f20113 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Sat, 1 Jun 2024 18:53:57 -0500 Subject: [PATCH 38/41] =?UTF-8?q?=F0=9F=9A=A2v0.1.17=20-=20add=20support?= =?UTF-8?q?=20for=20sessions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 101 +++++++++++++++++----------------- rag_assistant/__init__.py | 2 +- 2 files changed, 53 insertions(+), 50 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 12f96ad..89c2289 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -1,4 +1,5 @@ from datetime import datetime +import uuid import sqlite3 import gradio as gr import pandas as pd @@ -71,6 +72,7 @@ def __init__(self, 'anthropic_claude-3-haiku-20240307']) self.model = None + self.chat_idx = {} self.retrieval_table = [] self.document_table = [] self.long_term_memory_df = None @@ -231,19 +233,14 @@ def dataframe_to_documents(self, df): documents.append(document) return documents - def clear_chat(self): + def clear_chat(self, chat_id): # We could clear, but if we create a new instance, we get a new conversation id - max_size = self.agent.conversation.max_size - session_cache_size = self.agent.conversation.session_cache_max_size - self.conversation = SessionCacheConversation(max_size=max_size, - system_message_content="", - session_cache_max_size=session_cache_size) - self.agent.conversation = self.conversation - return "", [], [] + del self.chat_idx[chat_id] + return chat_id, "", [], [] async def chatbot_function(self, + chat_id, message, - history, api_key: str = None, model_name: str = None, system_context: str = None, @@ -254,50 +251,56 @@ async def chatbot_function(self, conversation_size: int = 2, session_cache_size: int = 2): try: + if not chat_id: + chat_id = str(uuid.uuid4()) start_datetime = datetime.now() - if self.agent.vector_store.document_count() == 0: - return "", [], [(message, "⚠️ Add Documents First")] - else: - - - # Set additional parameters - self.api_key = api_key - self.set_model(model_name) + # Set additional parameters + self.api_key = api_key + self.set_model(model_name) - # Set Conversation Size - self.agent.system_context = system_context - self.agent.conversation.max_size = conversation_size - self.agent.conversation.session_cache_max_size = session_cache_size - - # Predict - try: - response = self.agent.exec(message, - top_k=top_k, - fixed=fixed_retrieval, - model_kwargs={'temperature': temperature, 'max_tokens': max_tokens}) - except Exception as e: - print(f"chatbot_function agent error: {e}") - - - # Update Retrieval Document Table - self.last_recall_df = self.preprocess_documents(self.agent.last_retrieved) - - # Get History - history = [each['content'] for each in self.agent.conversation.session_to_dict()] - history = [(history[i], history[i+1]) for i in range(0, len(history), 2)] - # SQL Log - end_datetime = datetime.now() - self.sql_log(self.agent.conversation.id, model_name, message, response, start_datetime, end_datetime) + # Set Conversation Size + self.agent.system_context = system_context + + if chat_id not in self.chat_idx: + self.chat_idx[chat_id] = SessionCacheConversation(max_size=conversation_size, + system_message_content=system_context, + session_cache_max_size=session_cache_size) + + + self.agent.conversation = self.chat_idx[chat_id] + + # Predict + try: + response = self.agent.exec(message, + top_k=top_k, + fixed=fixed_retrieval, + model_kwargs={'temperature': temperature, 'max_tokens': max_tokens}) + except Exception as e: + print(f"chatbot_function agent error: {e}") - return "", self.last_recall_df, history + + # Update Retrieval Document Table + self.last_recall_df = self.preprocess_documents(self.agent.last_retrieved) + + + # Get History + + history = [each['content'] for each in self.agent.conversation.session_to_dict()] + history = [(history[i], history[i+1]) for i in range(0, len(history), 2)] + + # SQL Log + end_datetime = datetime.now() + self.sql_log(self.agent.conversation.id, model_name, message, response, start_datetime, end_datetime) + + return chat_id, "", self.last_recall_df, history except Exception as e: error_fn(f"chatbot_function error: {e}") self.agent.conversation._history.pop(0) print(f"chatbot_function error: {e}") - return "", [], history + return chat_id, "", [], history @@ -309,7 +312,8 @@ def setup_gradio_interface(self): with gr.Blocks(css = self.css) as self.chat: with gr.Row(): - self.chat_history = gr.Chatbot(label="Chat History", + chat_id = gr.State(None) + self.chatbot = gr.Chatbot(label="Chat History", layout="panel", elem_id="chat-dialogue-container", container=True, @@ -338,20 +342,20 @@ def setup_gradio_interface(self): ] - submit_inputs = [self.input_box, self.chat_history] + submit_inputs = [chat_id, self.input_box] submit_inputs.extend(self.additional_inputs) # Function to handle sending messages self.send_button.click( self.chatbot_function, inputs=submit_inputs, - outputs=[self.input_box, self.retrieval_table, self.chat_history] + outputs=[chat_id, self.input_box, self.retrieval_table, self.chatbot] ) # Function to handle clearing the chat self.clear_button.click( self.clear_chat, - inputs=[], - outputs=[self.input_box, self.retrieval_table, self.chat_history] + inputs=[chat_id], + outputs=[chat_id, self.input_box, self.retrieval_table, self.chatbot] ) @@ -388,7 +392,6 @@ def setup_gradio_interface(self): def launch(self, share: bool = False, - show_api_key: bool = False, show_provider_model: bool = False, show_system_context: bool = False, diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index b5520eb..de450f8 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.16" +__version__ = "0.1.17" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From ac9d12c14ce45b1caacf74f4134f6d31a7fbbefe Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Sun, 2 Jun 2024 22:19:48 -0500 Subject: [PATCH 39/41] =?UTF-8?q?=F0=9F=94=91v0.1.18=20-=20KeyError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rag_assistant/RagAssistant.py | 5 ++++- rag_assistant/__init__.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/rag_assistant/RagAssistant.py b/rag_assistant/RagAssistant.py index 89c2289..fd50f8a 100644 --- a/rag_assistant/RagAssistant.py +++ b/rag_assistant/RagAssistant.py @@ -235,7 +235,10 @@ def dataframe_to_documents(self, df): def clear_chat(self, chat_id): # We could clear, but if we create a new instance, we get a new conversation id - del self.chat_idx[chat_id] + try: + del self.chat_idx[chat_id] + except KeyError: + pass return chat_id, "", [], [] async def chatbot_function(self, diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index de450f8..f51df36 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.17" +__version__ = "0.1.18" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant From 85c4b48d665073211671c24c5a015d78deae4342 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Sun, 2 Jun 2024 22:21:19 -0500 Subject: [PATCH 40/41] v0.1.19 - force gradio 4.29.0 (gradio 4.32.x is failing) --- rag_assistant/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rag_assistant/__init__.py b/rag_assistant/__init__.py index f51df36..4aa5a36 100644 --- a/rag_assistant/__init__.py +++ b/rag_assistant/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.18" +__version__ = "0.1.19" __short_desc__ = """The Swarmauri Rag Assistant is part of the swarmaURI framework.""" __long_desc__ = """# Swarmauri Rag Assistant diff --git a/setup.py b/setup.py index c56f4d6..156030d 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ ] }, include_package_data=True, - install_requires=['gradio', + install_requires=['gradio==4.26.0', 'swarmauri[full]==0.2.5'], classifiers=[ 'License :: OSI Approved :: MIT License', From 0ccd5ba93586aa400d92c52b0a955f2b5e30172d Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Sat, 3 Aug 2024 19:10:34 -0500 Subject: [PATCH 41/41] Update README.md --- README.md | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 129 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c0a27bf..b2c02ea 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,138 @@ # Swarmauri Rag Assistant ## Overview -The Swarmauri Rag Assistant + +The Swarmauri Rag Assistant is your go-to tool for managing different configurations and settings for your application. With a simple command-line interface, you can customize and deploy the Assistant using various arguments according to your needs. ## Installation + +Getting started with Swarmauri’s RAG Assistant is straightforward. You can install it via pip by running the following command: + ```bash -pip install rag_assistant==0.1.1 --user +pip install rag_assistant==0.1.19 --user ``` -## Execution +## Usage + +Below is a comprehensive explanation of each argument you can provide to the Assistant and how to use them effectively: + +### Required Arguments + +**--api_key** + +- **Description**: Your API key. +- **Type**: `str` +- **Required**: Yes +- **Usage**: + ```bash + rag_assistant --api_key your_api_key + ``` + +### Optional Arguments + +**--show_api_key** + +- **Description**: Toggle displaying API key on the app. +- **Type**: `bool` +- **Default**: `False` +- **Usage**: + ```bash + rag_assistant --api_key your_api_key --show_api_key True + ``` + +**--provider_model** + +- **Description**: Your provider model. +- **Type**: `str` +- **Usage**: + ```bash + rag_assistant --api_key your_api_key --provider_model your_provider_model + ``` + +**--show_provider_model** + +- **Description**: Toggle displaying the provider model on the app. +- **Type**: `bool` +- **Default**: `False` +- **Usage**: + ```bash + rag_assistant --api_key your_api_key --show_provider_model True + ``` + +**--system_context** + +- **Description**: Assistant’s system context. +- **Type**: `str` +- **Usage**: + ```bash + rag_assistant --api_key your_api_key --system_context "Your system context" + ``` + +**--show_system_context** + +- **Description**: Toggle displaying the system context on the app. +- **Type**: `bool` +- **Default**: `False` +- **Usage**: + ```bash + rag_assistant --api_key your_api_key --show_system_context True + ``` + +**--documents_file_path** + +- **Description**: Filepath of documents JSON. +- **Type**: `str` +- **Usage**: + ```bash + rag_assistant --api_key your_api_key --documents_file_path "path/to/your/documents.json" + ``` + +**--show_documents_tab** + +- **Description**: Toggle displaying document tabs on the app. +- **Type**: `bool` +- **Default**: `False` +- **Usage**: + ```bash + rag_assistant --api_key your_api_key --show_documents_tab True + ``` + +**--db_path** + +- **Description**: Path to SQLite3 database. +- **Type**: `str` +- **Usage**: + ```bash + rag_assistant --api_key your_api_key --db_path "path/to/your/db.sqlite3" + ``` + +**--share** + +- **Description**: Deploy a live app on Gradio. +- **Type**: `bool` +- **Default**: `False` +- **Usage**: + ```bash + rag_assistant --api_key your_api_key --share True + ``` + +**--server_name** + +- **Description**: Server name. +- **Type**: `str` +- **Usage**: + ```bash + rag_assistant --api_key your_api_key --server_name "your_server_name" + ``` + +## Example Usage + +Here is an example command that utilizes multiple arguments to launch the Assistant: + ```bash -! rag_assistant --api_key "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" --db_path "E:\\swarmauri_github/prompt_responses.db" -``` \ No newline at end of file +rag_assistant --api_key your_api_key --show_api_key True \ +--provider_model your_provider_model --show_provider_model True \ +--system_context "Development Environment" --show_system_context True \ +--documents_file_path "path/to/your/documents.json" --show_documents_tab True \ +--db_path "path/to/your/db.sqlite3" --share True --server_name "your_server_name" +```