r
This commit is contained in:
1 parent
0d3e076115
commit
8e27e174a7
15 files changed
+161
-26
No files matched your search
+21
-1
@@ -10,7 +10,7 @@ android {
|
||||
defaultConfig {
|
||||
applicationId = "dev.alvin.litellmdashboard"
|
||||
minSdk = 26
|
||||
targetSdk = 35
|
||||
targetSdk = 36
|
||||
versionCode = 1
|
||||
versionName = "1.0.0"
|
||||
}
|
||||
@@ -19,6 +19,26 @@ android {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
signingConfigs {
|
||||
if (System.getenv("LITELLM_RELEASE_STORE_FILE") != null) {
|
||||
create("localRelease") {
|
||||
storeFile = file(System.getenv("LITELLM_RELEASE_STORE_FILE"))
|
||||
storePassword = System.getenv("LITELLM_RELEASE_STORE_PASSWORD")
|
||||
keyAlias = System.getenv("LITELLM_RELEASE_KEY_ALIAS")
|
||||
keyPassword = System.getenv("LITELLM_RELEASE_KEY_PASSWORD")
|
||||
}
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
getByName("release") {
|
||||
isMinifyEnabled = true
|
||||
isShrinkResources = true
|
||||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
||||
if (System.getenv("LITELLM_RELEASE_STORE_FILE") != null) {
|
||||
signingConfig = signingConfigs.getByName("localRelease")
|
||||
}
|
||||
}
|
||||
}
|
||||
packaging { resources.excludes += "/META-INF/{AL2.0,LGPL2.1}" }
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
# Keep rules can be added here when a dependency needs reflection at runtime.
|
||||
@@ -4,7 +4,9 @@
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:label="LiteLLM Dashboard"
|
||||
android:label="@string/app_name"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:roundIcon="@mipmap/ic_launcher"
|
||||
android:theme="@android:style/Theme.Material.Light.NoActionBar">
|
||||
<activity android:name=".MainActivity" android:exported="true" android:windowSoftInputMode="adjustResize">
|
||||
<intent-filter>
|
||||
|
||||
@@ -134,7 +134,7 @@ class LiteLlmApi(private val connection: Connection) {
|
||||
val params = row.optJSONObject("litellm_params") ?: JSONObject()
|
||||
val info = row.optJSONObject("model_info") ?: JSONObject()
|
||||
val name = row.string("model_name", "id", "model")
|
||||
ModelItem(name, info.string("litellm_provider", "provider").ifBlank { params.string("model").substringBefore('/', "Unknown") }, info.string("id").ifBlank { row.string("id") }, info.string("mode").ifBlank { "chat" }, info.number("max_tokens", "max_input_tokens")?.toInt()?.toString().orEmpty())
|
||||
ModelItem(name, info.string("litellm_provider", "provider").ifBlank { params.string("custom_llm_provider").ifBlank { params.string("model").substringBefore('/', "Unknown") } }, info.string("id").ifBlank { row.string("id") }, info.string("mode").ifBlank { "chat" }, info.number("max_tokens", "max_input_tokens")?.toInt()?.toString().orEmpty())
|
||||
}
|
||||
}.filter { it.name.isNotBlank() }.distinctBy { it.name }
|
||||
}
|
||||
@@ -175,18 +175,25 @@ class LiteLlmApi(private val connection: Connection) {
|
||||
}
|
||||
|
||||
fun overview(): Overview {
|
||||
val start = LocalDate.now().minusDays(6)
|
||||
val end = LocalDate.now()
|
||||
val spendRaw = try { get("/global/spend") } catch (e: ApiException) { if (e.status == 403 || e.status == 404) null else throw e }
|
||||
val spend = (spendRaw as? JSONObject)?.number("spend", "total_spend")
|
||||
val activityRaw = try { get("/global/activity") } catch (e: ApiException) { if (e.status == 403 || e.status == 404) null else throw e }
|
||||
val activityRaw = try { get("/global/activity?start_date=$start&end_date=$end") } catch (e: ApiException) { if (e.status == 400 || e.status == 403 || e.status == 404) null else throw e }
|
||||
val activity = activityRaw as? JSONObject
|
||||
val requests = activity?.number("total_requests", "total_api_requests", "total_requests_count")?.toLong()
|
||||
val successful = activity?.number("successful_requests", "success_count")?.toLong()
|
||||
val dailyRaw = try { get("/global/spend/report?start_date=${LocalDate.now().minusDays(6)}&end_date=${LocalDate.now()}") } catch (_: Exception) { null }
|
||||
val days = array(dailyRaw ?: JSONArray(), "data", "results")
|
||||
val gatewayRaw = try { get("/gateway/daily/activity?start_date=$start&end_date=$end") } catch (e: ApiException) { if (e.status == 400 || e.status == 403 || e.status == 404) null else throw e }
|
||||
val gateway = gatewayRaw as? JSONObject
|
||||
val successful = gateway?.number("total_successful_requests")?.toLong() ?: activity?.number("successful_requests", "success_count")?.toLong()
|
||||
val failed = gateway?.number("total_failed_requests")?.toLong()
|
||||
val requests = if (successful != null && failed != null) successful + failed else activity?.number("sum_api_requests", "total_requests", "total_api_requests", "total_requests_count")?.toLong()
|
||||
val gatewayDays = gateway?.optJSONArray("by_date") ?: JSONArray()
|
||||
val days = if (gatewayDays.length() > 0) gatewayDays else activity?.optJSONArray("daily_data") ?: JSONArray()
|
||||
val daily = (0 until days.length()).mapNotNull { i ->
|
||||
days.optJSONObject(i)?.let { row ->
|
||||
val date = row.string("group_by_day", "date").take(10)
|
||||
val value = row.number("spend", "total_spend") ?: row.optJSONArray("teams")?.let { teams -> (0 until teams.length()).sumOf { teams.optJSONObject(it)?.number("total_spend") ?: 0.0 } }
|
||||
val date = row.string("date").take(10)
|
||||
val value = if (gatewayDays.length() > 0) {
|
||||
(row.number("successful_requests") ?: 0.0) + (row.number("failed_requests") ?: 0.0)
|
||||
} else row.number("api_requests")
|
||||
if (date.isBlank() || value == null) null else date to value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,13 @@ private val Blue = Color(0xFF375BE8)
|
||||
private val Pale = Color(0xFFF4F7FB)
|
||||
private val Green = Color(0xFF13876A)
|
||||
|
||||
private fun usd(value: Double?): String = value?.let { NumberFormat.getCurrencyInstance(Locale.US).format(it) } ?: "—"
|
||||
private fun usd(value: Double?): String = value?.let {
|
||||
when {
|
||||
it == 0.0 || it >= 0.01 -> NumberFormat.getCurrencyInstance(Locale.US).format(it)
|
||||
it >= 0.0001 -> String.format(Locale.US, "$%.4f", it)
|
||||
else -> String.format(Locale.US, "$%.6f", it)
|
||||
}
|
||||
} ?: "—"
|
||||
private fun compact(value: Number?): String = value?.let { NumberFormat.getIntegerInstance(Locale.US).format(it) } ?: "—"
|
||||
private fun readableError(t: Throwable): String = when (t) {
|
||||
is ApiException -> t.message ?: "Request failed"
|
||||
@@ -307,9 +313,9 @@ private fun OverviewScreen(overview: Overview?, recent: List<LogItem>, logMessag
|
||||
MetricCard("Requests", compact(overview?.requests), Modifier.weight(1f))
|
||||
MetricCard("Successful", compact(overview?.successful), Modifier.weight(1f))
|
||||
}
|
||||
SectionTitle("Last 7 days", "Spend by day")
|
||||
SectionTitle("Last 7 days", "Requests per day")
|
||||
Card(colors = CardDefaults.cardColors(containerColor = Color.White), shape = RoundedCornerShape(18.dp)) {
|
||||
if (overview?.daily.isNullOrEmpty()) Text("No daily spend data available", Modifier.padding(22.dp), color = Muted)
|
||||
if (overview?.daily.isNullOrEmpty()) Text("No daily request data available", Modifier.padding(22.dp), color = Muted)
|
||||
else SpendChart(overview!!.daily, Modifier.fillMaxWidth().height(150.dp).padding(22.dp))
|
||||
}
|
||||
SectionTitle("Recent requests")
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="100"
|
||||
android:viewportHeight="100">
|
||||
<path android:fillColor="#FFFFFFFF" android:pathData="M24,20 L36,20 L36,58 L68,58 L68,70 L24,70 Z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<color name="launcher_background">#375BE8</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">LiteLLM Dashboard</string>
|
||||
</resources>
|
||||
Reference in new issue
Block a user