Skip to main content

ThinkHub is a versatile Python framework that provides a unified interface for interacting with multiple AI services, such as chat and transcription. It simplifies the integration process and allows developers to extend its functionality by creating and registering custom plugins. ThinkHub is designed for flexibility and scalability, making it an ideal choice for projects that rely on AI-driven services.

Project description

ThinkHub

ThinkHub is a Python-based framework that provides a unified interface for interacting with multiple AI services. Designed for extensibility, users can integrate new services by creating and registering their own plugins or classes. The project simplifies configurations, supports multiple providers, and prioritizes user-friendly customization.

Key Features

  • Lazy Loading: Only loads the dependencies required for the selected service, reducing memory and installation overhead.
  • Multi-Service Integration: Interact seamlessly with multiple AI services (e.g., chat, transcription, image processing).
  • Plugin System: Register and use custom classes to extend functionality.
  • Dynamic Configuration: Load and manage configurations with environment variable overrides.
  • Error Handling: Robust exception system for identifying and managing provider-related issues.
  • Poetry and pip Support: Flexible dependency and environment management.
  • Python 3.11+: Leverages the latest features of Python for performance and simplicity.

Supported Services

Audio Transcriptions

  • OpenAI: Using the whisper-1 model.
  • Google Speech-to-Text

Chat

  • OpenAI: Supporting models like gpt-4 and gpt-3.5.
  • Anthropic: Supporting Claude.ai.

Image Processing

  • OpenAI: Analyze and process images with AI models.

Installation

ThinkHub uses a lazy-loading strategy to optimize memory usage and avoid installing unused dependencies. You can install ThinkHub using either Poetry or pip, as shown below:

1. Install the Base Library

  • Poetry:
    poetry add /path/to/thinkhub/dist/thinkhub-0.3.1-py3-none-any.whl
    
  • pip:
    pip install /path/to/thinkhub/dist/thinkhub-0.3.1-py3-none-any.whl
    

2. Install with Specific Extras

Install only the required dependencies based on the service(s) you plan to use:

  • OpenAI Chat:

    • Poetry:
      poetry add /path/to/thinkhub/dist/thinkhub-0.3.1-py3-none-any.whl --extras openai
      
    • pip:
      pip install thinkhub[openai]
      
  • Google Transcription:

    • Poetry:
      poetry add /path/to/thinkhub/dist/thinkhub-0.3.1-py3-none-any.whl --extras google
      
    • pip:
      pip install thinkhub[google]
      
  • Anthropic Chat:

    • Poetry:
      poetry add /path/to/thinkhub/dist/thinkhub-0.3.1-py3-none-any.whl --extras anthropic
      
    • pip:
      pip install thinkhub[anthropic]
      
  • Multiple Services (e.g., OpenAI and Anthropic):

    • Poetry:
      poetry add /path/to/thinkhub/dist/thinkhub-0.3.1-py3-none-any.whl --extras openai --extras anthropic
      
    • pip:
      pip install thinkhub[openai,anthropic]
      

3. Install All Services

If you want to install all available services:

  • Poetry:
    poetry add /path/to/thinkhub/dist/thinkhub-0.3.1-py3-none-any.whl --extras all
    
  • pip:
    pip install thinkhub[all]
    

4. Activate the Virtual Environment

  • Poetry:
    poetry shell
    

Usage

Lazy Loading

ThinkHub uses lazy loading to dynamically import the dependencies required for a specific provider. This means that:

  1. Dependencies are only loaded when needed.
  2. Missing dependencies are flagged with clear error messages.

Example: If you attempt to use OpenAI services without the openai extra installed, ThinkHub will raise an error like this:

ImportError: Missing dependencies for provider 'openai': tiktoken. 
Install them using 'poetry install --extras openai' or 'pip install thinkhub[openai]'.

Chat Services

To use a chat service like OpenAI:

from thinkhub.chat import get_chat_service

chat_service = get_chat_service("openai", model="gpt-4o")
async for response in chat_service.stream_chat_response("Hello, ThinkHub!"):
    print(response)

Transcription Services

To use a transcription service like Google:

from thinkhub.transcription import get_transcription_service

transcription_service = get_transcription_service("google")
result = await transcription_service.transcribe("path/to/audio.flac")
print(result)

Image Processing with OpenAI

ThinkHub supports image processing with OpenAI. Here’s an example of how to process multiple images asynchronously:

import asyncio
from thinkhub.chat import get_chat_service

async def process_image_with_openai(image_payloads):
    chat_service = get_chat_service("openai", model="gpt-4")
    async for response in chat_service.stream_chat_response(
        input_data=image_payloads, 
        system_prompt="Analyze these images."
    ):
        print(response)

# Prepare image payloads
image_payloads = [{"image_path": "path/to/image1.jpg"}, {"image_path": "path/to/image2.jpg"}]

# Process images with OpenAI
asyncio.run(process_image_with_openai(image_payloads))

Error Handling

ThinkHub includes robust error handling to simplify debugging and configuration:

  • Dependency Validation: ThinkHub will check for required dependencies dynamically and provide clear installation instructions.

  • Custom Exceptions:

    • ProviderNotFoundError: Raised when a requested provider is not found.
    • ImportError: Raised when dependencies for a provider are missing.

Example:

from thinkhub.exceptions import ProviderNotFoundError

try:
    service = get_chat_service("unsupported_provider")
except ProviderNotFoundError as e:
    print(e)

Development

  1. Run Tests:

    poetry run pytest
    
  2. Code Linting:

    poetry run ruff check .
    
  3. Build the Project:

    poetry build
    

License

This project is licensed under the MIT License.


Acknowledgments

Special thanks to the open-source community for providing the tools and libraries that made this project possible.

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

thinkhub-0.3.2.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thinkhub-0.3.2-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file thinkhub-0.3.2.tar.gz.

File metadata

  • Download URL: thinkhub-0.3.2.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.2 Darwin/24.2.0

File hashes

Hashes for thinkhub-0.3.2.tar.gz
Algorithm Hash digest
SHA256 36eb9db03b793049b3a419c268d96e7b64eb4b26ae52edd20c5caa50e2a84278
MD5 bfa7573cf7e25d02e1179af1a9e692a1
BLAKE2b-256 45fb227f43e9176ef4d13673922055dc91dd8f77aac424a70f46bb47b0b873b8

See more details on using hashes here.

File details

Details for the file thinkhub-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: thinkhub-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.2 Darwin/24.2.0

File hashes

Hashes for thinkhub-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 000b3eaf3b347e6d16c3e3383286a9954202c4736f5ad2416d34f40469b05474
MD5 52d00993c5c82d90cb3c168a1113c9c3
BLAKE2b-256 513a91c384fdb0537899b31d257deca9d3f7b3a9b1a21bffdbe8176750da0b64

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page