Skip to content

Latest commit

 

History

History
107 lines (80 loc) · 2.72 KB

README.zh.md

File metadata and controls

107 lines (80 loc) · 2.72 KB

LLMApi Server

LLMApi Server

可自托管的LLMApi服务端

介绍

llmapi-server 是一个封装了多种大语言模型(LLM,如ChatGPT,GPT-3,GPT-4等)的抽象后端,并通过OpenAPI提供简单的访问服务

🌟 如果这个项目对您有帮助,欢迎添加star 🌟

框图

graph LR

subgraph llmapi server
OpenAPI --> session
OpenAPI --> pre_post
subgraph backend
style backend fill:#f9f
pre_post-->chatgpt
pre_post-->dall-e
pre_post-->llama
pre_post-->...
end
end
text-->OpenAPI
image-->OpenAPI
embedding-->OpenAPI
others--> OpenAPI

✨ 已支持的后端

  • chatgpt: openai官方ChatGPT接口
  • gpt3: openai官方GPT-3接口
  • gpt-embedding: openai官方embedding接口
  • dall-e: openai官方DALL·E接口
  • welm: 微信团队大模型接口
  • newbing: 基于ChatGPT的新Bing搜索接口(非官

⏳ WIP

  • llama
  • stable diffusion
  • controlNet
  • SAM(meta)

安装和运行

  1. 本地安装运行
# python >= 3.8
python3 -m pip install -r requirements.txt

python3 run_api_server.py
  1. 使用docker运行
./build_docker.sh
./start_docker.sh

访问server

  1. 使用curl命令访问:
# 1. 开始一个session
curl -X POST -H "Content-Type: application/json" -d '{"bot_type":"mock"}' http://127.0.0.1:5050/v1/chat/start
# response sample: {"code":0,"msg":"Success","session":"123456"}

# 2. 和后端进行对话交互
curl -X POST -H "Content-Type: application/json" -d '{"session":"123456","content":"hello"}' http://127.0.0.1:5050/v1/chat/ask
# response sample: {"code":0,"msg":"Success","reply":"Text mock reply for your prompt:hello","timestamp":1678865301.0842562}

# 3. 关闭session,结束对话
curl -X POST -H "Content-Type: application/json" -d '{"session":"123456"}' http://127.0.0.1:5050/v1/chat/end
# response: {"code":0,"msg":"Success"}
  1. 使用llmapi_cli命令工具访问
llmapi_cli --host="http://127.0.0.1:5050" --bot=mock
  1. 在你的python代码中使用llmapi_cli库访问
from llmapi_cli import LLMClient

client = LLMClient(host = "http://127.0.0.1:5050", bot = "mock")

rep = client.ask("hello")

print(rep)

接入你自己的LLM后端

  1. 需要在backend目录内新建一个新的后端名称(假设为newllm),可以直接cp -r mock newllm
  2. 参照mock的实现,更改后端名称为newllm
  3. newllm目录下,添加必要的依赖,所有相关的开发约束于该目录内
  4. backend.py中添加对newllm的支持