@aj-archipelago/cortex 1.3.17 → 1.3.18

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aj-archipelago/cortex",
3
- "version": "1.3.17",
3
+ "version": "1.3.18",
4
4
  "description": "Cortex is a GraphQL API for AI. It provides a simple, extensible interface for using AI services from OpenAI, Azure and others.",
5
5
  "private": false,
6
6
  "repository": {
@@ -40,13 +40,44 @@ class AzureVideoTranslatePlugin extends ModelPlugin {
40
40
  return {
41
41
  isAccessible: true,
42
42
  contentLength,
43
- durationSeconds: durationSeconds || 60
43
+ durationSeconds: durationSeconds || 60,
44
+ isAzureUrl: videoUrl.includes('.blob.core.windows.net')
44
45
  };
45
46
  } catch (error) {
46
47
  throw new Error(`Failed to access video: ${error.message}`);
47
48
  }
48
49
  }
49
50
 
51
+ async uploadToFileHandler(videoUrl) {
52
+ try {
53
+ // Get the file handler URL from config
54
+ const fileHandlerUrl = config.get("whisperMediaApiUrl");
55
+ if (!fileHandlerUrl) {
56
+ throw new Error("File handler URL is not configured");
57
+ }
58
+
59
+ // Use the file handler's fetch endpoint
60
+ const response = await axios.get(fileHandlerUrl, {
61
+ params: {
62
+ requestId: this.requestId,
63
+ fetch: videoUrl
64
+ }
65
+ });
66
+
67
+ if (!response.data?.url) {
68
+ throw new Error("File handler did not return a valid URL");
69
+ }
70
+
71
+ return response.data.url;
72
+ } catch (error) {
73
+ logger.error(`Failed to upload video to file handler: ${error.message}`);
74
+ if (error.response?.data) {
75
+ logger.error(`Response data: ${JSON.stringify(error.response.data)}`);
76
+ }
77
+ throw new Error(`Failed to upload video to file handler: ${error.message}`);
78
+ }
79
+ }
80
+
50
81
  async createTranslation(params) {
51
82
  const { videoUrl, sourceLanguage, targetLanguage, voiceKind, translationId } = params;
52
83
 
@@ -131,8 +162,8 @@ class AzureVideoTranslatePlugin extends ModelPlugin {
131
162
  if (AzureVideoTranslatePlugin.lastProcessingRate && this.videoContentLength) {
132
163
  estimatedTotalTime = this.videoContentLength / AzureVideoTranslatePlugin.lastProcessingRate;
133
164
  } else {
134
- // First run: estimate based on 1x calculated video duration
135
- estimatedTotalTime = (this.videoContentLength * 8) / (2.5 * 1024 * 1024);
165
+ // First run: estimate based on 2x calculated video duration
166
+ estimatedTotalTime = 2 * (this.videoContentLength * 8) / (2.5 * 1024 * 1024);
136
167
  }
137
168
 
138
169
  // eslint-disable-next-line no-constant-condition
@@ -248,7 +279,7 @@ class AzureVideoTranslatePlugin extends ModelPlugin {
248
279
 
249
280
  try {
250
281
  const translationId = `cortex-translation-${this.requestId}`;
251
- const videoUrl = requestParameters.sourcevideooraudiofilepath;
282
+ let videoUrl = requestParameters.sourcevideooraudiofilepath;
252
283
  const sourceLanguage = requestParameters.sourcelocale;
253
284
  const targetLanguage = requestParameters.targetlocale;
254
285
  const voiceKind = requestParameters.voicekind || 'PlatformVoice';
@@ -260,6 +291,13 @@ class AzureVideoTranslatePlugin extends ModelPlugin {
260
291
  this.videoContentLength = videoInfo.contentLength;
261
292
  logger.debug(`Video info: ${JSON.stringify(videoInfo, null, 2)}`);
262
293
 
294
+ // If the video is not from Azure storage, upload it to file handler
295
+ if (!videoInfo.isAzureUrl) {
296
+ logger.debug('Video is not from Azure storage, uploading to file handler...');
297
+ videoUrl = await this.uploadToFileHandler(videoUrl);
298
+ logger.debug(`Video uploaded to file handler: ${videoUrl}`);
299
+ }
300
+
263
301
  // Create translation
264
302
  const { operationUrl } = await this.createTranslation({
265
303
  videoUrl, sourceLanguage, targetLanguage, voiceKind, translationId