




















说明:llama.cpp 官方已废弃原来的 Makefile 构建方式,推荐改用 CMake 构建方式 来编译模型工具和推理引擎。
如果本地有安装Visual Studio,使用 Visual Studio + CMake 进行构建(适用于 Windows 用户,兼容性最佳):
git clone https://github.com/ggml-org/llama.cpp cd path/llama.cpp mkdir build cd build # 使用 Visual Studio 生成项目 cmake .. -G "Visual Studio 17 2022" -A x64 -DLLAMA_CURL=OFF # 或 使用 w64devkit和mingw 生成项目 cmake .. -G "MinGW Makefiles" -DLLAMA_CURL=OFF
# 或一键默认
cmake -S .. -B build
# 编译 Release 模式 cmake --build . --config Release
如果一切正常,你会在 build/bin/Release 目录下看到生成的程序。
# 模型下载地址 https://xxx.com/filipealmeida/open-llama-7b-v2-open-instruct-GGUF/blob/main/ggml-model-Q4_0.gguf # 验证 ./llama-cli.exe -m .\models\7B\ggml-model-Q4_0.gguf -p "Tell me a joke." --n-predict 100
#用的是 Qwen3.5-9B-Chat 对话模型,但你没加对话模板,直接丢了一句英文提示词,模型不知道该怎么正常回答,只会输出分析 / 思考,不会给最终答案llama-cli.exe -m ./Qwen3.5-9B-Q4_K_M.gguf -p "Tell me a joke." --n-predict 2000 --ctx-size 4096 --temp 0.7
#非流式输出
--no-stream
llama-cli.exe -m ./Qwen3.5-9B-Q4_K_M.gguf --server --host 0.0.0.0 --port 8080 llama-cli.exe -m ./Qwen3.5-9B-Q4_K_M.gguf -p "Tell me a joke." --n-predict 2000 --ctx-size 4096 --temp 0.7 --server --host 0.0.0.0 --port 8080 #启动成功后,在浏览器打开 http://127.0.0.1:8080 #curl 命令 curl http://127.0.0.1:8080/completion \ -H "Content-Type: application/json" \ -d '{ "prompt": "Tell me a joke.", "temperature": 0.7, "n_predict": 512, "top_p": 0.9, "stop": ["\n\n"] }' #常用可传参数 { "prompt": "你的问题", // 必须 "temperature": 0.7, // 随机性 "n_predict": 1024, // 最大生成token "top_p": 0.9, "top_k": 40, "repeat_penalty": 1.1, // 重复惩罚 "stop": ["<|endoftext|>"] // 停止符 } #Python 调用示例 import requests url = "http://127.0.0.1:8080/completion" data = { "prompt": "Hello, who are you?", "temperature": 0.7, "n_predict": 512 } resp = requests.post(url, json=data) print(resp.json()["content"]) # http://127.0.0.1:8080/props
下载模型: https://www.modelscope.cn/models
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。