pub trait ClassificationProvider: Send + Sync {
// Required method
fn classify_raw<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
system_prompt: &'life1 str,
user_prompt: &'life2 str,
schema: &'life3 Value,
config: &'life4 ClassifierConfig,
) -> Pin<Box<dyn Future<Output = Result<Value, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait;
}Expand description
Trait for AI classification backends.
Implement this trait to plug in any AI provider (Anthropic, OpenAI, local models). The single method receives raw prompts and a JSON schema, and returns a JSON value matching that schema.
§Object safety
This trait is object-safe and can be used as Arc<dyn ClassificationProvider>.
§Example
ⓘ
use ferro_ai::{ClassificationProvider, ClassifierConfig};
use async_trait::async_trait;
struct EchoProvider;
#[async_trait]
impl ClassificationProvider for EchoProvider {
async fn classify_raw(
&self,
_system_prompt: &str,
user_prompt: &str,
_schema: &serde_json::Value,
_config: &ClassifierConfig,
) -> Result<serde_json::Value, ferro_ai::Error> {
Ok(serde_json::json!({"echo": user_prompt}))
}
}Required Methods§
Sourcefn classify_raw<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
system_prompt: &'life1 str,
user_prompt: &'life2 str,
schema: &'life3 Value,
config: &'life4 ClassifierConfig,
) -> Pin<Box<dyn Future<Output = Result<Value, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn classify_raw<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
system_prompt: &'life1 str,
user_prompt: &'life2 str,
schema: &'life3 Value,
config: &'life4 ClassifierConfig,
) -> Pin<Box<dyn Future<Output = Result<Value, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Call the AI provider with raw prompts and return structured JSON.
The returned serde_json::Value must conform to the provided schema.
The schema is passed as a JSON Schema value; callers generate it via
schemars::schema_for!(T) or build it manually.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".