Module

Trait Module 

Source
pub trait Module: Send + Sync {
    // Required method
    async fn forward(&self, inputs: Example) -> Result<Prediction>;

    // Provided method
    async fn batch(
        &self,
        inputs: Vec<Example>,
        max_concurrency: usize,
        display_progress: bool,
    ) -> Result<Vec<Prediction>> { ... }
}

Required Methods§

Source

async fn forward(&self, inputs: Example) -> Result<Prediction>

Provided Methods§

Source

async fn batch( &self, inputs: Vec<Example>, max_concurrency: usize, display_progress: bool, ) -> Result<Vec<Prediction>>

Examples found in repository?
examples/06-oai-compatible-models-batch.rs (line 106)
78async fn main() {
79    // Anthropic
80    configure(
81        LM::builder()
82            .api_key(SecretString::from(
83                std::env::var("ANTHROPIC_API_KEY").unwrap(),
84            ))
85            .config(LMConfig {
86                model: "anthropic/claude-sonnet-4-20250514".to_string(),
87                ..LMConfig::default()
88            })
89            .build(),
90        ChatAdapter,
91    );
92
93    let example = vec![
94        example! {
95            "question": "input" => "What is the capital of France?",
96        },
97        example! {
98            "question": "input" => "What is the capital of Germany?",
99        },
100        example! {
101            "question": "input" => "What is the capital of Italy?",
102        },
103    ];
104
105    let qa_rater = QARater::builder().build();
106    let prediction = qa_rater.batch(example.clone(), 2, true).await.unwrap();
107    println!("Anthropic: {prediction:?}");
108
109    // Gemini
110    configure(
111        LM::builder()
112            .api_key(SecretString::from(std::env::var("GEMINI_API_KEY").unwrap()))
113            .config(LMConfig {
114                model: "google/gemini-2.0-flash".to_string(),
115                ..LMConfig::default()
116            })
117            .build(),
118        ChatAdapter,
119    );
120
121    let prediction = qa_rater.batch(example, 2, true).await.unwrap();
122    println!("Gemini: {prediction:?}");
123}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§