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 -e .
Supported Model IDs
Model ID using the format as such:
- HuggingFace repo with file name:
hf:<hf_repo_id>:<filename> - HuggingFace repo without file name:
hf:<hf_repo_id>, in this case the filename will beNone - 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,
),
),
)
result = lx.extract(
config=config,
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
),
)
result = lx.extract(
config=config,
...
)
Development
- Install in development mode:
uv pip install -e . - Run tests:
uv run test_plugin.py - Build package:
uv build - 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langextract_llamacpp-0.1.0.tar.gz.
File metadata
- Download URL: langextract_llamacpp-0.1.0.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2255036bccf0d8673d15a2d0a23f9d5d1516ac7f3e32ff93c71fdac1cd305726
|
|
| MD5 |
7ca40124c7bf389ae201fce9aa23b653
|
|
| BLAKE2b-256 |
a6dc8d82b9382178ad85e876ddd7b6c8e88fb3a327f102244e92cc8186125ea7
|
File details
Details for the file langextract_llamacpp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langextract_llamacpp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f1a499f96e93d30118b7547b71a720304b57d1655fbaa4e2bd9cd57c237bafb
|
|
| MD5 |
71b98afbaf2ca8c54e5c999b537addcd
|
|
| BLAKE2b-256 |
6841dbdc26b5935858dd025863dd39c9d2e6b8d11bda8925e1c51db375bce1a9
|