From 05d20f207fedf03c2a564438a0d44a2d85d4ed2d Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 9 Mar 2023 15:30:39 +0800 Subject: feat: add remain tokens indicator and max tokens guard (#50) --- src/utils/mod.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/utils/mod.rs (limited to 'src/utils/mod.rs') diff --git a/src/utils/mod.rs b/src/utils/mod.rs new file mode 100644 index 0000000..fd178ba --- /dev/null +++ b/src/utils/mod.rs @@ -0,0 +1,29 @@ +mod tiktoken; + +pub use self::tiktoken::{cl100k_base_singleton, count_tokens, text_to_tokens, tokens_to_text}; + +use chrono::prelude::*; +use crossterm::style::{Color, Stylize}; +use std::io::{stdout, Write}; + +#[macro_export] +macro_rules! print_now { + ($($arg:tt)*) => { + $crate::utils::print_now(&format!($($arg)*)) + }; +} + +pub fn print_now(text: T) { + print!("{}", text.to_string()); + let _ = stdout().flush(); +} + +pub fn now() -> String { + let now = Local::now(); + now.to_rfc3339_opts(SecondsFormat::Secs, false) +} + +#[allow(unused)] +pub fn emphasis(text: &str) -> String { + text.stylize().with(Color::White).to_string() +} -- cgit v1.2.3