orch is a library for building language model powered applications and agents for the Rust programming language.
It was primarily built for usage in magic-cli, but can be used in other contexts as well.
Examples
Basic Usage
Simple Text Generation
use *;
use *;
async
Streaming Text Generation
use *;
use *;
use StreamExt;
async
Structured Data Generation
use orch::execution::*;
use orch::lm::*;
use orch::response::*;
#[derive(OrchResponseOptions)]
pub enum CapitalCityExecutorResponseOptions {
#[response(
scenario = "You know the capital city of the country",
description = "Capital city of the country"
)]
#[schema(
field = "capital",
description = "Capital city of the received country",
example = "London"
)]
Answer { capital: String },
#[response(
scenario = "You don't know the capital city of the country",
description = "Reason why the capital city is not known"
)]
#[schema(
field = "reason",
description = "Reason why the capital city is not known",
example = "Country 'foobar' does not exist"
)]
Fail { reason: String },
}
#[tokio::main]
async fn main() {
let lm = OllamaBuilder::new().with_model(ollama_model::PHI3_MINI).try_build().unwrap();
let executor = StructuredExecutorBuilder::new()
.with_lm(&lm)
.with_preamble("You are a geography expert who helps users understand the capital city of countries around the world.")
.with_options(&options!(CapitalCityExecutorResponseOptions))
.try_build()
.unwrap();
let response = executor.execute("What is the capital of Fooland?").await.expect("Execution failed");
println!("Response:");
println!("{:?}", response.content);
}
Embedding Generation
use *;
use *;
async
More Examples
See the examples directory for usage examples.