Skip to main content

Generation

Struct Generation 

Source
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

Source

pub fn model(self, model: impl Into<String>) -> Generation

Source

pub fn system(self, system: impl Into<String>) -> Generation

Source

pub fn prompt(self, text: impl Into<String>) -> Generation

What to ask. Sugar for a single user message.

Source

pub fn message(self, message: Message) -> Generation

Source

pub fn conversation(self, conversation: Conversation) -> Generation

Source

pub fn temperature(self, temperature: f64) -> Generation

Source

pub fn max_tokens(self, max_tokens: u32) -> Generation

Source

pub fn stop(self, sequence: impl Into<String>) -> Generation

Source

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.

Source

pub fn tools(self, toolbox: Toolbox) -> Generation

Offer tools and run them: Generation::generate then loops until the model answers in words.

Source

pub fn max_rounds(self, max_rounds: usize) -> Generation

How many model turns the tool loop may take.

Source

pub fn request(&self) -> &Request

The request as it will be sent, for tests and for inspection.

Source

pub async fn generate(self) -> Result<Completion>

Ask, and wait for the whole answer.

Source

pub async fn text(self) -> Result<String>

Ask, and keep only the words — the shortest useful call there is.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.