#[cfg(feature = "client-async")]
#[tokio::main]
async fn main() {
use llm_kernel::llm::{ChatMessage, LLMClient, ModelConfig, OpenAIClient};
let config = ModelConfig {
provider: "openai".into(),
model: "gpt-4o-mini".into(),
api_key_env: "OPENAI_API_KEY".into(),
base_url: None,
temperature: 0.7,
max_tokens: Some(256),
};
let client = OpenAIClient::new(&config).expect("failed to create client");
let response = client
.complete(llm_kernel::llm::LLMRequest {
system: Some("You are a helpful assistant. Reply in one sentence.".into()),
messages: vec![ChatMessage::user("What is llm-kernel?")],
model: None,
temperature: 0.7,
max_tokens: Some(256),
response_format: None,
tools: None,
})
.await
.expect("completion failed");
println!("Model: {}", response.model);
println!(
"Tokens: {} in / {} out",
response.usage.prompt_tokens, response.usage.completion_tokens
);
println!("Reply: {}", response.content);
}
#[cfg(not(feature = "client-async"))]
fn main() {
eprintln!("This example requires the client-async feature.");
eprintln!("Run: cargo run --example chat_openai --features client-async");
}