Packages
liter_llm
1.0.0-rc.3
1.11.3
1.11.2
1.11.1
1.11.0
1.10.1
1.10.0
1.9.3
1.9.0
1.9.0-rc.2
1.9.0-rc.1
1.8.2
1.8.1
1.8.0
1.7.6
1.7.5
1.7.4
1.7.3
1.7.2
1.7.1
1.6.4
1.6.3
1.6.2
1.5.1
1.5.0
1.4.1
1.4.0-rc.61
1.4.0-rc.60
1.4.0-rc.59
1.4.0-rc.58
1.4.0-rc.57
1.4.0-rc.56
1.4.0-rc.55
1.4.0-rc.53
1.4.0-rc.52
1.4.0-rc.50
1.4.0-rc.48
1.4.0-rc.47
1.4.0-rc.46
1.4.0-rc.45
1.4.0-rc.44
1.4.0-rc.43
1.4.0-rc.39
1.4.0-rc.38
1.4.0-rc.37
1.4.0-rc.36
1.4.0-rc.35
1.4.0-rc.34
1.4.0-rc.33
1.4.0-rc.32
1.4.0-rc.31
1.4.0-rc.30
1.4.0-rc.27
1.4.0-rc.26
1.4.0-rc.25
1.4.0-rc.24
1.4.0-rc.22
1.4.0-rc.21
1.4.0-rc.20
1.4.0-rc.19
1.4.0-rc.18
1.4.0-rc.17
1.4.0-rc.16
1.4.0-rc.14
1.4.0-rc.13
1.4.0-rc.11
1.2.2
1.2.1
1.2.0
1.1.1
1.1.0
1.0.0
1.0.0-rc.9
1.0.0-rc.8
1.0.0-rc.7
1.0.0-rc.6
1.0.0-rc.5
1.0.0-rc.4
1.0.0-rc.3
1.0.0-rc.2
Universal LLM API client with Rust-powered polyglot bindings.
Current section
Files
Jump to
Current section
Files
lib/liter_llm/native.ex
defmodule LiterLlm.Native do
@moduledoc """
Rustler NIF bindings for liter-llm.
This module loads the precompiled Rust NIF (`liter_llm_rustler`) and
exposes raw NIF functions. Each function accepts JSON strings and returns
JSON strings; use `LiterLlm.Client` for the idiomatic Elixir interface.
## Building from source
Set the environment variable `LITER_LLM_BUILD=1` to compile the NIF from
source instead of downloading a precompiled binary:
LITER_LLM_BUILD=1 mix compile
This requires a Rust toolchain (Cargo ≥ 1.75) on the build machine.
## Precompiled targets
| Platform | Target triple |
|----------|--------------|
| macOS (Apple Silicon) | `aarch64-apple-darwin` |
| Linux x86_64 | `x86_64-unknown-linux-gnu` |
| Linux aarch64 | `aarch64-unknown-linux-gnu` |
"""
@version "1.0.0-rc.1"
use RustlerPrecompiled,
otp_app: :liter_llm,
crate: "liter_llm_rustler",
base_url: "https://github.com/kreuzberg-dev/liter-llm/releases/download/v#{@version}",
version: @version,
force_build: System.get_env("LITER_LLM_BUILD") in ["1", "true"],
targets: [
"aarch64-apple-darwin",
"aarch64-unknown-linux-gnu",
"x86_64-unknown-linux-gnu"
],
nif_versions: ["2.16", "2.17"]
# ── Core inference ────────────────────────────────────────────────────────
@doc """
Send a chat completion request.
- `config_json` — JSON string: `{"api_key":"...", "base_url":"...", "max_retries":3}`
- `request_json` — JSON string matching the OpenAI chat completion request shape
Returns `{:ok, response_json}` or `{:error, message}`.
"""
@spec chat(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def chat(_config_json, _request_json), do: :erlang.nif_error(:nif_not_loaded)
@doc "Send an embedding request."
@spec embed(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def embed(_config_json, _request_json), do: :erlang.nif_error(:nif_not_loaded)
@doc "List available models."
@spec list_models(String.t()) :: {:ok, String.t()} | {:error, String.t()}
def list_models(_config_json), do: :erlang.nif_error(:nif_not_loaded)
@doc "Generate an image from a text prompt."
@spec image_generate(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def image_generate(_config_json, _request_json), do: :erlang.nif_error(:nif_not_loaded)
@doc "Generate speech audio from text. Returns raw audio bytes."
@spec speech(String.t(), String.t()) :: {:ok, binary()} | {:error, String.t()}
def speech(_config_json, _request_json), do: :erlang.nif_error(:nif_not_loaded)
@doc "Transcribe audio to text."
@spec transcribe(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def transcribe(_config_json, _request_json), do: :erlang.nif_error(:nif_not_loaded)
@doc "Check content against moderation policies."
@spec moderate(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def moderate(_config_json, _request_json), do: :erlang.nif_error(:nif_not_loaded)
@doc "Rerank documents by relevance to a query."
@spec rerank(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def rerank(_config_json, _request_json), do: :erlang.nif_error(:nif_not_loaded)
# ── File management ───────────────────────────────────────────────────────
@doc "Upload a file."
@spec create_file(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def create_file(_config_json, _request_json), do: :erlang.nif_error(:nif_not_loaded)
@doc "Retrieve metadata for a file."
@spec retrieve_file(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def retrieve_file(_config_json, _file_id), do: :erlang.nif_error(:nif_not_loaded)
@doc "Delete a file."
@spec delete_file(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def delete_file(_config_json, _file_id), do: :erlang.nif_error(:nif_not_loaded)
@doc "List files. Pass `\"null\"` as query_json to list all files."
@spec list_files(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def list_files(_config_json, _query_json), do: :erlang.nif_error(:nif_not_loaded)
@doc "Retrieve the raw content of a file."
@spec file_content(String.t(), String.t()) :: {:ok, binary()} | {:error, String.t()}
def file_content(_config_json, _file_id), do: :erlang.nif_error(:nif_not_loaded)
# ── Batch management ──────────────────────────────────────────────────────
@doc "Create a new batch job."
@spec create_batch(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def create_batch(_config_json, _request_json), do: :erlang.nif_error(:nif_not_loaded)
@doc "Retrieve a batch by ID."
@spec retrieve_batch(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def retrieve_batch(_config_json, _batch_id), do: :erlang.nif_error(:nif_not_loaded)
@doc "List batches. Pass `\"null\"` as query_json to list all batches."
@spec list_batches(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def list_batches(_config_json, _query_json), do: :erlang.nif_error(:nif_not_loaded)
@doc "Cancel an in-progress batch."
@spec cancel_batch(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def cancel_batch(_config_json, _batch_id), do: :erlang.nif_error(:nif_not_loaded)
# ── Response management ───────────────────────────────────────────────────
@doc "Create a new response."
@spec create_response(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def create_response(_config_json, _request_json), do: :erlang.nif_error(:nif_not_loaded)
@doc "Retrieve a response by ID."
@spec retrieve_response(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def retrieve_response(_config_json, _response_id), do: :erlang.nif_error(:nif_not_loaded)
@doc "Cancel an in-progress response."
@spec cancel_response(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
def cancel_response(_config_json, _response_id), do: :erlang.nif_error(:nif_not_loaded)
end