Skip to main content

LLM Context Providers

A Python package to manage and fetch context from various sources like Asana, Quip, OneNote, Outlook Calendar, etc. This package is designed to be easily extensible, allowing new context providers to be added with minimal changes to the core logic.

Features

  • Fetch context from multiple sources asynchronously or synchronously.
  • Easily extendable with new context providers.
  • Configurable through YAML configuration.
  • Handles retries and errors gracefully.

Installation

pip install llm-context-providers

Quick Start

Create an app.py file with the following content to quickly get started:

from llm_context_providers import ContextManager

config = {
    'global': {
        'timezone': 'America/Toronto'
    },
    'context_providers': {
        'asana': {
            'enabled': True,
            'project_id': 'your_asana_project_id',
            'personal_access_token': 'your_personal_access_token',
            'fields': {
                'Task': 'name',
                'Task ID': 'gid',
                'Created At': 'created_at',
                'Modified At': 'modified_at',
                'Completed': 'completed',
                'Assignee': 'assignee',
                'Due On': 'due_on',
                'Notes': 'notes'
            }
        }
    }
}

def main_sync(config):
    manager = ContextManager(config)
    manager.fetch_contexts()
    context = manager.get_combined_context()
    print("Sync Fetch Context (All):\n", context)

if __name__ == "__main__":
    main_sync(config)

Run the application:

python app.py

Full Functionality

For easier maintainability and to handle more complex configurations, it's recommended to use a config.yml file. Here is an example configuration:

global:
  timezone: "America/Toronto"

context_providers:
  asana:
    enabled: true
    project_id: "your_asana_project_id"
    fields:
      Task: "name"
      Task ID: "gid"
      Created At: "created_at"
      Modified At: "modified_at"
      Completed: "completed"
      Assignee: "assignee"
      Due On: "due_on"
      Notes: "notes"
  # Add other context providers here

Using the Configuration File

Update your app.py to load configuration from config.yml and demonstrate the full functionality, including asynchronous and specific context fetching:

import yaml
import asyncio
from llm_context_providers import ContextManager

def load_config(config_file='config.yml'):
    with open(config_file, 'r') as file:
        return yaml.safe_load(file)

async def main_async(config):
    manager = ContextManager(config)
    await manager.fetch_contexts_async()
    context = manager.get_combined_context()
    print("Async Fetch Context (All):\n", context)

async def main_async_specific(config):
    manager = ContextManager(config)
    await manager.fetch_contexts_async(providers=['asana'])
    context = manager.get_combined_context(providers=['asana'])
    print("Async Fetch Context (Specific):\n", context)

def main_sync(config):
    manager = ContextManager(config)
    manager.fetch_contexts()
    context = manager.get_combined_context()
    print("Sync Fetch Context (All):\n", context)

def main_sync_specific(config):
    manager = ContextManager(config)
    manager.fetch_contexts(providers=['asana'])
    context = manager.get_combined_context(providers=['asana'])
    print("Sync Fetch Context (Specific):\n", context)

if __name__ == "__main__":
    config = load_config()

    print("Testing Async Fetch (All):")
    asyncio.run(main_async(config))

    print("\nTesting Async Fetch (Specific):")
    asyncio.run(main_async_specific(config))

    print("\nTesting Sync Fetch (All):")
    main_sync(config)

    print("\nTesting Sync Fetch (Specific):")
    main_sync_specific(config)

Run the application:

python app.py

Extending with New Context Providers

To add a new context provider, create a new class that inherits from ContextProvider and implement the necessary methods:

from llm_context_providers import ContextProvider

class NewContextProvider(ContextProvider):
    def __init__(self, **kwargs):
        super().__init__()
        # Initialize with necessary credentials and configurations

    async def fetch_context_async(self, full_fetch: bool = False):
        # Implement async context fetching logic
        pass

    def fetch_context(self, full_fetch: bool = False):
        # Implement sync context fetching logic
        pass

    def get_context(self):
        # Return the context information
        pass

    async def index_context(self):
        # Implement indexing logic
        pass

    async def search_index(self, query: str):
        # Implement search logic
        pass

    def load_from_index(self, search_results):
        # Implement logic to load search results into context
        pass

Add the new context provider to your configuration file and ensure the package's ContextProvider class can recognize the new provider.

Contributing

Contributions are welcome! Please create a pull request or raise an issue to discuss your ideas.

License

This project is licensed under the MIT License.

Metadata

Release files for llm-context-providers 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-context-providers 0.1.1
File Size Uploaded
llm_context_providers-0.1.1.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-context-providers 0.1.1
File Interpreter ABI Platform
llm_context_providers-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.7 kB

Release files / llm_context_providers-0.1.1.tar.gz

Download URL llm_context_providers-0.1.1.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0084ef9e7f133184e40a8acfb0b487c2e26b5d043fcbd8440a03697e91841b52
BLAKE2b-256 checksum
How to use checksums
082748892de42950502e72d9957e787f8c01490976997e17d5f99de5704de1e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / llm_context_providers-0.1.1-py3-none-any.whl

Download URL llm_context_providers-0.1.1-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
edf1dfed6c766140c5f4d22d710edb6198f952f535388e2d57f1c930d404b1ce
BLAKE2b-256 checksum
How to use checksums
0d4d0ba32725ed5d6c4b9ce8bc191846fb36825d6c9061931b220ba88a98b89e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page