Skip to main content

LangExtract provider plugin for llama-cpp-python

Project description

LangExtract llama-cpp-python Provider

A provider plugin for LangExtract that supports llama-cpp-python 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 crate_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,
    ...
)

Development

  1. Install in development mode: uv pip install -e .
  2. Run tests: uv run test_plugin.py
  3. Build package: uv build
  4. Publish to PyPI: uv publish

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langextract_llamacpp-0.1.2.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langextract_llamacpp-0.1.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file langextract_llamacpp-0.1.2.tar.gz.

File metadata

  • Download URL: langextract_llamacpp-0.1.2.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for langextract_llamacpp-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7fa8539a384d93a9cff37966133aaa08d3a5581813127d051eab20c9e7ac4078
MD5 f9dcaa295df6ad6008f165fae1ad489e
BLAKE2b-256 1de190d3b5816a7a7feb0fb3367f46997a35547390f27cfab9ed8e3e315be7d4

See more details on using hashes here.

File details

Details for the file langextract_llamacpp-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: langextract_llamacpp-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for langextract_llamacpp-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6ffa693904ea419989e1b1b3b8854377ea0579171713d61c54f7f28e697479d6
MD5 955732d1d18de8cfaebb3f9c8f0f8e56
BLAKE2b-256 b89513813fe05f8528b90e9ea9528471b039c0b2c519cb93171d3aa1c36ab35c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page