pub struct Generation { /* private fields */ }Expand description
One call being assembled.
Every setting is optional; ai.prompt("…").generate().await is a complete
program.
Implementations§
Source§impl Generation
impl Generation
pub fn model(self, model: impl Into<String>) -> Generation
pub fn system(self, system: impl Into<String>) -> Generation
Sourcepub fn prompt(self, text: impl Into<String>) -> Generation
pub fn prompt(self, text: impl Into<String>) -> Generation
What to ask. Sugar for a single user message.
pub fn message(self, message: Message) -> Generation
pub fn conversation(self, conversation: Conversation) -> Generation
pub fn temperature(self, temperature: f64) -> Generation
pub fn max_tokens(self, max_tokens: u32) -> Generation
pub fn stop(self, sequence: impl Into<String>) -> Generation
Sourcepub fn tool(self, tool: Tool) -> Generation
pub fn tool(self, tool: Tool) -> Generation
Offer the model a tool it may ask for but that this crate will not run — for a caller who wants to handle the tool call themselves.
Sourcepub fn tools(self, toolbox: Toolbox) -> Generation
pub fn tools(self, toolbox: Toolbox) -> Generation
Offer tools and run them: Generation::generate then loops until the
model answers in words.
Sourcepub fn max_rounds(self, max_rounds: usize) -> Generation
pub fn max_rounds(self, max_rounds: usize) -> Generation
How many model turns the tool loop may take.
Sourcepub fn request(&self) -> &Request
pub fn request(&self) -> &Request
The request as it will be sent, for tests and for inspection.
Sourcepub async fn generate(self) -> Result<Completion>
pub async fn generate(self) -> Result<Completion>
Ask, and wait for the whole answer.
Sourcepub async fn text(self) -> Result<String>
pub async fn text(self) -> Result<String>
Ask, and keep only the words — the shortest useful call there is.
Sourcepub async fn stream(self) -> Result<TextStream>
pub async fn stream(self) -> Result<TextStream>
Ask, and read the answer as it is written.
Tools are not run while streaming: a tool call is not text, and a caller
who wants both should use Generation::generate.
Sourcepub async fn generate_as(self, schema: &Schema) -> Result<Json>
pub async fn generate_as(self, schema: &Schema) -> Result<Json>
Ask for JSON matching a schema, and get it parsed.
Retries once if the model’s answer will not parse; see
structured::generate_as.