llamafile

llamafile 专家:将大型语言模型打包成可在任意操作系统(Linux、macOS、Windows、FreeBSD)上运行的可执行文件的工具,无需安装。帮助开发者创建便携式 AI 应用,可离线运行模型,并将 LLM 分发为自带 Web 界面且兼容 OpenAI API 的独立二进制文件。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "llamafile":https://skillpi.com/zh/skills/deepskill-40e88300a1bb8fc818545a2dd3669b3f1254cee1f6c01730dc6535f1f2bfbafe。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

llamafile 专家:将大型语言模型打包成可在任意操作系统(Linux、macOS、Windows、FreeBSD)上运行的可执行文件的工具,无需安装。帮助开发者创建便携式 AI 应用,可离线运行模型,并将 LLM 分发为自带 Web 界面且兼容 OpenAI API 的独立二进制文件。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: llamafile
description: Expert guidance for llamafile, the tool that packages LLMs into single executable files that run on any OS (Linux, macOS, Windows, FreeBSD) without installation. Helps developers create portable AI applications, run models offline, and distribute LLMs as self-contained binaries with built-in web UI and OpenAI-compatible API.
license: Apache-2.0
compatibility: No special requirements
metadata:
  author: terminal-skills
  version: 1.0.0
  category: data-ai
  tags:
  - local-llm
  - inference
  - portable
  - single-file
  - offline

llamafile — Single-File LLM Executables

Overview

Llamafile, the tool that packages LLMs into single executable files that run on any OS (Linux, macOS, Windows, FreeBSD) without installation. Helps developers create portable AI applications, run models offline, and distribute LLMs as self-contained binaries with built-in web UI and OpenAI-compatible API.

Instructions

Running a llamafile

# Download a pre-built llamafile (model + runtime in one file)
wget https://huggingface.co/Mozilla/Meta-Llama-3.1-8B-Instruct-llamafile/resolve/main/Meta-Llama-3.1-8B-Instruct.Q5_K_M.llamafile

# Make it executable and run
chmod +x Meta-Llama-3.1-8B-Instruct.Q5_K_M.llamafile
./Meta-Llama-3.1-8B-Instruct.Q5_K_M.llamafile

# Opens web UI at http://localhost:8080
# Also serves OpenAI-compatible API at http://localhost:8080/v1

# Run with specific settings
./Meta-Llama-3.1-8B-Instruct.Q5_K_M.llamafile \
  --host 0.0.0.0 \
  --port 8080 \
  --ctx-size 8192 \
  --threads 8 \
  --gpu auto                  # Use GPU if available (CUDA, Metal, ROCm)

Creating Custom llamafiles

# Build a llamafile from any GGUF model

# 1. Download the llamafile runtime
wget https://github.com/Mozilla-Ocho/llamafile/releases/latest/download/llamafile
chmod +x llamafile

# 2. Download a GGUF model from HuggingFace
wget https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF/resolve/main/mistral-7b-instruct-v0.2.Q5_K_M.gguf

# 3. Create the llamafile (packages model + runtime)
./llamafile \
  --model mistral-7b-instruct-v0.2.Q5_K_M.gguf \
  --create my-assistant.llamafile

# 4. The resulting file runs anywhere — no dependencies
./my-assistant.llamafile --port 8080

# With a custom system prompt baked in
./llamafile \
  --model mistral-7b-instruct-v0.2.Q5_K_M.gguf \
  --system-prompt "You are a customer support assistant for Acme Inc. Be helpful and concise." \
  --create acme-support-bot.llamafile

OpenAI-Compatible API

// src/local-llm.ts — Use llamafile with any OpenAI-compatible SDK
import OpenAI from "openai";

// Point to the local llamafile server
const llm = new OpenAI({
  apiKey: "not-needed",                    // llamafile doesn't require auth
  baseURL: "http://localhost:8080/v1",
});

async function chat(prompt: string) {
  const response = await llm.chat.completions.create({
    model: "local",                        // Model name doesn't matter for llamafile
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      { role: "user", content: prompt },
    ],
    temperature: 0.7,
    max_tokens: 512,
  });
  return response.choices[0].message.content;
}

// Streaming works too
async function streamChat(prompt: string) {
  const stream = await llm.chat.completions.create({
    model: "local",
    messages: [{ role: "user", content: prompt }],
    stream: true,
  });
  for await (const chunk of stream) {
    process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
  }
}

// Embeddings
async function embed(text: string) {
  const response = await llm.embeddings.create({
    model: "local",
    input: text,
  });
  return response.data[0].embedding;
}

CLI Usage (No Server)

# One-shot completion (no server, just stdin → stdout)
echo "Explain Docker in one sentence:" | ./llamafile --cli

# With a system prompt
./llamafile --cli \
  --system "You are a Linux expert. Answer in one line." \
  --prompt "How do I find files larger than 100MB?"

# Process a file
cat error_log.txt | ./llamafile --cli \
  --system "Analyze this error log. Identify the root cause."

# Batch processing with a script
for file in reports/*.txt; do
  echo "=== $file ==="
  cat "$file" | ./llamafile --cli \
    --system "Summarize this report in 3 bullet points." \
    --temp 0
done

Embedding in Applications

# Run llamafile as a subprocess from your application
import subprocess
import requests

class LlamafileServer:
    """Manage a llamafile server as a subprocess."""

    def __init__(self, model_path: str, port: int = 8080):
        self.model_path = model_path
        self.port = port
        self.process = None
        self.base_url = f"http://localhost:{port}"

    def start(self):
        self.process = subprocess.Popen(
            [self.model_path, "--port", str(self.port), "--host", "127.0.0.1"],
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )
        # Wait for server to be ready
        import time
        for _ in range(30):
            try:
                requests.get(f"{self.base_url}/health", timeout=1)
                return
            except requests.ConnectionError:
                time.sleep(1)
        raise RuntimeError("llamafile failed to start")

    def chat(self, prompt: str, system: str = "") -> str:
        response = requests.post(
            f"{self.base_url}/v1/chat/completions",
            json={
                "messages": [
                    {"role": "system", "content": system},
                    {"role": "user", "content": prompt},
                ],
                "temperature": 0.7,
            },
        )
        return response.json()["choices"][0]["message"]["content"]

    def stop(self):
        if self.process:
            self.process.terminate()
            self.process.wait()

# Usage
server = LlamafileServer("./my-model.llamafile", port=8081)
server.start()
answer = server.chat("What is the capital of France?")
server.stop()

Installation

# No installation needed — llamafile IS the installation
# Download and run. That's it.

# For creating llamafiles:
wget https://github.com/Mozilla-Ocho/llamafile/releases/latest/download/llamafile
chmod +x llamafile

Examples

Example 1: Integrating Llamafile into an existing application

User request:

Add Llamafile to my Next.js app for the AI chat feature. I want streaming responses.

The agent installs the SDK, creates an API route that initializes the Llamafile client, configures streaming, selects an appropriate model, and wires up the frontend to consume the stream. It handles error cases and sets up proper environment variable management for the API key.

Example 2: Optimizing creating custom llamafiles performance

User request:

My Llamafile calls are slow and expensive. Help me optimize the setup.

The agent reviews the current implementation, identifies issues (wrong model selection, missing caching, inefficient prompting, no batching), and applies optimizations specific to Llamafile's capabilities — adjusting model parameters, adding response caching, and implementing retry logic with exponential backoff.

Guidelines

  1. Single file = single deployment — Distribute your AI as one file; users double-click to run, no Python/Docker/CUDA setup
  2. GPU auto-detection — llamafile automatically uses GPU when available (CUDA, Metal, ROCm); falls back to CPU
  3. Quantized models for speed — Use Q5_K_M or Q4_K_M quantizations; they're 3-5x smaller with minimal quality loss
  4. OpenAI API compatibility — Use the same code for local llamafile and cloud APIs; swap by changing the base URL
  5. CLI mode for scripts — Use --cli for batch processing; pipe text in, get completions out, no server needed
  6. Air-gapped environments — llamafile runs completely offline; ideal for sensitive data or environments without internet
  7. Context size matters — Set --ctx-size based on your use case; larger contexts need more RAM
  8. One model per llamafile — Each llamafile contains one model; run multiple on different ports for model routing

当前收录版本

1.0.0

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值82/100

亮点

  • 提供 llamafile 的专业指导,帮助用户创建便携式 AI 应用、离线运行模型、分发 LLM 为独立二进制文件
  • 覆盖多种使用场景:本地 LLM 部署、开发辅助、AI 应用集成
触发精准88/100

亮点

  • description 明确描述了 llamafile 的功能和使用场景
  • 触发词覆盖合理(如 'llamafile', 'portable AI', 'offline LLM', 'single executable' 等),边界清晰
结构规范92/100

亮点

  • 文档结构清晰,包含 Overview、Instructions、Installation、Examples、Guidelines 等章节
  • 步骤划分明确,有端到端示例,frontmatter 完整
执行可靠75/100

待提升项

  • 异常处理覆盖不足 原报告严重程度:轻微

    部分命令缺少错误处理,未显式处理网络下载失败、模型加载错误等异常情况

    改进建议:建议在关键步骤添加错误处理说明,如 wget 失败重试、模型加载异常捕获等

亮点

  • 提供了多种使用方式的代码示例(bash、TypeScript、Python)
  • 工具来源明确(HuggingFace、GitHub),参数说明清晰
证据可验 (前四项均值)84/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

文档引用的域名或地址

这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。

  • github.com
  • huggingface.co
  • localhost

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。