pub struct Parameters { /* private fields */ }
Expand description

Parameters define the parameters sent into each step. The parameters are used to fill in the prompt template, and are also filled in by the output of the previous step. Parameters have a special key, text, which is used as a default key for simple use cases.

Parameters also implement a few convenience conversion traits to make it easier to work with them.

Examples

Creating a default parameter from a string

use llm_chain::Parameters;
let p: Parameters = "Hello world!".into();
assert_eq!(p.get("text").unwrap().as_str(), "Hello world!");

Creating a list of parameters from a list of pairs

use llm_chain::Parameters;
let p: Parameters = vec![("text", "Hello world!"), ("name", "John Doe")].into();
assert_eq!(p.get("text").unwrap().as_str(), "Hello world!");
assert_eq!(p.get("name").unwrap().as_str(), "John Doe");

Implementations§

source§

impl Parameters

source

pub fn new() -> Parameters

Creates a new empty set of parameters.

source

pub fn new_with_text<T: Into<String>>(text: T) -> Parameters

Creates a new set of parameters with a single key, text, set to the given value.

source

pub fn with<K: Into<String>, V: Into<String>>( &self, key: K, value: V ) -> Parameters

Copies the parameters and adds a new key-value pair.

source

pub fn with_dynamic<K: Into<String>, V: ParamFull>( &self, key: K, value: V ) -> Parameters

Copies the parameters and adds a new key-value pair pair, where the value is a dynamic parameter.

source

pub fn with_text<K: Into<String>>(&self, text: K) -> Parameters

Copies the parameters and adds a new key-value pair with the key text, which is the default key.

source

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

Combines two sets of parameters, returning a new set of parameters with all the keys from both sets.

source

pub fn get(&self, key: &str) -> Option<String>

Returns the value of the given key, or None if the key does not exist.

source

pub fn get_text(&self) -> Option<String>

Trait Implementations§

source§

impl Clone for Parameters

source§

fn clone(&self) -> Self

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 Debug for Parameters

source§

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

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

impl Default for Parameters

source§

fn default() -> Parameters

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

impl From<&str> for Parameters

source§

fn from(text: &str) -> Self

Converts to this type from the input type.
source§

impl From<BTreeMap<String, String>> for Parameters

source§

fn from(map: BTreeMap<String, String>) -> Self

Converts to this type from the input type.
source§

impl From<HashMap<String, String>> for Parameters

source§

fn from(map: HashMap<String, String>) -> Self

Converts to this type from the input type.
source§

impl From<String> for Parameters

source§

fn from(text: String) -> Self

Converts to this type from the input type.
source§

impl From<Vec<(&str, &str)>> for Parameters

source§

fn from(data: Vec<(&str, &str)>) -> Self

Converts to this type from the input type.
source§

impl From<Vec<(String, String)>> for Parameters

source§

fn from(data: Vec<(String, String)>) -> Self

Converts to this type from the input type.
source§

impl PartialEq for Parameters

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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.

§

impl<T> Instrument for T

§

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

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

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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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