pub struct Prompt<'a>(/* private fields */);Expand description
A prompt which is passed to the model for inference. Usually it is one text item, but it could also be a combination of several modalities like images and text.
Implementations§
Source§impl<'a> Prompt<'a>
impl<'a> Prompt<'a>
Sourcepub fn from_text(text: impl Into<Cow<'a, str>>) -> Self
pub fn from_text(text: impl Into<Cow<'a, str>>) -> Self
Create a prompt from a single text item.
Sourcepub fn from_vec(items: Vec<Modality<'a>>) -> Self
pub fn from_vec(items: Vec<Modality<'a>>) -> Self
Create a multimodal prompt from a list of individual items with any modality.
Sourcepub fn borrow(&'a self) -> Prompt<'a>
pub fn borrow(&'a self) -> Prompt<'a>
Allows you to borrow the contents of the prompt without allocating a new one.
Sourcepub fn join_consecutive_text_items(&mut self, separator: &str)
pub fn join_consecutive_text_items(&mut self, separator: &str)
When constructing prompts programatically, it can be beneficial to append several text items in a prompt. For example, if doing a fewshot prompt as the first item, and user input as a second item.
However, because of how tokenization works, having each item tokenized separately can sometimes have strange side effects (tokenizing two partial strings does not necessarily produce the same tokens as tokenizing the strings joined together).
This method will take an existing prompt and merge any consecutive prompt items by a given separator. You can use an empty string for the separator if you want to just concatenate them.
Trait Implementations§
impl<'a> Eq for Prompt<'a>
impl<'a> StructuralPartialEq for Prompt<'a>
Auto Trait Implementations§
impl<'a> Freeze for Prompt<'a>
impl<'a> RefUnwindSafe for Prompt<'a>
impl<'a> Send for Prompt<'a>
impl<'a> Sync for Prompt<'a>
impl<'a> Unpin for Prompt<'a>
impl<'a> UnwindSafe for Prompt<'a>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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>
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>
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