thinkhub


Namethinkhub JSON
Version 0.4.1 PyPI version JSON
download
home_pagehttps://github.com/mfenerich/thinkhub.git
SummaryThinkHub 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.
upload_time2025-03-07 08:41:48
maintainerNone
docs_urlNone
authorMarcel Fenerich
requires_python<4.0,>=3.11
licenseMIT
keywords ai chat transcription framework
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ThinkHub
[![PyPI Downloads](https://static.pepy.tech/badge/thinkhub)](https://pepy.tech/projects/thinkhub)

![ThinkHub Logo](assets/logo.png)

ThinkHub is a lightweight Python package designed for small and simple projects or for quickly testing LLM services. It provides a unified interface for interacting with multiple AI providers, making it easy to configure and switch between different services. Built with extensibility in mind, users can effortlessly integrate new providers by creating and registering their own plugins or classes. ThinkHub prioritizes simplicity, flexibility, and user-friendly customization, making it an ideal tool for rapid prototyping and experimentation with AI models.

## 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**

| Provider                                                                 | Completion | Streaming | Async Completion | Async Streaming | Async Embedding | Async Image Generation | Image Input |
|--------------------------------------------------------------------------|------------|------------|------------------|-----------------|-----------------|---------------------|-------------|
| [OpenAI](https://platform.openai.com/docs/overview)                      | ❌         | ❌         | ❌               | ✅               | ❌               | ❌                  | ✅           |
| [Google Gemini](https://ai.google.dev/)                                  | ❌         | ❌         | ❌               | ✅               | ❌               | ❌                  | ✅           |
| [Anthropic - Claude.ai](https://www.anthropic.com/api)                   | ❌         | ❌         | ❌               | ✅               | ❌               | ❌                  | ✅           |

---

## 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**:
     ```bash
     poetry add thinkhub
     ```
   - **pip**:
     ```bash
     pip install thinkhub
     ```

### 2. **Install with Specific Extras**
   Install only the required dependencies based on the service(s) you plan to use:

   - **OpenAI Chat**:
     - **Poetry**:
       ```bash
       poetry add thinkhub --extras openai
       ```
     - **pip**:
       ```bash
       pip install thinkhub[openai]
       ```

   - **Google Transcription**:
     - **Poetry**:
       ```bash
       poetry add thinkhub --extras google
       ```
     - **pip**:
       ```bash
       pip install thinkhub[google]
       ```

   - **Anthropic Chat**:
     - **Poetry**:
       ```bash
       poetry add thinkhub --extras anthropic
       ```
     - **pip**:
       ```bash
       pip install thinkhub[anthropic]
       ```

  - **Gemini Chat**:
     - **Poetry**:
       ```bash
       poetry add thinkhub --extras google-generativeai
       ```
     - **pip**:
       ```bash
       pip install thinkhub[google-generativeai]
       ```

   - **Multiple Services** (e.g., OpenAI and Anthropic):
     - **Poetry**:
       ```bash
       poetry add thinkhub --extras openai --extras anthropic
       ```
     - **pip**:
       ```bash
       pip install thinkhub[openai,anthropic]
       ```

### 3. **Install All Services**
   If you want to install all available services:
   - **Poetry**:
     ```bash
     poetry add thinkhub --extras all
     ```
   - **pip**:
     ```bash
     pip install thinkhub[all]
     ```

### 4. **Activate the Virtual Environment**
   - **Poetry**:
     ```bash
     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:
```plaintext
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:
```python
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:
```python
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:

```python
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:
```python
from thinkhub.exceptions import ProviderNotFoundError

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

---

## Development

1. **Run Tests:**
   ```bash
   poetry run pytest
   ```

2. **Code Linting:**
   ```bash
   poetry run pre-commit run -a
   ```

3. **Build the Project:**
   ```bash
   poetry build
   ```

---

## License

This project is licensed under the [MIT License](LICENSE)..

---

## Acknowledgments

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mfenerich/thinkhub.git",
    "name": "thinkhub",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.11",
    "maintainer_email": null,
    "keywords": "AI, chat, transcription, framework",
    "author": "Marcel Fenerich",
    "author_email": "marcel@feneri.ch",
    "download_url": "https://files.pythonhosted.org/packages/cd/2b/d1720ce09509dfba2c4dc1e38119e24ee8a559aa8cbe76d3e9e7bbdb210f/thinkhub-0.4.1.tar.gz",
    "platform": null,
    "description": "# ThinkHub\n[![PyPI Downloads](https://static.pepy.tech/badge/thinkhub)](https://pepy.tech/projects/thinkhub)\n\n![ThinkHub Logo](assets/logo.png)\n\nThinkHub is a lightweight Python package designed for small and simple projects or for quickly testing LLM services. It provides a unified interface for interacting with multiple AI providers, making it easy to configure and switch between different services. Built with extensibility in mind, users can effortlessly integrate new providers by creating and registering their own plugins or classes. ThinkHub prioritizes simplicity, flexibility, and user-friendly customization, making it an ideal tool for rapid prototyping and experimentation with AI models.\n\n## Key Features\n\n- **Lazy Loading**: Only loads the dependencies required for the selected service, reducing memory and installation overhead.\n- **Multi-Service Integration**: Interact seamlessly with multiple AI services (e.g., chat, transcription, image processing).\n- **Plugin System**: Register and use custom classes to extend functionality.\n- **Dynamic Configuration**: Load and manage configurations with environment variable overrides.\n- **Error Handling**: Robust exception system for identifying and managing provider-related issues.\n- **Poetry and pip Support**: Flexible dependency and environment management.\n- **Python 3.11+**: Leverages the latest features of Python for performance and simplicity.\n\n---\n\n## Supported Services\n\n### **Audio Transcriptions**\n- **OpenAI**: Using the `whisper-1` model.\n- **Google Speech-to-Text**\n\n| Provider                                                                 | Completion | Streaming | Async Completion | Async Streaming | Async Embedding | Async Image Generation | Image Input |\n|--------------------------------------------------------------------------|------------|------------|------------------|-----------------|-----------------|---------------------|-------------|\n| [OpenAI](https://platform.openai.com/docs/overview)                      | \u274c         | \u274c         | \u274c               | \u2705               | \u274c               | \u274c                  | \u2705           |\n| [Google Gemini](https://ai.google.dev/)                                  | \u274c         | \u274c         | \u274c               | \u2705               | \u274c               | \u274c                  | \u2705           |\n| [Anthropic - Claude.ai](https://www.anthropic.com/api)                   | \u274c         | \u274c         | \u274c               | \u2705               | \u274c               | \u274c                  | \u2705           |\n\n---\n\n## Installation\n\nThinkHub 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:\n\n### 1. **Install the Base Library**\n   - **Poetry**:\n     ```bash\n     poetry add thinkhub\n     ```\n   - **pip**:\n     ```bash\n     pip install thinkhub\n     ```\n\n### 2. **Install with Specific Extras**\n   Install only the required dependencies based on the service(s) you plan to use:\n\n   - **OpenAI Chat**:\n     - **Poetry**:\n       ```bash\n       poetry add thinkhub --extras openai\n       ```\n     - **pip**:\n       ```bash\n       pip install thinkhub[openai]\n       ```\n\n   - **Google Transcription**:\n     - **Poetry**:\n       ```bash\n       poetry add thinkhub --extras google\n       ```\n     - **pip**:\n       ```bash\n       pip install thinkhub[google]\n       ```\n\n   - **Anthropic Chat**:\n     - **Poetry**:\n       ```bash\n       poetry add thinkhub --extras anthropic\n       ```\n     - **pip**:\n       ```bash\n       pip install thinkhub[anthropic]\n       ```\n\n  - **Gemini Chat**:\n     - **Poetry**:\n       ```bash\n       poetry add thinkhub --extras google-generativeai\n       ```\n     - **pip**:\n       ```bash\n       pip install thinkhub[google-generativeai]\n       ```\n\n   - **Multiple Services** (e.g., OpenAI and Anthropic):\n     - **Poetry**:\n       ```bash\n       poetry add thinkhub --extras openai --extras anthropic\n       ```\n     - **pip**:\n       ```bash\n       pip install thinkhub[openai,anthropic]\n       ```\n\n### 3. **Install All Services**\n   If you want to install all available services:\n   - **Poetry**:\n     ```bash\n     poetry add thinkhub --extras all\n     ```\n   - **pip**:\n     ```bash\n     pip install thinkhub[all]\n     ```\n\n### 4. **Activate the Virtual Environment**\n   - **Poetry**:\n     ```bash\n     poetry shell\n     ```\n\n---\n\n## Usage\n\n### **Lazy Loading**\n\nThinkHub uses lazy loading to dynamically import the dependencies required for a specific provider. This means that:\n\n1. **Dependencies are only loaded when needed.**\n2. **Missing dependencies are flagged with clear error messages.**\n\nExample:\nIf you attempt to use OpenAI services without the `openai` extra installed, ThinkHub will raise an error like this:\n```plaintext\nImportError: Missing dependencies for provider 'openai': tiktoken. \nInstall them using 'poetry install --extras openai' or 'pip install thinkhub[openai]'.\n```\n\n### **Chat Services**\nTo use a chat service like OpenAI:\n```python\nfrom thinkhub.chat import get_chat_service\n\nchat_service = get_chat_service(\"openai\", model=\"gpt-4o\")\nasync for response in chat_service.stream_chat_response(\"Hello, ThinkHub!\"):\n    print(response)\n```\n\n### **Transcription Services**\nTo use a transcription service like Google:\n```python\nfrom thinkhub.transcription import get_transcription_service\n\ntranscription_service = get_transcription_service(\"google\")\nresult = await transcription_service.transcribe(\"path/to/audio.flac\")\nprint(result)\n```\n\n### **Image Processing with OpenAI**\nThinkHub supports image processing with OpenAI. Here\u2019s an example of how to process multiple images asynchronously:\n\n```python\nimport asyncio\nfrom thinkhub.chat import get_chat_service\n\nasync def process_image_with_openai(image_payloads):\n    chat_service = get_chat_service(\"openai\", model=\"gpt-4\")\n    async for response in chat_service.stream_chat_response(\n        input_data=image_payloads, \n        system_prompt=\"Analyze these images.\"\n    ):\n        print(response)\n\n# Prepare image payloads\nimage_payloads = [{\"image_path\": \"path/to/image1.jpg\"}, {\"image_path\": \"path/to/image2.jpg\"}]\n\n# Process images with OpenAI\nasyncio.run(process_image_with_openai(image_payloads))\n```\n\n---\n\n## Error Handling\n\nThinkHub includes robust error handling to simplify debugging and configuration:\n\n- **Dependency Validation**:\n  ThinkHub will check for required dependencies dynamically and provide clear installation instructions.\n\n- **Custom Exceptions**:\n  - `ProviderNotFoundError`: Raised when a requested provider is not found.\n  - `ImportError`: Raised when dependencies for a provider are missing.\n\nExample:\n```python\nfrom thinkhub.exceptions import ProviderNotFoundError\n\ntry:\n    service = get_chat_service(\"unsupported_provider\")\nexcept ProviderNotFoundError as e:\n    print(e)\n```\n\n---\n\n## Development\n\n1. **Run Tests:**\n   ```bash\n   poetry run pytest\n   ```\n\n2. **Code Linting:**\n   ```bash\n   poetry run pre-commit run -a\n   ```\n\n3. **Build the Project:**\n   ```bash\n   poetry build\n   ```\n\n---\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE)..\n\n---\n\n## Acknowledgments\n\nSpecial thanks to the open-source community for providing the tools and libraries that made this project possible.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "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.",
    "version": "0.4.1",
    "project_urls": {
        "Homepage": "https://github.com/mfenerich/thinkhub.git",
        "Repository": "https://github.com/mfenerich/thinkhub.git"
    },
    "split_keywords": [
        "ai",
        " chat",
        " transcription",
        " framework"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1b703d039d991cdcb36fe3fc5da2eac6ecc31fb8de652dea309d4a8532e0277c",
                "md5": "0b46983dd61589878a812afee23b850f",
                "sha256": "761a6b5380cc028bd4b481e655de6d8129192afddd879f5ffd54464e570b1658"
            },
            "downloads": -1,
            "filename": "thinkhub-0.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0b46983dd61589878a812afee23b850f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.11",
            "size": 24666,
            "upload_time": "2025-03-07T08:41:46",
            "upload_time_iso_8601": "2025-03-07T08:41:46.904746Z",
            "url": "https://files.pythonhosted.org/packages/1b/70/3d039d991cdcb36fe3fc5da2eac6ecc31fb8de652dea309d4a8532e0277c/thinkhub-0.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cd2bd1720ce09509dfba2c4dc1e38119e24ee8a559aa8cbe76d3e9e7bbdb210f",
                "md5": "f27f6acaf2ff548ef53174730f13e764",
                "sha256": "dfadb6024f0f80478c37f2ed8a3de296c21daf7edded94e2b5f4689a8f5b4ffd"
            },
            "downloads": -1,
            "filename": "thinkhub-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f27f6acaf2ff548ef53174730f13e764",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.11",
            "size": 18863,
            "upload_time": "2025-03-07T08:41:48",
            "upload_time_iso_8601": "2025-03-07T08:41:48.371798Z",
            "url": "https://files.pythonhosted.org/packages/cd/2b/d1720ce09509dfba2c4dc1e38119e24ee8a559aa8cbe76d3e9e7bbdb210f/thinkhub-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-03-07 08:41:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mfenerich",
    "github_project": "thinkhub",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "thinkhub"
}
        
Elapsed time: 0.40809s