Skip to main content

No project description provided

Project description

Assistant Processor Guides

Warning

The file processor_2.py is a temporary file used in the current branch and will be renamed to processor.py. Please be aware that any references to processor_2.py should be updated to processor.py once the renaming is complete.

Installation

Poetry Installation from Git

To install this package directly from Git using Poetry, add the following to your pyproject.toml:

[tool.poetry.dependencies]
surfaice-assistance = { git = "https://github.com/gdml/surfaice-assistant.git", branch = "feature/s42t207_add-ai-models-choice" }

or locally:

[tool.poetry.dependencies]
surfaice-assistant = { path = "path/to/surfaice-assistant"}

Usage

Basic Setup

from surfaice_assistance.processor2 import AssistantProcessor   

class YourClass:
    ...

    @property
    def assistant_processor(self) -> AssistantProcessor:
        return AssistantProcessor(api_key=self.api_key, provider=self.provider.value)
    ...

    def create_assistant(self) -> AssistantCreateResponse:
        return self.assistant_processor.create_assistant(
            name="Your Assistant Name",
            description="Your Assistant Description",
            instructions="Your Assistant Instructions",
            model="gpt-4o",
            tools=list[dict],
        )   

    def get_assistant(self) -> AssistantGetResponse:
        return self.assistant_processor.get_assistant(
            assistant_id="your_assistant_id",
        )
    
    def update_assistant(self) -> AssistantUpdateResponse:
        return self.assistant_processor.update_assistant(
            assistant_id="your_assistant_id",
            name="Your Assistant Name",
            description="Your Assistant Description",
            instructions="Your Assistant Instructions",
            model="gpt-4o",
            tools=list[dict],
        )
    
    # ... other methods

Adding a New Implementation

When adding a new assistant implementation to the system, follow these steps:

  1. Create a new implementation class that inherits from AssistantInterface:

    • Create a new file in the implementations/ directory
    • Implement all abstract methods from AssistantInterface
    • Follow the response models pattern using Pydantic models
    • Add import to __all__ in implementations/__init__.py
  2. Register the implementation in processor_2.py:

    from implementations.your_provider import YourProviderImpl
    
    processor_implementations: dict[str, Union[Type[OpenAIAssistantImpl], Type[YourProviderImpl], Any]] = {
        OPENAI: OpenAIAssistantImpl,
        "your_provider": YourProviderImpl,  # Add your implementation here
    }
    
  3. Define a constant for your provider name at the top of processor_2.py:

    YOUR_PROVIDER = "your_provider"
    
  4. Ensure your implementation:

    • Uses the standard response models from abstract_provider.assistant
    • Handles retries and error cases consistently
    • Includes proper logging
    • Has appropriate type hints
    • Follows the existing pattern for async methods

Implementation Requirements

Your implementation class must:

  1. Inherit from AssistantInterface
  2. Implement all abstract methods defined in the interface
  3. Use the standard response models:
    • AssistantCreateResponse
    • AssistantGetResponse
    • ThreadGetResponse
    • MessageCreateResponse
    • etc.

Example Implementation Structure

from abstract_provider import AssistantInterface
from abstract_provider.assistant import (
    AssistantCreateResponse,
    AssistantGetResponse,
# ... other response models
)
class YourProviderImpl(AssistantInterface):
    def init(self, api_key: str) -> None:
    # Initialize your provider's client
        pass
    async def create_assistant(
        self,
        name: str,
        description: str,
        instructions: str,
        model: str,
        tools: list[dict],
        max_retries: int = 5,
        ) -> AssistantCreateResponse:
        pass

Reference Implementation

See the OpenAI implementation (implementations/openai_provider.py) for a complete example of how to structure your implementation.

Guidelines for Response Models

  • Use Pydantic models for response models
  • Follow the response models pattern using Pydantic models
  • Add the response models to the implementations.your_provider module
  • Add the type of your models to unions in abstract_provider.assistant models
  • Example:
    from pydantic import BaseModel
    class YourResponseModel(BaseModel):
        # Define your model fields here
        success: bool   
        your_field: Optional[YourType] = None
        error: Optional[str] = None
    

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

surfaice_assistant-0.2.2.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

surfaice_assistant-0.2.2-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file surfaice_assistant-0.2.2.tar.gz.

File metadata

  • Download URL: surfaice_assistant-0.2.2.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.3 Darwin/24.1.0

File hashes

Hashes for surfaice_assistant-0.2.2.tar.gz
Algorithm Hash digest
SHA256 2e233400045ba8a45fae70aa287c8f46cafb29fc61bfc561ca6f9a9bb812821f
MD5 da50195a581613e426e0cc4b9e8e9f14
BLAKE2b-256 76df30365cc1f66deb92658ee6dc5196ded958deda47d763f8f4aa48c67b523a

See more details on using hashes here.

File details

Details for the file surfaice_assistant-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: surfaice_assistant-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.3 Darwin/24.1.0

File hashes

Hashes for surfaice_assistant-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 916733d018df76e71e180760810cb8d8223746ff195a770590213283e73b447d
MD5 0882ede5b0e43518477ebac81c0d99dc
BLAKE2b-256 27f96a3506897ca98669799a4fefe2c302d8c85bd2480addc7c158cad18f6061

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