use multi_llm::{
unwrap_response, DefaultLLMParams, LLMConfig, LMStudioConfig, LlmProvider, UnifiedLLMClient,
UnifiedLLMRequest, UnifiedMessage,
};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let config = LLMConfig {
provider: Box::new(LMStudioConfig {
base_url: "http://localhost:1234".to_string(),
default_model: "local-model".to_string(), max_context_tokens: 4096,
retry_policy: Default::default(),
}),
default_params: DefaultLLMParams::default(),
};
let client = UnifiedLLMClient::from_config(config)?;
let request = UnifiedLLMRequest::new(vec![
UnifiedMessage::system("You are a helpful assistant. Be concise."),
UnifiedMessage::user("What is the capital of France? Answer in one sentence."),
]);
println!("Sending request to LM Studio (local)...");
println!("Note: Make sure LM Studio is running with a model loaded.\n");
let response = unwrap_response!(client.execute_llm(request, None, None).await?);
println!("Response: {}", response.content);
if let Some(usage) = &response.usage {
println!(
"\nToken usage: {} input + {} output = {} total",
usage.prompt_tokens, usage.completion_tokens, usage.total_tokens
);
}
Ok(())
}