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

  • Multi-Service Integration: Interact seamlessly with multiple AI services (e.g., chat, transcription).
  • 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 Support: Modern dependency and environment management with Poetry.
  • Python 3.11+: Leverages the latest features of Python for performance and simplicity.

Installation

  1. Clone the repository:

    git clone https://github.com/mfenerich/thinkhub.git
    cd thinkhub
    
  2. Install dependencies with Poetry: Ensure Poetry is installed on your system. Then run:

    poetry install
    
  3. Activate the virtual environment:

    poetry shell
    

Usage

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)

Registering Custom Plugins

ThinkHub allows users to create and register their own services by extending the base classes and utilizing the factory functions (get_chat_service and get_transcription_service).

Example: Registering a Custom Chat Service

To register a custom chat service, extend the base class ChatServiceInterface and implement its methods:

from thinkhub.chat.base import ChatServiceInterface
from thinkhub.chat import register_chat_service

class CustomChatService(ChatServiceInterface):
    """A custom implementation of a chat service."""
    
    def __init__(self, **kwargs):
        self.custom_param = kwargs.get("custom_param", "default_value")
    
    async def stream_chat_response(self, input_data, system_prompt=""):
        yield f"Custom response to: {input_data}"

# Register the service
register_chat_service("custom", CustomChatService)

Usage

Once registered, the custom service can be retrieved via get_chat_service:

from thinkhub.chat import get_chat_service

chat_service = get_chat_service("custom", custom_param="example")
async for response in chat_service.stream_chat_response("Hello!"):
    print(response)

Example: Registering a Custom Transcription Service

Similarly, transcription services can be registered by extending the TranscriptionServiceInterface:

from thinkhub.transcription.base import TranscriptionServiceInterface
from thinkhub.transcription import register_transcription_service

class CustomTranscriptionService(TranscriptionServiceInterface):
    """A custom implementation of a transcription service."""
    
    async def transcribe(self, file_path):
        return f"Transcription for {file_path}"

# Register the service
register_transcription_service("custom", CustomTranscriptionService)

Usage

The custom transcription service can then be retrieved via get_transcription_service:

from thinkhub.transcription import get_transcription_service

transcription_service = get_transcription_service("custom")
result = await transcription_service.transcribe("path/to/file")
print(result)

Error Handling

Custom exceptions are provided to make debugging easier:

  • BaseServiceError: Base class for all service-related errors.
  • ProviderNotFoundError: Raised when a requested provider is not found.

Example:

from thinkhub.exceptions import ProviderNotFoundError

try:
    raise ProviderNotFoundError("Provider not found!")
except ProviderNotFoundError as e:
    print(e)

Development

  1. Run Tests: Add your tests in the appropriate directories and run:

    poetry run pytest
    
  2. Code Linting: Ensure code quality with:

    poetry run flake8
    
  3. Build the Project:

    poetry build
    

Contributing

Contributions are welcome! Please fork the repository and create a pull request for any changes.


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.1.tar.gz (14.3 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.1-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: thinkhub-0.3.1.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for thinkhub-0.3.1.tar.gz
Algorithm Hash digest
SHA256 04ad71d42b49238bc891577c17c00b1d0596c4b4c8bce08e1f81ab50db90979d
MD5 617cb061e8ecc3ec1f1cf6c9ada5b370
BLAKE2b-256 f65c5e30a70ac81ad0cb2005cdf6542d652989b817a7046fb3c9067edbf3d126

See more details on using hashes here.

File details

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

File metadata

  • Download URL: thinkhub-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for thinkhub-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cc9113b37b2cbed72c073759d2d21140f711b8930d6d549cbc472208339ccce8
MD5 9c9edd0eae067ed8ed78e0aa38faa104
BLAKE2b-256 47c3c2f6f183aa6582422e7ff2c8c134fb171838ddb752d8420f5627dee6083e

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