Struct llm_chain::Parameters

source ·
pub struct Parameters(_);
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_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.

Trait Implementations§

source§

impl Clone for Parameters

source§

fn clone(&self) -> Parameters

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

source§

fn get_index(&self, index: usize) -> Result<Option<Argument<'_>>, ()>

Returns the argument with the specified index. Read more
source§

fn get_key(&self, key: &str) -> Result<Option<Argument<'_>>, ()>

Returns the argument with the given name. 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<HashMap<String, String, RandomState>> 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), Global>> for Parameters

source§

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

Converts to this type from the input type.
source§

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

source§

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

Converts to this type from the input type.

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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.
const: unstable · 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.
const: unstable · source§

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

Performs the conversion.