LingualLens
A unified interface for interacting with language models from multiple providers.
Features
- Multi-Provider Support: Interact with models from OpenAI, Anthropic, Google, and HuggingFace through a single consistent API
- Simple Interface: Generate text, classify sentiment, and extract entities with just a few lines of code
- Provider-Agnostic: Switch between different providers and models without changing your code
- Extensible: Easy to add support for additional providers
- Configurable: Configure models and providers through code or configuration files
Installation
# Basic installation
pip install linguallens
# With support for specific providers
pip install linguallens[openai] # OpenAI support
pip install linguallens[anthropic] # Anthropic support
pip install linguallens[google] # Google support
pip install linguallens[huggingface] # HuggingFace support
# Full installation with all providers
pip install linguallens[all]
Quick Start
from linguallens import LingualLens
# Initialize with API keys for different providers
lens = LingualLens(
openai_api_key="your-openai-key",
anthropic_api_key="your-anthropic-key",
google_api_key="your-google-key",
default_provider="openai",
default_model="gpt-3.5-turbo"
)
# Generate text with the default provider and model
response = lens.generate("Explain quantum computing in simple terms")
print(response)
# Use a different provider and model
response = lens.generate(
"What are the ethical implications of AI?",
provider="anthropic",
model="claude-3-opus-20240229"
)
print(response)
# Analyze sentiment
sentiment = lens.classify_sentiment("I love this product! It works great.")
print(sentiment) # {'score': 1.0, 'label': 'positive', ...}
# Extract entities
entities = lens.extract_entities("Contact us at support@example.com or visit https://example.com")
print(entities) # [{'type': 'EMAIL', 'value': 'support@example.com', ...}, ...]
Advanced Usage
Configuration Files
LingualLens supports configuration through JSON or YAML files:
lens = LingualLens(config_path="config.yaml")
Example config.yaml:
providers:
openai:
api_key: "your-openai-key"
models:
gpt-4:
max_tokens: 8192
default_params:
temperature: 0.7
top_p: 1.0
anthropic:
api_key: "your-anthropic-key"
models:
claude-3-opus-20240229:
max_tokens: 4096
default_params:
temperature: 0.5
Working with Local Models
For HuggingFace models, you can choose between using the Inference API or local models:
# Use a local model
response = lens.generate(
"What is machine learning?",
provider="huggingface",
model="mistralai/Mistral-7B-Instruct-v0.2",
use_api=False # Use local model instead of API
)
Adding a New Provider
LingualLens is designed to be easily extensible. To add a new provider:
- Create a new class that inherits from
BaseProvider - Implement the required methods:
generate,load_model, andavailable_models - Register the provider with LingualLens
from linguallens import BaseProvider, LingualLens
class MyCustomProvider(BaseProvider):
def __init__(self, api_key=None):
super().__init__(api_key)
# Initialize your provider here
def generate(self, prompt, model, max_tokens=100, temperature=0.7, top_p=1.0,
stop_sequences=None, streaming=False):
# Implement text generation
return "Generated text"
def load_model(self, model_name):
# Load or get a reference to a model
return model_proxy
def available_models(self):
# Return a list of available models
return ["model1", "model2"]
# Register the provider
LingualLens.register_provider("my_provider", MyCustomProvider)
# Use the provider
lens = LingualLens(my_provider_api_key="your-key")
response = lens.generate("Hello", provider="my_provider", model="model1")
License
MIT
Metadata
Release files for linguallens 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| linguallens-0.1.0.tar.gz | 56.8 kB | Without provenance | Details for linguallens-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| linguallens-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for linguallens-0.1.0-py3-none-any.whl |
Total release size: 123.2 kB
Release files / linguallens-0.1.0.tar.gz
| Download URL | linguallens-0.1.0.tar.gz |
|---|---|
| Size | 56.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
916251d1b2c0d08e4f97e44f0778a79f54977bbb1df4953e3bd7334121e8bb25
|
|
BLAKE2b-256 checksum How to use checksums |
d44f3e5df075313822a79e8345455b359e63b938d3373124bede5a2811f4ba2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.4
|
Release files / linguallens-0.1.0-py3-none-any.whl
| Download URL | linguallens-0.1.0-py3-none-any.whl |
|---|---|
| Size | 66.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0361eae664b27c2e6dfbe8da264bce58ece8cb4294d9d8b6c9ec166123237a86
|
|
BLAKE2b-256 checksum How to use checksums |
322105caeb935d408b76f17bb1fd5ca964b7ff6e94e75bc7ee5a3b5ba5774b43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.4
|
Security for linguallens 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.