Skip to content

Commit

Permalink
add tiktoken
Browse files Browse the repository at this point in the history
  • Loading branch information
trevyn committed Jul 29, 2024
1 parent e2d69df commit 23ead05
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ rfd = "0.14"
serde = {version = "1.0.196", features = ["derive"]}
serde_json = "1"
stream-cancel = "0.8"
tiktoken-rs = "0.5.9"
tokio = {version = "1", features = ["full"]}
tracked = "0.5"
turbosql = "0.11"
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ pub struct App {
is_recording: bool,
#[serde(skip)]
promise: Option<Promise<ehttp::Result<Resource>>>,
#[serde(skip)]
tokenizer: Option<tiktoken_rs::CoreBPE>,
}

impl App {
Expand All @@ -204,6 +206,7 @@ impl App {
debounce_tx: Some(debounce_tx),
sessions: session::Session::calculate_sessions(),
completion_prompt: COMPLETION_PROMPT.lock().unwrap().clone(),
tokenizer: Some(tiktoken_rs::o200k_base().unwrap()),
..Default::default()
};

Expand Down Expand Up @@ -473,7 +476,10 @@ impl eframe::App for App {
// WHEEL_WINDOWS.lock().unwrap().get_mut(i).unwrap().0.remove(j);
// }
});
let tokens = self.tokenizer.as_ref().unwrap().encode_with_special_tokens(&entry.content);
ui.label(format!("{} tokens", tokens.len()));
}

ui.label("[command-enter to send]");

if let Some(id) = request_focus {
Expand Down

0 comments on commit 23ead05

Please sign in to comment.