Skip to content

Commit 8a892c6

Browse files
committed
fix quota period config and other feedback
Signed-off-by: Lukas Schaefer <[email protected]>
1 parent 9add2f7 commit 8a892c6

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

lib/AppInfo/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Application extends App implements IBootstrap {
5555
public const MIN_CHUNK_SIZE = 500;
5656
public const DEFAULT_MAX_NUM_OF_TOKENS = 1000;
5757
public const DEFAULT_QUOTA_PERIOD = 30;
58-
public const DEFAULT_QUOTA_CONFIG = ['length' => self::DEFAULT_QUOTA_PERIOD, 'unit' => 'day'];
58+
public const DEFAULT_QUOTA_CONFIG = ['length' => self::DEFAULT_QUOTA_PERIOD, 'unit' => 'day', 'day' => 1];
5959

6060
public const DEFAULT_OPENAI_TEXT_GENERATION_TIME = 10; // seconds
6161
public const DEFAULT_LOCALAI_TEXT_GENERATION_TIME = 60; // seconds

lib/Service/OpenAiSettingsService.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public function __construct(
6565
}
6666

6767
/**
68+
* Gets the timestamp of the beginning of the quota period
69+
*
6870
* @return int
6971
* @throws Exception
7072
*/
@@ -93,6 +95,9 @@ public function getQuotaStart(): int {
9395
}
9496

9597
/**
98+
* Gets the timestamp of the end of the quota period
99+
* if the period is floating, then this will be the current time
100+
*
96101
* @return int
97102
* @throws Exception
98103
*/
@@ -262,11 +267,14 @@ public function getQuotaPeriod(): array {
262267
$this->appConfig->getValueString(Application::APP_ID, 'quota_period', json_encode(Application::DEFAULT_QUOTA_CONFIG)),
263268
true
264269
) ?: Application::DEFAULT_QUOTA_CONFIG;
270+
// Migrate from old quota period to new one
265271
if (is_int($value)) {
266-
return [
267-
'length' => $value,
268-
'unit' => 'day',
269-
];
272+
$value = ['length' => $value];
273+
}
274+
foreach (Application::DEFAULT_QUOTA_CONFIG as $key => $defaultValue) {
275+
if (!isset($value[$key])) {
276+
$value[$key] = $defaultValue;
277+
}
270278
}
271279
return $value;
272280
}

src/components/PersonalSettings.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ export default {
168168
computed: {
169169
quotaRangeText() {
170170
return this.quotaInfo?.period?.unit === 'month'
171-
? t('integration_openai', 'This quota period is from {startDate} to {endDate}.', {
171+
? t('integration_openai', 'This quota period is from {startDate} to {endDate}', {
172172
startDate: formatRelativeTime(this.quotaInfo.start * 1000),
173173
endDate: formatRelativeTime(this.quotaInfo.end * 1000),
174174
})
175-
: n('integration_openai', 'The quota is kept over a floating period of the last %n day.',
176-
'The quota is kept over a floating period of the last %n days.', this.quotaInfo.period.length)
175+
: n('integration_openai', 'The quota is kept over a floating period of the last %n day',
176+
'The quota is kept over a floating period of the last %n days', this.quotaInfo.period.length)
177177
},
178178
},
179179

src/components/QuotaPeriodPicker.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="container">
77
<NcNoteCard type="info">
88
{{
9-
t('integration_openai', 'Daily quotas are floating quotas while monthly reset on a certain day of the month.')
9+
t('integration_openai', 'Daily quotas are floating quotas while monthly reset on a certain day of the month')
1010
}}
1111
</NcNoteCard>
1212
<div class="line">
@@ -85,8 +85,8 @@ export default {
8585
},
8686
resetText() {
8787
return this.floating
88-
? n('integration_openai', 'Quota will be enforced based on last %n day of usage.', 'Quota will be enforced based on last %n days of usage.', this.value.length)
89-
: n('integration_openai', 'Quota will reset all users every month on day {day}.', 'Quota will reset for all users every %n months on day {day}.', this.value.length, { day: this.value.day })
88+
? n('integration_openai', 'Quota will be enforced based on last %n day of usage', 'Quota will be enforced based on last %n days of usage', this.value.length)
89+
: n('integration_openai', 'Quota will reset all users every month on day {day}', 'Quota will reset for all users every %n months on day {day}', this.value.length, { day: this.value.day })
9090
},
9191
},
9292

0 commit comments

Comments
 (0)