Skip to main content

LangExtract llama-cpp-python Provider

PyPI version

A provider plugin for LangExtract that supports llama.cpp models.

Installation

pip install langextract-llamacpp

Supported Model IDs

Model ID using the format as such:

  1. HuggingFace repo with file name: hf:<hf_repo_id>:<filename>
  2. HuggingFace repo without file name: hf:<hf_repo_id>, in this case the filename will be None
  3. Local file: file:<path_to_model>

hf_repo_id is existing huggingface model repository.

Usage

Using HuggingFace repository; this will call Llama.from_pretrained(...).

import langextract as lx

config = lx.factory.ModelConfig(
    model_id="hf:MaziyarPanahi/Mistral-7B-Instruct-v0.3-GGUF:*Q4_K_M.gguf",
    provider="LlamaCppLanguageModel", # optional as hf: will resolve to the model
    provider_kwargs=dict(
        n_gpu_layers=-1,
        n_ctx=4096,
        verbose=False,
        completion_kwargs=dict(
            temperature=1.1,
            seed=42,
        ),
    ),
)

model = lx.factory.create_model(config)

result = lx.extract(
    model=model,
    text_or_documents="Your input text",
    prompt_description="Extract entities",
    examples=[...],
)

Using local file path; this will call Llama(...).

import langextract as lx

config = lx.factory.ModelConfig(
    model_id="file:Mistral-7B-Instruct-v0.3.Q4_K_M.gguf",
    provider="LlamaCppLanguageModel", # optional as file: will resolve to the model
    provider_kwargs=dict(
        ...
    ),
)

...

For provider_kwargs refer to documentation for Llama class.

For completion_kwargs refer to documentation for create_chat_completion method.

OpenAI compatible Web Server

When using llama-cpp-python server (or llama.cpp), you can use OpenAILanguageModel in the provider field as they implement OpenAI compatible web server.

To set this up, choose OpenAILanguageModel as the provider and supply the server’s base URL and an API key (any value) in provider_kwargs. The model_id field is optional.

config = lx.factory.ModelConfig(
    model_id="local", # optional
    provider="OpenAILanguageModel", # explicitly set the provider to `OpenAILanguageModel`
    provider_kwargs=dict(
        base_url="http://localhost:8000/v1/",
        api_key="llama-cpp", # any value; mandatory
    ),
)

model = lx.factory.create_model(config)

result = lx.extract(
    model=model,
    ...
)

Metadata

Release files for langextract-llamacpp 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langextract-llamacpp 0.1.3
File Size Uploaded
langextract_llamacpp-0.1.3.tar.gz 3.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langextract-llamacpp 0.1.3
File Interpreter ABI Platform
langextract_llamacpp-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 8.0 kB

Release files / langextract_llamacpp-0.1.3.tar.gz

Download URL langextract_llamacpp-0.1.3.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1b00230b75a02a89a1bfb4664a11f0a692a9951a0efb7fa1ac0a1d327f43b708
BLAKE2b-256 checksum
How to use checksums
ae8b1f4d2f89b7e678aad563626e45311b89c99756f0a1e564aeae846365788c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / langextract_llamacpp-0.1.3-py3-none-any.whl

Download URL langextract_llamacpp-0.1.3-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac45695b8eae6d2ac5fdac427b61e9f2bd8a3ec7149e245c375be2c4ce5ddc1f
BLAKE2b-256 checksum
How to use checksums
7537bd00f887d399b099a37308e452460d8c67858930e68831790a9a1e7a6a10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page