Move preferences from the database to a YAML config file
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,7 +20,7 @@ use tools::{
|
||||
#[cfg(test)]
|
||||
use tools::{canonical_tools, validate_tool_results};
|
||||
|
||||
use crate::database::AppPreferences;
|
||||
use crate::config::Config;
|
||||
use crate::engine::ChatTurn;
|
||||
use crate::metrics::Metrics;
|
||||
use crate::model::{self, ModelChoice};
|
||||
@@ -70,7 +70,7 @@ pub(crate) struct ServerHandle {
|
||||
|
||||
struct State {
|
||||
generation: GenerationService,
|
||||
preferences: Arc<RwLock<AppPreferences>>,
|
||||
config: Arc<RwLock<Config>>,
|
||||
models_path: PathBuf,
|
||||
cache_path: PathBuf,
|
||||
sequence: AtomicU64,
|
||||
@@ -212,7 +212,7 @@ struct RawOpenAiTool<'a> {
|
||||
impl ServerHandle {
|
||||
pub(crate) fn spawn(
|
||||
generation: GenerationService,
|
||||
preferences: Arc<RwLock<AppPreferences>>,
|
||||
config: Arc<RwLock<Config>>,
|
||||
models_path: PathBuf,
|
||||
cache_path: PathBuf,
|
||||
port: u16,
|
||||
@@ -230,7 +230,7 @@ impl ServerHandle {
|
||||
let tool_memory = read_tool_memory(&cache_path);
|
||||
let state = Arc::new(State {
|
||||
generation,
|
||||
preferences,
|
||||
config,
|
||||
models_path,
|
||||
cache_path,
|
||||
sequence: AtomicU64::new(0),
|
||||
@@ -417,12 +417,12 @@ fn handle(mut stream: TcpStream, state: &State) {
|
||||
let installed = installed_endpoint_models(&state.models_path);
|
||||
let model = model_alias(id).filter(|model| installed.contains(model));
|
||||
if let Some(model) = model {
|
||||
let (context, tokens) = state
|
||||
.preferences
|
||||
.read()
|
||||
.map_or((32_768, 32_768), |preferences| {
|
||||
(preferences.context_tokens, preferences.max_generated_tokens)
|
||||
});
|
||||
let (context, tokens) = state.config.read().map_or((32_768, 32_768), |config| {
|
||||
(
|
||||
config.generation.context_tokens,
|
||||
config.generation.max_generated_tokens,
|
||||
)
|
||||
});
|
||||
send_json_with_cors(
|
||||
&mut stream,
|
||||
200,
|
||||
@@ -549,12 +549,12 @@ fn installed_endpoint_models(models_path: &std::path::Path) -> Vec<ModelChoice>
|
||||
}
|
||||
|
||||
fn models_json(state: &State) -> Value {
|
||||
let (context, tokens) = state
|
||||
.preferences
|
||||
.read()
|
||||
.map_or((32_768, 32_768), |preferences| {
|
||||
(preferences.context_tokens, preferences.max_generated_tokens)
|
||||
});
|
||||
let (context, tokens) = state.config.read().map_or((32_768, 32_768), |config| {
|
||||
(
|
||||
config.generation.context_tokens,
|
||||
config.generation.max_generated_tokens,
|
||||
)
|
||||
});
|
||||
json!({
|
||||
"object": "list",
|
||||
"data": installed_endpoint_models(&state.models_path)
|
||||
@@ -735,7 +735,7 @@ mod tests {
|
||||
let metrics = Arc::new(Metrics::new(PathBuf::new().as_path()));
|
||||
let state = State {
|
||||
generation: GenerationService::spawn(Arc::clone(&metrics)).unwrap(),
|
||||
preferences: Arc::new(RwLock::new(AppPreferences::default())),
|
||||
config: Arc::new(RwLock::new(Config::default())),
|
||||
models_path: PathBuf::new(),
|
||||
cache_path: PathBuf::new(),
|
||||
sequence: AtomicU64::new(0),
|
||||
@@ -773,7 +773,7 @@ mod tests {
|
||||
let metrics = Arc::new(Metrics::new(&directory));
|
||||
let state = State {
|
||||
generation: GenerationService::spawn(Arc::clone(&metrics)).unwrap(),
|
||||
preferences: Arc::new(RwLock::new(AppPreferences::default())),
|
||||
config: Arc::new(RwLock::new(Config::default())),
|
||||
models_path: PathBuf::new(),
|
||||
cache_path: directory.clone(),
|
||||
sequence: AtomicU64::new(0),
|
||||
@@ -794,7 +794,7 @@ mod tests {
|
||||
let metrics = Arc::new(Metrics::new(PathBuf::new().as_path()));
|
||||
let state = State {
|
||||
generation: GenerationService::spawn(Arc::clone(&metrics)).unwrap(),
|
||||
preferences: Arc::new(RwLock::new(AppPreferences::default())),
|
||||
config: Arc::new(RwLock::new(Config::default())),
|
||||
models_path: PathBuf::new(),
|
||||
cache_path: PathBuf::new(),
|
||||
sequence: AtomicU64::new(0),
|
||||
@@ -847,7 +847,7 @@ mod tests {
|
||||
let metrics = Arc::new(Metrics::new(PathBuf::new().as_path()));
|
||||
let state = State {
|
||||
generation: GenerationService::spawn(Arc::clone(&metrics)).unwrap(),
|
||||
preferences: Arc::new(RwLock::new(AppPreferences::default())),
|
||||
config: Arc::new(RwLock::new(Config::default())),
|
||||
models_path: PathBuf::new(),
|
||||
cache_path: PathBuf::new(),
|
||||
sequence: AtomicU64::new(0),
|
||||
|
||||
Reference in New Issue
Block a user