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-assistant = { git = "https://github.com/gdml/surfaice-assistant.git", branch = "function_calling" }
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:
-
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__inimplementations/__init__.py
- Create a new file in the
-
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 }
-
Define a constant for your provider name at the top of
processor_2.py:YOUR_PROVIDER = "your_provider"
-
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
- Uses the standard response models from
Implementation Requirements
Your implementation class must:
- Inherit from
AssistantInterface - Implement all abstract methods defined in the interface
- 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_providermodule - Add the type of your models to unions in
abstract_provider.assistantmodels - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file surfaice_assistant-0.2.7.tar.gz.
File metadata
- Download URL: surfaice_assistant-0.2.7.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/6.8.0-1017-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f4bd8fed8867bd7b3a9f0b81469b0c9c70d27c6fe80376e4eb421b4821a2eeb
|
|
| MD5 |
280be1478ef9eda9886a0610f7d9cacd
|
|
| BLAKE2b-256 |
96fb696669519b660a36580270994813e6acc153eca0b923f0f3dff06cea7da0
|
File details
Details for the file surfaice_assistant-0.2.7-py3-none-any.whl.
File metadata
- Download URL: surfaice_assistant-0.2.7-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/6.8.0-1017-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
763fdcf68a318222a220a2f102c8f520839adc827a9423d376ec4875f707a059
|
|
| MD5 |
af17ab228a586acf2521ed162b22a2bf
|
|
| BLAKE2b-256 |
19832fb178c47ae2fe47ff349c4099775b4612b7eec37463750e9ee021f94181
|