Implementation:869413421 Ai moive studio ProviderFactory
| Knowledge Sources | |
|---|---|
| Domains | Architecture, Generative_AI |
| Last Updated | 2026-10-23 12:00 GMT |
Overview
Factory class that constructs GatewayProvider instances from provider names, API key models, or video task contexts, with credential validation and protocol version checking.
Description
ProviderFactory provides three construction paths:
- create(): Constructs from a raw provider name and plaintext API key
- from_key(): Constructs from an APIKey model object; decrypts the key via key.get_api_key(), validates the key is active, and optionally checks protocol version and connection consistency for video task contexts
- resume_video(): Constructs a provider for resuming video task polling; uses from_key with the saved context, or falls back to LegacyVideoQuery for historical tasks without a protocol snapshot
⚠️ Deprecation Notice: The resume_video() fallback to LegacyVideoQuery (in backend/src/services/provider/legacy_video.py) is a legacy code path for tasks created before protocol context snapshots existed. Do not extend it. See Heuristic:869413421_Ai_moive_studio_Warning_Deprecated_Legacy_Video_Query for details.
Usage
Import when you need to create a GatewayProvider for any generation operation. Used by all services that call the gateway.
Code Reference
Source Location
- Repository: ai-moive-studio
- File: backend/src/services/provider/factory.py:L6-33
Signature
class ProviderFactory:
@staticmethod
def create(provider: str, api_key: str, **kwargs) -> GatewayProvider: ...
@staticmethod
def from_key(key, *, context=None, max_concurrency=5) -> GatewayProvider: ...
@staticmethod
def resume_video(key, context) -> GatewayProvider: ...
Import
from src.services.provider.factory import ProviderFactory
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| provider | str | Yes (create) | Provider name |
| api_key | str | Yes (create) | Plaintext API key |
| key | APIKey | Yes (from_key) | API key model with encrypted value |
| context | dict | No | Video task protocol context |
| max_concurrency | int | No | Semaphore limit (default 5) |
Outputs
| Name | Type | Description |
|---|---|---|
| return value | GatewayProvider | Configured provider instance |
Usage Examples
Creating from API Key Model
from src.services.provider.factory import ProviderFactory
# From APIKey model
provider = ProviderFactory.from_key(api_key_model, max_concurrency=10)
# From raw provider name
provider = ProviderFactory.create(provider="openai", api_key="sk-...")
# Resume video task polling
provider = ProviderFactory.resume_video(api_key_model, saved_context)
Related Pages
Implements Principle
- Principle:869413421_Ai_moive_studio_Multi_Provider_Gateway
- Principle:869413421_Ai_moive_studio_Provider_Registry