























Flama 2.0 brings first-class support for generative AI: downloading, packaging, and serving large language models (LLMs) is now as simple as running a few commands in your terminal. No boilerplate code, no custom serving infrastructure, no configuration files. Just the CLI and a model.
In this post, we walk through the entire workflow: fetching a model from HuggingFace, interacting with it locally in your terminal, and serving it over HTTP with a production-ready API and a built-in chat interface. We will also show how a locally served model can power agentic workflows, using Claude CLI as a practical example.
Before we dive into the details, we recommend you to have the following resources at hand:
flama get
flama model runflama model streamflama serve commandflama getThe first step in serving an LLM with Flama is downloading and packaging a model into a .flm artifact (a Flama
Lightweight Model file). The flama get command handles this in a single step: it downloads the model weights and
configuration from a supported source and serialises them into the portable .flm format.
All examples in this post assume Flama has been installed with the LLM extras via uv:
Alternatively, you can run any command without a prior install by using
uvx --from "flama[llm,pydantic]" flama ..., but for brevity we assume Flama is already installed throughout.
Let us fetch a quantised version of Google's Gemma 4 model, optimised for Apple Silicon via the MLX Community:
Two options are required: --source tells Flama where to download from (currently HuggingFace), and --family declares
whether the artifact is a traditional machine-learning model (ml) or a generative model (llm). For large language
models, you always pass --family llm.
The output path defaults to <model-name>.flm with slashes replaced by underscores. If you prefer a custom path, pass
--output:
When you run flama get, the following happens:
--max-concurrent)..flm archive alongside a manifest that records the model family, the originating library, and metadata such as the model name and creation timestamp.The result is a self-contained, portable artifact. The .flm format is framework-agnostic: the same file runs on vLLM
(Linux with CUDA) or MLX (Apple Silicon), with Flama selecting the appropriate backend at load time based on what is
available in the environment.
Once you have a packaged .flm artifact, you can interact with it directly from your terminal using the
flama model command. No server, no HTTP, no code. This is invaluable for quick testing, prompt experimentation, and
pipeline scripting.
flama model runThe run sub-command sends a prompt to the model, waits for the full response, and prints it:
You can tune generation with --param flags:
For multi-turn conversations, use the --transport conversation flag and pass a JSON message list:
flama model streamFor an interactive, token-by-token experience (especially useful with larger responses), use stream instead of run.
Tokens are printed as they are generated, giving you immediate feedback:
The streaming output appears progressively in your terminal, character by character, making it feel like a real conversation. This is especially satisfying when working with models that produce longer, more detailed responses.
You can also ask the model about itself and the framework it runs on:
If you want to see multiple output channels (for instance, reasoning and output), pass --channel:
The true power of Flama lies in going from a local model to a production-ready HTTP API in a single command. No Python
code, no configuration files, no Docker images. Just flama serve.
flama serve commandTo serve the model we downloaded earlier:
That is it. A single command and your model is live behind a full HTTP API. Let us unpack what --model accepts:
file (required): Path to the .flm artifact.url: The URL prefix under which the model's endpoints are mounted (default: /).name: The resource name, used for OpenAPI tags and dependency injection.serving: Comma-separated list of dialects to enable (e.g., native,openai,anthropic,ollama). When omitted, all
dialects are mounted.params: Default generation parameters (e.g., temperature=0.7).You can serve multiple models in a single application:
And you can configure the server with the usual options:
When the native serving dialect is enabled (which it is by default), your model comes with a built-in chat interface
accessible at the /chat/ route (relative to the model's URL prefix). If you served the model at /, then navigate
to http://127.0.0.1:8000/chat/
You will be greeted with a polished, production-quality chat interface where you can type prompts and watch the model's responses stream in token by token. The interface renders Markdown, LaTeX math (via KaTeX), and Mermaid diagrams out of the box, so technical answers look exactly as intended.
The chat interface requires no frontend code, no build step, and no external dependencies. It is a self-contained
single-page application served directly from the framework. Every model you serve gets its own chat window (e.g.,
/gemma/chat/, /qwen/chat/), each connected to its respective model's streaming endpoint.
One of the most compelling use cases for a locally served LLM is powering agentic workflows. Because Flama exposes your model through industry-standard protocols (OpenAI, Anthropic, Ollama), any tool that speaks those protocols can use your local model as its backend.
A practical example is using the Claude CLI with a local model served by Flama. Instead of sending your prompts to Anthropic's servers, you can route them through your own locally-running model.
First, make sure your model is serving with the Anthropic dialect enabled:
Then, configure Claude CLI to use your local Flama endpoint by adding the following to your
~/.claude/settings.json (or .claude/settings.local.json for a project-specific override):
With this configuration in place, simply launch Claude CLI as usual:
Claude CLI will now route all its requests through your local Flama-served model instead of Anthropic's cloud. Here is what a typical interaction looks like:
Your agentic tasks (code generation, file editing, research) run entirely on your local hardware. This gives you:
This same pattern works with any agent framework that supports custom API base URLs: LangChain, CrewAI, AutoGen, or any custom tool that accepts a base URL configuration.
Flama 2.0 makes the journey from "I want to use an LLM" to "I have a production-ready API" as short as possible. The CLI provides three levels of interaction:
flama get: Download and package any model from HuggingFace into a portable .flm artifact.flama model: Interact with the model directly in your terminal, for quick testing and scripting.flama serve: Serve the model over HTTP with OpenAI/Anthropic/Ollama compatibility, a built-in chat interface,
and streaming support.No boilerplate Python code, no YAML configuration, no container orchestration. Just the CLI.
The fact that Flama speaks the protocols your tools already understand (OpenAI, Anthropic, Ollama) means that adopting a local model in your workflow requires changing nothing but a base URL. Your existing SDKs, agent frameworks, and chat interfaces work without modification.
In upcoming posts, we will explore how to build MCP servers with Flama to expose tools and resources to AI agents, and how to combine LLM serving with the Model Context Protocol for truly powerful agentic applications.
If you find Flama useful for building robust Machine Learning and Generative AI APIs, we'd be thrilled if you showed your support by giving us a ⭐ on GitHub. Your stars are the best fuel for our development efforts!
You can also stay updated with the latest news and development threads by following us on 𝕏.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。