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().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)
}