Skip to content

Commit 0cfd445

Browse files
committedOct 29, 2024
update cli
1 parent aa651ce commit 0cfd445

File tree

4 files changed

+25
-40
lines changed

4 files changed

+25
-40
lines changed
 

‎MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include gpt_server/script/*.yaml

‎gpt_server/cli.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
import argparse
21
import subprocess
32
import os
3+
import typer
44

5+
app = typer.Typer()
56
root_dir = os.path.dirname(__file__)
67
root_dir = os.path.abspath(root_dir)
78
chat_ui_path = os.path.join(root_dir, "serving", "chat_ui.py")
89
server_ui_path = os.path.join(root_dir, "serving", "server_ui.py")
910

1011

11-
def run():
12-
parser = argparse.ArgumentParser(description="GPT Server CLI")
13-
parser.add_argument("--chat_ui", action="store_true", help="启动问答UI界面")
14-
parser.add_argument("--server_ui", action="store_true", help="启动服务UI界面")
15-
args = parser.parse_args()
16-
print(args)
17-
if args.chat_ui:
18-
cmd = f"streamlit run {chat_ui_path}"
19-
subprocess.run(cmd, shell=True)
20-
if args.server_ui:
12+
@app.command(help="启动 GPT Server UI")
13+
def ui(
14+
server: bool = typer.Option(False, help="启动服务UI界面"),
15+
chat: bool = typer.Option(False, help="启动问答UI界面"),
16+
):
17+
if server:
2118
cmd = f"streamlit run {server_ui_path}"
2219
subprocess.run(cmd, shell=True)
20+
if chat:
21+
cmd = f"streamlit run {chat_ui_path}"
22+
subprocess.run(cmd, shell=True)
23+
24+
25+
def main():
26+
app()
2327

2428

2529
if __name__ == "__main__":
26-
run()
30+
main()

‎pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,10 @@ dependencies = [
2424
"vllm==0.6.3",
2525
]
2626

27+
2728
[project.scripts]
28-
gpt_server = "gpt_server.cli:run"
29+
gpt_server = "gpt_server.cli:main"
30+
31+
[build-system]
32+
requires = ["setuptools", "wheel"]
33+
build-backend = "setuptools.build_meta"

‎setup.py

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import os
2-
import sys
3-
import subprocess
42
from setuptools import setup, find_packages
53
from setuptools.command.install import install
64

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

119

12-
# 自定义安装类
13-
class CustomInstallCommand(install):
14-
"""自定义安装命令类,用于在安装过程中执行额外的脚本"""
15-
16-
def run(self):
17-
# 调用父类的 run 方法
18-
install.run(self)
19-
20-
# 运行 Bash 脚本
21-
script_path = os.path.join(os.path.dirname(__file__), "install.sh")
22-
if os.path.exists(script_path):
23-
print("Running install_script.sh...")
24-
try:
25-
subprocess.check_call(["/bin/bash", script_path])
26-
except subprocess.CalledProcessError as e:
27-
print(f"Error executing script {script_path}: {e}")
28-
sys.exit(1)
29-
else:
30-
print(f"Script {script_path} not found!")
31-
32-
3310
def readme():
3411
with open(os.path.join(pwd, "README.md"), encoding="utf-8") as f:
3512
content = f.read()
@@ -51,9 +28,7 @@ def get_version():
5128
long_description_content_type="text/markdown",
5229
author="Yu Liu",
5330
author_email="506610466@qq.com",
54-
packages=find_packages(exclude=()),
31+
packages=find_packages(),
32+
include_package_data=True, # 确保包含 MANIFEST.in 中的文件
5533
# ... 其他 setup 参数 ...
56-
cmdclass={
57-
"install": CustomInstallCommand, # 关联自定义安装类
58-
},
5934
)

0 commit comments

Comments
 (0)