@dataclouder/nest-vertex 0.0.26 → 0.0.28
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/comfyui/controllers/comfy-ui.controller.d.ts +3 -6
- package/comfyui/controllers/comfy-ui.controller.js +3 -12
- package/comfyui/dto/video-generation.dto.d.ts +6 -0
- package/comfyui/dto/video-generation.dto.js +11 -0
- package/comfyui/models/comfy.models.d.ts +3 -0
- package/comfyui/providers/comfy-services.providers.js +2 -2
- package/comfyui/services/comfy-connection.service.d.ts +1 -0
- package/comfyui/services/comfy-connection.service.js +25 -14
- package/comfyui/services/comfy-video.service.d.ts +10 -14
- package/comfyui/services/comfy-video.service.js +43 -66
- package/models/generated-asset.entity.d.ts +1 -0
- package/models/generated-asset.entity.js +5 -0
- package/models/generated-asset.model.d.ts +1 -0
- package/models/google-voices.js +0 -4
- package/package.json +1 -1
- package/services/adapter-audio-gen.service.d.ts +0 -2
- package/services/adapter-audio-gen.service.js +0 -14
- package/services/vertex-gemini-chat.service.js +1 -1
- package/services/vertex-image.service.js +27 -7
|
@@ -17,16 +17,13 @@ export declare class ComfyUiController {
|
|
|
17
17
|
constructor(comfyImageService: ComfyImageService, comfyVideoService: ComfyVideoService, generatedAssetService: GeneratedAssetService, httpService: HttpService, eventEmitter: EventEmitter2);
|
|
18
18
|
generateImage(generateImageDto: ImageGenRequestAdapter): Promise<ImageGenAdapterResponse>;
|
|
19
19
|
generateVideoFromLocalImage(positivePrompt: string, negativePrompt: string): Promise<{
|
|
20
|
-
|
|
21
|
-
asset: import("../..").GeneratedAsset;
|
|
20
|
+
prompt_id: string;
|
|
22
21
|
}>;
|
|
23
22
|
generateVideoFromAsset(id: string): Promise<{
|
|
24
|
-
|
|
25
|
-
asset: import("../..").GeneratedAsset;
|
|
23
|
+
prompt_id: string;
|
|
26
24
|
}>;
|
|
27
25
|
generateVideoFromUrl(videoUrlRequestDto: VideoUrlRequestDto): Promise<{
|
|
28
|
-
|
|
29
|
-
asset: import("../..").GeneratedAsset;
|
|
26
|
+
prompt_id: string;
|
|
30
27
|
}>;
|
|
31
28
|
sse(): Observable<MessageEvent>;
|
|
32
29
|
}
|
|
@@ -79,16 +79,7 @@ let ComfyUiController = ComfyUiController_1 = class ComfyUiController {
|
|
|
79
79
|
if (!asset || !asset.assets?.firstFrame?.url) {
|
|
80
80
|
throw new common_1.NotFoundException(`Asset with id ${id} not found or does not have a valid image url.`);
|
|
81
81
|
}
|
|
82
|
-
const
|
|
83
|
-
const response = await this.httpService.axiosRef.get(imageUrl, { responseType: 'arraybuffer' });
|
|
84
|
-
const imageBuffer = Buffer.from(response.data, 'binary');
|
|
85
|
-
const videoRequest = {
|
|
86
|
-
workflowPath: path.resolve('./comfy_workflows/video-15_seconds.json'),
|
|
87
|
-
inputImage: imageBuffer,
|
|
88
|
-
positivePrompt: 'Faces are smiling',
|
|
89
|
-
negativePrompt: 'low quality, blurry, static',
|
|
90
|
-
};
|
|
91
|
-
const videoResponse = await this.comfyVideoService.runVideoGenerationFromWorkflow(videoRequest, id);
|
|
82
|
+
const videoResponse = await this.comfyVideoService.runVideoGenerationForAssetId(id);
|
|
92
83
|
this.logger.log(`ComfyUI video generation started. Response: ${JSON.stringify(videoResponse)}`);
|
|
93
84
|
return videoResponse;
|
|
94
85
|
}
|
|
@@ -98,13 +89,13 @@ let ComfyUiController = ComfyUiController_1 = class ComfyUiController {
|
|
|
98
89
|
}
|
|
99
90
|
}
|
|
100
91
|
async generateVideoFromUrl(videoUrlRequestDto) {
|
|
101
|
-
const { url
|
|
92
|
+
const { url } = videoUrlRequestDto;
|
|
102
93
|
this.logger.log(`Received request to generate video from url: ${url}`);
|
|
103
94
|
try {
|
|
104
95
|
const newAsset = await this.generatedAssetService.save({
|
|
105
96
|
assets: { firstFrame: { url } },
|
|
106
97
|
});
|
|
107
|
-
const videoResponse = await this.comfyVideoService.runVideoGenerationForAssetId(newAsset.id
|
|
98
|
+
const videoResponse = await this.comfyVideoService.runVideoGenerationForAssetId(newAsset.id);
|
|
108
99
|
this.logger.log(`ComfyUI video generation started. Response: ${JSON.stringify(videoResponse)}`);
|
|
109
100
|
return videoResponse;
|
|
110
101
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RunVideoGenerationForAssetIdDto = void 0;
|
|
4
|
+
class RunVideoGenerationForAssetIdDto {
|
|
5
|
+
assetId;
|
|
6
|
+
positivePrompt;
|
|
7
|
+
negativePrompt;
|
|
8
|
+
metadata;
|
|
9
|
+
}
|
|
10
|
+
exports.RunVideoGenerationForAssetIdDto = RunVideoGenerationForAssetIdDto;
|
|
11
|
+
//# sourceMappingURL=video-generation.dto.js.map
|
|
@@ -32,11 +32,11 @@ exports.comfyServicesProviders = [
|
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
34
|
provide: comfy_video_service_1.ComfyVideoService,
|
|
35
|
-
useFactory: (connectionService, httpService, generatedAssetService
|
|
35
|
+
useFactory: (connectionService, httpService, generatedAssetService) => {
|
|
36
36
|
if (!connectionService) {
|
|
37
37
|
return null;
|
|
38
38
|
}
|
|
39
|
-
return new comfy_video_service_1.ComfyVideoService(connectionService,
|
|
39
|
+
return new comfy_video_service_1.ComfyVideoService(connectionService, generatedAssetService, httpService);
|
|
40
40
|
},
|
|
41
41
|
inject: [comfy_connection_service_1.ComfyConnectionService, axios_1.HttpService, generated_asset_service_1.GeneratedAssetService, nest_storage_1.CloudStorageService],
|
|
42
42
|
},
|
|
@@ -29,6 +29,7 @@ export declare class ComfyConnectionService implements OnModuleInit, OnModuleDes
|
|
|
29
29
|
queuePrompt(workflow: any): Promise<{
|
|
30
30
|
prompt_id: string;
|
|
31
31
|
}>;
|
|
32
|
+
uploadImage(imageBuffer: Buffer, filename: string): Promise<any>;
|
|
32
33
|
queuePromptAndWait(workflow: any, timeoutMs?: number): Promise<any>;
|
|
33
34
|
getAssetData(filename: string, subfolder: string, type: string): Promise<Buffer>;
|
|
34
35
|
}
|
|
@@ -23,6 +23,7 @@ const rxjs_1 = require("rxjs");
|
|
|
23
23
|
const generated_asset_service_1 = require("../../services/generated-asset.service");
|
|
24
24
|
const nest_storage_1 = require("@dataclouder/nest-storage");
|
|
25
25
|
const event_emitter_1 = require("@nestjs/event-emitter");
|
|
26
|
+
const FormData = require("form-data");
|
|
26
27
|
let ComfyConnectionService = ComfyConnectionService_1 = class ComfyConnectionService {
|
|
27
28
|
configService;
|
|
28
29
|
httpService;
|
|
@@ -122,8 +123,8 @@ let ComfyConnectionService = ComfyConnectionService_1 = class ComfyConnectionSer
|
|
|
122
123
|
this.logger.log(`Resolved pending promise for prompt ${prompt_id}.`);
|
|
123
124
|
return;
|
|
124
125
|
}
|
|
125
|
-
const
|
|
126
|
-
if (!
|
|
126
|
+
const generatedAsset = await this.generatedAssetService.findOneByOperationId(prompt_id);
|
|
127
|
+
if (!generatedAsset) {
|
|
127
128
|
this.logger.warn(`No asset found for prompt_id: ${prompt_id}`);
|
|
128
129
|
return;
|
|
129
130
|
}
|
|
@@ -136,26 +137,26 @@ let ComfyConnectionService = ComfyConnectionService_1 = class ComfyConnectionSer
|
|
|
136
137
|
videoFilename = video.filename;
|
|
137
138
|
this.logger.log(`Found video output: ${videoFilename}`);
|
|
138
139
|
if (videoBuffer) {
|
|
139
|
-
const uploadResult = await this.cloudStorageService.uploadFileAndMakePublic(process.env.STORAGE_BUCKET, `generated-videos/${
|
|
140
|
+
const uploadResult = await this.cloudStorageService.uploadFileAndMakePublic(process.env.STORAGE_BUCKET, `generated-videos/${generatedAsset.id}.mp4`, videoBuffer, 'video/mp4');
|
|
140
141
|
this.logger.log(`Successfully uploaded video to: ${uploadResult.url}`);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
await this.generatedAssetService.update(
|
|
145
|
-
this.eventEmitter.emit('asset.updated',
|
|
142
|
+
generatedAsset.url = uploadResult.url;
|
|
143
|
+
generatedAsset.result = uploadResult;
|
|
144
|
+
generatedAsset.status = 'completed';
|
|
145
|
+
await this.generatedAssetService.update(generatedAsset.id, generatedAsset);
|
|
146
|
+
this.eventEmitter.emit('asset.updated', generatedAsset);
|
|
146
147
|
}
|
|
147
148
|
else {
|
|
148
149
|
this.logger.error(`No video found in the output for prompt ${prompt_id}.`);
|
|
149
|
-
|
|
150
|
-
await this.generatedAssetService.update(
|
|
151
|
-
this.eventEmitter.emit('asset.updated',
|
|
150
|
+
generatedAsset.status = 'failed';
|
|
151
|
+
await this.generatedAssetService.update(generatedAsset.id, generatedAsset);
|
|
152
|
+
this.eventEmitter.emit('asset.updated', generatedAsset);
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
155
|
catch (error) {
|
|
155
156
|
this.logger.error(`Failed to process output for prompt ${prompt_id}:`, error);
|
|
156
|
-
|
|
157
|
-
await this.generatedAssetService.update(
|
|
158
|
-
this.eventEmitter.emit('asset.updated',
|
|
157
|
+
generatedAsset.status = 'failed';
|
|
158
|
+
await this.generatedAssetService.update(generatedAsset.id, generatedAsset);
|
|
159
|
+
this.eventEmitter.emit('asset.updated', generatedAsset);
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
162
|
getClient() {
|
|
@@ -178,6 +179,16 @@ let ComfyConnectionService = ComfyConnectionService_1 = class ComfyConnectionSer
|
|
|
178
179
|
};
|
|
179
180
|
return (0, rxjs_1.firstValueFrom)(this.httpService.post(url, payload)).then((res) => res.data);
|
|
180
181
|
}
|
|
182
|
+
async uploadImage(imageBuffer, filename) {
|
|
183
|
+
const url = `http://${this.comfyApiHost}/upload/image`;
|
|
184
|
+
const form = new FormData();
|
|
185
|
+
form.append('image', imageBuffer, { filename });
|
|
186
|
+
form.append('overwrite', 'true');
|
|
187
|
+
const response = await (0, rxjs_1.firstValueFrom)(this.httpService.post(url, form, {
|
|
188
|
+
headers: form.getHeaders(),
|
|
189
|
+
}));
|
|
190
|
+
return response.data;
|
|
191
|
+
}
|
|
181
192
|
async queuePromptAndWait(workflow, timeoutMs = 300000) {
|
|
182
193
|
const { prompt_id } = await this.queuePrompt(workflow);
|
|
183
194
|
this.logger.log(`Queued prompt with ID: ${prompt_id}. Waiting for execution...`);
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
import { ComfyConnectionService } from './comfy-connection.service';
|
|
2
|
-
import { VideoGenRequest } from '../models/comfy.models';
|
|
3
|
-
import { HttpService } from '@nestjs/axios';
|
|
4
2
|
import { GeneratedAssetService } from '../../services/generated-asset.service';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { HttpService } from '@nestjs/axios';
|
|
4
|
+
import { VideoGenRequest } from '../models/comfy.models';
|
|
7
5
|
export declare class ComfyVideoService {
|
|
8
|
-
private readonly
|
|
9
|
-
private readonly httpService;
|
|
6
|
+
private readonly comfyConnectionService;
|
|
10
7
|
private readonly generatedAssetService;
|
|
11
|
-
private readonly
|
|
8
|
+
private readonly httpService;
|
|
12
9
|
private readonly logger;
|
|
13
|
-
constructor(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
constructor(comfyConnectionService: ComfyConnectionService, generatedAssetService: GeneratedAssetService, httpService: HttpService);
|
|
11
|
+
updateWorkflow(width: number, height: number, seconds: number): Promise<any>;
|
|
12
|
+
runVideoGenerationFromWorkflow(videoRequest: VideoGenRequest, assetId?: string): Promise<{
|
|
13
|
+
prompt_id: string;
|
|
17
14
|
}>;
|
|
18
|
-
runVideoGenerationForAssetId(assetId: string
|
|
19
|
-
|
|
20
|
-
asset: GeneratedAsset;
|
|
15
|
+
runVideoGenerationForAssetId(assetId: string): Promise<{
|
|
16
|
+
prompt_id: string;
|
|
21
17
|
}>;
|
|
22
18
|
}
|
|
@@ -15,86 +15,64 @@ const common_1 = require("@nestjs/common");
|
|
|
15
15
|
const fs = require("fs/promises");
|
|
16
16
|
const path = require("path");
|
|
17
17
|
const comfy_connection_service_1 = require("./comfy-connection.service");
|
|
18
|
-
const axios_1 = require("@nestjs/axios");
|
|
19
18
|
const generated_asset_service_1 = require("../../services/generated-asset.service");
|
|
20
|
-
const
|
|
19
|
+
const axios_1 = require("@nestjs/axios");
|
|
21
20
|
let ComfyVideoService = ComfyVideoService_1 = class ComfyVideoService {
|
|
22
|
-
|
|
23
|
-
httpService;
|
|
21
|
+
comfyConnectionService;
|
|
24
22
|
generatedAssetService;
|
|
25
|
-
|
|
23
|
+
httpService;
|
|
26
24
|
logger = new common_1.Logger(ComfyVideoService_1.name);
|
|
27
|
-
constructor(
|
|
28
|
-
this.
|
|
29
|
-
this.httpService = httpService;
|
|
25
|
+
constructor(comfyConnectionService, generatedAssetService, httpService) {
|
|
26
|
+
this.comfyConnectionService = comfyConnectionService;
|
|
30
27
|
this.generatedAssetService = generatedAssetService;
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
this.httpService = httpService;
|
|
29
|
+
}
|
|
30
|
+
async updateWorkflow(width, height, seconds) {
|
|
31
|
+
const workflowPath = path.join(process.cwd(), 'comfy_workflows', 'video-15_seconds.json');
|
|
32
|
+
const workflowData = await fs.readFile(workflowPath, 'utf-8');
|
|
33
|
+
const workflow = JSON.parse(workflowData);
|
|
34
|
+
if (workflow['84']) {
|
|
35
|
+
workflow['84'].inputs.width = width;
|
|
36
|
+
workflow['84'].inputs.height = height;
|
|
37
|
+
}
|
|
38
|
+
if (workflow['63']) {
|
|
39
|
+
const lengthInFrames = seconds * 16 + 1;
|
|
40
|
+
workflow['63'].inputs.length = lengthInFrames;
|
|
34
41
|
}
|
|
42
|
+
return workflow;
|
|
35
43
|
}
|
|
36
|
-
async runVideoGenerationFromWorkflow(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const formData = new FormData();
|
|
46
|
-
const uniqueFilename = `input_${Date.now()}.png`;
|
|
47
|
-
formData.append('image', new Blob([request.inputImage]), uniqueFilename);
|
|
48
|
-
formData.append('overwrite', 'true');
|
|
49
|
-
const uploadResponse = await fetch(`http://${host}/upload/image`, {
|
|
50
|
-
method: 'POST',
|
|
51
|
-
body: formData,
|
|
52
|
-
});
|
|
53
|
-
if (!uploadResponse.ok) {
|
|
54
|
-
throw new Error(`Failed to upload image: ${await uploadResponse.text()}`);
|
|
55
|
-
}
|
|
56
|
-
const uploadedImage = await uploadResponse.json();
|
|
57
|
-
this.logger.log(`Successfully uploaded image: ${uploadedImage.name}`);
|
|
58
|
-
const workflowJson = await fs.readFile(request.workflowPath, 'utf-8');
|
|
59
|
-
const workflow = JSON.parse(workflowJson);
|
|
60
|
-
workflow['6'].inputs.text = request.positivePrompt;
|
|
61
|
-
workflow['7'].inputs.text = request.negativePrompt;
|
|
62
|
-
workflow['62'].inputs.image = uploadedImage.name;
|
|
63
|
-
if (request.outputFilenamePrefix) {
|
|
64
|
-
workflow['90'].inputs.filename_prefix = request.outputFilenamePrefix;
|
|
65
|
-
}
|
|
66
|
-
const response = await this.connectionService.queuePrompt(workflow);
|
|
67
|
-
this.logger.log(`Workflow queued, received prompt id: ${response.prompt_id}`);
|
|
68
|
-
asset.operationId = response.prompt_id;
|
|
69
|
-
await this.generatedAssetService.partialUpdate(asset.id, { operationId: response.prompt_id });
|
|
70
|
-
return {
|
|
71
|
-
message: 'Video generation workflow has been queued successfully.',
|
|
72
|
-
asset,
|
|
73
|
-
};
|
|
44
|
+
async runVideoGenerationFromWorkflow(videoRequest, assetId) {
|
|
45
|
+
const { inputImage, positivePrompt, negativePrompt } = videoRequest;
|
|
46
|
+
const workflow = await this.updateWorkflow(videoRequest.width, videoRequest.height, videoRequest.seconds);
|
|
47
|
+
workflow['6'].inputs.text = positivePrompt;
|
|
48
|
+
workflow['7'].inputs.text = negativePrompt;
|
|
49
|
+
const uploadResponse = await this.comfyConnectionService.uploadImage(inputImage, 'input_image.jpg');
|
|
50
|
+
const imageName = uploadResponse.name;
|
|
51
|
+
if (workflow['62']) {
|
|
52
|
+
workflow['62'].inputs.image = imageName;
|
|
74
53
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
asset.status = 'failed';
|
|
79
|
-
await this.generatedAssetService.partialUpdate(asset.id, { status: 'failed' });
|
|
80
|
-
}
|
|
81
|
-
throw new common_1.InternalServerErrorException(`Failed to run video generation workflow: ${error.message}`);
|
|
54
|
+
const response = await this.comfyConnectionService.queuePrompt(workflow);
|
|
55
|
+
if (assetId) {
|
|
56
|
+
await this.generatedAssetService.update(assetId, { operationId: response.prompt_id });
|
|
82
57
|
}
|
|
58
|
+
return response;
|
|
83
59
|
}
|
|
84
|
-
async runVideoGenerationForAssetId(assetId
|
|
85
|
-
this.
|
|
86
|
-
|
|
87
|
-
if (!asset || !asset.assets?.firstFrame?.url) {
|
|
60
|
+
async runVideoGenerationForAssetId(assetId) {
|
|
61
|
+
const genAsset = await this.generatedAssetService.findOne(assetId);
|
|
62
|
+
if (!genAsset || !genAsset.assets?.firstFrame?.url) {
|
|
88
63
|
throw new common_1.NotFoundException(`Asset with id ${assetId} not found or does not have a valid image url.`);
|
|
89
64
|
}
|
|
90
|
-
const imageUrl =
|
|
65
|
+
const imageUrl = genAsset.assets.firstFrame.url;
|
|
91
66
|
const response = await this.httpService.axiosRef.get(imageUrl, { responseType: 'arraybuffer' });
|
|
92
67
|
const imageBuffer = Buffer.from(response.data, 'binary');
|
|
93
68
|
const videoRequest = {
|
|
94
|
-
workflowPath: path.
|
|
69
|
+
workflowPath: path.join(process.cwd(), 'comfy_workflows', 'video-15_seconds.json'),
|
|
95
70
|
inputImage: imageBuffer,
|
|
96
|
-
positivePrompt:
|
|
97
|
-
negativePrompt:
|
|
71
|
+
positivePrompt: genAsset.prompt || genAsset?.description || 'Random movement for video',
|
|
72
|
+
negativePrompt: 'low quality, blurry, static',
|
|
73
|
+
width: genAsset.request?.width || null,
|
|
74
|
+
height: genAsset.request?.height || null,
|
|
75
|
+
seconds: genAsset.request?.seconds || null,
|
|
98
76
|
};
|
|
99
77
|
return this.runVideoGenerationFromWorkflow(videoRequest, assetId);
|
|
100
78
|
}
|
|
@@ -103,8 +81,7 @@ exports.ComfyVideoService = ComfyVideoService;
|
|
|
103
81
|
exports.ComfyVideoService = ComfyVideoService = ComfyVideoService_1 = __decorate([
|
|
104
82
|
(0, common_1.Injectable)(),
|
|
105
83
|
__metadata("design:paramtypes", [comfy_connection_service_1.ComfyConnectionService,
|
|
106
|
-
axios_1.HttpService,
|
|
107
84
|
generated_asset_service_1.GeneratedAssetService,
|
|
108
|
-
|
|
85
|
+
axios_1.HttpService])
|
|
109
86
|
], ComfyVideoService);
|
|
110
87
|
//# sourceMappingURL=comfy-video.service.js.map
|
|
@@ -19,6 +19,7 @@ export declare class GeneratedAsset implements IGeneratedAsset {
|
|
|
19
19
|
result: CloudFileStorage;
|
|
20
20
|
name: string;
|
|
21
21
|
description: string;
|
|
22
|
+
metadata: any;
|
|
22
23
|
}
|
|
23
24
|
export declare const GeneratedAssetSchema: import("mongoose").Schema<GeneratedAsset, import("mongoose").Model<GeneratedAsset, any, any, any, Document<unknown, any, GeneratedAsset, any> & GeneratedAsset & Required<{
|
|
24
25
|
_id: string;
|
|
@@ -29,6 +29,7 @@ let GeneratedAsset = class GeneratedAsset {
|
|
|
29
29
|
result;
|
|
30
30
|
name;
|
|
31
31
|
description;
|
|
32
|
+
metadata;
|
|
32
33
|
};
|
|
33
34
|
exports.GeneratedAsset = GeneratedAsset;
|
|
34
35
|
__decorate([
|
|
@@ -91,6 +92,10 @@ __decorate([
|
|
|
91
92
|
(0, mongoose_1.Prop)({ required: false }),
|
|
92
93
|
__metadata("design:type", String)
|
|
93
94
|
], GeneratedAsset.prototype, "description", void 0);
|
|
95
|
+
__decorate([
|
|
96
|
+
(0, mongoose_1.Prop)({ required: false, type: Object }),
|
|
97
|
+
__metadata("design:type", Object)
|
|
98
|
+
], GeneratedAsset.prototype, "metadata", void 0);
|
|
94
99
|
exports.GeneratedAsset = GeneratedAsset = __decorate([
|
|
95
100
|
(0, mongoose_1.Schema)({ collection: 'generated_assets' })
|
|
96
101
|
], GeneratedAsset);
|
package/models/google-voices.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { NestTtsService } from './vertex-tts.service';
|
|
2
|
-
import { AudioGenRequestAdapter, AudioGenAdapterResponse } from '../models/adapter.models';
|
|
3
2
|
import { google } from '@google-cloud/text-to-speech/build/protos/protos';
|
|
4
3
|
export declare class AudioGenAdapterService {
|
|
5
4
|
private nestTtsService;
|
|
6
5
|
private readonly logger;
|
|
7
6
|
constructor(nestTtsService: NestTtsService);
|
|
8
7
|
listVoices(provider?: string, languageCode?: string): Promise<google.cloud.texttospeech.v1.IVoice[]>;
|
|
9
|
-
generateAudio(audioDto: AudioGenRequestAdapter): Promise<AudioGenAdapterResponse>;
|
|
10
8
|
}
|
|
@@ -28,20 +28,6 @@ let AudioGenAdapterService = AudioGenAdapterService_1 = class AudioGenAdapterSer
|
|
|
28
28
|
return [];
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
async generateAudio(audioDto) {
|
|
32
|
-
if (audioDto.provider === 'google' || !audioDto.provider) {
|
|
33
|
-
const audioBuffer = await this.nestTtsService.synthesizeSpeech(audioDto);
|
|
34
|
-
return {
|
|
35
|
-
audio: audioBuffer,
|
|
36
|
-
mimeType: 'audio/mpeg',
|
|
37
|
-
provider: 'google',
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
this.logger.error(`Provider ${audioDto.provider} not supported for audio generation.`);
|
|
42
|
-
throw new Error(`Provider ${audioDto.provider} not supported for audio generation.`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
31
|
};
|
|
46
32
|
exports.AudioGenAdapterService = AudioGenAdapterService;
|
|
47
33
|
exports.AudioGenAdapterService = AudioGenAdapterService = AudioGenAdapterService_1 = __decorate([
|
|
@@ -138,7 +138,7 @@ let GeminiChatService = GeminiChatService_1 = class GeminiChatService {
|
|
|
138
138
|
this.logger.error(`Gemini chat.sendMessage failed: Service Unavailable ${model} - ${balancedKey?.name} con clave ${balancedKey?.apiKey}`);
|
|
139
139
|
await this.keyBalancer.recordFailedRequest(balancedKey.id, error, key_balancer_models_1.ModelType.LLM, model, 40);
|
|
140
140
|
throw new nest_core_1.AppException({
|
|
141
|
-
error_message: `
|
|
141
|
+
error_message: `Problema de Google, No puede procesar la solicitud, invalidar ${balancedKey?.name} clave ${balancedKey?.apiKey} por unos segundos.`,
|
|
142
142
|
explanation: error.message,
|
|
143
143
|
});
|
|
144
144
|
}
|
|
@@ -37,27 +37,32 @@ let ImageVertexService = ImageVertexService_1 = class ImageVertexService {
|
|
|
37
37
|
async _getGenAiClient(model, tierType = null) {
|
|
38
38
|
let apiKey;
|
|
39
39
|
let keyId;
|
|
40
|
+
let availableKey = null;
|
|
40
41
|
if (this.gemini_key) {
|
|
41
42
|
apiKey = this.gemini_key;
|
|
42
43
|
keyId = 'local';
|
|
43
44
|
}
|
|
44
45
|
else {
|
|
45
|
-
|
|
46
|
-
if (
|
|
46
|
+
availableKey = await this.keyBalancerApiService.getImageKey(model, tierType || 'tier 1');
|
|
47
|
+
if (availableKey === null) {
|
|
48
|
+
this.logger.error('KEY BALANCER IS DOWN: :::: No available API key from key balancer.');
|
|
49
|
+
}
|
|
50
|
+
if (availableKey?.error === 'RateLimited') {
|
|
47
51
|
this.logger.error('No available API key from key balancer.');
|
|
48
52
|
throw new Error('RateLimited');
|
|
49
53
|
}
|
|
50
|
-
if (!
|
|
54
|
+
if (!availableKey || availableKey?.error) {
|
|
51
55
|
this.logger.error('No available API key from key balancer.');
|
|
52
56
|
throw new Error('Not available API key');
|
|
53
57
|
}
|
|
54
|
-
apiKey =
|
|
55
|
-
keyId =
|
|
58
|
+
apiKey = availableKey.apiKey;
|
|
59
|
+
keyId = availableKey.id;
|
|
56
60
|
}
|
|
57
61
|
return {
|
|
58
62
|
client: new genai_1.GoogleGenAI({ apiKey }),
|
|
59
63
|
keyId,
|
|
60
64
|
model,
|
|
65
|
+
availableKey,
|
|
61
66
|
};
|
|
62
67
|
}
|
|
63
68
|
async startImageGeneration(generateImageDto) {
|
|
@@ -150,8 +155,23 @@ let ImageVertexService = ImageVertexService_1 = class ImageVertexService {
|
|
|
150
155
|
if (error instanceof nest_core_1.AppException) {
|
|
151
156
|
throw error;
|
|
152
157
|
}
|
|
153
|
-
|
|
154
|
-
|
|
158
|
+
if (error.name === 'ApiError') {
|
|
159
|
+
console.log(error);
|
|
160
|
+
error = JSON.parse(error.message);
|
|
161
|
+
console.log(error.error);
|
|
162
|
+
throw new nest_core_1.AppException({
|
|
163
|
+
error_message: `Error ${error?.error?.code} De Google ${error?.error?.message} con Model: ${genAiClient.model} 🔑 KeyId: ${genAiClient.availableKey.apiKey} Alias: ${genAiClient.availableKey.name} `,
|
|
164
|
+
explanation: JSON.stringify(error?.error?.details),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (error.status === 400) {
|
|
168
|
+
throw new nest_core_1.AppException({
|
|
169
|
+
error_message: `Error 400, la llave probablemente no tiene permisos o saldo. Model: ${genAiClient.model} 🔑 KeyId: ${genAiClient.availableKey.apiKey} ${genAiClient.availableKey.name}`,
|
|
170
|
+
explanation: error.message,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
this.logger.error(`startImageGenerationAdapter() Model: ${genAiClient.model} 🔑 KeyId: ${genAiClient.availableKey.apiKey} ${genAiClient.availableKey.name} Error:`, error.message || error);
|
|
174
|
+
throw error + ' 📝 ' + genAiClient.model + '🔑' + genAiClient.availableKey.apiKey + ' ' + genAiClient.availableKey.name;
|
|
155
175
|
}
|
|
156
176
|
}
|
|
157
177
|
};
|