# 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
```bash
# For users - install from PyPI
pip install local-conjurer
```
### Basic Usage
```python
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
```bash
# 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:
```bash
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.
```python
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.
```python
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:**
```python
# 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.
```python
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:**
```python
# 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.
```python
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:
```python
# 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:
```python
# 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 modes
- **`conjure_multiple(prompt, \*\*kwargs)`** - Multiple varying results
- **`conjure_with_scores(prompt, \*\*kwargs)`** - With scores
- **`conjure_batches(prompt, \*\*kwargs)`** - Generate with batches
- **`decode(tokens)`** - Convert tokens back to text
- **`get_model()`** - Access the underlying Hugging Face model
- **`get_tokenizer()`** - Access the tokenizer
### BERT-Specific Methods
- **`similarity(text1, text2)`** - Calculate similarity between texts
- **`search(query, documents, top_k)`** - Semantic search through documents
- **`get_embeddings(text)`** - Get text embeddings
- **`batch_similarity(query, documents)`** - Efficient batch similarity
### CodeGemma-Specific Methods
- **`generate_code(prompt)`** - Optimized code generation
- **`complete_function(signature, description)`** - Function completion
- **`refactor_code(code, instruction)`** - Code refactoring
## Testing
Run the comprehensive test suite:
```bash
# 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:
```python
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
1. Fork the repository
2. Create a feature branch
3. Add tests for new functionality
4. Run the test suite
5. Submit a pull request
## License
[Your License Here]
---
**Need help?** Check the test files in `tests/extension/` for more usage examples!
Raw data
{
"_id": null,
"home_page": null,
"name": "local-conjurer",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "ai, llm, transformers, code-generation, text-generation",
"author": null,
"author_email": "Joni T\u00f6yryl\u00e4 <info@jonitoyryla.eu>",
"download_url": null,
"platform": null,
"description": "# LLM Transformer Wrappers\n\nA 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.\n\n## Features\n\n- \ud83c\udfaf **Unified API** - Consistent interface across different transformer types\n- \ud83d\ude80 **Easy Integration** - Simple setup and usage\n- \ud83e\udde0 **Multiple AI Models** - Support for text generation, understanding, and code completion\n- \ud83d\udd0d **Advanced Search** - Built-in semantic search capabilities\n- \u26a1 **Efficient Processing** - Batch operations and caching support\n- \ud83e\uddea **Well Tested** - Comprehensive test suite with proper mocking\n\n## Quick Start\n\n### Installation\n\n```bash\n# For users - install from PyPI\npip install local-conjurer\n```\n\n### Basic Usage\n\n```python\nfrom local_conjurer import CodeGemma, T5, Bert\n\n# Summon your personal conjurer\nconjurer = CodeGemma()\n\n# Cast your first spell! \u2728\ncode = conjurer.conjure(\"def fibonacci(n):\")\nprint(code) # Beautiful code appears!\n```\n\n### Development Installation\n\n```bash\n# For developers - clone and install in development mode\ngit clone https://github.com/Nerdman4U/llm\ncd llm\n\n# Set up virtual environment\npython -m venv .venv\nsource .venv/bin/activate # Linux/Mac\n# or .venv\\Scripts\\activate # Windows\n\n# Install development dependencies\npip install -r dev-requirements.txt\n\n# Install in development mode\npip install -e .\n\n# Run tests\npytest\n\n# Dry-run\npython src/local_conjurer\n```\n\n### Environment Setup\n\nFor Google CodeGemma models, set your Hugging Face access token:\n\n```bash\nexport HUGGING_FACE_TOKEN=\"your_hf_token_here\"\n```\n\n## Supported Models\n\n### \ud83d\udd24 **T5 (Text-to-Text Transfer Transformer)**\n\n**Purpose**: General text-to-text generation (translation, summarization, question answering)\n\nT5 treats every NLP task as a text-to-text problem. Excellent for translation, summarization, and text transformation tasks.\n\n```python\nfrom local_conjurer.extension.t5_transformer import T5Transformer\n\nai = T5Transformer()\nresponse = ai.conjure(\n \"Translate English to French: The house is wonderful.\",\n generation_kwargs={\"max_length\": 50},\n).value\nprint(response) # Output: \"La maison est merveilleuse.\"\n```\n\n### \ud83e\udde0 **BERT (Bidirectional Encoder Representations)**\n\n**Purpose**: Text understanding, similarity, and semantic search\n\nBERT excels at understanding text context and meaning. Perfect for similarity comparison, semantic search, and text classification.\n\n```python\nfrom local_conjurer.extension.bert_transformer import BertTransformer\n\nai = BertTransformer()\ndocuments = [\n \"The cat sat on the mat\",\n \"Dogs are loyal animals\",\n \"Felines are independent creatures\",\n \"Python is a programming language\",\n]\nresults = ai.search(\"cats and kittens\", documents, top_k=3)\nfor doc, score in results:\n print(f\"{score:.3f}: {doc}\")\n```\n\n**Additional BERT capabilities:**\n\n```python\n# Text similarity\nscore = ai.similarity(\"I love cats\", \"I adore felines\") # Returns ~0.85\n\n# Batch similarity\nscores = ai.batch_similarity(\"machine learning\", documents)\n```\n\n### \ud83d\udcbb **CodeGemma (Code Generation)**\n\n**Purpose**: Code completion, generation, and programming assistance\n\nCodeGemma specializes in understanding and generating code. Great for code completion, refactoring suggestions, and programming help.\n\n```python\nfrom local_conjurer.extension.code_gemma_transformer import CodeGemmaTransformer\n\nai = CodeGemmaTransformer()\ncode_prompt = \"\"\"\nclass Person:\n def __init__(self, name):\n self.name = name\n # Add age attribute with getter and setter\n\"\"\"\nresponse = ai.conjure(code_prompt, generation_kwargs={\"max_length\": 150}).value\nprint(response)\n```\n\n**Advanced code generation:**\n\n```python\n# Function completion\ncode = ai.complete_function(\n \"def fibonacci(n):\",\n \"Calculate fibonacci recursively\"\n)\n\n# Code refactoring\nbetter_code = ai.refactor_code(\n \"old_code_here\",\n \"Make it more efficient and add error handling\"\n)\n```\n\n### \ud83c\udfe2 **Salesforce CodeT5+ (Advanced Code Understanding)**\n\n**Purpose**: Enterprise-grade code generation and understanding\n\nSalesforce's CodeT5+ provides advanced code generation capabilities with better understanding of code context and structure.\n\n```python\nfrom local_conjurer.extension.salesforce_transformer import SalesforceTransformer\n\nai = SalesforceTransformer()\nresponse = ai.conjure(\"def calculate_fibonacci(n):\")\nprint(response)\n```\n\n## Advanced Usage\n\n### Generation Options\n\nAll transformers support flexible generation parameters:\n\n```python\n# Multiple alternative outputs\nresult = ai.conjure(\n \"Your prompt here\",\n generate_type=\"multiple\",\n num_sequences=3,\n temperature=0.8\n)\n\n# Batch processing\nresult = ai.conjure(\n None,\n generate_type=\"batch\",\n input_texts=[\"prompt1\", \"prompt2\", \"prompt3\"]\n)\n\n# Generation with confidence scores\nresult = ai.conjure(\n \"Your prompt here\",\n generate_type=\"with_scores\",\n temperature=0.7\n)\n```\n\n### Caching\n\nModels are cached locally for faster subsequent loads:\n\n```python\n# Default cache location: ./cache\n# Custom cache location:\nai = T5Transformer(cache_dir=\"/custom/cache/path\")\n```\n\n## API Reference\n\n### Common Methods\n\nAll transformer classes inherit these methods:\n\n- **`conjure(prompt, \\*\\*kwargs)`** - Main generation method with multiple modes\n- **`conjure_multiple(prompt, \\*\\*kwargs)`** - Multiple varying results\n- **`conjure_with_scores(prompt, \\*\\*kwargs)`** - With scores\n- **`conjure_batches(prompt, \\*\\*kwargs)`** - Generate with batches\n- **`decode(tokens)`** - Convert tokens back to text\n- **`get_model()`** - Access the underlying Hugging Face model\n- **`get_tokenizer()`** - Access the tokenizer\n\n### BERT-Specific Methods\n\n- **`similarity(text1, text2)`** - Calculate similarity between texts\n- **`search(query, documents, top_k)`** - Semantic search through documents\n- **`get_embeddings(text)`** - Get text embeddings\n- **`batch_similarity(query, documents)`** - Efficient batch similarity\n\n### CodeGemma-Specific Methods\n\n- **`generate_code(prompt)`** - Optimized code generation\n- **`complete_function(signature, description)`** - Function completion\n- **`refactor_code(code, instruction)`** - Code refactoring\n\n## Testing\n\nRun the comprehensive test suite:\n\n```bash\n# All tests\npyt\n\n# Specific transformer tests\npython -m pytest tests/extension/test_t5_transformer.py\npython -m pytest tests/extension/test_bert_transformer.py\n```\n\n## Configuration\n\nModels can be customized during initialization:\n\n```python\nai = T5Transformer(\n transformers_model_name=\"t5-large\", # Use larger model\n cache_dir=\"./my_cache\", # Custom cache location\n device=\"cuda\" # Use GPU if available\n)\n```\n\n## Requirements\n\n- Python 3.8+\n- PyTorch\n- Transformers\n- Additional dependencies in `requirements.txt`\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Add tests for new functionality\n4. Run the test suite\n5. Submit a pull request\n\n## License\n\n[Your License Here]\n\n---\n\n**Need help?** Check the test files in `tests/extension/` for more usage examples!\n",
"bugtrack_url": null,
"license": null,
"summary": null,
"version": "0.3.2",
"project_urls": {
"Source": "https://github.com/Nerdman4U/llm"
},
"split_keywords": [
"ai",
" llm",
" transformers",
" code-generation",
" text-generation"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "7ded4a6814db3e5689897c3b87b16ee4aedf4ea9cd6c5342bf87a439644bc8d4",
"md5": "abcbd411fe8ed7589ee9308edc3708f5",
"sha256": "a70c513bee0d1f204e1958489021af41fda7b807acde169dbee0bcf7d6690de0"
},
"downloads": -1,
"filename": "local_conjurer-0.3.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "abcbd411fe8ed7589ee9308edc3708f5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 27633,
"upload_time": "2025-07-20T13:15:47",
"upload_time_iso_8601": "2025-07-20T13:15:47.821892Z",
"url": "https://files.pythonhosted.org/packages/7d/ed/4a6814db3e5689897c3b87b16ee4aedf4ea9cd6c5342bf87a439644bc8d4/local_conjurer-0.3.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-20 13:15:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Nerdman4U",
"github_project": "llm",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "packaging",
"specs": []
},
{
"name": "build",
"specs": []
},
{
"name": "python-dotenv",
"specs": []
},
{
"name": "PyYAML",
"specs": []
},
{
"name": "inflection",
"specs": []
},
{
"name": "pydantic",
"specs": []
},
{
"name": "loguru_wrapper",
"specs": []
},
{
"name": "sentencepiece",
"specs": []
},
{
"name": "transformers",
"specs": []
},
{
"name": "torch",
"specs": []
}
],
"lcname": "local-conjurer"
}