@dataclouder/nest-vertex 0.0.55 → 0.0.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -16,4 +16,5 @@ export declare class KeyBalancerClientService {
|
|
|
16
16
|
getKeys(): Promise<AvailableKeyResult[]>;
|
|
17
17
|
private getUnavailableServiceResult;
|
|
18
18
|
recordFailedRequest(keyId: string, error: any, modelType: ModelType, model: string, ttlSeconds?: number): Promise<void>;
|
|
19
|
+
updateUsage(keyUsageId: string, usageCount: number): Promise<any>;
|
|
19
20
|
}
|
|
@@ -74,6 +74,19 @@ let KeyBalancerClientService = KeyBalancerClientService_1 = class KeyBalancerCli
|
|
|
74
74
|
this.logger.warn(`Failed to get LLM key for model ${model} from the external service.`, data);
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
|
+
async updateUsage(keyUsageId, usageCount) {
|
|
78
|
+
const keyBalancerHost = process.env.KEY_BALANCER_HOST || 'http://localhost:8085';
|
|
79
|
+
const url = `${keyBalancerHost}/api/key-usage/update-usage`;
|
|
80
|
+
try {
|
|
81
|
+
const { data } = await (0, rxjs_1.firstValueFrom)(this.httpService.post(url, { keyUsageId, usageCount }));
|
|
82
|
+
this.logger.verbose(`Usage updated for keyUsageId: ${keyUsageId} with usageCount: ${usageCount}`);
|
|
83
|
+
return data;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
this.logger.error(`Failed to update usage for keyUsageId: ${keyUsageId}`, error.stack);
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
77
90
|
};
|
|
78
91
|
exports.KeyBalancerClientService = KeyBalancerClientService;
|
|
79
92
|
exports.KeyBalancerClientService = KeyBalancerClientService = KeyBalancerClientService_1 = __decorate([
|
|
@@ -32,6 +32,7 @@ let VertextTtsService = class VertextTtsService extends base_tts_service_1.BaseT
|
|
|
32
32
|
keyType: 'service_account',
|
|
33
33
|
}, token);
|
|
34
34
|
if (selectedKey.key) {
|
|
35
|
+
this.keyBalancerClient.updateUsage(selectedKey.id, input.text.length);
|
|
35
36
|
this.logger.verbose(` Balanced key Found : ${selectedKey.name} ${selectedKey.id}`);
|
|
36
37
|
try {
|
|
37
38
|
const credentials = JSON.parse(selectedKey.key);
|