匿名用户2024年07月31日
28阅读
所属分类aiPytorch
开源地址https://modelscope.cn/models/hankwang/chatglm.cpp
授权协议Apache License 2.0

作品详情

模型文件和权重,请浏览“模型文件”页面获取。
当前模型的贡献者未提供更加详细的模型介绍,但是您可以通过如下git clone命令,或者ModelScope SDK来下载模型。
Clone with HTTP
git clone https://www.modelscope.cn/hankwang/chatglm.cpp.git
如果您是本模型的贡献者,我们邀请您根据模型贡献文档说明,及时完善模型卡片内容。

API Server

We support various kinds of API servers to integrate with popular frontends. Extra dependencies can be installed by:

pip install 'chatglm-cpp[api]'

Remember to add the corresponding CMAKE_ARGS to enable acceleration.

LangChain API

Start the api server for LangChain:

MODEL=./chatglm-ggml.bin uvicorn chatglm_cpp.langchain_api:app --host 127.0.0.1 --port 8000

Test the api endpoint with curl:

curl http://127.0.0.1:8000 -H 'Content-Type: application/json' -d '{"prompt": "你好"}'

Run with LangChain:

>>> from langchain.llms import ChatGLM
>>> 
>>> llm = ChatGLM(endpoint_url="http://127.0.0.1:8000")
>>> llm.predict("你好")
'你好?!我是人工智能助手 ChatGLM2-6B,很高兴见到你,欢迎问我任何问题。'

For more options, please refer to examples/langchain_client.py and LangChain ChatGLM Integration.

OpenAI API

Start an API server compatible with OpenAI chat completions protocol:

MODEL=./chatglm-ggml.bin uvicorn chatglm_cpp.openai_api:app --host 0.0.0.0 --port 8000
或
MODEL=./chatglm-ggml.bin daphne chatglm_cpp.openai_api:app --b 127.0.0.1 --port 8000

Test your endpoint with curl:

curl http://127.0.0.1:8000/v1/chat/completions -H 'Content-Type: application/json' \
    -d '{"messages": [{"role": "user", "content": "你好"}]}'

Use the OpenAI client to chat with your model:

>>> import openai
>>> 
>>> openai.api_base = "http://127.0.0.1:8000/v1"
>>> response = openai.ChatCompletion.create(model="default-model", messages=[{"role": "user", "content": "你好"}])
>>> response["choices"][0]["message"]["content"]
'你好?!我是人工智能助手 ChatGLM2-6B,很高兴见到你,欢迎问我任何问题。'

For stream response, check out the example client script:

OPENAI_API_BASE=http://127.0.0.1:8000/v1 python3 examples/openai_client.py --stream --prompt 你好

With this API server as backend, ChatGLM.cpp models can be seamlessly integrated into any frontend that uses OpenAI-style API, including mckaywrigley/chatbot-ui, fuergaosi233/wechat-chatgpt, Yidadaa/ChatGPT-Next-Web, and more.

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论