feat: first cut at openai compatible server
This commit is contained in:
@@ -51,6 +51,7 @@ pub struct AppPreferences {
|
||||
pub directional_steering_attn: Option<f32>,
|
||||
pub simulated_used_memory_gib: Option<i64>,
|
||||
pub expert_profile_path: Option<String>,
|
||||
pub endpoint_port: i32,
|
||||
}
|
||||
|
||||
impl Default for AppPreferences {
|
||||
@@ -90,6 +91,7 @@ impl Default for AppPreferences {
|
||||
directional_steering_attn: None,
|
||||
simulated_used_memory_gib: None,
|
||||
expert_profile_path: None,
|
||||
endpoint_port: 4000,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -234,6 +236,7 @@ struct PreferenceChanges<'a> {
|
||||
directional_steering_attn: Option<f32>,
|
||||
simulated_used_memory_gib: Option<i64>,
|
||||
expert_profile_path: Option<&'a str>,
|
||||
endpoint_port: i32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Identifiable, Queryable, Selectable)]
|
||||
@@ -360,6 +363,7 @@ impl Database {
|
||||
&mut self,
|
||||
selected_model: &str,
|
||||
idle_timeout_minutes: i32,
|
||||
endpoint_port: i32,
|
||||
generation: &GenerationPreferences,
|
||||
runtime: &RuntimePreferences,
|
||||
) -> Result<AppPreferences, String> {
|
||||
@@ -367,6 +371,9 @@ impl Database {
|
||||
let model = crate::model::ModelChoice::from_id(selected_model)
|
||||
.ok_or_else(|| format!("Unsupported model: {selected_model}"))?;
|
||||
runtime.validate(model)?;
|
||||
if !(1..=65_535).contains(&endpoint_port) {
|
||||
return Err("Endpoint port must be between 1 and 65535.".into());
|
||||
}
|
||||
let execution = &runtime.execution;
|
||||
let speculative = &runtime.speculative;
|
||||
let (ssd_cache_experts, ssd_cache_gib) = match runtime.ssd.cache {
|
||||
@@ -416,6 +423,7 @@ impl Database {
|
||||
.simulated_used_memory_gib
|
||||
.map(|value| value as i64),
|
||||
expert_profile_path: runtime.diagnostics.expert_profile_path.as_deref(),
|
||||
endpoint_port,
|
||||
})
|
||||
.returning(AppPreferences::as_returning())
|
||||
.get_result(&mut self.connection)
|
||||
@@ -572,6 +580,7 @@ mod tests {
|
||||
assert_eq!(preferences.selected_model, "deepseek-v4-flash");
|
||||
assert!(!preferences.dspark_enabled);
|
||||
assert_eq!(preferences.idle_timeout_minutes, 10);
|
||||
assert_eq!(preferences.endpoint_port, 4000);
|
||||
let generation = GenerationPreferences::default();
|
||||
let runtime = RuntimePreferences::default();
|
||||
assert!(
|
||||
@@ -579,6 +588,7 @@ mod tests {
|
||||
.update_preferences(
|
||||
"glm-5.2",
|
||||
30,
|
||||
4000,
|
||||
&generation,
|
||||
&RuntimePreferences {
|
||||
speculative: SpeculativePreferences {
|
||||
@@ -592,7 +602,7 @@ mod tests {
|
||||
);
|
||||
assert!(
|
||||
database
|
||||
.update_preferences("deepseek-v4-flash", 0, &generation, &runtime,)
|
||||
.update_preferences("deepseek-v4-flash", 0, 4000, &generation, &runtime,)
|
||||
.is_err()
|
||||
);
|
||||
let generation = GenerationPreferences {
|
||||
@@ -630,7 +640,7 @@ mod tests {
|
||||
..RuntimePreferences::default()
|
||||
};
|
||||
database
|
||||
.update_preferences("glm-5.2", 30, &generation, &runtime)
|
||||
.update_preferences("glm-5.2", 30, 4567, &generation, &runtime)
|
||||
.unwrap();
|
||||
|
||||
let project = database.create_project("DS4", "/tmp/ds4").unwrap();
|
||||
@@ -652,6 +662,7 @@ mod tests {
|
||||
let preferences = reopened.load_preferences().unwrap();
|
||||
assert_eq!(preferences.selected_model, "glm-5.2");
|
||||
assert_eq!(preferences.idle_timeout_minutes, 30);
|
||||
assert_eq!(preferences.endpoint_port, 4567);
|
||||
assert_eq!(preferences.generation().unwrap(), generation);
|
||||
assert_eq!(preferences.runtime().unwrap(), runtime);
|
||||
drop(reopened);
|
||||
|
||||
Reference in New Issue
Block a user