Refactor and clean up code across multiple modules
- Simplified token type assignment in OAuth service. - Removed unused session_lock module and re-exported Session from zesdex_entities. - Cleaned up session entity by removing unnecessary comments and code. - Consolidated session handling in HTTP handlers for better readability. - Improved formatting and readability in OAuth repository tests. - Enhanced session lock repository with clearer match statements. - Streamlined session repository error handling. - Refined RNG tests for better clarity. - Adjusted module visibility and organization in lib.rs. - Updated IPC client and connection code for better error handling and clarity. - Improved frame handling in IPC for better readability. - Organized module imports and added test utilities for IPC. - Enhanced database connection error handling. - Simplified JWT token creation error handling. - Improved password verification error handling. - Cleaned up state management code for better readability. - Refactored middleware for session authentication and rate limiting. - Simplified clipboard utility for better error handling. - Enhanced logging initialization for better error reporting. - Improved pagination utility with clearer method annotations. - Cleaned up sanitization functions for filenames and paths. - Enhanced slug generation functions for better clarity and usability.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
//! `o200k_base` is an approximation for non-OpenAI providers but is far
|
||||
//! closer than a flat byte-per-token guess; it's only used for the
|
||||
//! 85%/95% budget thresholds, not for billing-accurate counts.
|
||||
use crate::dto::chat::message::ChatMessage;
|
||||
|
||||
|
||||
/// Count tokens in a single string under `o200k_base`.
|
||||
///
|
||||
@@ -25,20 +25,16 @@ pub fn count_tokens(text: &str) -> usize {
|
||||
.len()
|
||||
}
|
||||
|
||||
/// Count tokens in a `ChatMessage`'s text content.
|
||||
///
|
||||
/// Return: 0 for a message with no `content` (e.g. an assistant message
|
||||
/// that only carries `tool_calls`).
|
||||
#[allow(dead_code)]
|
||||
pub fn count_message_tokens(msg: &ChatMessage) -> usize {
|
||||
msg.content.as_deref().map_or(0, count_tokens)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::dto::chat::message::ChatMessage;
|
||||
|
||||
/// Count tokens in a `ChatMessage`'s text content.
|
||||
fn count_message_tokens(msg: &ChatMessage) -> usize {
|
||||
msg.content.as_deref().map_or(0, count_tokens)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_string_has_zero_tokens() {
|
||||
assert_eq!(count_tokens(""), 0);
|
||||
|
||||
@@ -43,9 +43,11 @@ mod tests {
|
||||
temperature: None,
|
||||
},
|
||||
);
|
||||
let mut settings = Settings::default();
|
||||
settings.provider = "zen".to_string();
|
||||
settings.model = "deepseek-v4-flash-free".to_string();
|
||||
let settings = Settings {
|
||||
provider: "zen".to_string(),
|
||||
model: "deepseek-v4-flash-free".to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_eq!(resolve(&app_config, &settings), 128_000);
|
||||
}
|
||||
@@ -53,9 +55,11 @@ mod tests {
|
||||
#[test]
|
||||
fn falls_back_to_default_context_window_when_no_role_matches() {
|
||||
let app_config = AppConfig::default();
|
||||
let mut settings = Settings::default();
|
||||
settings.provider = "nonexistent".to_string();
|
||||
settings.model = "nonexistent-model".to_string();
|
||||
let settings = Settings {
|
||||
provider: "nonexistent".to_string(),
|
||||
model: "nonexistent-model".to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
resolve(&app_config, &settings),
|
||||
@@ -76,9 +80,11 @@ mod tests {
|
||||
temperature: None,
|
||||
},
|
||||
);
|
||||
let mut settings = Settings::default();
|
||||
settings.provider = "zen".to_string();
|
||||
settings.model = "deepseek-v4-flash-free".to_string();
|
||||
let settings = Settings {
|
||||
provider: "zen".to_string(),
|
||||
model: "deepseek-v4-flash-free".to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
resolve(&app_config, &settings),
|
||||
|
||||
Reference in New Issue
Block a user