项目地址
- 首先获取MiniCPM官方代码
git clone https://github.com/OpenBMB/MiniCPM.git
cd MiniCPM/demo/openai_api_demo
- 根据需要修改
MiniCPM/demo/openai_api_demo\openai_api_server_demo.py
以下参数
MODEL_PATH = os.environ.get('MODEL_PATH', 'openbmb/MiniCPM-2B-dpo-fp16')
TOKENIZER_PATH = os.environ.get("TOKENIZER_PATH", MODEL_PATH)
EMBEDDING_PATH = os.environ.get('EMBEDDING_PATH', 'BAAI/bge-m3')
- 运行
MiniCPM/demo/openai_api_demo\openai_api_server_demo.py
文件:
python openai_api_server_demo.py
- 修改
MiniCPM/demo/openai_api_demo/openai_api_request_demo.py
文件中的请求内容。
def chat(use_stream=True):
messages = [
{
"role": "user",
"content": "tell me a story" # 如果不携带历史上下问的请求,可以仅修改content
}
]
# 携带历史上下问如下
# messages = [
# {
# "role": "user",
# "content": "hello"
# },
# {
# "role": "assistant",
# "content": "hello, can i help you?"
# }
# {
# "role": "user",
# "content": "can you tell me a story?"
# }
# ]
- 修改后,直接运行
MiniCPM/demo/openai_api_demo/openai_api_request_demo.py
即可以获得回复。