Skip to content

Commit d45dc8a

Browse files
erangi-arThirunayan22erangi-arnuwangeek
authored
Show used budget for llm connection (buerokratt#215)
* updated docker compose ec2 * integrate streaming endpoint with test prodction connection page * formatted response with markdown * fe logic for the encryption * vault secret update after fixing issues * fixed formatting issue * integration with be * update cron manager vault script * tested integration of vault security update * fix security issues * fixed issue references are not sending with streming tokens * complete #192 and buerokratt#206 bug fixes * change production inference display logic * Add budget management features to LLMConnectionCard and translations * Remove obsolete Vite configuration files and associated plugins --------- Co-authored-by: Thiru Dinesh <56014038+Thirunayan22@users.noreply.github.com> Co-authored-by: Thiru Dinesh <thiru.dinesh@rootcodelabs.com> Co-authored-by: erangi-ar <erangika.ariyasena@rootcode.io> Co-authored-by: nuwangeek <charith.bimsara@rootcode.io> Co-authored-by: Charith Nuwan Bimsara <59943919+nuwangeek@users.noreply.github.com>
1 parent 3324f68 commit d45dc8a

4 files changed

Lines changed: 54 additions & 1 deletion

File tree

GUI/src/components/molecules/LLMConnectionCard/index.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ type LLMConnectionCardProps = {
2121
isActive?: boolean;
2222
deploymentEnv?: string;
2323
budgetStatus?: string;
24+
usedBudget?: number;
25+
monthlyBudget?: number;
26+
stopBudgetThreshold?: number;
27+
disconnectOnBudgetExceed?: boolean;
2428
onStatusChange?: (id: number | string, newStatus: boolean) => void;
2529
};
2630

@@ -32,6 +36,10 @@ const LLMConnectionCard: FC<PropsWithChildren<LLMConnectionCardProps>> = ({
3236
isActive,
3337
deploymentEnv,
3438
budgetStatus,
39+
usedBudget,
40+
monthlyBudget,
41+
stopBudgetThreshold,
42+
disconnectOnBudgetExceed,
3543
onStatusChange,
3644
}) => {
3745
const { open, close } = useDialog();
@@ -40,6 +48,31 @@ const LLMConnectionCard: FC<PropsWithChildren<LLMConnectionCardProps>> = ({
4048
const toast = useToast();
4149
const queryClient = useQueryClient();
4250

51+
// Format currency
52+
const formatCurrency = (amount?: number): string => {
53+
if (amount === undefined || amount === null) {
54+
return '0,00 €';
55+
}
56+
57+
return new Intl.NumberFormat('et-EE', {
58+
style: 'currency',
59+
currency: 'EUR',
60+
minimumFractionDigits: 2,
61+
maximumFractionDigits: 2,
62+
}).format(amount);
63+
};
64+
65+
66+
// Get the relevant budget threshold
67+
const getRelevantBudget = (): number | undefined => {
68+
// here if disconnect on budget exceed is enabled and stop threshold is set, calculate the actual amount from percentage
69+
if (disconnectOnBudgetExceed && stopBudgetThreshold && stopBudgetThreshold > 0 && monthlyBudget) {
70+
return (monthlyBudget * stopBudgetThreshold) / 100;
71+
}
72+
// Otherwise using monthly budget
73+
return monthlyBudget;
74+
};
75+
4376
const updateStatusMutation = useMutation({
4477
mutationFn: ({ id, status }: { id: string | number; status: 'active' | 'inactive' }) =>
4578
updateLLMConnectionStatus(id, status),
@@ -145,6 +178,16 @@ const LLMConnectionCard: FC<PropsWithChildren<LLMConnectionCardProps>> = ({
145178
</span>
146179
<span className="label-value">{model ?? 'N/A'}</span>
147180
</div>
181+
{(usedBudget !== undefined || monthlyBudget !== undefined) && (
182+
<div className="label-row">
183+
<span className="label-title">
184+
{t('dataModels.budgetUsage')}:
185+
</span>
186+
<span className="label-value">
187+
{formatCurrency(usedBudget)} / {formatCurrency(getRelevantBudget())}
188+
</span>
189+
</div>
190+
)}
148191
<div className='label-row'>
149192
{renderDeploymentEnv(deploymentEnv)}
150193
{renderBudgetStatus(budgetStatus)}

GUI/src/pages/LLMConnections/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,11 @@ const LLMConnections: FC = () => {
257257
deploymentEnv={productionConnection.environment}
258258
budgetStatus={productionConnection.budgetStatus}
259259
platform={productionConnection.llmPlatform}
260-
model={productionConnection.llmModel}
260+
model={productionConnection.llmModel}
261+
usedBudget={productionConnection.usedBudget}
262+
monthlyBudget={productionConnection.monthlyBudget}
263+
stopBudgetThreshold={productionConnection.stopBudgetThreshold}
264+
disconnectOnBudgetExceed={productionConnection.disconnectOnBudgetExceed}
261265
/>
262266
</div>
263267
</div>
@@ -278,6 +282,10 @@ const LLMConnections: FC = () => {
278282
budgetStatus={llmConnection.budgetStatus}
279283
platform={llmConnection.llmPlatform}
280284
model={llmConnection.llmModel}
285+
usedBudget={llmConnection.usedBudget}
286+
monthlyBudget={llmConnection.monthlyBudget}
287+
stopBudgetThreshold={llmConnection.stopBudgetThreshold}
288+
disconnectOnBudgetExceed={llmConnection.disconnectOnBudgetExceed}
281289
/>
282290
);
283291
})}

GUI/translations/en/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
"testing": "Testing",
164164
"production": "Production"
165165
},
166+
"budgetUsage": "Budget usage",
166167
"budgetStatus": {
167168
"withinBudget": "Within budget",
168169
"overBudget": "Over budget",

GUI/translations/et/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
"testing": "Testimine",
164164
"production": "Toodang"
165165
},
166+
"budgetUsage": "Eelarve kasutamine",
166167
"budgetStatus": {
167168
"withinBudget": "Eelarve piires",
168169
"overBudget": "Eelarve ületatud",

0 commit comments

Comments
 (0)