mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-08 02:17:46 +08:00
feat: update admin config import and runtime handling
This commit is contained in:
@@ -664,6 +664,8 @@ RETURNING id
|
||||
&self,
|
||||
record: &CreateAdminGlobalModelRecord,
|
||||
) -> Result<Option<StoredAdminGlobalModel>, DataLayerError> {
|
||||
let usage_count =
|
||||
optional_admin_global_model_usage_count_i64(record.usage_count)?.unwrap_or_default();
|
||||
let inserted = sqlx::query(
|
||||
r#"
|
||||
INSERT INTO global_models (
|
||||
@@ -690,7 +692,7 @@ RETURNING id
|
||||
.bind(record.default_price_per_request)
|
||||
.bind(record.default_tiered_pricing.clone())
|
||||
.bind(record.supported_capabilities.clone())
|
||||
.bind(0_i32)
|
||||
.bind(usage_count)
|
||||
.bind(record.config.clone())
|
||||
.fetch_optional(&self.pool)
|
||||
.await
|
||||
@@ -707,6 +709,7 @@ RETURNING id
|
||||
&self,
|
||||
record: &UpdateAdminGlobalModelRecord,
|
||||
) -> Result<Option<StoredAdminGlobalModel>, DataLayerError> {
|
||||
let usage_count = optional_admin_global_model_usage_count_i64(record.usage_count)?;
|
||||
let updated = sqlx::query(
|
||||
r#"
|
||||
UPDATE global_models
|
||||
@@ -717,6 +720,7 @@ SET
|
||||
default_tiered_pricing = $5,
|
||||
supported_capabilities = $6,
|
||||
config = $7,
|
||||
usage_count = COALESCE($8, usage_count),
|
||||
updated_at = NOW()
|
||||
WHERE id = $1
|
||||
RETURNING id
|
||||
@@ -729,6 +733,7 @@ RETURNING id
|
||||
.bind(record.default_tiered_pricing.clone())
|
||||
.bind(record.supported_capabilities.clone())
|
||||
.bind(record.config.clone())
|
||||
.bind(usage_count)
|
||||
.fetch_optional(&self.pool)
|
||||
.await
|
||||
.map_postgres_err()?;
|
||||
@@ -1203,6 +1208,20 @@ fn map_provider_active_global_model_row(
|
||||
)
|
||||
}
|
||||
|
||||
fn optional_admin_global_model_usage_count_i64(
|
||||
value: Option<u64>,
|
||||
) -> Result<Option<i64>, DataLayerError> {
|
||||
value
|
||||
.map(|value| {
|
||||
i64::try_from(value).map_err(|_| {
|
||||
DataLayerError::InvalidInput(
|
||||
"global_models.usage_count exceeds i64 range".to_string(),
|
||||
)
|
||||
})
|
||||
})
|
||||
.transpose()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
|
||||
Reference in New Issue
Block a user