Skip to main content

AIProvider

Trait AIProvider 

Source
pub trait AIProvider: Send + Sync {
    // Required methods
    fn analyze_content<'life0, 'async_trait>(
        &'life0 self,
        request: AnalysisRequest,
    ) -> Pin<Box<dyn Future<Output = Result<MatchResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn verify_match<'life0, 'async_trait>(
        &'life0 self,
        verification: VerificationRequest,
    ) -> Pin<Box<dyn Future<Output = Result<ConfidenceScore>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn chat_completion<'life0, 'async_trait>(
        &'life0 self,
        _messages: Vec<Value>,
    ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

AI provider trait for content analysis and subtitle matching.

This trait defines the interface for AI services that can analyze video and subtitle content to determine optimal matches.

Required Methods§

Source

fn analyze_content<'life0, 'async_trait>( &'life0 self, request: AnalysisRequest, ) -> Pin<Box<dyn Future<Output = Result<MatchResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Analyze multimedia files and subtitle files for matching results.

§Arguments
  • request - Analysis request containing files and content samples
§Returns

A MatchResult containing potential matches with confidence scores

Source

fn verify_match<'life0, 'async_trait>( &'life0 self, verification: VerificationRequest, ) -> Pin<Box<dyn Future<Output = Result<ConfidenceScore>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Verify file matching confidence.

§Arguments
  • verification - Verification request for existing matches
§Returns

A confidence score for the verification request

Provided Methods§

Source

fn chat_completion<'life0, 'async_trait>( &'life0 self, _messages: Vec<Value>, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a raw chat completion request to the provider.

This provides a provider-neutral entry point for callers (such as the translation engine) that need to issue prompts that do not fit the matching/verification request shape. Each provider implementation is responsible for handling authentication, retries, response size limits, and error sanitization, mirroring its specialized methods.

§Arguments
  • messages - OpenAI-compatible chat messages, e.g. [{"role":"system","content":"..."},{"role":"user","content":"..."}].
§Returns

The assistant message text from the first choice in the response.

§Errors

Returns crate::error::SubXError::AiService for HTTP, parsing, or upstream provider errors. The default implementation returns crate::error::SubXError::AiService indicating the provider does not support raw chat completion; only providers that override this method support translation prompts.

Implementors§