Skip to content

Latest commit

 

History

History
44 lines (44 loc) · 1.41 KB

openai_api.md

File metadata and controls

44 lines (44 loc) · 1.41 KB

openai_api

使用方法

项目地址

  1. 首先获取MiniCPM官方代码
git clone https://github.com/OpenBMB/MiniCPM.git
cd MiniCPM/demo/openai_api_demo
  1. 根据需要修改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')
  1. 运行MiniCPM/demo/openai_api_demo\openai_api_server_demo.py文件:
python openai_api_server_demo.py
  1. 修改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?" 
    #      }
    # ]
  1. 修改后,直接运行MiniCPM/demo/openai_api_demo/openai_api_request_demo.py即可以获得回复。