登录 注册

llama-cpp-python

去点 Star
开发者工具数据分析与数据处理AI 模型与开发框架
10,674
Stars
1,488
Forks
83
Watchers
715
Open Issues
MIT
许可证
Python
语言
2023-03-23
创建时间
2026-11-08
最近更新

项目能做什么

llama.cpp 的 Python 绑定库
来源:AI 基于仓库事实生成 · 内容以仓库实际 README 为准

使用说明 查看原始 README 原仓库文档

中文使用说明暂未生成。下面保留原仓库 README 摘录,命令与配置均以原文为准。
原始 README 摘录(英文原文,节选前 3000 字符)
<p align="center">
  <img src="https://raw.githubusercontent.com/abetlen/llama-cpp-python/main/docs/icon.svg" style="height: 5rem; width: 5rem">
</p>

#  Python Bindings for [`llama.cpp`](https://github.com/ggerganov/llama.cpp)

[![Documentation Status](https://readthedocs.org/projects/llama-cpp-python/badge/?version=latest)](https://llama-cpp-python.readthedocs.io/en/latest/?badge=latest)
[![Tests](https://github.com/abetlen/llama-cpp-python/actions/workflows/test.yaml/badge.svg?branch=main)](https://github.com/abetlen/llama-cpp-python/actions/workflows/test.yaml)
[![PyPI](https://img.shields.io/pypi/v/llama-cpp-python)](https://pypi.org/project/llama-cpp-python/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/llama-cpp-python)](https://pypi.org/project/llama-cpp-python/)
[![PyPI - License](https://img.shields.io/pypi/l/llama-cpp-python)](https://pypi.org/project/llama-cpp-python/)
[![PyPI - Downloads](https://static.pepy.tech/badge/llama-cpp-python/month)](https://pepy.tech/projects/llama-cpp-python)
[![Github All Releases](https://img.shields.io/github/downloads/abetlen/llama-cpp-python/total.svg?label=Github%20Downloads)]()

Simple Python bindings for **@ggerganov's** [`llama.cpp`](https://github.com/ggerganov/llama.cpp) library.
This package provides:

- Low-level access to C API via `ctypes` interface.
- High-level Python API for text completion
    - OpenAI-like API
    - [LangChain compatibility](https://python.langchain.com/docs/integrations/llms/llamacpp)
    - [LlamaIndex compatibility](https://docs.llamaindex.ai/en/stable/examples/llm/llama_2_llama_cpp.html)
- OpenAI compatible web server
    - [Local Copilot replacement](https://llama-cpp-python.readthedocs.io/en/latest/server/#code-completion)
    - [Function Calling support](https://llama-cpp-python.readthedocs.io/en/latest/server/#function-calling)
    - [Vision API support](https://llama-cpp-python.readthedocs.io/en/latest/server/#multimodal-models)
    - [Multiple Models](https://llama-cpp-python.readthedocs.io/en/latest/server/#configuration-and-multi-model-support)

Documentation is available at [https://llama-cpp-python.readthedocs.io/en/latest](https://llama-cpp-python.readthedocs.io/en/latest).

## Installation

Requirements:

  - Python 3.8+
  - C compiler
      - Linux: gcc or clang
      - Windows: Visual Studio or MinGW
      - MacOS: Xcode

To install the package, run:

```bash
pip install llama-cpp-python
```

This will also build `llama.cpp` from source and install it alongside this python package.

If this fails, add `--verbose` to the `pip install` see the full cmake build log.

**Pre-built Wheel (New)**

It is also possible to install a pre-built wheel with basic CPU support.

```bash
pip install llama-cpp-python \
  --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
```

### Installation Configuration

`llama.cpp` supports a number of hardware acceleration backends to speed up inference as well as backend specific options. See 
阅读完整原文

商业机会分析 AI 生成

跨平台一键式本地 LLM 运行时与应用分发引擎

产品构想解决 llama.cpp 编译链复杂(特别是在 Windows/多架构 GPU 下)的痛点,提供带有打包加密、自动检测驱动与量化模型更新的桌面/边缘端私有发行包。
核心功能免安装编译运行环境、驱动/架构自适应调度、量化模型权重加密与授权验证模块、极简本地 IPC/API 接口。
目标用户希望在桌面客户端、IoT 设备上离线集成 LLM 的独立软件开发者与企业客户。
难度/周期中等 · 1-2 个月 · 成本:极低(主要是跨平台测试硬件或云多架构虚拟机成本)
收费模式商业授权许可费、按分发客户端席位/授权量阶梯收费。
竞争风险各操作系统对底层 C++ 依赖及图形驱动更新频繁,长效维护适配工作量较大。
依据 数据支持的判断

轻量级私有化 OpenAI 兼容微服务网关平台

产品构想基于 llama-cpp-python 内置的 Web 框架,扩展企业级 API 路由、多模型轮替、并发排队、限流计费与本地日志审计功能。
核心功能完全兼容 OpenAI REST API、多卡/多模型并发调度、Token 消耗监控与权限管理、Web 管理控制台、健康检查与自愈机制。
目标用户有数据隐私合规要求的中小企业、内网自建 AI 基础设施的研发团队。
难度/周期较低 · 3-4 周 · 成本:低(基础测试服务器与原型开发)
收费模式按企业实例售卖闭源增强版(Open-core 模式)、技术支持与定制部署服务费。
竞争风险市面上存在 vLLM、Ollama 等强力竞争对手,在纯服务器端吞吐上可能面临同质化竞争。
依据 已验证事实

垂直领域本地化 RAG 与知识库一体化微引擎

产品构想结合 llama-cpp-python 构建超低资源消耗的单机离线文档检索与分析工具包,专为金融、法律或医疗私域数据处理优化。
核心功能本地向量化与文本切分管道、基于 llama-cpp 的 CPU/消费级显卡极致低延迟推理、离线格式(PDF/Word/Excel)即查即用、结构化问答导出。
目标用户对数据绝对不能出内网有强需求的专业人士(律师、分析师、研究所研发)。
难度/周期中等 · 2 个月 · 成本:低
收费模式专业版单机永久授权/按年订阅(SaaS/本地 License 激活码)。
竞争风险由于纯本地低算力限制,长文本上下文与大模型幻觉处理对调优要求极高。
依据 AI推测
AI 基于仓库公开数据分析生成,含推测成分,不构成收益承诺。
报告会保存到 个人中心

竞品与相似项目 GitHub Search 真实检索

项目中文简介Stars语言
Michael-A-Kuykendall/shimmy 中文介绍暂未生成
⚡ Pure-Rust WebGPU inference engine — OpenAI-API compatible,
6,016 Rust
Woolverine94/biniou 中文介绍暂未生成
a self-hosted webui for 30+ generative ai
1,153 Python
nomic-ai/pygpt4all 中文介绍暂未生成
Official supported Python bindings for llama.cpp + gpt4all
1,008 C++
TheBlewish/Web-LLM-Assistant-Llamacpp-Ollama 中文介绍暂未生成
A Python-based web-assisted large language model (LLM) searc
376 Python
jasonacox/TinyLLM 中文介绍暂未生成
Setup and run a local LLM and Chatbot using consumer grade h
354 JavaScript
thomasantony/llamacpp-python 中文介绍暂未生成
Python bindings for llama.cpp
199 C++
以上为通过 GitHub 官方 Search API 检索的相似项目,功能差异与优劣势需进一步人工确认,配置 AI 后可生成对比分析。

项目优势与风险

技术成熟度创建于 2023-03-23,近 30 天仍在推送,发布过 100 个 Release
社区活跃Star 10,674 / Fork 1,488 / Issue 715(数据支持,可自行核实)
许可证MIT
主要风险上游项目方向可能变化;同赛道竞争者较多(见竞品表);热度与需求不完全等价

安装与使用

快速开始(以仓库 README 为准)
git clone https://github.com/abetlen/llama-cpp-python.git
cd llama-cpp-python
docker compose up -d   # 或参考 README 中的 docker run 命令
阅读原仓库文档
术语说明:Docker=应用容器(把程序和依赖打包运行);API Key=调用外部服务的密钥;Git Clone=把仓库代码下载到本地。常见错误:API Key 未配置 / 端口占用 / 数据库连接失败,多数项目在 README 的 Troubleshooting 章节有说明。