pub struct Example {
pub data: HashMap<String, Value>,
pub input_keys: Vec<String>,
pub output_keys: Vec<String>,
}
Fields§
§data: HashMap<String, Value>
§input_keys: Vec<String>
§output_keys: Vec<String>
Implementations§
Source§impl Example
impl Example
Sourcepub fn new(
data: HashMap<String, Value>,
input_keys: Vec<String>,
output_keys: Vec<String>,
) -> Self
pub fn new( data: HashMap<String, Value>, input_keys: Vec<String>, output_keys: Vec<String>, ) -> Self
Examples found in repository?
examples/01-simple.rs (lines 56-63)
50 async fn forward(&self, inputs: Example) -> Result<Prediction> {
51 let answerer_prediction = self.answerer.forward(inputs.clone()).await?;
52
53 let question = inputs.data.get("question").unwrap().clone();
54 let answer = answerer_prediction.data.get("answer").unwrap().clone();
55
56 let inputs = Example::new(
57 hashmap! {
58 "answer".to_string() => answer.clone(),
59 "question".to_string() => question.clone()
60 },
61 vec!["answer".to_string(), "question".to_string()],
62 vec![],
63 );
64 let rating_prediction = self.rater.forward(inputs).await?;
65 Ok(prediction! {
66 "answer"=> answer,
67 "question"=> question,
68 "rating"=> rating_prediction.data.get("rating").unwrap().clone(),
69 }
70 .set_lm_usage(rating_prediction.lm_usage))
71 }
More examples
examples/02-module-iteration-and-updation.rs (lines 72-79)
66 async fn forward(&self, inputs: Example) -> Result<Prediction> {
67 let answerer_prediction = self.answerer.forward(inputs.clone()).await?;
68
69 let question = inputs.data.get("question").unwrap().clone();
70 let answer = answerer_prediction.data.get("answer").unwrap().clone();
71
72 let inputs = Example::new(
73 hashmap! {
74 "answer".to_string() => answer.clone(),
75 "question".to_string() => question.clone()
76 },
77 vec!["answer".to_string(), "question".to_string()],
78 vec![],
79 );
80 let rating_prediction = self.rater.forward(inputs).await?;
81 Ok(prediction! {
82 "answer"=> answer,
83 "question"=> question,
84 "rating"=> rating_prediction.data.get("rating").unwrap().clone(),
85 }
86 .set_lm_usage(rating_prediction.lm_usage))
87 }
pub fn get(&self, key: &str, default: Option<&str>) -> Value
pub fn keys(&self) -> Vec<String>
pub fn values(&self) -> Vec<Value>
pub fn set_input_keys(&mut self, keys: Vec<String>)
pub fn with_input_keys(&self, keys: Vec<String>) -> Self
pub fn without(&self, keys: Vec<String>) -> Self
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Example
impl<'de> Deserialize<'de> for Example
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 IntoIterator for Example
impl IntoIterator for Example
Auto Trait Implementations§
impl Freeze for Example
impl RefUnwindSafe for Example
impl Send for Example
impl Sync for Example
impl Unpin for Example
impl UnwindSafe for Example
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more