No project description provided
Project description
LLM Transformer Wrappers
A Python library providing clean, easy-to-use wrapper classes for popular Hugging Face Transformer models. Simplifies working with different types of language models through a unified interface.
Features
- 🎯 Unified API - Consistent interface across different transformer types
- 🚀 Easy Integration - Simple setup and usage
- 🧠 Multiple AI Models - Support for text generation, understanding, and code completion
- 🔍 Advanced Search - Built-in semantic search capabilities
- ⚡ Efficient Processing - Batch operations and caching support
- 🧪 Well Tested - Comprehensive test suite with proper mocking
Quick Start
Installation
# For users - install from PyPI
pip install local-conjurer
Basic Usage
from local_conjurer import CodeGemma, T5, Bert
# Summon your personal conjurer
conjurer = CodeGemma()
# Cast your first spell! ✨
code = conjurer.conjure("def fibonacci(n):")
print(code) # Beautiful code appears!
Development Installation
# For developers - clone and install in development mode
git clone https://github.com/Nerdman4U/llm
cd llm
# Set up virtual environment
python -m venv .venv
source .venv/bin/activate # Linux/Mac
# or .venv\Scripts\activate # Windows
# Install development dependencies
pip install -r dev-requirements.txt
# Install in development mode
pip install -e .
# Run tests
pytest
# Dry-run
python src/local_conjurer
Environment Setup
For Google CodeGemma models, set your Hugging Face access token:
export HUGGING_FACE_TOKEN="your_hf_token_here"
Supported Models
🔤 T5 (Text-to-Text Transfer Transformer)
Purpose: General text-to-text generation (translation, summarization, question answering)
T5 treats every NLP task as a text-to-text problem. Excellent for translation, summarization, and text transformation tasks.
from local_conjurer.extension.t5_transformer import T5Transformer
ai = T5Transformer()
response = ai.conjure(
"Translate English to French: The house is wonderful.",
generation_kwargs={"max_length": 50},
).value
print(response) # Output: "La maison est merveilleuse."
🧠 BERT (Bidirectional Encoder Representations)
Purpose: Text understanding, similarity, and semantic search
BERT excels at understanding text context and meaning. Perfect for similarity comparison, semantic search, and text classification.
from local_conjurer.extension.bert_transformer import BertTransformer
ai = BertTransformer()
documents = [
"The cat sat on the mat",
"Dogs are loyal animals",
"Felines are independent creatures",
"Python is a programming language",
]
results = ai.search("cats and kittens", documents, top_k=3)
for doc, score in results:
print(f"{score:.3f}: {doc}")
Additional BERT capabilities:
# Text similarity
score = ai.similarity("I love cats", "I adore felines") # Returns ~0.85
# Batch similarity
scores = ai.batch_similarity("machine learning", documents)
💻 CodeGemma (Code Generation)
Purpose: Code completion, generation, and programming assistance
CodeGemma specializes in understanding and generating code. Great for code completion, refactoring suggestions, and programming help.
from local_conjurer.extension.code_gemma_transformer import CodeGemmaTransformer
ai = CodeGemmaTransformer()
code_prompt = """
class Person:
def __init__(self, name):
self.name = name
# Add age attribute with getter and setter
"""
response = ai.conjure(code_prompt, generation_kwargs={"max_length": 150}).value
print(response)
Advanced code generation:
# Function completion
code = ai.complete_function(
"def fibonacci(n):",
"Calculate fibonacci recursively"
)
# Code refactoring
better_code = ai.refactor_code(
"old_code_here",
"Make it more efficient and add error handling"
)
🏢 Salesforce CodeT5+ (Advanced Code Understanding)
Purpose: Enterprise-grade code generation and understanding
Salesforce's CodeT5+ provides advanced code generation capabilities with better understanding of code context and structure.
from local_conjurer.extension.salesforce_transformer import SalesforceTransformer
ai = SalesforceTransformer()
response = ai.conjure("def calculate_fibonacci(n):")
print(response)
Advanced Usage
Generation Options
All transformers support flexible generation parameters:
# Multiple alternative outputs
result = ai.conjure(
"Your prompt here",
generate_type="multiple",
num_sequences=3,
temperature=0.8
)
# Batch processing
result = ai.conjure(
None,
generate_type="batch",
input_texts=["prompt1", "prompt2", "prompt3"]
)
# Generation with confidence scores
result = ai.conjure(
"Your prompt here",
generate_type="with_scores",
temperature=0.7
)
Caching
Models are cached locally for faster subsequent loads:
# Default cache location: ./cache
# Custom cache location:
ai = T5Transformer(cache_dir="/custom/cache/path")
API Reference
Common Methods
All transformer classes inherit these methods:
conjure(prompt, \*\*kwargs)- Main generation method with multiple modesconjure_multiple(prompt, \*\*kwargs)- Multiple varying resultsconjure_with_scores(prompt, \*\*kwargs)- With scoresconjure_batches(prompt, \*\*kwargs)- Generate with batchesdecode(tokens)- Convert tokens back to textget_model()- Access the underlying Hugging Face modelget_tokenizer()- Access the tokenizer
BERT-Specific Methods
similarity(text1, text2)- Calculate similarity between textssearch(query, documents, top_k)- Semantic search through documentsget_embeddings(text)- Get text embeddingsbatch_similarity(query, documents)- Efficient batch similarity
CodeGemma-Specific Methods
generate_code(prompt)- Optimized code generationcomplete_function(signature, description)- Function completionrefactor_code(code, instruction)- Code refactoring
Testing
Run the comprehensive test suite:
# All tests
pyt
# Specific transformer tests
python -m pytest tests/extension/test_t5_transformer.py
python -m pytest tests/extension/test_bert_transformer.py
Configuration
Models can be customized during initialization:
ai = T5Transformer(
transformers_model_name="t5-large", # Use larger model
cache_dir="./my_cache", # Custom cache location
device="cuda" # Use GPU if available
)
Requirements
- Python 3.8+
- PyTorch
- Transformers
- Additional dependencies in
requirements.txt
Contributing
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Run the test suite
- Submit a pull request
License
[Your License Here]
Need help? Check the test files in tests/extension/ for more usage examples!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 local_conjurer-0.3.2-py3-none-any.whl.
File metadata
- Download URL: local_conjurer-0.3.2-py3-none-any.whl
- Upload date:
- Size: 27.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a70c513bee0d1f204e1958489021af41fda7b807acde169dbee0bcf7d6690de0
|
|
| MD5 |
abcbd411fe8ed7589ee9308edc3708f5
|
|
| BLAKE2b-256 |
7ded4a6814db3e5689897c3b87b16ee4aedf4ea9cd6c5342bf87a439644bc8d4
|