赞
踩
参考视频:ChatGLM+Langchain构建本地知识库,只需6G显存,支持实时上传文档_哔哩哔哩_bilibili
在ChatGLM2项目下有个 api.py 文件,先将文件内的模型文件改为自己本地的模型文件,同时将host 改为 127.0.0.1 。
- if __name__ == '__main__':
- tokenizer = AutoTokenizer.from_pretrained("/home/ChatGLM2-6B/model//chatglm2-6b", trust_remote_code=True)
- model = AutoModel.from_pretrained("/home/ChatGLM2-6B/model/chatglm2-6b", trust_remote_code=True, device='cuda')
- model.eval()
- uvicorn.run(app, host='127.0.0.1', port=8000, workers=1)
启动 api.py
- $ python api.py
- Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
- Explicitly passing a `revision` is encouraged when loading a configuration with custom code to ensure no malicious code has been contributed in a newer revision.
- Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
- Loading checkpoint shards: 100%|██████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:12<00:00, 1.83s/it]
- INFO: Started server process [340455]
- INFO: Waiting for application startup.
- INFO: Application startup complete.
- INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
创建 api_access.py
- import requests
-
- def chat(prompt,history):
- resp = requests.post(
- url = 'http://127.0.0.1:8000',
- json = {"prompt":prompt, "history":history},
- headers = {"Content-Type":"application/json;charset=utf-8"}
- )
- return resp.json()['response'], resp.json()['history']
-
- history = []
-
- while True:
- response, history = chat(input("Question:"), history)
- print('Answer:', response)
运行 api_access.py
- $ python api_access.py
- Question:你好
- Answer: 你好声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/817544推荐阅读
相关标签
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。