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
impl Parameters
Sourcepub fn new() -> Parameters
pub fn new() -> Parameters
Creates a new empty set of parameters.
Sourcepub fn new_with_text<T: Into<String>>(text: T) -> Parameters
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.
Sourcepub fn with<K: Into<String>, V: Into<String>>(
&self,
key: K,
value: V,
) -> Parameters
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.
Sourcepub fn with_dynamic<K: Into<String>, V: ParamFull>(
&self,
key: K,
value: V,
) -> Parameters
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.
Sourcepub fn with_text<K: Into<String>>(&self, text: K) -> Parameters
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.
Sourcepub fn combine(&self, other: &Parameters) -> Parameters
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.
Sourcepub fn get(&self, key: &str) -> Option<String>
pub fn get(&self, key: &str) -> Option<String>
Returns the value of the given key, or None
if the key does not exist.