1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#![allow(unused)]
use kalosm::language::*;
// You can derive an efficient parser for your struct with the `Parse` trait
#[derive(Schema, Parse, Clone, Debug)]
struct Account {
/// A summary of the account holder
#[parse(pattern = r"[a-zA-Z,.?!\d ]{1,80}")]
summary: String,
/// The name of the account holder. This may be the full name of the user or a pseudonym
#[parse(pattern = "[a-zA-Z ]{1,20}")]
name: String,
/// The age of the account holder
#[parse(range = 1..=100)]
age: u8,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Download default chat model or get the model from the cache
let llm = Llama::new_chat().await?;
// Create a task that generates a list of accounts
let task = llm
.task("You generate accounts based on a description of the account holder")
// The typed combinator constraints the task for the default parser for the type you get out. (In
// this case, Account)
.typed();
// Task can be called like a function with the input to the task. You can await the stream, modify the
// constraints, or sampler
let account: Account =
task("Candice is the CEO of a fortune 500 company. She is a 30 years old.").await?;
println!("{:#?}", account);
Ok(())
}