Skip to main content

gpt_oss/
main.rs

1use anyhow::Result;
2use mistralrs::{TextMessageRole, TextMessages, TextModelBuilder};
3
4#[tokio::main]
5async fn main() -> Result<()> {
6    let model = TextModelBuilder::new("openai/gpt-oss-20b")
7        .with_logging()
8        .build()
9        .await?;
10
11    let messages = TextMessages::new()
12        .add_message(
13            TextMessageRole::System,
14            "You are an AI agent with a specialty in programming.",
15        )
16        .add_message(
17            TextMessageRole::User,
18            "Hello! How are you? Please write generic binary search function in Rust.",
19        );
20
21    let response = model.send_chat_request(messages).await?;
22
23    println!("{}", response.choices[0].message.content.as_ref().unwrap());
24    dbg!(
25        response.usage.avg_prompt_tok_per_sec,
26        response.usage.avg_compl_tok_per_sec
27    );
28
29    Ok(())
30}