pub struct Context {
pub messages: Vec<Message>,
pub context_tokens: usize,
pub context_limit: usize,
}Fields§
§messages: Vec<Message>§context_tokens: usize§context_limit: usizeImplementations§
Source§impl Context
impl Context
Sourcepub fn new<S>(context: S, context_limit: usize) -> Self
pub fn new<S>(context: S, context_limit: usize) -> Self
Examples found in repository?
examples/chat_completion.rs (lines 7-10)
4async fn main() {
5 let mut chat = Chat::new(
6 Model::Kimiko13b,
7 Context::new(
8 "You're Jarvis – my assistant.",
9 4090
10 ),
11 );
12
13 let request = Request {
14 messages: vec!["Hello, Jarvis.".into()],
15 context: true,
16 stream: false,
17 ..Default::default()
18 };
19
20 match chat.send(request).await {
21 Ok(Some(res)) => println!("{}", res.text()),
22 Err(e) => eprintln!("Error: {e}"),
23 _ => {}
24 }
25}More examples
examples/chat_completion_streaming.rs (line 7)
4async fn main() {
5 let mut chat = Chat::new(
6 Model::Kimiko13b, // Replace model if you are using a different one
7 Context::new("You're Jarvis – my assistant.", 4090),
8 );
9
10 loop {
11 eprint!("\n>> ");
12 let mut buf = String::new();
13 std::io::stdin().read_line(&mut buf).unwrap();
14
15 let request = Request {
16 messages: vec![buf.into()],
17 context: true,
18 stream: true,
19 ..Default::default()
20 };
21
22 let _ = chat.send(request).await.unwrap();
23
24 while let Some(result) = chat.next().await {
25 match result {
26 Ok(text) if !text.is_empty() => eprint!("{text}"),
27 Err(e) => {
28 eprintln!("Error: {e}");
29 break;
30 }
31 _ => {}
32 }
33 }
34 }
35}pub fn edit<S>(&mut self, modification: S)
pub fn add<M>(&mut self, message: M)
pub fn get(&self) -> Vec<Message>
pub fn clear(&mut self)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl UnwindSafe for Context
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