Skip to content

Commit

Permalink
add save conversation btn
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-husky committed Oct 23, 2023
1 parent 1e84622 commit 15569b2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
2 changes: 1 addition & 1 deletion autogen/gradio_gui/gradio_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('|')])

Expand Down
65 changes: 58 additions & 7 deletions autogen/launch_gui.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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")
Expand All @@ -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",
Expand All @@ -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
},
}
)
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"nbconvert",
"nbformat",
"pre-commit",
"void-terminal>=0.0.8",
"pydantic==1.10.9",
"pytest-asyncio",
"pytest>=6.1.1",
Expand All @@ -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",
Expand Down

0 comments on commit 15569b2

Please sign in to comment.