Skip to content

Commit 1a727e5

Browse files
committed
feat: update personal settings for rules
Signed-off-by: Lukas Schaefer <[email protected]>
1 parent 15beacb commit 1a727e5

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

lib/Service/OpenAiAPIService.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public function translatedQuotaUnit(int $type): string {
315315
*/
316316
public function getUserQuotaInfo(string $userId): array {
317317
// Get quota limits (if the user has specified an own OpenAI API key, no quota limit, just supply default values as fillers)
318-
$quotas = $this->hasOwnOpenAiApiKey($userId) ? Application::DEFAULT_QUOTAS : $this->openAiSettingsService->getQuotas();
318+
$ownApikey = $this->hasOwnOpenAiApiKey($userId);
319319
// Get quota period
320320
$quotaPeriod = $this->openAiSettingsService->getQuotaPeriod();
321321
// Get quota usage for each quota type:
@@ -328,7 +328,15 @@ public function getUserQuotaInfo(string $userId): array {
328328
$this->logger->warning('Could not retrieve quota usage for user: ' . $userId . ' and quota type: ' . $quotaType . '. Error: ' . $e->getMessage(), ['app' => Application::APP_ID]);
329329
throw new Exception($this->l10n->t('Unknown error while retrieving quota usage.'), Http::STATUS_INTERNAL_SERVER_ERROR);
330330
}
331-
$quotaInfo[$quotaType]['limit'] = intval($quotas[$quotaType]);
331+
if ($ownApikey) {
332+
$quotaInfo[$quotaType]['limit'] = Application::DEFAULT_QUOTAS[$quotaType];
333+
} else {
334+
$rule = $this->quotaRuleService->getRule($quotaType, $userId);
335+
$quotaInfo[$quotaType]['limit'] = $rule['amount'];
336+
if ($rule['pool']) {
337+
$quotaInfo[$quotaType]['used_pool'] = $this->quotaUsageMapper->getQuotaUnitsOfUserInTimePeriod($userId, $quotaType, $quotaPeriod, $rule['id']);
338+
}
339+
}
332340
$quotaInfo[$quotaType]['unit'] = $this->translatedQuotaUnit($quotaType);
333341
}
334342

lib/Service/QuotaRuleService.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ public function getRule(int $quotaType, string $userId) {
4343
try {
4444
$rule = $this->quotaRuleMapper->getRule($quotaType, $userId, $groups)->jsonSerialize();
4545
} catch (DoesNotExistException) {
46-
$cache->set($cacheKey, [
46+
$rule = [
4747
'amount' => $this->openAiSettingsService->getQuotas()[$quotaType],
4848
'pool' => false,
4949
'id' => null,
50-
]);
51-
return [];
50+
];
51+
$cache->set($cacheKey, $rule);
52+
return $rule;
5253
}
5354
$cache->set($cacheKey, $rule);
5455
}

src/components/PersonalSettings.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@
9595
{{ t('integration_openai', 'Quota type') }}
9696
</th>
9797
<th>{{ t('integration_openai', 'Usage') }}</th>
98+
<th v-if="poolUsed">
99+
{{ t('integration_openai', 'Shared Usage') }}
100+
</th>
98101
</tr>
99102
</thead>
100103
<tbody>
@@ -106,6 +109,12 @@
106109
<td v-else>
107110
{{ quota.used + ' ' + quota.unit }}
108111
</td>
112+
<td v-if="quota.used_pool">
113+
{{ Math.round(quota.used_pool / quota.limit * 100) + ' %' }}
114+
</td>
115+
<td v-else-if="poolUsed">
116+
{{ t('integration_openai', 'Not Shared') }}
117+
</td>
109118
</tr>
110119
</tbody>
111120
</table>
@@ -162,6 +171,9 @@ export default {
162171
},
163172
164173
computed: {
174+
poolUsed() {
175+
return this.quotaInfo !== null && this.quotaInfo.quota_usage.some((quota) => quota.used_pool)
176+
},
165177
},
166178
167179
watch: {

0 commit comments

Comments
 (0)