llama.cpp 的安装、编译

alternative: llama-cpp-python

提供了 llama.cpp 的 Python 接口。通过 llama-cpp-python 也可以启动一个 LLM Server

启动一个 LLM server

直接在命令行里输入启动服务器

1
llama-server -m [模型路径] --port 8080

模型要保证必须是 .gguf 格式,可以使用 llama.cpp 项目根目录下的 convert_hf_to_gguf.py 进行转换。

convert_hf_to_gguf 食用方法

配置好虚拟环境后,命令行里输入

1
python convert_hf_to_gguf.py [模型.bin文件所在的目录]

这个目录末尾应该是哈希码,例如 ~/.cache/huggingface/hub/models--deepseek-ai--DeepSeek-R1-Distill-Qwen-1.5B/snapshots/ad9f0ae0864d7fbcd1cd905e3c6c5b069cc8b562

连接

如果用 LangChain 进行连接,必须注意要输入 http://localhost:8080http://(被坑了)