LLMlight is a Python library for ...
Project description
LLMlight
LLMlight is a Python package for running Large Language Models (LLMs) locally with minimal dependencies. It provides a simple interface to interact with various LLM models, including support for GGUF models and local API endpoints.
🌟 Key Features
- Local LLM Support: Run LLMs locally with minimal dependencies
- Full Promp Control:
- Query
- Instructions
- System
- Context
- Response Format
- Automatic formatting
- Temperature
- Top P
- Single Endpoint will Connect All Local Models: Compatible with various models including:
- Hermes-3-Llama-3.2-3B
- Mistral-7B-Grok
- OpenHermes-2.5-Mistral-7B
- Gemma-2-9B-IT
- Flexible Embedding Methods: Support for multiple embedding approaches:
- TF-IDF for structured documents
- Bag of Words (BOW)
- BERT for free text
- BGE-Small
- Advanced Retrieval Methods:
- Naive RAG with fixed chunking
- RSE (Relevant Segment Extraction)
- Advanced Preprocessing Methods: Advanced reasoning capabilities for complex queries.
- Global-reasoning
- chunk-wise
- Local Memory:
- Video memory for storage
- PDF Processing: Built-in support for reading and processing PDF documents
📚 Documentation & Resources
🚀 Quick Start
Installation
# Install from PyPI
pip install LLMlight
# Install from GitHub
pip install git+https://github.com/erdogant/LLMlight
Basic Usage with Endpoint
from LLMlight import LLMlight
# Initialize with default settings
client = LLMlight(endpoint='http://localhost:1234/v1/chat/completions')
# Run a simple query
response = client.prompt('What is the capital of France?',
context='The capital of France is Amsterdam.',
instructions='Do not argue with the information in the context. Only return the information from the context.')
print(response)
# According to the provided context, the capital of France is Amsterdam.
📊 Examples
1. Basic Usage with Local GGUF
from LLMlight import LLMlight
# Use with a local GGUF client
client = LLMlight(endpoint='path/to/your/client.gguf')
# Run a simple query
response = client.prompt('What is the capital of France?',
context='The capital of France is Amsterdam.',
instructions='Do not argue with the information in the context. Only return the information from the context.')
print(response)
# According to the provided context, the capital of France is Amsterdam.
2. Using with LM Studio
from LLMlight import LLMlight
# Initialize with LM Studio endpoint
client = LLMlight(endpoint="http://localhost:1234/v1/chat/completions")
# Run queries
response = client.prompt('Explain quantum computing in simple terms')
3. Check Available Models at Endpoint
from LLMlight import LLMlight
# Initialize client
from LLMlight import LLMlight
client = LLMlight(verbose='info')
modelnames = client.get_available_models(validate=False)
print(modelnames)
3. Query against PDF files
from LLMlight import LLMlight
# Initialize client
client = LLMlight()
# Read PDF
context = client.read_pdf(r'path/to/document.pdf', return_type='string')
# Query the document
response = client.prompt('Summarize the main points of this document',
context=context)
print(response)
4. Global Reasoning
from LLMlight import LLMlight
# Initialize client
client = LLMlight(preprocessing='global_reasoning')
# Read PDF
context = client.read_pdf(r'path/to/document.pdf', return_type='string')
# Query about the document
response = client.prompt('Summarize the main points of this document',
context=context,
instructions='Do not argue with the information in the context. Only return the information from the context.')
print(response)
5. Creating Local Memory Database
# Import library
from LLMlight import LLMlight
# Initialize with default settings
client = LLMlight(preprocessing=None, retrieval_method=None)
# Load existing video memory
client.memory_init(path_to_memory="knowledge_base.mp4")
# Append more documents: PDF/txt/etc files
filepaths = [r'c://path_to_your_files//article_1.pdf', r'c://path_to_your_files//my_file.txt']
client.memory_add(input_files=filepaths)
# Add text chunks if you like
client.memory_add(text=['Apes like USB sticks', 'Trees are mainly yellow'])
# Save Memory to disk. You can either create new one or overwite existing one.
client.memory_save(filepath="knowledge_base_with_more_data.mp4", overwrite=False)
# Run a simple query
response = client.prompt('What do apes like?', instructions='Only return the information from the context. Answer with maximum of 3 words, and starts with "Apes like: "')
print(response)
response = client.prompt('What is the capital of France?', context='The capital of France is Amsterdam.', instructions='Do not argue with the information in the context. Only return the information from the context.')
print(response)
response = client.prompt('Provide a summary of HyperSpectral from the pdf or text file.', instructions='Do not argue with the information in the context. Only return the information from the context.')
print(response)
6. Load Local Memory Database
# Import library
from LLMlight import LLMlight
# Initialize with default settings
client = LLMlight(preprocessing=None, retrieval_method=None, path_to_memory="knowledge_base.mp4")
# Create queries
response = client.prompt('What do apes like?', instructions='Only return the information from the context. Answer with maximum of 3 words, and starts with "Apes like: "')
print(response)
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
👥 Contributors
👨💻 Maintainer
- Erdogan Taskesen (@erdogant)
☕ Support
This library is free and open source. If you find it useful, consider supporting its development:
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
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 llmlight-0.3.0.tar.gz.
File metadata
- Download URL: llmlight-0.3.0.tar.gz
- Upload date:
- Size: 43.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cc0d051fe166bcc14f538c538c72d1c889c23eff214641eea0ac1c2c358f056
|
|
| MD5 |
374c083cd4c9064b88210ed76b76f974
|
|
| BLAKE2b-256 |
ffe561406c1c319c495e0c6fc8736fb61a5ea10767e0f8c54c69433c1dba8d82
|
File details
Details for the file llmlight-0.3.0-py3-none-any.whl.
File metadata
- Download URL: llmlight-0.3.0-py3-none-any.whl
- Upload date:
- Size: 46.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2318754ee066c00a4f0fa9ca0679626a1eb6577d03896798c9b1bb246fe426c9
|
|
| MD5 |
7eb475413036f860c5bb60e2e29982c7
|
|
| BLAKE2b-256 |
b4c715a8150646ddc06920b210b466a20872d2429b01d1c105ca3759deb57711
|