Skip to main content

TaskBuilder

Struct TaskBuilder 

Source
pub struct TaskBuilder {
    pub id: u128,
    pub model: Option<String>,
    pub max_tokens: Option<u64>,
    pub payload: Option<Value>,
    pub system: Option<String>,
    pub history: Option<Vec<Interaction>>,
    pub schema: Option<Value>,
    pub prompt: Option<String>,
}
Expand description

Builds a chat task; only the prompt is required at build time.

Prefer Self::new for a generated ID: derived Default uses ID zero.

Fields§

§id: u128

Correlation ID; must be unique among outstanding memory-queue tasks.

§model: Option<String>

Explicit model, overriding the producer/executor default when present.

§max_tokens: Option<u64>

Requested output limit; the API executor casts this to u32 unchecked.

§payload: Option<Value>

Caller metadata carried through the response, not sent to the model.

§system: Option<String>

System instruction, separate from conversation history.

§history: Option<Vec<Interaction>>

Earlier turns; the API executor ignores system entries here.

§schema: Option<Value>

JSON schema requested as strict structured output; not locally validated.

§prompt: Option<String>

Current prompt; None fails to build, but an empty string is accepted.

Implementations§

Source§

impl TaskBuilder

Source

pub fn new() -> Self

Creates an empty builder with an ID from utils::id.

Source

pub fn with_model<M: ToString>(self, model: M) -> Self

Overrides the default model; NATS uses this model to select a subject.

Source

pub fn with_max_tokens(self, max_tokens: u64) -> Self

Sets the requested output limit; keep it within u32 for the API executor.

Source

pub fn with_payload<P: Serialize>(self, payload: P) -> Self

Attaches caller metadata without including it in the model request.

§Panics

Panics if the payload cannot be serialized as JSON.

Source

pub fn with_system<S: ToString>(self, system: S) -> Self

Sets the system instruction prepended to the model’s messages.

Source

pub fn with_history<H: IntoIterator<Item = Interaction>>( self, history: H, ) -> Self

Replaces earlier turns; the API executor discards system entries.

Source

pub fn with_schema<S: Serialize>(self, schema: S) -> Self

Sets a strict output schema without validating schema correctness.

§Panics

Panics if the schema cannot be serialized as JSON.

Source

pub fn with_prompt<P: ToString>(self, prompt: P) -> Self

Sets the current prompt, sent as a user message by the API executor.

Source

pub fn build_chat(self) -> Result<Task>

Builds a chat task, returning an error if no prompt was supplied.

Model availability, token limits, and schema correctness are not checked.

Trait Implementations§

Source§

impl Clone for TaskBuilder

Source§

fn clone(&self) -> TaskBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TaskBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TaskBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for TaskBuilder

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for TaskBuilder

Source§

impl PartialEq for TaskBuilder

Source§

fn eq(&self, other: &TaskBuilder) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for TaskBuilder

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for TaskBuilder

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> MaybeSend for T
where T: Send,

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more