mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-09 10:57:03 +08:00
Merge remote-tracking branch 'upstream/main'
# Conflicts: # apps/aether-gateway/src/handlers/admin/provider/endpoints_admin/payloads.rs # apps/aether-gateway/src/handlers/admin/provider/endpoints_admin/reads.rs # apps/aether-gateway/src/handlers/admin/provider/endpoints_admin/update.rs # apps/aether-gateway/src/tests/control/admin/endpoints/routes.rs # frontend/src/features/models/components/GlobalModelFormDialog.vue # frontend/src/features/providers/components/ProviderModelFormDialog.vue # frontend/src/features/providers/components/provider-tabs/__tests__/model-test-request.spec.ts # frontend/src/features/providers/components/provider-tabs/model-test-request.ts
This commit is contained in:
@@ -502,7 +502,9 @@ pub(super) async fn maybe_build_local_admin_usage_summary_response(
|
||||
.summarize_usage_audits(&UsageAuditSummaryQuery {
|
||||
created_from_unix_secs,
|
||||
created_until_unix_secs,
|
||||
..Default::default()
|
||||
user_id: query_param_value(query, "user_id"),
|
||||
provider_name: query_param_value(query, "provider"),
|
||||
model: query_param_value(query, "model"),
|
||||
})
|
||||
.await?;
|
||||
return Ok(Some(build_admin_usage_summary_stats_response_from_summary(
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
use crate::handlers::admin::shared::AdminTypedObjectPatch;
|
||||
use crate::provider_key_auth::provider_key_effective_api_formats;
|
||||
use aether_admin::provider::endpoints as admin_provider_endpoints_pure;
|
||||
use aether_data_contracts::repository::provider_catalog::{
|
||||
StoredProviderCatalogEndpoint, StoredProviderCatalogKey, StoredProviderCatalogProvider,
|
||||
StoredProviderCatalogEndpoint, StoredProviderCatalogKey,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
pub(super) fn key_api_formats_without_entry(
|
||||
key: &StoredProviderCatalogKey,
|
||||
@@ -15,50 +13,14 @@ pub(super) fn key_api_formats_without_entry(
|
||||
}
|
||||
|
||||
pub(super) fn endpoint_key_counts_by_format(
|
||||
provider: &StoredProviderCatalogProvider,
|
||||
provider_type: &str,
|
||||
endpoints: &[StoredProviderCatalogEndpoint],
|
||||
keys: &[StoredProviderCatalogKey],
|
||||
) -> (
|
||||
std::collections::BTreeMap<String, usize>,
|
||||
std::collections::BTreeMap<String, usize>,
|
||||
) {
|
||||
let mut active_endpoint_formats = BTreeSet::new();
|
||||
for endpoint in endpoints.iter().filter(|endpoint| endpoint.is_active) {
|
||||
active_endpoint_formats.insert(endpoint.api_format.clone());
|
||||
}
|
||||
|
||||
let mut total_by_format = BTreeMap::<String, BTreeSet<String>>::new();
|
||||
let mut active_by_format = BTreeMap::<String, BTreeSet<String>>::new();
|
||||
for key in keys {
|
||||
for api_format in
|
||||
provider_key_effective_api_formats(key, &provider.provider_type, endpoints)
|
||||
{
|
||||
if !active_endpoint_formats.contains(&api_format) {
|
||||
continue;
|
||||
}
|
||||
total_by_format
|
||||
.entry(api_format.clone())
|
||||
.or_default()
|
||||
.insert(key.id.clone());
|
||||
if key.is_active {
|
||||
active_by_format
|
||||
.entry(api_format)
|
||||
.or_default()
|
||||
.insert(key.id.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(
|
||||
total_by_format
|
||||
.into_iter()
|
||||
.map(|(api_format, keys)| (api_format, keys.len()))
|
||||
.collect(),
|
||||
active_by_format
|
||||
.into_iter()
|
||||
.map(|(api_format, keys)| (api_format, keys.len()))
|
||||
.collect(),
|
||||
)
|
||||
admin_provider_endpoints_pure::endpoint_key_counts_by_format(provider_type, endpoints, keys)
|
||||
}
|
||||
|
||||
pub(super) fn build_admin_provider_endpoint_response(
|
||||
|
||||
@@ -39,7 +39,7 @@ pub(crate) async fn build_admin_provider_endpoints_payload(
|
||||
.ok()
|
||||
.unwrap_or_default();
|
||||
let (total_keys_by_format, active_keys_by_format) =
|
||||
endpoint_key_counts_by_format(&provider, &endpoints, &keys);
|
||||
endpoint_key_counts_by_format(&provider.provider_type, &endpoints, &keys);
|
||||
let now_unix_secs = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.ok()
|
||||
@@ -52,15 +52,17 @@ pub(crate) async fn build_admin_provider_endpoints_payload(
|
||||
.skip(skip)
|
||||
.take(limit)
|
||||
.map(|endpoint| {
|
||||
let endpoint_api_format =
|
||||
aether_ai_formats::normalize_api_format_alias(&endpoint.api_format);
|
||||
build_admin_provider_endpoint_response(
|
||||
&endpoint,
|
||||
&provider.name,
|
||||
total_keys_by_format
|
||||
.get(endpoint.api_format.as_str())
|
||||
.get(endpoint_api_format.as_str())
|
||||
.copied()
|
||||
.unwrap_or(0),
|
||||
active_keys_by_format
|
||||
.get(endpoint.api_format.as_str())
|
||||
.get(endpoint_api_format.as_str())
|
||||
.copied()
|
||||
.unwrap_or(0),
|
||||
now_unix_secs,
|
||||
@@ -93,23 +95,27 @@ pub(crate) async fn build_admin_endpoint_payload(
|
||||
.await
|
||||
.ok()
|
||||
.unwrap_or_default();
|
||||
let (total_keys_by_format, active_keys_by_format) =
|
||||
endpoint_key_counts_by_format(&provider, std::slice::from_ref(&endpoint), &keys);
|
||||
let (total_keys_by_format, active_keys_by_format) = endpoint_key_counts_by_format(
|
||||
&provider.provider_type,
|
||||
std::slice::from_ref(&endpoint),
|
||||
&keys,
|
||||
);
|
||||
let now_unix_secs = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.ok()
|
||||
.map(|duration| duration.as_secs())
|
||||
.unwrap_or(0);
|
||||
let endpoint_api_format = aether_ai_formats::normalize_api_format_alias(&endpoint.api_format);
|
||||
|
||||
Some(build_admin_provider_endpoint_response(
|
||||
&endpoint,
|
||||
&provider.name,
|
||||
total_keys_by_format
|
||||
.get(endpoint.api_format.as_str())
|
||||
.get(endpoint_api_format.as_str())
|
||||
.copied()
|
||||
.unwrap_or(0),
|
||||
active_keys_by_format
|
||||
.get(endpoint.api_format.as_str())
|
||||
.get(endpoint_api_format.as_str())
|
||||
.copied()
|
||||
.unwrap_or(0),
|
||||
now_unix_secs,
|
||||
|
||||
@@ -147,19 +147,23 @@ pub(super) async fn maybe_handle(
|
||||
.list_provider_catalog_keys_by_provider_ids(std::slice::from_ref(&provider.id))
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
let (total_keys_by_format, active_keys_by_format) =
|
||||
endpoint_key_counts_by_format(&provider, std::slice::from_ref(&updated), &keys);
|
||||
let (total_keys_by_format, active_keys_by_format) = endpoint_key_counts_by_format(
|
||||
&provider.provider_type,
|
||||
std::slice::from_ref(&updated),
|
||||
&keys,
|
||||
);
|
||||
let updated_api_format = aether_ai_formats::normalize_api_format_alias(&updated.api_format);
|
||||
|
||||
Ok(Some(
|
||||
Json(build_admin_provider_endpoint_response(
|
||||
&updated,
|
||||
&provider.name,
|
||||
total_keys_by_format
|
||||
.get(updated.api_format.as_str())
|
||||
.get(updated_api_format.as_str())
|
||||
.copied()
|
||||
.unwrap_or(0),
|
||||
active_keys_by_format
|
||||
.get(updated.api_format.as_str())
|
||||
.get(updated_api_format.as_str())
|
||||
.copied()
|
||||
.unwrap_or(0),
|
||||
now_unix_secs,
|
||||
|
||||
Reference in New Issue
Block a user