Skip to content

Commit

Permalink
解决无法从cli.py启动cli_demo的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hzg0601 committed Jun 12, 2023
1 parent a3ee718 commit 17f9a00
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
22 changes: 18 additions & 4 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,30 @@ def start_api(ip, port):
shared.loaderCheckPoint = LoaderCheckPoint(DEFAULT_ARGS)
api_start(host=ip, port=port)

# # 通过cli.py调用cli_demo时需要在cli.py里初始化模型,否则会报错:
# langchain-ChatGLM: error: unrecognized arguments: start cli
# 为此需要先将
# args = None
# args = parser.parse_args()
# args_dict = vars(args)
# shared.loaderCheckPoint = LoaderCheckPoint(args_dict)
# 语句从main函数里取出放到函数外部
# 然后在cli.py里初始化

@start.command(name="cli", context_settings=dict(help_option_names=['-h', '--help']))
@click.option('-i', '--info', default="start client", show_default=True, type=str)
def start_cli(info):
print(info)
print("通过cli.py调用cli_demo...")

from models.loader.args import parser
from models import shared
from models.loader import LoaderCheckPoint
from models.loader.args import DEFAULT_ARGS
shared.loaderCheckPoint = LoaderCheckPoint(DEFAULT_ARGS)
cli_start()


# 同cli命令,通过cli.py调用webui时,argparse的初始化需要放到cli.py里,
# 但由于webui.py里,模型初始化通过init_model函数实现,也无法简单地分离出主函数,
# 因此除非对webui进行大改,否则无法通过python cli.py start webui 调用webui。
# 故建议不要通过以上命令启动webui,将下述语句注释掉

@start.command(name="webui", context_settings=dict(help_option_names=['-h', '--help']))
@click.option('-i', '--info', default="start client", show_default=True, type=str)
Expand Down
18 changes: 14 additions & 4 deletions cli_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@


def main():
args = None
args = parser.parse_args()
args_dict = vars(args)
shared.loaderCheckPoint = LoaderCheckPoint(args_dict)

llm_model_ins = shared.loaderLLM()
llm_model_ins.history_len = LLM_HISTORY_LEN

Expand Down Expand Up @@ -53,4 +50,17 @@ def main():


if __name__ == "__main__":
# # 通过cli.py调用cli_demo时需要在cli.py里初始化模型,否则会报错:
# langchain-ChatGLM: error: unrecognized arguments: start cli
# 为此需要先将
# args = None
# args = parser.parse_args()
# args_dict = vars(args)
# shared.loaderCheckPoint = LoaderCheckPoint(args_dict)
# 语句从main函数里取出放到函数外部
# 然后在cli.py里初始化
args = None
args = parser.parse_args()
args_dict = vars(args)
shared.loaderCheckPoint = LoaderCheckPoint(args_dict)
main()

0 comments on commit 17f9a00

Please sign in to comment.