Skip to content

Commit

Permalink
update cli
Browse files Browse the repository at this point in the history
  • Loading branch information
shell-nlp committed Oct 29, 2024
1 parent aa651ce commit 0cfd445
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 40 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include gpt_server/script/*.yaml
28 changes: 16 additions & 12 deletions gpt_server/cli.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import argparse
import subprocess
import os
import typer

app = typer.Typer()
root_dir = os.path.dirname(__file__)
root_dir = os.path.abspath(root_dir)
chat_ui_path = os.path.join(root_dir, "serving", "chat_ui.py")
server_ui_path = os.path.join(root_dir, "serving", "server_ui.py")


def run():
parser = argparse.ArgumentParser(description="GPT Server CLI")
parser.add_argument("--chat_ui", action="store_true", help="启动问答UI界面")
parser.add_argument("--server_ui", action="store_true", help="启动服务UI界面")
args = parser.parse_args()
print(args)
if args.chat_ui:
cmd = f"streamlit run {chat_ui_path}"
subprocess.run(cmd, shell=True)
if args.server_ui:
@app.command(help="启动 GPT Server UI")
def ui(
server: bool = typer.Option(False, help="启动服务UI界面"),
chat: bool = typer.Option(False, help="启动问答UI界面"),
):
if server:
cmd = f"streamlit run {server_ui_path}"
subprocess.run(cmd, shell=True)
if chat:
cmd = f"streamlit run {chat_ui_path}"
subprocess.run(cmd, shell=True)


def main():
app()


if __name__ == "__main__":
run()
main()
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ dependencies = [
"vllm==0.6.3",
]


[project.scripts]
gpt_server = "gpt_server.cli:run"
gpt_server = "gpt_server.cli:main"

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
29 changes: 2 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os
import sys
import subprocess
from setuptools import setup, find_packages
from setuptools.command.install import install

Expand All @@ -9,27 +7,6 @@
version_file = "gpt_server/version.py"


# 自定义安装类
class CustomInstallCommand(install):
"""自定义安装命令类,用于在安装过程中执行额外的脚本"""

def run(self):
# 调用父类的 run 方法
install.run(self)

# 运行 Bash 脚本
script_path = os.path.join(os.path.dirname(__file__), "install.sh")
if os.path.exists(script_path):
print("Running install_script.sh...")
try:
subprocess.check_call(["/bin/bash", script_path])
except subprocess.CalledProcessError as e:
print(f"Error executing script {script_path}: {e}")
sys.exit(1)
else:
print(f"Script {script_path} not found!")


def readme():
with open(os.path.join(pwd, "README.md"), encoding="utf-8") as f:
content = f.read()
Expand All @@ -51,9 +28,7 @@ def get_version():
long_description_content_type="text/markdown",
author="Yu Liu",
author_email="[email protected]",
packages=find_packages(exclude=()),
packages=find_packages(),
include_package_data=True, # 确保包含 MANIFEST.in 中的文件
# ... 其他 setup 参数 ...
cmdclass={
"install": CustomInstallCommand, # 关联自定义安装类
},
)

0 comments on commit 0cfd445

Please sign in to comment.