Skip to content

Commit

Permalink
precommit-format
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-sky committed Nov 1, 2023
1 parent 82d2c2d commit 311a0b1
Show file tree
Hide file tree
Showing 10 changed files with 739 additions and 348 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,4 @@ tmp/

# logs
gpt_log
debug_gui.py
debug_gui.py
3 changes: 1 addition & 2 deletions autogen/gradio_gui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class AutoGenGroupChat(AutoGenGroupChat):
def define_group_chat_manager_config(self):
llm_config.update({"temperature": 0})
return {"llm_config": llm_config}

def autogen_terminal_groupchat(*args, **kwargs):
return autogen_terminal(*args, AutoGenFn=AutoGenGroupChat, Callback=f"{os.path.basename(__file__).split('.py')[0]}->autogen_terminal_fn_02", **kwargs)

Expand All @@ -101,4 +101,3 @@ if __name__ == "__main__":
}
)
```

64 changes: 40 additions & 24 deletions autogen/gradio_gui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import subprocess
import sys
import importlib


def install_dependencies():
# <------------------- 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
input(f"You are about to install dependencies {str(deps)}, press Enter to continue ...")

for dep in deps:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--user', dep])
subprocess.check_call([sys.executable, "-m", "pip", "install", "--user", dep])
import site

importlib.reload(site)
for m in reload_m:
importlib.reload(__import__(m))
Expand All @@ -17,27 +23,37 @@ def try_install_deps(deps, reload_m=[]):
try:
import gradio as gr
import void_terminal
except:
try_install_deps(deps=["void-terminal>=0.0.9"])
try_install_deps(deps=["https://github.com/binary-husky/gpt_academic/raw/master/docs/gradio-3.32.6-py3-none-any.whl"])
except Exception:
try_install_deps(deps=["void-terminal>=0.0.9"])
try_install_deps(
deps=["https://github.com/binary-husky/gpt_academic/raw/master/docs/gradio-3.32.6-py3-none-any.whl"]
)
return True

if gr.__version__ not in ['3.32.6']:
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"])
try_install_deps(
deps=["https://github.com/binary-husky/gpt_academic/raw/master/docs/gradio-3.32.6-py3-none-any.whl"]
)
return True


def init_config_list():
import os
from autogen import config_list_from_json

config_file_path = os.environ.get("OAI_CONFIG_LIST")
if config_file_path is None:
raise EnvironmentError("""
raise EnvironmentError(
"""
OAI_CONFIG_LIST path is not set.
Please run with
Please run with
`export OAI_CONFIG_LIST='/path/to/OAI_CONFIG_LIST'`
to set the path to config list file, and then run
to set the path to config list file, and then run
`python -m autogen.launch_gui`
to start the GUI.
""")
"""
)
config_list = config_list_from_json(env_or_file=config_file_path)
llm_config = {"config_list": config_list}
print(config_list)
Expand All @@ -47,7 +63,7 @@ def init_config_list():
def init_config():
import void_terminal
import os

llm_config = init_config_list()
# set network proxy

Expand All @@ -67,19 +83,19 @@ def init_config():
void_terminal.set_conf(key="LLM_MODEL", value=llm_config["config_list"][0]["model"])
# void_terminal.set_conf(key="API_KEY",value="sk-yourapikey")
# void_terminal.set_conf(key="LLM_MODEL", value="gpt-3.5-turbo-16k")
if llm_config["config_list"][0].get('api_type', '') == 'azure':
model = 'azure-'+llm_config["config_list"][0]["model"]
if llm_config["config_list"][0].get("api_type", "") == "azure":
model = "azure-" + llm_config["config_list"][0]["model"]
api_base = llm_config["config_list"][0]["api_base"]
if api_base.endswith('/'): api_base = api_base[:-1]
if api_base.endswith("/"):
api_base = api_base[:-1]
AZURE_CFG_ARRAY = {
model:
{
"AZURE_ENDPOINT": llm_config["config_list"][0]["api_base"] + '/',
"AZURE_API_KEY": llm_config["config_list"][0]["api_key"],
"AZURE_ENGINE": llm_config["config_list"][0]["deployment_id"],
"AZURE_MODEL_MAX_TOKEN": 8192,
},
model: {
"AZURE_ENDPOINT": llm_config["config_list"][0]["api_base"] + "/",
"AZURE_API_KEY": llm_config["config_list"][0]["api_key"],
"AZURE_ENGINE": llm_config["config_list"][0]["deployment_id"],
"AZURE_MODEL_MAX_TOKEN": 8192,
},
}
void_terminal.set_conf(key="LLM_MODEL", value=model)
void_terminal.set_conf(key="AZURE_CFG_ARRAY", value=str(AZURE_CFG_ARRAY))
return llm_config
return llm_config
Loading

0 comments on commit 311a0b1

Please sign in to comment.