From 15569b23aa217d2b7924cd20f73ccb8aaefd339a Mon Sep 17 00:00:00 2001 From: binary-husky Date: Mon, 23 Oct 2023 23:22:55 +0800 Subject: [PATCH] add save conversation btn --- autogen/gradio_gui/gradio_service.py | 2 +- autogen/launch_gui.py | 65 +++++++++++++++++++++++++--- setup.py | 4 +- 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/autogen/gradio_gui/gradio_service.py b/autogen/gradio_gui/gradio_service.py index 994cc7f8d144..68d70807c46d 100644 --- a/autogen/gradio_gui/gradio_service.py +++ b/autogen/gradio_gui/gradio_service.py @@ -50,7 +50,7 @@ def main(plugins): # plugins = get_crazy_functions() # for k, v in plugins.items(): plugins[k]['Group'] = "Agent" # DEFAULT_FN_GROUPS, = get_conf('DEFAULT_FN_GROUPS') - DEFAULT_FN_GROUPS = ["Agent"] + DEFAULT_FN_GROUPS = ["Agent", "Conversation"] all_plugin_groups = list(set([g for _, plugin in plugins.items() for g in plugin['Group'].split('|')])) match_group = lambda tags, groups: any([g in groups for g in tags.split('|')]) diff --git a/autogen/launch_gui.py b/autogen/launch_gui.py index ded2a099f9e4..ddbbe1b119fc 100644 --- a/autogen/launch_gui.py +++ b/autogen/launch_gui.py @@ -1,15 +1,41 @@ +# <------------------- install dependencies -------------------> +def try_install_deps(deps, reload_m=[]): + """ + install dependencies if not installed. + """ + input(f'You are about to install dependencies {str(deps)}, press Enter to continue ...') + import subprocess, sys, importlib + for dep in deps: + subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--user', dep]) + import site + importlib.reload(site) + for m in reload_m: + importlib.reload(__import__(m)) + +# <------------------- dependencies -------------------> +try: + import gradio as gr + import void_terminal +except: + try_install_deps(deps=["void-terminal>=0.0.8"]) + try_install_deps(deps=["https://github.com/binary-husky/gpt_academic/raw/master/docs/gradio-3.32.6-py3-none-any.whl"]) + +if gr.__version__ not in ['3.32.6']: + # this is a special version of gradio, which is not available on pypi.org + try_install_deps(deps=["https://github.com/binary-husky/gpt_academic/raw/master/docs/gradio-3.32.6-py3-none-any.whl"]) + + + +# <------------------- import -------------------> import void_terminal from gradio_gui.gradio_service import main from gradio_gui.plugin import autogen_terminal from gradio_gui.utils.general import AutoGenGeneral -from void_terminal.crazy_functions.crazy_utils import try_install_deps -from void_terminal.toolbox import CatchException, HotReload +from void_terminal.toolbox import CatchException -import gradio as gr -if gr.__version__ not in ['3.32.6']: - try_install_deps(deps=["https://github.com/binary-husky/gpt_academic/raw/master/docs/gradio-3.32.6-py3-none-any.whl"]) - # this is a special version of gradio, which is not available on pypi.org + +# <------------------- define autogen agents -------------------> class AutoGenAskHuman(AutoGenGeneral): def define_agents(self): from autogen import AssistantAgent, UserProxyAgent @@ -25,7 +51,6 @@ def define_agents(self): "llm_config": False, # disables llm-based auto reply. }, ] - class AutoGenNeverAsk(AutoGenGeneral): def define_agents(self): from autogen import AssistantAgent, UserProxyAgent @@ -42,6 +67,7 @@ def define_agents(self): }, ] +# <------------------- define autogen buttons -------------------> @CatchException def autogen_terminal_fn_01(*args, **kwargs): return autogen_terminal(*args, AutoGenFn=AutoGenAskHuman, Callback="launch_gui->autogen_terminal_fn_01", **kwargs) @@ -52,6 +78,8 @@ def autogen_terminal_fn_02(*args, **kwargs): if __name__ == "__main__": + # <------------------- change configurations -------------------> + # void_terminal.set_conf(key="USE_PROXY", value=True) # void_terminal.set_conf(key="proxies", value='{"http": "http://localhost:10881", "https": "http://localhost:10881"}') void_terminal.set_conf(key="API_KEY",value="sk-yourapikey") @@ -61,8 +89,13 @@ def autogen_terminal_fn_02(*args, **kwargs): void_terminal.set_conf(key="DARK_MODE", value=True) void_terminal.set_conf(key="AUTO_CLEAR_TXT", value=True) + + # <------------------- add fn buttons to GUI & launch gradio -------------------> + from void_terminal.crazy_functions.ConversationHistoryArchive import ConversationHistoryArchive + from void_terminal.crazy_functions.Accessibility import ClearCache main( { + # <------------------- autogen functions we defined above -------------------> "AutoGen_Fn_01": { "Group": "Agent", "Color": "stop", @@ -77,5 +110,23 @@ def autogen_terminal_fn_02(*args, **kwargs): "AdvancedArgs": False, "Function": autogen_terminal_fn_02 }, + + # <------------------- other functions from void terminal -------------------> + "Save the current conversation": { + "Group": "Conversation", + "Color": "stop", + "AsButton": True, + "Info": "Save current conversation | No input parameters required", + "AdvancedArgs": False, + "Function": ConversationHistoryArchive + }, + "Clear all cache files(Handle with caution)": { + "Group": "Conversation", + "Color": "stop", + "AsButton": True, + "Info": "Clear all cache files,Handle with caution | No input parameters required", + "AdvancedArgs": False, + "Function": ClearCache + }, } ) diff --git a/setup.py b/setup.py index 2d14e0bb3a5d..32b99aa23b23 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,6 @@ "nbconvert", "nbformat", "pre-commit", - "void-terminal>=0.0.8", "pydantic==1.10.9", "pytest-asyncio", "pytest>=6.1.1", @@ -59,6 +58,9 @@ "mathchat": ["sympy", "pydantic==1.10.9", "wolframalpha"], "retrievechat": ["chromadb", "tiktoken", "sentence_transformers", "pypdf"], "teachable": ["chromadb"], + "gui":[ + "void-terminal>=0.0.8", + ] }, classifiers=[ "Programming Language :: Python :: 3",