Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加fschat启动方式 #236

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions fschat_openaiapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 需要安装fastchat: pip install fschat 详细见repo:https://github.com/lm-sys/FastChat
# 加载不同的模型更改 command2 中的 --model-path 参数就可以,注意模型路径是config.json所在的文件夹

import subprocess

def execute_command(command):
process = subprocess.Popen(command, shell=True)
return process.pid


# 启动任务
command1 = 'nohup python -m fastchat.serve.controller >> fastchat_log.txt 2>&1 &'
process1 = execute_command(command1)

print(f"Process 1 started with PID: {process1}")

command2 = 'nohup python -m fastchat.serve.model_worker --model-path /root/ChatGLM2-6B_0/chatglm2-6b >> fastchat_log.txt 2>&1 &'
process2 = execute_command(command2)
print(f"Process 2 started with PID: {process2}")

command3 = 'nohup python -m fastchat.serve.openai_api_server --host "0.0.0.0" --port 8000 >> fastchat_log.txt 2>&1 &'
process3 = execute_command(command3)
print(f"Process 3 started with PID: {process3}")





# 服务启动后接口调用示例:
# import openai
# openai.api_key = "EMPTY" # Not support yet
# openai.api_base = "http://0.0.0.0:8000/v1"

# model = "chatglm2-6b"

# # create a chat completion
# completion = openai.ChatCompletion.create(
# model=model,
# messages=[{"role": "user", "content": "Hello! What is your name?"}]
# )
# # print the completion
# print(completion.choices[0].message.content)