use ailloy::{ChatOptions, Client, Message};
pub async fn generate_text(system_prompt: &str, user_prompt: &str) -> anyhow::Result<String> {
generate_text_with_limit(system_prompt, user_prompt, 2000).await
}
pub async fn generate_text_with_limit(
system_prompt: &str,
user_prompt: &str,
max_tokens: u32,
) -> anyhow::Result<String> {
let client = Client::from_config()?;
let opts = ChatOptions::builder()
.temperature(0.3)
.max_tokens(max_tokens)
.build();
let response = client
.chat_with(
&[Message::system(system_prompt), Message::user(user_prompt)],
&opts,
)
.await?;
Ok(response.content)
}
pub fn is_configured() -> bool {
ailloy::config::Config::load()
.map(|c| c.default_chat_node().is_ok())
.unwrap_or(false)
}
pub fn provider_display_name() -> Option<String> {
let config = ailloy::config::Config::load().ok()?;
let (id, _node) = config.default_chat_node().ok()?;
Some(id.to_string())
}