pub struct ChatHistory {
core: CoreBPE,
total_token_limit: usize,
token_limit: usize,
token_count: usize,
history: VecDeque<Element>,
}
Expand description
会話履歴管理。
Fields§
§core: CoreBPE
トークナイザ。
total_token_limit: usize
トークン数。
token_limit: usize
トークン数合計上限。
token_count: usize
現在のトークン数合計。
history: VecDeque<Element>
履歴データのキュー。
Implementations§
Source§impl ChatHistory
impl ChatHistory
Sourcepub fn reserve_tokens(&mut self, token_count: usize)
pub fn reserve_tokens(&mut self, token_count: usize)
トークン数合計上限を減らす。
pub fn push_input_message(&mut self, role: Role, text: &str) -> Result<()>
pub fn push_input_and_images( &mut self, role: Role, text: &str, images: impl IntoIterator<Item = InputContent>, ) -> Result<()>
pub fn push_output_message(&mut self, text: &str) -> Result<()>
pub fn push_output_and_tools( &mut self, text: Option<&str>, web_search_ids: impl Iterator<Item = WebSearchCall>, ) -> Result<()>
pub fn push_function( &mut self, call_id: &str, name: &str, arguments: &str, output: &str, ) -> Result<()>
Sourcefn push(&mut self, items: Vec<InputItem>, token_count: usize) -> Result<()>
fn push(&mut self, items: Vec<InputItem>, token_count: usize) -> Result<()>
ヒストリの最後にエントリを追加する。
合計サイズを超えた場合、超えなくなるように先頭から削除する。 このエントリだけでサイズを超えてしまっている場合、エラー。
Sourcepub fn get_total_limit(&self) -> usize
pub fn get_total_limit(&self) -> usize
トークン制限総量を返す。
Sourcepub fn token_count(&self, text: &str) -> usize
pub fn token_count(&self, text: &str) -> usize
文章のトークン数を数える。
Auto Trait Implementations§
impl Freeze for ChatHistory
impl RefUnwindSafe for ChatHistory
impl Send for ChatHistory
impl Sync for ChatHistory
impl Unpin for ChatHistory
impl UnwindSafe for ChatHistory
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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