use lazy_static::lazy_static;
const PROMPT: &str = r#"task-js-snippet-web-int.
HTML, URL, user-prompt-action -> provide pure js.
Exec-in-browser, no extra fmt/annot.
Only raw-js for function/applic.
Ex: window.location.href='https://www.google.com/search?q=Movies';"#;
const PROMPT_EXTRA: &str = r#"Provide a JSON response, e.g., {"content": ["Something"], "js": "window.location.href = 'https://www.google.com/search?q=Movies';"}. Use this structure. If no JS is needed, set "js" to ""."#;
lazy_static! {
pub static ref BROWSER_ACTIONS_SYSTEM_PROMPT: String = PROMPT.trim().to_string();
pub static ref BROWSER_ACTIONS_SYSTEM_EXTRA_PROMPT: String = PROMPT_EXTRA.trim().to_string();
}
pub fn estimate_token_count(text: &str) -> usize {
text.len() / 4
}
pub fn calculate_max_tokens(
model_name: &str,
max_tokens: u16,
resource: &str,
prompt: &str,
) -> usize {
let model_max: usize = if model_name.contains("1.5-pro")
|| model_name.contains("2.0")
|| model_name.contains("2.5")
|| model_name.contains("1.5-flash")
|| model_name.contains("flash")
{
1_000_000 } else {
32_000 };
let system_tokens = estimate_token_count(&BROWSER_ACTIONS_SYSTEM_PROMPT);
let resource_tokens = estimate_token_count(resource);
let prompt_tokens = estimate_token_count(prompt);
let input_tokens = system_tokens + resource_tokens + prompt_tokens;
let available = model_max.saturating_sub(input_tokens);
available.min(max_tokens as usize)
}