hibiz-any-llm


Namehibiz-any-llm JSON
Version 0.0.4 PyPI version JSON
download
home_pageNone
SummaryA comprehensive Python wrapper for Large Language Models with database integration and usage tracking
upload_time2025-08-01 13:43:38
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords llm language-model openai azure gpt ai machine-learning database postgresql mysql mongodb usage-tracking api-wrapper
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # LLM Wrapper - Universal Large Language Model Library

A comprehensive, modular Python library for seamless integration with multiple Large Language Model providers. Built with enterprise-grade features including token tracking, usage analytics, and robust error handling.

## πŸš€ Features

- **Multi-Provider Support**: Azure OpenAI, OpenAI, Anthropic Claude, and extensible for more
- **Unified API**: Single interface for all LLM providers
- **Token Tracking**: Comprehensive token usage logging with PostgreSQL backend
- **Usage Analytics**: Detailed statistics and monitoring capabilities
- **Enterprise Ready**: Connection pooling, error handling, and production-grade logging
- **Type Safety**: Full type hints and data validation
- **Modular Architecture**: Clean separation of concerns with factory pattern
- **Backward Compatible**: Legacy API support for existing integrations

## πŸ“¦ Installation

```bash
pip install hibiz-any-llm
```

## πŸ—οΈ Architecture

```
llm_wrapper/
β”œβ”€β”€ core/           # Core functionality and factory
β”œβ”€β”€ providers/      # LLM provider implementations
β”œβ”€β”€ models/         # Data models and schemas
β”œβ”€β”€ database/       # Database management
└──utils/          # Token Calculation and validators
```

## πŸ› οΈ Quick Start

### 1. Basic Setup

```python
from hibiz_any_llm import LLMWrapper, LLMProvider

# Configure your provider
azure_config = {
    'service_url': 'https://your-resource.openai.azure.com',
    'api_key': 'your-api-key',
    'deployment_name': 'gpt-4',
    'api_version': '2023-12-01-preview'
}

# Database configuration
db_config = {
    'host': 'localhost',
    'port': 5432,
    'dbname': 'llm_usage',
    'user': 'username',
    'password': 'password'
}

# Initialize wrapper
wrapper = LLMWrapper(
    provider_type=LLMProvider.AZURE_OPENAI,
    provider_config=azure_config,
    db_config=db_config,
    enable_logging=True
)
```

### 2. Chat Completion

```python
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What is machine learning?"}
]

response = wrapper.send_request(
    prompt_payload=messages,
    customer_id="customer_123",
    organization_id="org_456",
    app_name="chatbot",
    module_name="education",
    function_name="explain_concepts",
    model="gpt-4",
    temperature=0.7,
    max_tokens=500
)

print(f"Response: {response['output_text']}")
print(f"Tokens used: {response['total_tokens']}")
```

### 3. Embeddings

```python
embedding_response = wrapper.create_embeddings(
    input_texts=["Machine learning is amazing", "AI will change the world"],
    customer_id="customer_123",
    organization_id="org_456",
    app_name="search_engine",
    module_name="vectorization",
    function_name="create_embeddings",
    model="text-embedding-3-small"
)

print(f"Embeddings: {embedding_response['embeddings']}")
```

## πŸ”§ Provider Configurations

### Azure OpenAI

```python
azure_config = {
    'service_url': 'https://your-resource.openai.azure.com',
    'api_key': 'your-api-key',
    'deployment_name': 'gpt-4',
    'api_version': '2023-12-01-preview',
    'timeout': 600
}

wrapper = LLMWrapper(LLMProvider.AZURE_OPENAI, azure_config, db_config)
```

### OpenAI

```python
openai_config = {
    'api_key': 'sk-your-openai-api-key',
    'organization_id': 'org-your-org-id',  # Optional
    'timeout': 600
}

wrapper = LLMWrapper(LLMProvider.OPENAI, openai_config, db_config)
```

### Anthropic Claude

```python
anthropic_config = {
    'api_key': 'sk-ant-your-anthropic-api-key',
    'default_model': 'claude-opus-4-20250514',
    'timeout': 300
}

wrapper = LLMWrapper(LLMProvider.ANTHROPIC, anthropic_config, db_config)
```
### Google Gemini

```python
google_config = {
    'api_key': 'your-gemini-api-key',
    'default_model': 'gemini-2.0-flash',
    'timeout': 300
}

wrapper = LLMWrapper(LLMProvider.GOOGLE, google_config, db_config)
```
### Twitter GROK

```python
grok_config = {
    'api_key': 'your-grok-api-key',
    'default_model': 'grok-4',
    'timeout': 300
}

wrapper = LLMWrapper(LLMProvider.GROK, grok_config, db_config)
```
### Alibaba QWEN

```python
qwen_config = {
    'api_key': 'your-qwen-api-key',
    'default_model': 'qwen-plus',
    'timeout': 300
}

wrapper = LLMWrapper(LLMProvider.QWEN, qwen_config, db_config)
```
### DeepSeek

```python
deepseek_config = {
    'api_key': 'your-deepseek-api-key',
    'default_model': 'deepseek-chat',
    'timeout': 300
}

wrapper = LLMWrapper(LLMProvider.DEEP_SEEK, deepseek_config, db_config)
```

## πŸ“Š Usage Analytics

### Get Usage Statistics

```python
stats = wrapper.get_usage_stats(
    customer_id="customer_123",
    start_date="2024-01-01T00:00:00",
    end_date="2024-12-31T23:59:59",
    app_name="chatbot"
)

print(f"Total requests: {stats['summary']['total_requests']}")
print(f"Total tokens: {stats['summary']['total_tokens']}")
print(f"Success rate: {stats['summary']['success_rate']}")
```

### Filter by Different Dimensions

```python
# By application
app_stats = wrapper.get_usage_stats(app_name="chatbot")

# By model
model_stats = wrapper.get_usage_stats(filters={"model_name": "gpt-4"})

# By request type
embedding_stats = wrapper.get_usage_stats(request_type="embedding")
```

## 🎯 Advanced Features

### JSON Response Format

```python
response = wrapper.send_request(
    prompt_payload=[
        {"role": "user", "content": "List 3 benefits of exercise in JSON format"}
    ],
    customer_id="customer_789",
    organization_id="org_456",
    app_name="health_app",
    module_name="exercise",
    function_name="get_benefits",
    response_type="json"  # Automatically ensures JSON output
)

# Access parsed JSON
json_data = response['processed_output']
```

### Context Manager Support

```python
with LLMWrapper(LLMProvider.AZURE_OPENAI, azure_config, db_config) as wrapper:
    response = wrapper.send_request(
        prompt_payload=messages,
        customer_id="customer_123",
        organization_id="org_456",
        app_name="temp_app",
        module_name="test",
        function_name="context_test"
    )
    # Automatic cleanup on exit
```

### Multi-Provider Switching

```python
providers = {
    LLMProvider.AZURE_OPENAI: azure_config,
    LLMProvider.OPENAI: openai_config,
    LLMProvider.ANTHROPIC: anthropic_config
}

for provider_type, config in providers.items():
    wrapper = LLMWrapper(provider_type, config, db_config)
    response = wrapper.send_request(
        prompt_payload=[{"role": "user", "content": "Hello!"}],
        customer_id="multi_test",
        organization_id="org_test",
        app_name="provider_comparison",
        module_name="testing",
        function_name="hello_test"
    )
    print(f"{provider_type.value}: {response['output_text']}")
    wrapper.close()
```

## πŸ—„οΈ Database Schema

The library automatically creates the following PostgreSQL table:

```sql
CREATE TABLE token_usage_log (
    id SERIAL PRIMARY KEY,
    customer_id VARCHAR(255) NOT NULL,
    organization_id VARCHAR(255) NOT NULL,
    provider VARCHAR(100) NOT NULL,
    model_name VARCHAR(255) NOT NULL,
    app_name VARCHAR(255),
    module_name VARCHAR(255),
    function_name VARCHAR(255),
    request_type VARCHAR(50) NOT NULL,
    request_params JSONB,
    response_params JSONB,
    input_tokens INTEGER DEFAULT 0,
    output_tokens INTEGER DEFAULT 0,
    total_tokens INTEGER DEFAULT 0,
    request_timestamp TIMESTAMP DEFAULT NOW(),
    response_time_ms INTEGER DEFAULT 0,
    status VARCHAR(50) DEFAULT 'success',
    request_id VARCHAR(255),
    cost FLOAT
);
```

### Indexes for Performance

- `idx_customer_date` on (customer_id, request_timestamp)
- `idx_org_model` on (organization_id, model_name)
- `idx_app_module` on (app_name, module_name)

## πŸ§ͺ Error Handling

```python
from llm_wrapper import APIError, DatabaseError, ConfigurationError

try:
    response = wrapper.send_request(...)
except APIError as e:
    print(f"API Error: {e}")
except DatabaseError as e:
    print(f"Database Error: {e}")
except ConfigurationError as e:
    print(f"Configuration Error: {e}")
```

## πŸ”’ Security Best Practices

1. **Environment Variables**: Store API keys in environment variables
```python
import os

config = {
    'api_key': os.getenv('AZURE_OPENAI_API_KEY'),
    'service_url': os.getenv('AZURE_OPENAI_SERVICE_URL'),
    # ...
}
```

2. **Database Security**: Use connection pooling and proper credentials
```python
db_config = {
    'host': os.getenv('DB_HOST'),
    'user': os.getenv('DB_USER'),
    'password': os.getenv('DB_PASSWORD'),
    'pool_size': 10,
    'max_overflow': 20
}
```

## πŸ“ˆ Performance Optimization

### Connection Pooling

The library uses SQLAlchemy's connection pooling:

```python
db_config = {
    'host': 'localhost',
    'port': 5432,
    'dbname': 'llm_usage',
    'user': 'username',
    'password': 'password',
    'pool_size': 10,        # Number of persistent connections
    'max_overflow': 20,     # Additional connections when needed
    'pool_pre_ping': True   # Validate connections before use
}
```

### Batch Processing

For multiple requests, use connection reuse:

```python
with LLMWrapper(provider_type, config, db_config) as wrapper:
    for request_data in batch_requests:
        response = wrapper.send_request(**request_data)
        # Process response
```

## πŸ“ Logging

Configure logging for production:

```python
import logging

# Configure logging
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    handlers=[
        logging.FileHandler('llm_wrapper.log'),
        logging.StreamHandler()
    ]
)
```

## πŸ”„ Migration from Legacy Version

### Old API (v0.1.x)

```python
# Old way
wrapper = LLMWrapper(service_url, api_key, deployment_name, api_version, db_config)
response = wrapper.send_request(messages, customer_id, ...)
```

### New API (v0.2.x)

```python
# New way
wrapper = LLMWrapper(LLMProvider.AZURE_OPENAI, provider_config, db_config)
response = wrapper.send_request(messages, customer_id, ...)
```

The response format remains the same for backward compatibility.

## 🀝 Contributing

1. Fork the repository
2. Create a feature branch: `git checkout -b feature/new-provider`
3. Make your changes
4. Add tests for new functionality
5. Run tests: `pytest`
6. Submit a pull request

### Adding New Providers

1. Create a new provider class inheriting from `BaseLLMProvider`
2. Implement required methods: `send_chat_completion`, `create_embeddings`, `validate_config`
3. Add the provider to `LLMProviderFactory`
4. Add provider-specific configuration in constants
5. Write tests


## πŸ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## πŸ†˜ Support

- **Email**: akilan@hibizsolutions.com

## 🏷️ Changelog

### v0.2.0 (Latest)
- βœ… Multi-provider support (Azure OpenAI, OpenAI, Anthropic)
- βœ… Modular architecture with factory pattern
- βœ… Enhanced token tracking and analytics
- βœ… Improved error handling and validation
- βœ… Type safety with full type hints
- βœ… Performance optimizations
- βœ… Backward compatibility

### v0.1.0
- βœ… Basic Azure OpenAI support
- βœ… Token tracking
- βœ… PostgreSQL logging

## 🎯 Roadmap

- [ ] Google PaLM/Gemini support
- [ ] Cost calculation and tracking
- [ ] Rate limiting and retry mechanisms
- [ ] Async support
- [ ] Streaming responses
- [ ] Fine-tuning integration
- [ ] Monitoring dashboard

---

**Made with ❀️ by [Hibiz Solutions](https://hibizsolutions.com)**

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "hibiz-any-llm",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Akilan R M <akilan@hibizsolutions.com>",
    "keywords": "llm, language-model, openai, azure, gpt, ai, machine-learning, database, postgresql, mysql, mongodb, usage-tracking, api-wrapper",
    "author": null,
    "author_email": "Akilan R M <akilan@hibizsolutions.com>",
    "download_url": "https://files.pythonhosted.org/packages/16/d3/c45714baacb390affd3690ccfdde4a210c7d0bfee14d29e6061eb7b5c49c/hibiz_any_llm-0.0.4.tar.gz",
    "platform": null,
    "description": "# LLM Wrapper - Universal Large Language Model Library\r\n\r\nA comprehensive, modular Python library for seamless integration with multiple Large Language Model providers. Built with enterprise-grade features including token tracking, usage analytics, and robust error handling.\r\n\r\n## \ud83d\ude80 Features\r\n\r\n- **Multi-Provider Support**: Azure OpenAI, OpenAI, Anthropic Claude, and extensible for more\r\n- **Unified API**: Single interface for all LLM providers\r\n- **Token Tracking**: Comprehensive token usage logging with PostgreSQL backend\r\n- **Usage Analytics**: Detailed statistics and monitoring capabilities\r\n- **Enterprise Ready**: Connection pooling, error handling, and production-grade logging\r\n- **Type Safety**: Full type hints and data validation\r\n- **Modular Architecture**: Clean separation of concerns with factory pattern\r\n- **Backward Compatible**: Legacy API support for existing integrations\r\n\r\n## \ud83d\udce6 Installation\r\n\r\n```bash\r\npip install hibiz-any-llm\r\n```\r\n\r\n## \ud83c\udfd7\ufe0f Architecture\r\n\r\n```\r\nllm_wrapper/\r\n\u251c\u2500\u2500 core/           # Core functionality and factory\r\n\u251c\u2500\u2500 providers/      # LLM provider implementations\r\n\u251c\u2500\u2500 models/         # Data models and schemas\r\n\u251c\u2500\u2500 database/       # Database management\r\n\u2514\u2500\u2500utils/          # Token Calculation and validators\r\n```\r\n\r\n## \ud83d\udee0\ufe0f Quick Start\r\n\r\n### 1. Basic Setup\r\n\r\n```python\r\nfrom hibiz_any_llm import LLMWrapper, LLMProvider\r\n\r\n# Configure your provider\r\nazure_config = {\r\n    'service_url': 'https://your-resource.openai.azure.com',\r\n    'api_key': 'your-api-key',\r\n    'deployment_name': 'gpt-4',\r\n    'api_version': '2023-12-01-preview'\r\n}\r\n\r\n# Database configuration\r\ndb_config = {\r\n    'host': 'localhost',\r\n    'port': 5432,\r\n    'dbname': 'llm_usage',\r\n    'user': 'username',\r\n    'password': 'password'\r\n}\r\n\r\n# Initialize wrapper\r\nwrapper = LLMWrapper(\r\n    provider_type=LLMProvider.AZURE_OPENAI,\r\n    provider_config=azure_config,\r\n    db_config=db_config,\r\n    enable_logging=True\r\n)\r\n```\r\n\r\n### 2. Chat Completion\r\n\r\n```python\r\nmessages = [\r\n    {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\r\n    {\"role\": \"user\", \"content\": \"What is machine learning?\"}\r\n]\r\n\r\nresponse = wrapper.send_request(\r\n    prompt_payload=messages,\r\n    customer_id=\"customer_123\",\r\n    organization_id=\"org_456\",\r\n    app_name=\"chatbot\",\r\n    module_name=\"education\",\r\n    function_name=\"explain_concepts\",\r\n    model=\"gpt-4\",\r\n    temperature=0.7,\r\n    max_tokens=500\r\n)\r\n\r\nprint(f\"Response: {response['output_text']}\")\r\nprint(f\"Tokens used: {response['total_tokens']}\")\r\n```\r\n\r\n### 3. Embeddings\r\n\r\n```python\r\nembedding_response = wrapper.create_embeddings(\r\n    input_texts=[\"Machine learning is amazing\", \"AI will change the world\"],\r\n    customer_id=\"customer_123\",\r\n    organization_id=\"org_456\",\r\n    app_name=\"search_engine\",\r\n    module_name=\"vectorization\",\r\n    function_name=\"create_embeddings\",\r\n    model=\"text-embedding-3-small\"\r\n)\r\n\r\nprint(f\"Embeddings: {embedding_response['embeddings']}\")\r\n```\r\n\r\n## \ud83d\udd27 Provider Configurations\r\n\r\n### Azure OpenAI\r\n\r\n```python\r\nazure_config = {\r\n    'service_url': 'https://your-resource.openai.azure.com',\r\n    'api_key': 'your-api-key',\r\n    'deployment_name': 'gpt-4',\r\n    'api_version': '2023-12-01-preview',\r\n    'timeout': 600\r\n}\r\n\r\nwrapper = LLMWrapper(LLMProvider.AZURE_OPENAI, azure_config, db_config)\r\n```\r\n\r\n### OpenAI\r\n\r\n```python\r\nopenai_config = {\r\n    'api_key': 'sk-your-openai-api-key',\r\n    'organization_id': 'org-your-org-id',  # Optional\r\n    'timeout': 600\r\n}\r\n\r\nwrapper = LLMWrapper(LLMProvider.OPENAI, openai_config, db_config)\r\n```\r\n\r\n### Anthropic Claude\r\n\r\n```python\r\nanthropic_config = {\r\n    'api_key': 'sk-ant-your-anthropic-api-key',\r\n    'default_model': 'claude-opus-4-20250514',\r\n    'timeout': 300\r\n}\r\n\r\nwrapper = LLMWrapper(LLMProvider.ANTHROPIC, anthropic_config, db_config)\r\n```\r\n### Google Gemini\r\n\r\n```python\r\ngoogle_config = {\r\n    'api_key': 'your-gemini-api-key',\r\n    'default_model': 'gemini-2.0-flash',\r\n    'timeout': 300\r\n}\r\n\r\nwrapper = LLMWrapper(LLMProvider.GOOGLE, google_config, db_config)\r\n```\r\n### Twitter GROK\r\n\r\n```python\r\ngrok_config = {\r\n    'api_key': 'your-grok-api-key',\r\n    'default_model': 'grok-4',\r\n    'timeout': 300\r\n}\r\n\r\nwrapper = LLMWrapper(LLMProvider.GROK, grok_config, db_config)\r\n```\r\n### Alibaba QWEN\r\n\r\n```python\r\nqwen_config = {\r\n    'api_key': 'your-qwen-api-key',\r\n    'default_model': 'qwen-plus',\r\n    'timeout': 300\r\n}\r\n\r\nwrapper = LLMWrapper(LLMProvider.QWEN, qwen_config, db_config)\r\n```\r\n### DeepSeek\r\n\r\n```python\r\ndeepseek_config = {\r\n    'api_key': 'your-deepseek-api-key',\r\n    'default_model': 'deepseek-chat',\r\n    'timeout': 300\r\n}\r\n\r\nwrapper = LLMWrapper(LLMProvider.DEEP_SEEK, deepseek_config, db_config)\r\n```\r\n\r\n## \ud83d\udcca Usage Analytics\r\n\r\n### Get Usage Statistics\r\n\r\n```python\r\nstats = wrapper.get_usage_stats(\r\n    customer_id=\"customer_123\",\r\n    start_date=\"2024-01-01T00:00:00\",\r\n    end_date=\"2024-12-31T23:59:59\",\r\n    app_name=\"chatbot\"\r\n)\r\n\r\nprint(f\"Total requests: {stats['summary']['total_requests']}\")\r\nprint(f\"Total tokens: {stats['summary']['total_tokens']}\")\r\nprint(f\"Success rate: {stats['summary']['success_rate']}\")\r\n```\r\n\r\n### Filter by Different Dimensions\r\n\r\n```python\r\n# By application\r\napp_stats = wrapper.get_usage_stats(app_name=\"chatbot\")\r\n\r\n# By model\r\nmodel_stats = wrapper.get_usage_stats(filters={\"model_name\": \"gpt-4\"})\r\n\r\n# By request type\r\nembedding_stats = wrapper.get_usage_stats(request_type=\"embedding\")\r\n```\r\n\r\n## \ud83c\udfaf Advanced Features\r\n\r\n### JSON Response Format\r\n\r\n```python\r\nresponse = wrapper.send_request(\r\n    prompt_payload=[\r\n        {\"role\": \"user\", \"content\": \"List 3 benefits of exercise in JSON format\"}\r\n    ],\r\n    customer_id=\"customer_789\",\r\n    organization_id=\"org_456\",\r\n    app_name=\"health_app\",\r\n    module_name=\"exercise\",\r\n    function_name=\"get_benefits\",\r\n    response_type=\"json\"  # Automatically ensures JSON output\r\n)\r\n\r\n# Access parsed JSON\r\njson_data = response['processed_output']\r\n```\r\n\r\n### Context Manager Support\r\n\r\n```python\r\nwith LLMWrapper(LLMProvider.AZURE_OPENAI, azure_config, db_config) as wrapper:\r\n    response = wrapper.send_request(\r\n        prompt_payload=messages,\r\n        customer_id=\"customer_123\",\r\n        organization_id=\"org_456\",\r\n        app_name=\"temp_app\",\r\n        module_name=\"test\",\r\n        function_name=\"context_test\"\r\n    )\r\n    # Automatic cleanup on exit\r\n```\r\n\r\n### Multi-Provider Switching\r\n\r\n```python\r\nproviders = {\r\n    LLMProvider.AZURE_OPENAI: azure_config,\r\n    LLMProvider.OPENAI: openai_config,\r\n    LLMProvider.ANTHROPIC: anthropic_config\r\n}\r\n\r\nfor provider_type, config in providers.items():\r\n    wrapper = LLMWrapper(provider_type, config, db_config)\r\n    response = wrapper.send_request(\r\n        prompt_payload=[{\"role\": \"user\", \"content\": \"Hello!\"}],\r\n        customer_id=\"multi_test\",\r\n        organization_id=\"org_test\",\r\n        app_name=\"provider_comparison\",\r\n        module_name=\"testing\",\r\n        function_name=\"hello_test\"\r\n    )\r\n    print(f\"{provider_type.value}: {response['output_text']}\")\r\n    wrapper.close()\r\n```\r\n\r\n## \ud83d\uddc4\ufe0f Database Schema\r\n\r\nThe library automatically creates the following PostgreSQL table:\r\n\r\n```sql\r\nCREATE TABLE token_usage_log (\r\n    id SERIAL PRIMARY KEY,\r\n    customer_id VARCHAR(255) NOT NULL,\r\n    organization_id VARCHAR(255) NOT NULL,\r\n    provider VARCHAR(100) NOT NULL,\r\n    model_name VARCHAR(255) NOT NULL,\r\n    app_name VARCHAR(255),\r\n    module_name VARCHAR(255),\r\n    function_name VARCHAR(255),\r\n    request_type VARCHAR(50) NOT NULL,\r\n    request_params JSONB,\r\n    response_params JSONB,\r\n    input_tokens INTEGER DEFAULT 0,\r\n    output_tokens INTEGER DEFAULT 0,\r\n    total_tokens INTEGER DEFAULT 0,\r\n    request_timestamp TIMESTAMP DEFAULT NOW(),\r\n    response_time_ms INTEGER DEFAULT 0,\r\n    status VARCHAR(50) DEFAULT 'success',\r\n    request_id VARCHAR(255),\r\n    cost FLOAT\r\n);\r\n```\r\n\r\n### Indexes for Performance\r\n\r\n- `idx_customer_date` on (customer_id, request_timestamp)\r\n- `idx_org_model` on (organization_id, model_name)\r\n- `idx_app_module` on (app_name, module_name)\r\n\r\n## \ud83e\uddea Error Handling\r\n\r\n```python\r\nfrom llm_wrapper import APIError, DatabaseError, ConfigurationError\r\n\r\ntry:\r\n    response = wrapper.send_request(...)\r\nexcept APIError as e:\r\n    print(f\"API Error: {e}\")\r\nexcept DatabaseError as e:\r\n    print(f\"Database Error: {e}\")\r\nexcept ConfigurationError as e:\r\n    print(f\"Configuration Error: {e}\")\r\n```\r\n\r\n## \ud83d\udd12 Security Best Practices\r\n\r\n1. **Environment Variables**: Store API keys in environment variables\r\n```python\r\nimport os\r\n\r\nconfig = {\r\n    'api_key': os.getenv('AZURE_OPENAI_API_KEY'),\r\n    'service_url': os.getenv('AZURE_OPENAI_SERVICE_URL'),\r\n    # ...\r\n}\r\n```\r\n\r\n2. **Database Security**: Use connection pooling and proper credentials\r\n```python\r\ndb_config = {\r\n    'host': os.getenv('DB_HOST'),\r\n    'user': os.getenv('DB_USER'),\r\n    'password': os.getenv('DB_PASSWORD'),\r\n    'pool_size': 10,\r\n    'max_overflow': 20\r\n}\r\n```\r\n\r\n## \ud83d\udcc8 Performance Optimization\r\n\r\n### Connection Pooling\r\n\r\nThe library uses SQLAlchemy's connection pooling:\r\n\r\n```python\r\ndb_config = {\r\n    'host': 'localhost',\r\n    'port': 5432,\r\n    'dbname': 'llm_usage',\r\n    'user': 'username',\r\n    'password': 'password',\r\n    'pool_size': 10,        # Number of persistent connections\r\n    'max_overflow': 20,     # Additional connections when needed\r\n    'pool_pre_ping': True   # Validate connections before use\r\n}\r\n```\r\n\r\n### Batch Processing\r\n\r\nFor multiple requests, use connection reuse:\r\n\r\n```python\r\nwith LLMWrapper(provider_type, config, db_config) as wrapper:\r\n    for request_data in batch_requests:\r\n        response = wrapper.send_request(**request_data)\r\n        # Process response\r\n```\r\n\r\n## \ud83d\udcdd Logging\r\n\r\nConfigure logging for production:\r\n\r\n```python\r\nimport logging\r\n\r\n# Configure logging\r\nlogging.basicConfig(\r\n    level=logging.INFO,\r\n    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',\r\n    handlers=[\r\n        logging.FileHandler('llm_wrapper.log'),\r\n        logging.StreamHandler()\r\n    ]\r\n)\r\n```\r\n\r\n## \ud83d\udd04 Migration from Legacy Version\r\n\r\n### Old API (v0.1.x)\r\n\r\n```python\r\n# Old way\r\nwrapper = LLMWrapper(service_url, api_key, deployment_name, api_version, db_config)\r\nresponse = wrapper.send_request(messages, customer_id, ...)\r\n```\r\n\r\n### New API (v0.2.x)\r\n\r\n```python\r\n# New way\r\nwrapper = LLMWrapper(LLMProvider.AZURE_OPENAI, provider_config, db_config)\r\nresponse = wrapper.send_request(messages, customer_id, ...)\r\n```\r\n\r\nThe response format remains the same for backward compatibility.\r\n\r\n## \ud83e\udd1d Contributing\r\n\r\n1. Fork the repository\r\n2. Create a feature branch: `git checkout -b feature/new-provider`\r\n3. Make your changes\r\n4. Add tests for new functionality\r\n5. Run tests: `pytest`\r\n6. Submit a pull request\r\n\r\n### Adding New Providers\r\n\r\n1. Create a new provider class inheriting from `BaseLLMProvider`\r\n2. Implement required methods: `send_chat_completion`, `create_embeddings`, `validate_config`\r\n3. Add the provider to `LLMProviderFactory`\r\n4. Add provider-specific configuration in constants\r\n5. Write tests\r\n\r\n\r\n## \ud83d\udcc4 License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n\r\n## \ud83c\udd98 Support\r\n\r\n- **Email**: akilan@hibizsolutions.com\r\n\r\n## \ud83c\udff7\ufe0f Changelog\r\n\r\n### v0.2.0 (Latest)\r\n- \u2705 Multi-provider support (Azure OpenAI, OpenAI, Anthropic)\r\n- \u2705 Modular architecture with factory pattern\r\n- \u2705 Enhanced token tracking and analytics\r\n- \u2705 Improved error handling and validation\r\n- \u2705 Type safety with full type hints\r\n- \u2705 Performance optimizations\r\n- \u2705 Backward compatibility\r\n\r\n### v0.1.0\r\n- \u2705 Basic Azure OpenAI support\r\n- \u2705 Token tracking\r\n- \u2705 PostgreSQL logging\r\n\r\n## \ud83c\udfaf Roadmap\r\n\r\n- [ ] Google PaLM/Gemini support\r\n- [ ] Cost calculation and tracking\r\n- [ ] Rate limiting and retry mechanisms\r\n- [ ] Async support\r\n- [ ] Streaming responses\r\n- [ ] Fine-tuning integration\r\n- [ ] Monitoring dashboard\r\n\r\n---\r\n\r\n**Made with \u2764\ufe0f by [Hibiz Solutions](https://hibizsolutions.com)**\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A comprehensive Python wrapper for Large Language Models with database integration and usage tracking",
    "version": "0.0.4",
    "project_urls": null,
    "split_keywords": [
        "llm",
        " language-model",
        " openai",
        " azure",
        " gpt",
        " ai",
        " machine-learning",
        " database",
        " postgresql",
        " mysql",
        " mongodb",
        " usage-tracking",
        " api-wrapper"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "729897fd601f0aa01567534b495b0854dd7d967535d4e27d3dba19e273b53a7c",
                "md5": "b57ccd92a2139e28498a4b3340653f59",
                "sha256": "3590a580092309cb883e2b897406a030d215d68abd3a7ddf2267eb3bd6dcfa48"
            },
            "downloads": -1,
            "filename": "hibiz_any_llm-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b57ccd92a2139e28498a4b3340653f59",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 36635,
            "upload_time": "2025-08-01T13:43:37",
            "upload_time_iso_8601": "2025-08-01T13:43:37.795926Z",
            "url": "https://files.pythonhosted.org/packages/72/98/97fd601f0aa01567534b495b0854dd7d967535d4e27d3dba19e273b53a7c/hibiz_any_llm-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "16d3c45714baacb390affd3690ccfdde4a210c7d0bfee14d29e6061eb7b5c49c",
                "md5": "07acda36c769b79f701ad5e6caf81288",
                "sha256": "688bcb2d4a897c875730f00b6662eceac5026ee5fe17a272e92b359336feaacf"
            },
            "downloads": -1,
            "filename": "hibiz_any_llm-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "07acda36c769b79f701ad5e6caf81288",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 30927,
            "upload_time": "2025-08-01T13:43:38",
            "upload_time_iso_8601": "2025-08-01T13:43:38.872948Z",
            "url": "https://files.pythonhosted.org/packages/16/d3/c45714baacb390affd3690ccfdde4a210c7d0bfee14d29e6061eb7b5c49c/hibiz_any_llm-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-01 13:43:38",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "hibiz-any-llm"
}
        
Elapsed time: 0.71770s