llm_chain::prompt

Enum Data

Source
pub enum Data<T> {
    Chat(ChatMessageCollection<T>),
    Text(T),
}
Expand description

An enum representing either a collection of chat messages or a single text.

Variants§

§

Chat(ChatMessageCollection<T>)

A collection of chat messages.

§

Text(T)

A text prompt.

Implementations§

Source§

impl<T> Data<T>

Source

pub fn text(text: T) -> Self

Source

pub fn map<U, F: Fn(&T) -> U>(&self, f: F) -> Data<U>

Maps the body of the chat messages or the text in the Data enum using the provided function.

§Arguments
  • f - A function that takes a reference to the body of a chat message or the text and returns a value of type U.
§Returns

A new Data<U> with the body of the chat messages or the text mapped by the provided function.

Source

pub fn try_map<U, E, F: Fn(&T) -> Result<U, E>>( &self, f: F, ) -> Result<Data<U>, E>

Maps the body of the chat messages or the text in the Data enum using the provided function that might fail.

§Arguments
  • f - A function that takes a reference to the body of a chat message or the text and returns a Result<U, E> value.
§Returns

A Result<Data<U>, E> with the body of the chat messages or the text mapped by the provided function. If the provided function returns an error, the error will be propagated in the result.

Source

pub fn extract_last_body(&self) -> Option<&T>

Extracts the body of the last message in the Data, or simply returns the Text if it is a text prompt

Source§

impl Data<String>

Source

pub fn to_chat(&self) -> ChatMessageCollection<String>

Source

pub fn to_text(&self) -> String

Source

pub fn combine(&self, other: &Self) -> Self

Combines two Data values into one.

If both values are Chat, the two chat collections will be combined. If one value is Chat and the other is Text, the text will be added as a message to the chat collection.

§Arguments
  • other - The other Data value to combine with.
Source§

impl Data<StringTemplate>

Source

pub async fn run<E: Executor>( &self, parameters: &Parameters, executor: &E, ) -> Result<Output, FormatAndExecuteError>

Helper function to run a prompt template.

§Arguments

parameters: &Parameters - The parameters to use for the prompt template. executor: &E - The executor to use for the prompt template.

§Returns

The output of applying the prompt template to the model.

Source

pub fn format( &self, parameters: &Parameters, ) -> Result<Data<String>, StringTemplateError>

Trait Implementations§

Source§

impl<T: Clone> Clone for Data<T>

Source§

fn clone(&self) -> Data<T>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Data<T>

Source§

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

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

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

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<T: Display> Display for Data<T>

Source§

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

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

impl<T> From<ChatMessage<T>> for Data<T>

Source§

fn from(chat: ChatMessage<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<ChatMessageCollection<T>> for Data<T>

Source§

fn from(chat: ChatMessageCollection<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for Data<T>

Source§

fn from(text: T) -> Self

Converts to this type from the input type.
Source§

impl<T> Serialize for Data<T>
where T: Serialize,

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<T> StorableEntity for Data<T>

Source§

fn get_metadata() -> Vec<(String, String)>

Source§

fn to_envelope(self) -> Envelope<Self>
where Self: Sized,

Source§

fn from_envelope(envelope: Envelope<Self>) -> Self

Source§

fn read_file_sync(path: &str) -> Result<Self, EnvelopeError>

Source§

fn write_file_sync(self, path: &str) -> Result<(), EnvelopeError>

Auto Trait Implementations§

§

impl<T> Freeze for Data<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Data<T>
where T: RefUnwindSafe,

§

impl<T> Send for Data<T>
where T: Send,

§

impl<T> Sync for Data<T>
where T: Sync,

§

impl<T> Unpin for Data<T>
where T: Unpin,

§

impl<T> UnwindSafe for Data<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

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

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

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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
Source§

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