@mate-academy/llm-gateway 2.1.7 → 2.2.0

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.
Files changed (33) hide show
  1. package/README.md +28 -13
  2. package/dist/LLMService.typedefs.d.ts +40 -21
  3. package/dist/LLMService.typedefs.js +1 -1
  4. package/dist/LLMService.typedefs.js.map +1 -1
  5. package/dist/promptBuilder.d.ts +1 -1
  6. package/dist/promptBuilder.js.map +1 -1
  7. package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.entity.d.ts +4 -2
  8. package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.entity.js +1 -1
  9. package/dist/providers/GoogleGenerativeAI/GoogleGenerativeAI.entity.js.map +1 -1
  10. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.d.ts +3 -3
  11. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.js +1 -1
  12. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.js.map +1 -1
  13. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAICompletion.service.js +1 -1
  14. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAICompletion.service.js.map +1 -1
  15. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.js +1 -1
  16. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.js.map +1 -1
  17. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAITextToSpeech.service.js +1 -1
  18. package/dist/providers/GoogleGenerativeAI/services/GoogleGenerativeAITextToSpeech.service.js.map +1 -1
  19. package/dist/providers/OpenAI/OpenAI.entity.d.ts +11 -5
  20. package/dist/providers/OpenAI/OpenAI.entity.js +1 -1
  21. package/dist/providers/OpenAI/OpenAI.entity.js.map +1 -1
  22. package/dist/providers/OpenAI/services/OpenAIAssistance.service.d.ts +2 -2
  23. package/dist/providers/OpenAI/services/OpenAIAssistance.service.js +1 -1
  24. package/dist/providers/OpenAI/services/OpenAIAssistance.service.js.map +1 -1
  25. package/dist/providers/OpenAI/services/OpenAICompletion.service.js +1 -1
  26. package/dist/providers/OpenAI/services/OpenAICompletion.service.js.map +1 -1
  27. package/dist/providers/OpenAI/services/OpenAISpeechToText.service.js +1 -1
  28. package/dist/providers/OpenAI/services/OpenAISpeechToText.service.js.map +1 -1
  29. package/dist/providers/OpenAI/services/OpenAITextToSpeech.service.js +1 -1
  30. package/dist/providers/OpenAI/services/OpenAITextToSpeech.service.js.map +1 -1
  31. package/dist/services/LLMAssistanceService.abstract.d.ts +4 -4
  32. package/dist/services/LLMAssistanceService.abstract.js.map +1 -1
  33. package/package.json +4 -4
package/README.md CHANGED
@@ -19,6 +19,7 @@ npm install @mate-academy/llm-gateway
19
19
  - Standardized assistance service interface with file handling
20
20
  - Speech-to-text transcription capabilities
21
21
  - Text-to-speech generation capabilities
22
+ - Abort signal support for cancelling long-running operations
22
23
  - Token counting functionality for precise context management
23
24
  - Type-safe prompt templates with dynamic replacements
24
25
  - Factory pattern for easy provider selection
@@ -330,6 +331,32 @@ if (tokenCount > 50000) {
330
331
  }
331
332
  ```
332
333
 
334
+ #### Abort Signal Support
335
+
336
+ All operations support abort signals for cancellation:
337
+
338
+ ```typescript
339
+ const controller = new AbortController();
340
+
341
+ // Cancel after 30 seconds
342
+ setTimeout(() => controller.abort(), 30000);
343
+
344
+ const result = await completionService.sendMessage({
345
+ message: {
346
+ role: LLMRoles.User,
347
+ content: [{ type: LLMMessageContentType.TEXT, text: 'Long request...' }],
348
+ },
349
+ model: preferredModel,
350
+ abortSignal: controller.signal,
351
+ });
352
+
353
+ if (result.error) {
354
+ console.error('Operation failed or was cancelled:', result.error);
355
+ } else {
356
+ console.log('Success:', result.text);
357
+ }
358
+ ```
359
+
333
360
  ## API Reference
334
361
 
335
362
  ### LLMProviders
@@ -383,28 +410,16 @@ Interface for chat/assistance services with file handling capabilities.
383
410
 
384
411
  #### Methods
385
412
 
386
- - `uploadFile(file)`: Upload a file to the LLM service
387
- - Parameters: `LLMUploadFile` with `name`, `path`, and `mimeType`
388
- - Returns: `Promise<LLMUploadFileResult>`
413
+ - `uploadFile(fileOptions)`: Upload a file to the LLM service
389
414
  - `deleteFile(fileId)`: Delete a file from the LLM service
390
415
  - `createFileStorage(options)`: Create a file storage for organizing files
391
- - Parameters: `LLMCreateFileStorageOptions` with `uploadedFiles`, `model`, and optional `instructions`
392
- - Returns: `Promise<LLMCreateFileStorageResult>`
393
416
  - `deleteFileStorage(fileStorageId)`: Delete a file storage
394
417
  - `createAssistant(options)`: Create an AI assistant with specific instructions
395
- - Parameters: `LLMCreateAssistantOptions` with `model`, optional `instructions` and `storageIds`
396
- - Returns: `Promise<LLMCreateAssistantResult>`
397
418
  - `deleteAssistant(assistantId)`: Delete an assistant
398
419
  - `createChat(options)`: Create a new chat/conversation
399
- - Parameters: `LLMCreateChatOptions` with `model`, optional `instructions`, `history`, `files`, and `storageId`
400
- - Returns: `Promise<LLMCreateChatResult>`
401
420
  - `deleteChat(chatId)`: Delete a chat
402
421
  - `assistInChat(options)`: Send a message in an existing chat and get an assistant response
403
- - Parameters: `LLMAssistanceOptions` with `model`, `message`, `chatId`, and `assistantId`
404
- - Returns: `Promise<LLMAssistanceResult>`
405
422
  - `countTokens(messages, model)`: Count tokens in messages for context management
406
- - Parameters: `messages` array of `LLMCompletionMessage`, `model` of type `LLMModel<Provider>`
407
- - Returns: `Promise<number>` - Total number of tokens in the messages
408
423
 
409
424
  ### LLMSpeechToTextService
410
425
 
@@ -113,7 +113,8 @@ export declare enum LLMRoles {
113
113
  export declare enum LLMMessageContentType {
114
114
  TEXT = "text",
115
115
  IMAGE_URL = "image_url",
116
- IMAGE_FILE = "image_file"
116
+ IMAGE_FILE = "image_file",
117
+ AUDIO_FILE = "audio_file"
117
118
  }
118
119
  /**
119
120
  * Represents a text part in a message in an LLM conversation.
@@ -145,15 +146,27 @@ export interface LLMMessageImageFileContent {
145
146
  };
146
147
  }
147
148
  /**
148
- * Union type for all possible message content types in an LLM conversation.
149
+ * Union type for all possible message content types in an LLM completion.
149
150
  */
150
- export type LLMMessageContent = LLMMessageTextContent | LLMMessageImageUrlContent | LLMMessageImageFileContent;
151
+ export type LLMCompletionsMessageContent = LLMMessageTextContent | LLMMessageImageUrlContent;
151
152
  /**
152
- * Represents a message in an LLM conversation.
153
+ * Union type for all possible message content types in an LLM assistance.
154
+ */
155
+ export type LLMAssistanceMessageContent = LLMMessageTextContent | LLMMessageImageUrlContent | LLMMessageImageFileContent;
156
+ /**
157
+ * Represents a message in an LLM completion request.
153
158
  */
154
159
  export interface LLMCompletionMessage {
155
160
  role: LLMRoles;
156
- content: LLMMessageContent[];
161
+ content: LLMCompletionsMessageContent[];
162
+ }
163
+ /**
164
+ * Represents a message in an LLM assistance request.
165
+ */
166
+ export interface LLMAssistanceMessage {
167
+ role: LLMRoles;
168
+ content: LLMAssistanceMessageContent[];
169
+ attachments?: LLMUploadedFile[];
157
170
  }
158
171
  /**
159
172
  * Represents an error that occurred during an LLM request.
@@ -172,11 +185,18 @@ export type LLMRequestResult<ResponseType> = ResponseType | {
172
185
  export type LLMCompletionResult = LLMRequestResult<{
173
186
  text: string;
174
187
  }>;
188
+ /**
189
+ * Base options for LLM methods that can be extended by specific method options.
190
+ * Contains common properties like abort signal for cancellation.
191
+ */
192
+ export interface LLMMethodBaseOptions {
193
+ abortSignal?: AbortSignal;
194
+ }
175
195
  /**
176
196
  * Options for sending a message to an LLM service.
177
197
  * @template Provider - The LLM provider type
178
198
  */
179
- export interface LLMSendMessageOptions<Provider extends LLMProviders> {
199
+ export interface LLMSendMessageOptions<Provider extends LLMProviders> extends LLMMethodBaseOptions {
180
200
  message: LLMCompletionMessage;
181
201
  model: LLMModel<Provider>;
182
202
  history?: LLMCompletionMessage[];
@@ -207,11 +227,15 @@ export declare enum LLMUploadFileMimeTypes {
207
227
  AUDIO_WAV = "audio/wav",
208
228
  AUDIO_WEBM = "audio/webm"
209
229
  }
230
+ /**
231
+ * Represents the MIME types for images that can be uploaded to LLM services.
232
+ */
210
233
  export type LLMImageMimeType = LLMUploadFileMimeTypes.IMAGE_PNG | LLMUploadFileMimeTypes.IMAGE_JPEG | LLMUploadFileMimeTypes.IMAGE_JPG | LLMUploadFileMimeTypes.IMAGE_GIF | LLMUploadFileMimeTypes.IMAGE_WEBP | LLMUploadFileMimeTypes.IMAGE_SVG_XML | LLMUploadFileMimeTypes.IMAGE_BMP;
234
+ export type LLMAudioMimeType = LLMUploadFileMimeTypes.AUDIO_MP3 | LLMUploadFileMimeTypes.AUDIO_MPEG | LLMUploadFileMimeTypes.AUDIO_WAV | LLMUploadFileMimeTypes.AUDIO_WEBM;
211
235
  /**
212
236
  * Represents a file to be uploaded to an LLM service.
213
237
  */
214
- export interface LLMUploadFile {
238
+ export interface LLMUploadFileOptions extends LLMMethodBaseOptions {
215
239
  mimeType: LLMUploadFileMimeTypes;
216
240
  name: string;
217
241
  path: string;
@@ -219,7 +243,7 @@ export interface LLMUploadFile {
219
243
  /**
220
244
  * Represents a file that has been successfully uploaded to an LLM service.
221
245
  */
222
- export interface LLMUploadedFile extends LLMUploadFile {
246
+ export interface LLMUploadedFile extends LLMUploadFileOptions {
223
247
  fileId: string;
224
248
  }
225
249
  /**
@@ -230,7 +254,7 @@ export type LLMUploadFileResult = LLMRequestResult<LLMUploadedFile>;
230
254
  * Options for creating a file storage for a specific LLM provider.
231
255
  * @template Provider - The LLM provider type
232
256
  */
233
- export interface LLMCreateFileStorageOptions<Provider extends LLMProviders> {
257
+ export interface LLMCreateFileStorageOptions<Provider extends LLMProviders> extends LLMMethodBaseOptions {
234
258
  uploadedFiles: LLMUploadedFile[];
235
259
  model: LLMModel<Provider>;
236
260
  instructions?: string;
@@ -249,7 +273,7 @@ export type LLMCreateFileStorageResult = LLMRequestResult<LLMCreatedFileStorage>
249
273
  * Options for creating an assistant with a specific LLM provider.
250
274
  * @template Provider - The LLM provider type
251
275
  */
252
- export interface LLMCreateAssistantOptions<Provider extends LLMProviders> {
276
+ export interface LLMCreateAssistantOptions<Provider extends LLMProviders> extends LLMMethodBaseOptions {
253
277
  model: LLMModel<Provider>;
254
278
  instructions?: string;
255
279
  storageIds?: string[];
@@ -269,10 +293,10 @@ export type LLMCreateAssistantResult = LLMRequestResult<LLMCreatedAssistant>;
269
293
  * Options for creating a chat session with a specific LLM provider.
270
294
  * @template Provider - The LLM provider type
271
295
  */
272
- export interface LLMCreateChatOptions<Provider extends LLMProviders> {
296
+ export interface LLMCreateChatOptions<Provider extends LLMProviders> extends LLMMethodBaseOptions {
273
297
  model: LLMModel<Provider>;
274
298
  instructions?: string;
275
- history?: LLMCompletionMessage[];
299
+ history?: LLMAssistanceMessage[];
276
300
  files?: LLMUploadedFile[];
277
301
  storageId?: string;
278
302
  }
@@ -286,17 +310,11 @@ export interface LLMCreatedChat {
286
310
  * Result type for chat creation operations.
287
311
  */
288
312
  export type LLMCreateChatResult = LLMRequestResult<LLMCreatedChat>;
289
- /**
290
- * Extends LLMMessage with optional attachments
291
- */
292
- export interface LLMAssistanceMessage extends LLMCompletionMessage {
293
- attachments?: LLMUploadedFile[];
294
- }
295
313
  /**
296
314
  * Options for using an assistant with a specific LLM provider.
297
315
  * @template Provider - The LLM provider type
298
316
  */
299
- export interface LLMAssistanceOptions {
317
+ export interface LLMAssistanceOptions extends LLMMethodBaseOptions {
300
318
  message: LLMAssistanceMessage;
301
319
  chatId: string;
302
320
  assistantId: string;
@@ -327,13 +345,14 @@ export interface CombineMessagesOptions<Provider extends LLMProviders, TokenCoun
327
345
  message: LLMCompletionMessage;
328
346
  model: LLMModel<Provider>;
329
347
  instance: LLMInstances[Provider];
348
+ logger: Logger;
330
349
  countTokensFn: TokenCountFunction;
331
350
  }
332
351
  /**
333
352
  * Options for transcribing audio to text using an LLM service.
334
353
  * @template Provider - The LLM provider type
335
354
  */
336
- export interface LLMTranscribeOptions<Provider extends LLMProviders> {
355
+ export interface LLMTranscribeOptions<Provider extends LLMProviders> extends LLMMethodBaseOptions {
337
356
  pathToAudio: string;
338
357
  mimeType?: LLMUploadFileMimeTypes;
339
358
  model: LLMModel<Provider>;
@@ -355,7 +374,7 @@ export type LLMSpeechOptions = {
355
374
  * Options for creating speech from text using an LLM service.
356
375
  * @template Provider - The LLM provider type
357
376
  */
358
- export interface LLMCreateSpeechOptions<Provider extends LLMProviders> {
377
+ export interface LLMCreateSpeechOptions<Provider extends LLMProviders> extends LLMMethodBaseOptions {
359
378
  text: string;
360
379
  model: LLMModel<Provider>;
361
380
  instructions?: string;
@@ -1 +1 @@
1
- "use strict";var LLMProviders,LLMPurposes,LLMRoles,LLMMessageContentType,LLMUploadFileMimeTypes;Object.defineProperty(exports,"__esModule",{value:!0}),exports.LLMUploadFileMimeTypes=exports.LLMMessageContentType=exports.LLMRoles=exports.LLMPurposes=exports.LLMProviders=void 0,function(e){e.OpenAI="OpenAI",e.GoogleGenerativeAI="GoogleGenerativeAI"}(LLMProviders||(exports.LLMProviders=LLMProviders={})),function(e){e.Completion="completion",e.Assistance="assistance",e.SpeechToText="speech_to_text",e.TextToSpeech="text_to_speech"}(LLMPurposes||(exports.LLMPurposes=LLMPurposes={})),function(e){e.User="user",e.Assistant="assistant"}(LLMRoles||(exports.LLMRoles=LLMRoles={})),function(e){e.TEXT="text",e.IMAGE_URL="image_url",e.IMAGE_FILE="image_file"}(LLMMessageContentType||(exports.LLMMessageContentType=LLMMessageContentType={})),function(e){e.IMAGE_PNG="image/png",e.IMAGE_JPEG="image/jpeg",e.IMAGE_JPG="image/jpg",e.IMAGE_GIF="image/gif",e.IMAGE_WEBP="image/webp",e.IMAGE_SVG_XML="image/svg+xml",e.IMAGE_BMP="image/bmp",e.PLAIN_TEXT="text/plain",e.MARKDOWN="text/markdown",e.AUDIO_MP3="audio/mp3",e.AUDIO_MPEG="audio/mpeg",e.AUDIO_WAV="audio/wav",e.AUDIO_WEBM="audio/webm"}(LLMUploadFileMimeTypes||(exports.LLMUploadFileMimeTypes=LLMUploadFileMimeTypes={}));
1
+ "use strict";var LLMProviders,LLMPurposes,LLMRoles,LLMMessageContentType,LLMUploadFileMimeTypes;Object.defineProperty(exports,"__esModule",{value:!0}),exports.LLMUploadFileMimeTypes=exports.LLMMessageContentType=exports.LLMRoles=exports.LLMPurposes=exports.LLMProviders=void 0,function(e){e.OpenAI="OpenAI",e.GoogleGenerativeAI="GoogleGenerativeAI"}(LLMProviders||(exports.LLMProviders=LLMProviders={})),function(e){e.Completion="completion",e.Assistance="assistance",e.SpeechToText="speech_to_text",e.TextToSpeech="text_to_speech"}(LLMPurposes||(exports.LLMPurposes=LLMPurposes={})),function(e){e.User="user",e.Assistant="assistant"}(LLMRoles||(exports.LLMRoles=LLMRoles={})),function(e){e.TEXT="text",e.IMAGE_URL="image_url",e.IMAGE_FILE="image_file",e.AUDIO_FILE="audio_file"}(LLMMessageContentType||(exports.LLMMessageContentType=LLMMessageContentType={})),function(e){e.IMAGE_PNG="image/png",e.IMAGE_JPEG="image/jpeg",e.IMAGE_JPG="image/jpg",e.IMAGE_GIF="image/gif",e.IMAGE_WEBP="image/webp",e.IMAGE_SVG_XML="image/svg+xml",e.IMAGE_BMP="image/bmp",e.PLAIN_TEXT="text/plain",e.MARKDOWN="text/markdown",e.AUDIO_MP3="audio/mp3",e.AUDIO_MPEG="audio/mpeg",e.AUDIO_WAV="audio/wav",e.AUDIO_WEBM="audio/webm"}(LLMUploadFileMimeTypes||(exports.LLMUploadFileMimeTypes=LLMUploadFileMimeTypes={}));
@@ -1 +1 @@
1
- {"version":3,"file":"LLMService.typedefs.js","sourceRoot":"","sources":["../src/LLMService.typedefs.ts"],"names":[],"mappings":";;;AAkBA;;GAEG;AACH,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,iCAAiB,CAAA;IACjB,yDAAyC,CAAA;AAC3C,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB;AAkBD;;GAEG;AACH,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,wCAAyB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AClB,yBAAa,CAAA;IACb,mCAAuB,CAAA;AACzB,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB;AAED;;GAEG;AACH,IAAY,qBAKX;AALD,WAAY,qBAAqB;IAC/B,sCAAa,CAAA;IACb,gDAAuB,CAAA;IACvB,kDAAyB,CAAA;IACzB,kDAAyB,CAAA;AAC3B,CAAC,EALW,qBAAqB,qCAArB,qBAAqB,QAKhC;AA8GD;;GAEG;AACH,IAAY,sBAcX;AAdD,WAAY,sBAAsB;IAChC,iDAAuB,CAAA;IACvB,mDAAyB,CAAA;IACzB,iDAAuB,CAAA;IACvB,iDAAuB,CAAA;IACvB,mDAAyB,CAAA;IACzB,yDAA+B,CAAA;IAC/B,iDAAuB,CAAA;IACvB,mDAAyB,CAAA;IACzB,oDAA0B,CAAA;IAC1B,iDAAuB,CAAA;IACvB,mDAAyB,CAAA;IACzB,iDAAuB,CAAA;IACvB,mDAAyB,CAAA;AAC3B,CAAC,EAdW,sBAAsB,sCAAtB,sBAAsB,QAcjC"}
@@ -35,7 +35,7 @@ type ConditionalValue = RegularValue | boolean | undefined | null;
35
35
  type ExtractAllVariables<T extends string> = T extends `${string}{{${infer Key}}}${infer Rest}` ? Key extends `${infer CleanKey}` ? CleanKey | ExtractAllVariables<Rest> : never : never;
36
36
  type ExtractSectionVariables<T extends string> = T extends `${string}{{#${infer Key}}}${infer Rest}` ? Key | ExtractSectionVariables<Rest> : T extends `${string}{{/${infer Key}}}${infer Rest}` ? Key | ExtractSectionVariables<Rest> : never;
37
37
  type ExtractRegularVariables<T extends string> = ExtractAllVariables<T> extends infer All ? All extends string ? All extends `#${string}` | `/${string}` ? never : All : never : never;
38
- type CreateVariableRecord<T extends string> = ExtractRegularVariables<T> extends never ? ExtractSectionVariables<T> extends never ? Record<string, never> : Record<ExtractSectionVariables<T>, RegularValue> : ExtractSectionVariables<T> extends never ? Record<ExtractRegularVariables<T>, RegularValue> : Record<ExtractRegularVariables<T>, RegularValue> & Record<ExtractSectionVariables<T>, ConditionalValue>;
38
+ type CreateVariableRecord<T extends string> = ExtractRegularVariables<T> extends never ? ExtractSectionVariables<T> extends never ? Record<string, never> : Record<ExtractSectionVariables<T>, RegularValue> : ExtractSectionVariables<T> extends never ? Record<ExtractRegularVariables<T>, RegularValue> : Omit<Record<ExtractRegularVariables<T>, RegularValue>, ExtractSectionVariables<T>> & Record<ExtractSectionVariables<T>, ConditionalValue>;
39
39
  type HasVariables<T extends string> = ExtractAllVariables<T> extends never ? false : true;
40
40
  /**
41
41
  * Creates a prompt template function that can be used to generate prompts with dynamic replacements and conditional sections.
@@ -1 +1 @@
1
- {"version":3,"file":"promptBuilder.js","sourceRoot":"","sources":["../src/promptBuilder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;;AAkHH,oDAQC;AA1DD,SAAS,aAAa,CACpB,MAAc,EACd,SAA2D;IAE3D,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,gBAAgB,GAAG,CAAC,MAAc,EAAU,EAAE,CAAC;IACnD,+DAA+D;IAC/D,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CACtD,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,SAAS,GAAG,QAAQ,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAClE,EAAE,MAAM,CAAC,CACX,CAAC;IAEF,MAAM,0BAA0B,GAAG,CAAC,MAAc,EAAU,EAAE;QAC5D,qEAAqE;QACrE,OAAO,MAAM,CAAC,OAAO,CAAC,+BAA+B,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE;YACjF,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;YAErC,IAAI,KAAK,EAAE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CACX,CAAC;IAEF,MAAM,0BAA0B,GAAG,CAAC,MAAc,EAAU,EAAE;QAC5D,qEAAqE;QACrE,OAAO,MAAM,CAAC,OAAO,CAAC,+BAA+B,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE;YACjF,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;YAErC,IAAI,KAAK,EAAE,CAAC;gBACV,6EAA6E;gBAC7E,MAAM,gBAAgB,GAAG,0BAA0B,CAAC,OAAO,CAAC,CAAC;gBAC7D,OAAO,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;YAC5C,CAAC;YAED,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,IAAI,MAAM,GAAG,MAAM,CAAC;IAEpB,mFAAmF;IACnF,MAAM,GAAG,0BAA0B,CAAC,MAAM,CAAC,CAAC;IAE5C,6CAA6C;IAC7C,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,oBAAoB,CAAmB,QAAW;IAChE,MAAM,eAAe,GAAG,QAAQ,CAAC,IAAI,EAAO,CAAC;IAE7C,OAAO,CACL,GAAG,IAEqC,EAChC,EAAE,CAAC,aAAa,CAAC,eAAe,EAAE,GAAG,IAAI,CAAC,CAAC;AACvD,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { type Logger } from '@mate-academy/core';
1
2
  import { type Part, type GoogleGenAI, type GenerateContentParameters, type Content, type ContentListUnion } from '@google/genai';
2
3
  import { type CombineMessagesOptions, type LLMCountTokensFunction, type LLMCompletionMessage, type LLMModel, type LLMProviders, type LLMUploadedFile, type LLMFileLimits, type LLMAssistanceMessage } from '../../LLMService.typedefs';
3
4
  export declare class GoogleGenerativeAIEntity {
@@ -5,12 +6,13 @@ export declare class GoogleGenerativeAIEntity {
5
6
  model: LLMModel<LLMProviders.GoogleGenerativeAI>;
6
7
  messages: Content[];
7
8
  instructions?: string;
9
+ abortSignal?: AbortSignal;
8
10
  }): GenerateContentParameters;
9
11
  static getFileDataParts(uploadedFiles: LLMUploadedFile[]): Pick<Part, 'fileData'>[];
10
12
  static getTextParts(messages: string[]): Pick<Part, 'text'>[];
11
- static getContent(message: LLMCompletionMessage | LLMAssistanceMessage, instance: GoogleGenAI): Promise<Content>;
13
+ static getContent(message: LLMCompletionMessage | LLMAssistanceMessage, instance: GoogleGenAI, logger: Logger): Promise<Content>;
12
14
  static getCountTokensFn(instance: GoogleGenAI): LLMCountTokensFunction<LLMProviders.GoogleGenerativeAI, ContentListUnion>;
13
- static combineMessagesWithLimit({ modelContext, history, message, model, countTokensFn, instance, }: CombineMessagesOptions<LLMProviders.GoogleGenerativeAI, LLMCountTokensFunction<LLMProviders.GoogleGenerativeAI, ContentListUnion>>): Promise<Content[]>;
15
+ static combineMessagesWithLimit({ modelContext, history, message, model, countTokensFn, instance, logger, }: CombineMessagesOptions<LLMProviders.GoogleGenerativeAI, LLMCountTokensFunction<LLMProviders.GoogleGenerativeAI, ContentListUnion>>): Promise<Content[]>;
14
16
  static get transcribeLimits(): LLMFileLimits;
15
17
  static get transcribeInstructions(): string;
16
18
  }
@@ -1 +1 @@
1
- "use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GoogleGenerativeAIEntity=void 0;const axios_1=__importDefault(require("axios")),LLMService_typedefs_1=require("../../LLMService.typedefs");class GoogleGenerativeAIEntity{static getContentParameters(e){const{model:t,messages:i,instructions:s}=e;return{model:t.name,contents:i,config:{systemInstruction:s,temperature:t.config.temperature}}}static getFileDataParts(e){return e.map(e=>({fileData:{fileUri:e.path,mimeType:e.mimeType}}))}static getTextParts(e){return e.map(e=>({text:e}))}static async getContent(e,t){const i=e.role===LLMService_typedefs_1.LLMRoles.Assistant?"model":e.role,s=[];for(const i of e.content)switch(i.type){case LLMService_typedefs_1.LLMMessageContentType.TEXT:s.push({text:i.text});break;case LLMService_typedefs_1.LLMMessageContentType.IMAGE_URL:{const e=await axios_1.default.head(i.image_url.url),a=e.headers["content-type"]?.split(";")[0]??LLMService_typedefs_1.LLMUploadFileMimeTypes.IMAGE_PNG,r=await axios_1.default.get(i.image_url.url,{responseType:"arraybuffer"}),n=new Uint8Array(r.data),o=new Blob([n],{type:a}),l=await t.files.upload({file:o});s.push({fileData:{fileUri:l.uri,mimeType:a}});break}case LLMService_typedefs_1.LLMMessageContentType.IMAGE_FILE:s.push({fileData:{fileUri:i.image_file.path,mimeType:i.image_file.mime_type}})}return"attachments"in e&&e.attachments&&s.push(...this.getFileDataParts(e.attachments)),{role:i,parts:s}}static getCountTokensFn(e){const t=e=>Boolean(e&&"object"==typeof e&&"role"in e&&"parts"in e);return async(i,s)=>{if(!i)return 0;const a=[];Array.isArray(i)?a.push(...i.filter(t)):t(i)&&a.push(i);const r=a.filter(e=>e&&"string"==typeof e.role&&Array.isArray(e.parts));if(0===r.length)return 0;const{totalTokens:n}=await e.models.countTokens({model:s.name,contents:r});return n??0}}static async combineMessagesWithLimit({modelContext:e=[],history:t=[],message:i,model:s,countTokensFn:a,instance:r}){const n=await Promise.all(e.map(e=>GoogleGenerativeAIEntity.getContent(e,r))),o=await Promise.all(t.map(e=>GoogleGenerativeAIEntity.getContent(e,r))),l={role:LLMService_typedefs_1.LLMRoles.User,content:i.content},p=[...n,await GoogleGenerativeAIEntity.getContent(l,r)],c=[...o].reverse();let m=await a(p,s)??0,y=0;for(const e of c){const t=await a(e,s)??0;if(!(m+t<=s.limits.maxInputTokens))break;y+=1,p.splice(-y,0,e),m+=t}return p}static get transcribeLimits(){return{maxFileSize:2*1024**3,supportedMimeTypes:[LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_WAV,LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_MP3,LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_MPEG,LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_WEBM]}}static get transcribeInstructions(){return"Transcribe the audio file to text."}}exports.GoogleGenerativeAIEntity=GoogleGenerativeAIEntity;
1
+ "use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GoogleGenerativeAIEntity=void 0;const axios_1=__importDefault(require("axios")),LLMService_typedefs_1=require("../../LLMService.typedefs");class GoogleGenerativeAIEntity{static getContentParameters(e){const{model:t,messages:i,instructions:a,abortSignal:s}=e;return{model:t.name,contents:i,config:{systemInstruction:a,temperature:t.config.temperature,abortSignal:s}}}static getFileDataParts(e){return e.map(e=>({fileData:{fileUri:e.path,mimeType:e.mimeType}}))}static getTextParts(e){return e.map(e=>({text:e}))}static async getContent(e,t,i){const a=e.role===LLMService_typedefs_1.LLMRoles.Assistant?"model":e.role,s=[];for(const a of e.content)switch(a.type){case LLMService_typedefs_1.LLMMessageContentType.TEXT:s.push({text:a.text});break;case LLMService_typedefs_1.LLMMessageContentType.IMAGE_URL:{const e=await axios_1.default.head(a.image_url.url),i=e.headers["content-type"]?.split(";")[0]??LLMService_typedefs_1.LLMUploadFileMimeTypes.IMAGE_PNG,r=await axios_1.default.get(a.image_url.url,{responseType:"arraybuffer"}),n=new Uint8Array(r.data),o=new Blob([n],{type:i}),l=await t.files.upload({file:o});s.push({fileData:{fileUri:l.uri,mimeType:i}});break}case LLMService_typedefs_1.LLMMessageContentType.IMAGE_FILE:s.push({fileData:{fileUri:a.image_file.path,mimeType:a.image_file.mime_type}});break;default:i.child("GoogleGenerativeAIEntity.getContent").warn("Unsupported content type in message item",{contentItem:a})}return"attachments"in e&&e.attachments&&s.push(...this.getFileDataParts(e.attachments)),{role:a,parts:s}}static getCountTokensFn(e){const t=e=>Boolean(e&&"object"==typeof e&&"role"in e&&"parts"in e);return async(i,a)=>{if(!i)return 0;const s=[];Array.isArray(i)?s.push(...i.filter(t)):t(i)&&s.push(i);const r=s.filter(e=>e&&"string"==typeof e.role&&Array.isArray(e.parts));if(0===r.length)return 0;const{totalTokens:n}=await e.models.countTokens({model:a.name,contents:r});return n??0}}static async combineMessagesWithLimit({modelContext:e=[],history:t=[],message:i,model:a,countTokensFn:s,instance:r,logger:n}){const o=await Promise.all(e.map(e=>GoogleGenerativeAIEntity.getContent(e,r,n))),l=await Promise.all(t.map(e=>GoogleGenerativeAIEntity.getContent(e,r,n))),p={role:LLMService_typedefs_1.LLMRoles.User,content:i.content},c=[...o,await GoogleGenerativeAIEntity.getContent(p,r,n)],m=[...l].reverse();let y=await s(c,a)??0,u=0;for(const e of m){const t=await s(e,a)??0;if(!(y+t<=a.limits.maxInputTokens))break;u+=1,c.splice(-u,0,e),y+=t}return c}static get transcribeLimits(){return{maxFileSize:2*1024**3,supportedMimeTypes:[LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_WAV,LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_MP3,LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_MPEG,LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_WEBM]}}static get transcribeInstructions(){return"Transcribe the audio file to text."}}exports.GoogleGenerativeAIEntity=GoogleGenerativeAIEntity;
@@ -1 +1 @@
1
- {"version":3,"file":"GoogleGenerativeAI.entity.js","sourceRoot":"","sources":["../../../src/providers/GoogleGenerativeAI/GoogleGenerativeAI.entity.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAS1B,+DAY+B;AAE/B,MAAa,wBAAwB;IACnC,MAAM,CAAC,oBAAoB,CAAC,OAI3B;QACC,MAAM,EACJ,KAAK,EACL,QAAQ,EACR,YAAY,GACb,GAAG,OAAO,CAAC;QAEZ,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,IAAI;YACjB,QAAQ,EAAE,QAAQ;YAClB,MAAM,EAAE;gBACN,iBAAiB,EAAE,YAAY;gBAC/B,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,WAAW;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AM,KAAK,gBAAgB;QACzB,OAAO;YACL,WAAW,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,OAAO;YACrC,kBAAkB,EAAE;gBAClB,4CAAsB,CAAC,SAAS;gBAChC,4CAAsB,CAAC,SAAS;gBAChC,4CAAsB,CAAC,UAAU;gBACjC,4CAAsB,CAAC,UAAU;aAClC;SACF,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,sBAAsB;QAC/B,OAAO,oCAAoC,CAAC;IAC9C,CAAC;CACF;AA5OD,4DA4OC"}
1
+ {"version":3,"file":"GoogleGenerativeAI.entity.js","sourceRoot":"","sources":["../../../src/providers/GoogleGenerativeAI/GoogleGenerativeAI.entity.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAU1B,+DAY+B;AAE/B,MAAa,wBAAwB;IACnC,MAAM,CAAC,oBAAoB,CAAC,OAK3B;QACC,MAAM,EACJ,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,WAAW,GACZ,GAAG,OAAO,CAAC;QAEZ,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,IAAI;YACjB,QAAQ,EAAE,QAAQ;YAClB,MAAM,EAAE;gBACN,iBAAiB,EAAE,YAAY;gBAC/B,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,WAAW;gBACrC,WAAW;aACZ;SACF,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,gBAAgB,CACrB,aAAgC;QAEhC,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAClC,QAAQ,EAAE;gBACR,OAAO,EAAE,IAAI,CAAC,IAAI;gBAClB,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACxB;SACF,CAAC,CAAC,CAAC;IACN,CAAC;IAED,MAAM,CAAC,YAAY,CACjB,QAAkB;QAElB,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAA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ACJ,CAAC;IAED,MAAM,KAAK,sBAAsB;QAC/B,OAAO,oCAAoC,CAAC;IAC9C,CAAC;CACF;AArPD,4DAqPC"}
@@ -1,6 +1,6 @@
1
1
  import { type Logger } from '@mate-academy/core';
2
2
  import { GoogleGenAI } from '@google/genai';
3
- import { type LLMAssistanceOptions, type LLMAssistanceResult, type LLMCompletionMessage, type LLMCreateAssistantResult, type LLMCreateChatOptions, type LLMCreateChatResult, type LLMCreateFileStorageOptions, type LLMCreateFileStorageResult, type LLMInstanceOptions, type LLMModel, LLMProviders, type LLMUploadFile, type LLMUploadFileResult } from '../../../LLMService.typedefs';
3
+ import { type LLMAssistanceOptions, type LLMAssistanceResult, type LLMCompletionMessage, type LLMCreateAssistantOptions, type LLMCreateAssistantResult, type LLMCreateChatOptions, type LLMCreateChatResult, type LLMCreateFileStorageOptions, type LLMCreateFileStorageResult, type LLMInstanceOptions, type LLMModel, LLMProviders, type LLMUploadFileOptions, type LLMUploadFileResult } from '../../../LLMService.typedefs';
4
4
  import { LLMAssistanceService } from '../../../services';
5
5
  export declare class GoogleGenerativeAIAssistanceService extends LLMAssistanceService<LLMProviders.GoogleGenerativeAI> {
6
6
  #private;
@@ -10,13 +10,13 @@ export declare class GoogleGenerativeAIAssistanceService extends LLMAssistanceSe
10
10
  private uncachedFileStorages;
11
11
  constructor(logger: Logger, options: LLMInstanceOptions[LLMProviders.GoogleGenerativeAI]);
12
12
  protected get instance(): GoogleGenAI;
13
- uploadFile(file: LLMUploadFile): Promise<LLMUploadFileResult>;
13
+ uploadFile(fileOptions: LLMUploadFileOptions): Promise<LLMUploadFileResult>;
14
14
  deleteFile(fileId: string): Promise<void>;
15
15
  createFileStorage(options: LLMCreateFileStorageOptions<LLMProviders.GoogleGenerativeAI>): Promise<LLMCreateFileStorageResult>;
16
16
  deleteFileStorage(fileStorageId: string): Promise<void>;
17
17
  createChat(options: LLMCreateChatOptions<LLMProviders.GoogleGenerativeAI>): Promise<LLMCreateChatResult>;
18
18
  deleteChat(chatId: string): Promise<void>;
19
- createAssistant(): Promise<LLMCreateAssistantResult>;
19
+ createAssistant(options: LLMCreateAssistantOptions<LLMProviders.GoogleGenerativeAI>): Promise<LLMCreateAssistantResult>;
20
20
  deleteAssistant(): Promise<void>;
21
21
  assistInChat(options: LLMAssistanceOptions): Promise<LLMAssistanceResult>;
22
22
  countTokens(messages: LLMCompletionMessage[], model: LLMModel<LLMProviders.GoogleGenerativeAI>): Promise<number>;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GoogleGenerativeAIAssistanceService=void 0;const uuid_1=require("uuid"),genai_1=require("@google/genai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services"),GoogleGenerativeAI_typedefs_1=require("../../../providers/GoogleGenerativeAI/GoogleGenerativeAI.typedefs"),GoogleGenerativeAI_entity_1=require("../../../providers/GoogleGenerativeAI/GoogleGenerativeAI.entity"),GoogleGenerativeAI_constants_1=require("../../../providers/GoogleGenerativeAI/GoogleGenerativeAI.constants");class GoogleGenerativeAIAssistanceService extends services_1.LLMAssistanceService{#e=null;cachedContent=new Map;chatSessions=new Map;uploadedFiles=new Map;uncachedFileStorages=new Map;constructor(e,t){super(LLMService_typedefs_1.LLMProviders.GoogleGenerativeAI,e,t)}get instance(){return this.#e||(this.#e=new genai_1.GoogleGenAI({apiKey:this.options.apiKey})),this.#e}async uploadFile(e){try{const{path:t,mimeType:r,name:i}=e,n=this.uploadedFiles.get(t);if(n)return n;const o=await this.instance.files.upload({file:t,config:{mimeType:r,displayName:i}});if(!o.name)throw new Error("Upload result did not return a name");if(!o.uri)throw new Error("Upload result did not return a uri");if(o.error)throw o.error;const s={...e,fileId:o.name,path:o.uri};return this.uploadedFiles.set(t,s),s}catch(t){return this.logger.child("uploadFile").error("Error uploading file",{error:t,file:e}),{error:t}}}async deleteFile(e){this.uploadedFiles.delete(e),await this.instance.files.delete({name:e})}async createFileStorage(e){const{uploadedFiles:t,model:r,instructions:i}=e;try{const e=GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getFileDataParts(t),n=GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getCountTokensFn(this.instance),o=await n(e,r);if(o<GoogleGenerativeAI_constants_1.MIN_CACHE_CONTENT_LENGTH){const e=(0,uuid_1.v4)();return this.uncachedFileStorages.set(e,t),this.logger.child("createFileStorage").info("File storage created without caching (content too small)",{storageId:e,tokenCount:o,minRequired:GoogleGenerativeAI_constants_1.MIN_CACHE_CONTENT_LENGTH}),{storageId:e}}const s=await this.instance.caches.create({model:r.name,config:{contents:[{role:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIRoles.User,parts:e}],systemInstruction:i,ttl:"1h"}});if(!s.name)throw new Error("Cache result did not return a name");return this.cachedContent.set(s.name,s),{storageId:s.name}}catch(e){return this.logger.child("createFileStorage").error("Error creating file storage",{error:e,uploadedFiles:t,model:r}),{error:e}}}async deleteFileStorage(e){if(""===e)return;this.cachedContent.get(e)&&(this.cachedContent.delete(e),await this.instance.caches.delete({name:e})),this.uncachedFileStorages.delete(e)}async createChat(e){try{const{storageId:t,model:r,instructions:i,history:n,files:o}=e,s=t?this.cachedContent.get(t):void 0,a=t?this.uncachedFileStorages.get(t):void 0,c=n?await Promise.all(n.map(e=>GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getContent(e,this.instance))):[];if(!s&&o&&o.length>0){const e=GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getFileDataParts(o);c.push({role:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIRoles.User,parts:e})}if(!s&&a){const e=GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getFileDataParts(a);c.push({role:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIRoles.User,parts:e})}const l=this.instance.chats.create({model:r.name,history:c,config:{systemInstruction:i,temperature:r.config.temperature,...s&&{cachedContent:s.name}}}),g=(0,uuid_1.v4)();return this.chatSessions.set(g,l),Promise.resolve({chatId:g})}catch(t){return this.logger.child("createChat").error("Error creating chat",{error:t,options:e}),Promise.resolve({error:t})}}deleteChat(e){return this.chatSessions.delete(e),Promise.resolve()}createAssistant(){return Promise.resolve({assistantId:""})}deleteAssistant(){return Promise.resolve()}async assistInChat(e){try{const{message:t,chatId:r}=e,i=this.chatSessions.get(r);if(!i)throw new Error("Chat session not found");const n=await GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getContent(t,this.instance);if(!n.parts)return{text:""};return{text:(await i.sendMessage({message:n.parts})).text??""}}catch(t){return this.logger.child("assistInChat").error("Error assisting in chat",{error:t,options:e}),{error:t}}}async countTokens(e,t){return GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getCountTokensFn(this.instance)(e,t)}}exports.GoogleGenerativeAIAssistanceService=GoogleGenerativeAIAssistanceService;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GoogleGenerativeAIAssistanceService=void 0;const uuid_1=require("uuid"),genai_1=require("@google/genai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services"),GoogleGenerativeAI_typedefs_1=require("../../../providers/GoogleGenerativeAI/GoogleGenerativeAI.typedefs"),GoogleGenerativeAI_entity_1=require("../../../providers/GoogleGenerativeAI/GoogleGenerativeAI.entity"),GoogleGenerativeAI_constants_1=require("../../../providers/GoogleGenerativeAI/GoogleGenerativeAI.constants");class GoogleGenerativeAIAssistanceService extends services_1.LLMAssistanceService{#e=null;cachedContent=new Map;chatSessions=new Map;uploadedFiles=new Map;uncachedFileStorages=new Map;constructor(e,t){super(LLMService_typedefs_1.LLMProviders.GoogleGenerativeAI,e,t)}get instance(){return this.#e||(this.#e=new genai_1.GoogleGenAI({apiKey:this.options.apiKey})),this.#e}async uploadFile(e){try{const{path:t,mimeType:r,name:o,abortSignal:i}=e,n=this.uploadedFiles.get(t);if(n)return n;const a=await this.instance.files.upload({file:t,config:{mimeType:r,displayName:o,abortSignal:i}});if(!a.name)throw new Error("Upload result did not return a name");if(!a.uri)throw new Error("Upload result did not return a uri");if(a.error)throw a.error;const s={name:o,mimeType:r,fileId:a.name,path:a.uri};if(i?.aborted)throw new Error("File upload aborted");return this.uploadedFiles.set(t,s),s}catch(t){return this.logger.child("uploadFile").error("Error uploading file",{error:t,file:e}),{error:t}}}async deleteFile(e){this.uploadedFiles.delete(e),await this.instance.files.delete({name:e})}async createFileStorage(e){const{uploadedFiles:t,model:r,instructions:o,abortSignal:i}=e;try{const e=GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getFileDataParts(t),n=GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getCountTokensFn(this.instance),a=await n(e,r);if(a<GoogleGenerativeAI_constants_1.MIN_CACHE_CONTENT_LENGTH){const e=(0,uuid_1.v4)();if(this.uncachedFileStorages.set(e,t),this.logger.child("createFileStorage").info("File storage created without caching (content too small)",{storageId:e,tokenCount:a,minRequired:GoogleGenerativeAI_constants_1.MIN_CACHE_CONTENT_LENGTH}),i?.aborted)throw new Error("File storage creation aborted");return{storageId:e}}const s=await this.instance.caches.create({model:r.name,config:{contents:[{role:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIRoles.User,parts:e}],systemInstruction:o,ttl:"1h",abortSignal:i}});if(!s.name)throw new Error("Cache result did not return a name");if(i?.aborted)throw new Error("File storage creation aborted");return this.cachedContent.set(s.name,s),{storageId:s.name}}catch(e){return this.logger.child("createFileStorage").error("Error creating file storage",{error:e,uploadedFiles:t,model:r}),{error:e}}}async deleteFileStorage(e){if(""===e)return;this.cachedContent.get(e)&&(this.cachedContent.delete(e),await this.instance.caches.delete({name:e})),this.uncachedFileStorages.delete(e)}async createChat(e){try{const{storageId:t,model:r,instructions:o,history:i,files:n,abortSignal:a}=e,s=t?this.cachedContent.get(t):void 0,l=t?this.uncachedFileStorages.get(t):void 0,c=i?await Promise.all(i.map(e=>GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getContent(e,this.instance,this.logger))):[];if(!s&&n&&n.length>0){const e=GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getFileDataParts(n);c.push({role:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIRoles.User,parts:e})}if(!s&&l){const e=GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getFileDataParts(l);c.push({role:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIRoles.User,parts:e})}const g=this.instance.chats.create({model:r.name,history:c,config:{systemInstruction:o,temperature:r.config.temperature,abortSignal:a,...s&&{cachedContent:s.name}}}),d=(0,uuid_1.v4)();if(a?.aborted)throw new Error("Chat creation aborted");return this.chatSessions.set(d,g),Promise.resolve({chatId:d})}catch(t){return this.logger.child("createChat").error("Error creating chat",{error:t,options:e}),Promise.resolve({error:t})}}deleteChat(e){return this.chatSessions.delete(e),Promise.resolve()}createAssistant(e){const{abortSignal:t}=e;try{if(t?.aborted)throw new Error("Assistant creation aborted");return Promise.resolve({assistantId:""})}catch(t){return this.logger.child("createAssistant").error("Error creating assistant",{error:t,options:e}),Promise.resolve({error:t})}}deleteAssistant(){return Promise.resolve()}async assistInChat(e){try{const{message:t,chatId:r,abortSignal:o}=e,i=this.chatSessions.get(r);if(!i)throw new Error("Chat session not found");const n=await GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getContent(t,this.instance,this.logger);if(!n.parts)return{text:""};const a=await i.sendMessage({message:n.parts,config:{abortSignal:o}});if(o?.aborted)throw new Error("Chat assistance aborted");return{text:a.text??""}}catch(t){return this.logger.child("assistInChat").error("Error assisting in chat",{error:t,options:e}),{error:t}}}async countTokens(e,t){return GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getCountTokensFn(this.instance)(e,t)}}exports.GoogleGenerativeAIAssistanceService=GoogleGenerativeAIAssistanceService;
@@ -1 +1 @@
1
- {"version":3,"file":"GoogleGenerativeAIAssistance.service.js","sourceRoot":"","sources":["../../../../src/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.ts"],"names":[],"mappings":";;;AACA,+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IAED,KAAK,CAAC,WAAW,CACf,QAAgC,EAChC,KAAgD;QAEhD,MAAM,aAAa,GAAG,oDAAwB;aAC3C,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEnC,OAAO,aAAa,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;CACF;AAjVD,kFAiVC"}
1
+ {"version":3,"file":"GoogleGenerativeAIAssistance.service.js","sourceRoot":"","sources":["../../../../src/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.ts"],"names":[],"mappings":";;;AACA,+BAAoC;AACpC,yCAKuB;AACvB,+DAgB+B;AAC/B,yCAAkD;AAClD,4GAAqG;AACrG,wGAAoG;AACpG,8GAAuG;AAEvG,MAAa,mCACX,SAAQ,+BAAqD;IAC7D,SAAS,GAAuB,IAAI,CAAC;IAE7B,aAAa,GAA+B,IAAI,GAAG,EAAE,CAAC;IAEtD,YAAY,GAAsB,IAAI,GAAG,EAAE,CAAC;IAE5C,aAAa,GAAiC,IAAI,GAAG,EAAE,CAAC;IAExD,oBAAoB,GAAmC,IAAI,GAAG,EAAE,CAAC;IAEzE,YACE,MAAc,EACd,OAA4D;QAE5D,KAAK,CAAC,kCAAY,CAAC,kBAAkB,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,IAAc,QAAQ;QACpB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,SAAS,GAAG,IAAI,mBAAW,CAAC;gBAC/B,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;aAC5B,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,WAAiC;QAChD,IAAI,CAAC;YACH,MAAM,EACJ,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,WAAW,GACZ,GAAG,WAAW,CAAC;YAEhB,MAAM,YAAY,GAAG,IAAI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,IAAI,EAAE,YAAY,CAAC,IAAI,IAAI,EAAE;aAC9B,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM;iBACR,KAAK,CAAC,cAAc,CAAC;iBACrB,KAAK,CAAC,yBAAyB,EAAE;gBAChC,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;YAEL,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,WAAW,CACf,QAAgC,EAChC,KAAgD;QAEhD,MAAM,aAAa,GAAG,oDAAwB;aAC3C,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEnC,OAAO,aAAa,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;CACF;AA1YD,kFA0YC"}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GoogleGenerativeAICompletionService=void 0;const genai_1=require("@google/genai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services"),GoogleGenerativeAI_entity_1=require("../../../providers/GoogleGenerativeAI/GoogleGenerativeAI.entity");class GoogleGenerativeAICompletionService extends services_1.LLMCompletionService{#e=null;constructor(e,t){super(LLMService_typedefs_1.LLMProviders.GoogleGenerativeAI,e,t)}get instance(){return this.#e||(this.#e=new genai_1.GoogleGenAI({apiKey:this.options.apiKey})),this.#e}async sendMessage(e){try{const{model:t,message:i,history:n=[],instructions:o}=e,r=GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getCountTokensFn(this.instance),s=await GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.combineMessagesWithLimit({history:n,message:i,model:t,countTokensFn:r,instance:this.instance});return{text:(await this.instance.models.generateContent(GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getContentParameters({model:t,messages:s,instructions:o}))).text??""}}catch(t){return this.logger.child("sendMessage").error("Error sending message",{error:t,options:e}),{error:t}}}}exports.GoogleGenerativeAICompletionService=GoogleGenerativeAICompletionService;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GoogleGenerativeAICompletionService=void 0;const genai_1=require("@google/genai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services"),GoogleGenerativeAI_entity_1=require("../../../providers/GoogleGenerativeAI/GoogleGenerativeAI.entity");class GoogleGenerativeAICompletionService extends services_1.LLMCompletionService{#e=null;constructor(e,t){super(LLMService_typedefs_1.LLMProviders.GoogleGenerativeAI,e,t)}get instance(){return this.#e||(this.#e=new genai_1.GoogleGenAI({apiKey:this.options.apiKey})),this.#e}async sendMessage(e){try{const{model:t,message:i,history:n=[],instructions:o,abortSignal:r}=e,s=GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getCountTokensFn(this.instance),a=await GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.combineMessagesWithLimit({history:n,message:i,model:t,countTokensFn:s,instance:this.instance,logger:this.logger}),g=await this.instance.models.generateContent(GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getContentParameters({model:t,messages:a,instructions:o,abortSignal:r}));if(r?.aborted)throw new Error("Message sending aborted");return{text:g.text??""}}catch(t){return this.logger.child("sendMessage").error("Error sending message",{error:t,options:e}),{error:t}}}}exports.GoogleGenerativeAICompletionService=GoogleGenerativeAICompletionService;
@@ -1 +1 @@
1
- {"version":3,"file":"GoogleGenerativeAICompletion.service.js","sourceRoot":"","sources":["../../../../src/providers/GoogleGenerativeAI/services/GoogleGenerativeAICompletion.service.ts"],"names":[],"mappings":";;;AACA,yCAA4C;AAC5C,+DAK+B;AAC/B,yCAEoB;AACpB,wGAAoG;AAEpG,MAAa,mCACX,SAAQ,+BAAqD;IAC7D,SAAS,GAAuB,IAAI,CAAC;IAErC,YACE,MAAc,EACd,OAA4D;QAE5D,KAAK,CAAC,kCAAY,CAAC,kBAAkB,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,IA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zB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;YAC7C,CAAC;YAED,OAAO;gBACL,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE;aACxB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM;iBACR,KAAK,CAAC,aAAa,CAAC;iBACpB,KAAK,CAAC,uBAAuB,EAAE;gBAC9B,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;YAEL,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AAxED,kFAwEC"}
@@ -1 +1 @@
1
- "use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GoogleGenerativeAISpeechToTextService=void 0;const fs_1=require("fs"),genai_1=require("@google/genai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services"),GoogleGenerativeAI_entity_1=require("../../../providers/GoogleGenerativeAI/GoogleGenerativeAI.entity"),mime_types_1=__importDefault(require("mime-types"));class GoogleGenerativeAISpeechToTextService extends services_1.LLMSpeechToTextService{#e=null;constructor(e,t){super(LLMService_typedefs_1.LLMProviders.GoogleGenerativeAI,e,t)}get instance(){return this.#e||(this.#e=new genai_1.GoogleGenAI({apiKey:this.options.apiKey})),this.#e}async transcribe(e){try{const{model:t,pathToAudio:i,mimeType:r}=e,{maxFileSize:o,supportedMimeTypes:n}=GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.transcribeLimits;if((0,fs_1.statSync)(i).size>o)throw new Error(`File size exceeds the limit of ${o} bytes`);const s=r??mime_types_1.default.lookup(i);if(!s||!n.includes(s))throw new Error(`Unsupported audio file type: ${s}. Supported types are: ${n.join(", ")}`);const a=await this.instance.files.upload({file:i,config:{mimeType:r}});if(!a||!a.uri||!a.mimeType)throw new Error(`Failed to upload audio file, response: ${JSON.stringify(a)}`);return{text:(await this.instance.models.generateContent({model:t.name,contents:(0,genai_1.createUserContent)([(0,genai_1.createPartFromUri)(a.uri,a.mimeType),GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.transcribeInstructions]),config:t.config})).text??""}}catch(t){return this.logger.child("transcribe").error("Error transcribing audio",{error:t,options:e}),{error:t}}}}exports.GoogleGenerativeAISpeechToTextService=GoogleGenerativeAISpeechToTextService;
1
+ "use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.GoogleGenerativeAISpeechToTextService=void 0;const fs_1=require("fs"),genai_1=require("@google/genai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services"),GoogleGenerativeAI_entity_1=require("../../../providers/GoogleGenerativeAI/GoogleGenerativeAI.entity"),mime_types_1=__importDefault(require("mime-types"));class GoogleGenerativeAISpeechToTextService extends services_1.LLMSpeechToTextService{#e=null;constructor(e,t){super(LLMService_typedefs_1.LLMProviders.GoogleGenerativeAI,e,t)}get instance(){return this.#e||(this.#e=new genai_1.GoogleGenAI({apiKey:this.options.apiKey})),this.#e}async transcribe(e){try{const{model:t,pathToAudio:i,mimeType:r,abortSignal:o}=e,{maxFileSize:n,supportedMimeTypes:s}=GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.transcribeLimits;if((0,fs_1.statSync)(i).size>n)throw new Error(`File size exceeds the limit of ${n} bytes`);const a=r??mime_types_1.default.lookup(i);if(!a||!s.includes(a))throw new Error(`Unsupported audio file type: ${a}. Supported types are: ${s.join(", ")}`);const c=await this.instance.files.upload({file:i,config:{mimeType:r,abortSignal:o}});if(!c||!c.uri||!c.mimeType)throw new Error(`Failed to upload audio file, response: ${JSON.stringify(c)}`);const l=await this.instance.models.generateContent({model:t.name,contents:(0,genai_1.createUserContent)([(0,genai_1.createPartFromUri)(c.uri,c.mimeType),GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.transcribeInstructions]),config:{...t.config,abortSignal:o}});if(o?.aborted)throw new Error("Transcription aborted");return{text:l.text??""}}catch(t){return this.logger.child("transcribe").error("Error transcribing audio",{error:t,options:e}),{error:t}}}}exports.GoogleGenerativeAISpeechToTextService=GoogleGenerativeAISpeechToTextService;
@@ -1 +1 @@
1
- {"version":3,"file":"GoogleGenerativeAISpeechToText.service.js","sourceRoot":"","sources":["../../../../src/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA8B;AAE9B,yCAIuB;AACvB,+DAK+B;AAC/B,yCAEoB;AACpB,wGAAoG;AACpG,4DAA8B;AAE9B,MAAa,qCACX,SAAQ,iCAAuD;IAC/D,SAAS,GAAuB,IAAI,CAAC;IAErC,YACE,MAAc,EACd,OAA4D;QAE5D,KAAK,CAAC,kCAAY,CAAC,kBAAkB,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,IAAc,QAAQ;QACpB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,SAAS,GAAG,IAAI,mBAAW,CAAC;gBAC/B,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;aAC5B,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,UAAU,CACd,OAAmD;QAEnD,IAAI,CAAC;YACH,MAAM,EACJ,KAAK,EACL,WAAW,EACX,QAAQ,GACT,GAAG,OAAO,CAAC;YAEZ,MAAM,EACJ,WAAW,EACX,kBAAkB,GACnB,GAAG,oDAAwB,CAAC,gBAAgB,CAAC;YAE9C,MAAM,QAAQ,GAAG,IAAA,aAAQ,EAAC,WAAW,CAAC,CAAC,IAAI,CAAC;YAE5C,IAAI,QAAQ,GAAG,WAAW,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CACb,kCAAkC,WAAW,QAAQ,CACtD,CAAC;YACJ,CAAC;YAED,MAAM,gBAAgB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,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AAtFD,sFAsFC"}
1
+ {"version":3,"file":"GoogleGenerativeAISpeechToText.service.js","sourceRoot":"","sources":["../../../../src/providers/GoogleGenerativeAI/services/GoogleGenerativeAISpeechToText.service.ts"],"names":[],"mappings":";;;;;;AAAA,2BAA8B;AAE9B,yCAIuB;AACvB,+DAK+B;AAC/B,yCAEoB;AACpB,wGAAoG;AACpG,4DAA8B;AAE9B,MAAa,qCACX,SAAQ,iCAAuD;IAC/D,SAAS,GAAuB,IAAI,CAAC;IAErC,YACE,MAAc,EACd,OAA4D;QAE5D,KAAK,CAAC,kCAAY,CAAC,kBAAkB,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,IAAc,QAAQ;QACpB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,SAAS,GAAG,IAAI,mBAAW,CAAC;gBAC/B,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;aAC5B,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,UAAU,CACd,OAAmD;QAEnD,IAAI,CAAC;YACH,MAAM,EACJ,KAAK,EACL,WAAW,EACX,QAAQ,EACR,WAAW,GACZ,GAAG,OAAO,CAAC;YAEZ,MAAM,EACJ,WAAW,EACX,kBAAkB,GACnB,GAAG,oDAAwB,CAAC,gBAAgB,CAAC;YAE9C,MAAM,QAAQ,GAAG,IAAA,aAAQ,EAAC,WAAW,CAAC,CAAC,IAAI,CAAC;YAE5C,IAAI,QAAQ,GAAG,WAAW,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CACb,kCAAkC,WAAW,QAAQ,CACtD,CAAC;YACJ,CAAC;YAED,MAAM,gBAAgB,GAAG,QAAQ,IAAI,oBAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YAE9D,IAA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,KAAK,CAAC,0BAA0B,EAAE;gBACjC,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;YAEL,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AA/FD,sFA+FC"}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GoogleGenerativeAITextToSpeechService=void 0;const genai_1=require("@google/genai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services");class GoogleGenerativeAITextToSpeechService extends services_1.LLMTextToSpeechService{#e=null;constructor(e,t){super(LLMService_typedefs_1.LLMProviders.GoogleGenerativeAI,e,t)}get instance(){return this.#e||(this.#e=new genai_1.GoogleGenAI(this.options)),this.#e}async createSpeech(e){try{const{text:t,model:r,instructions:i,speechOptions:o}=e,s=await this.instance.models.generateContent({model:r.name,contents:t,config:{...r.config,systemInstruction:i,responseModalities:["AUDIO"],speechConfig:o?.speechConfig}}),n=s.candidates?.[0]?.content?.parts?.[0]?.inlineData?.data;if(!n)throw new Error("No audio data received from the model");return{audio:Buffer.from(n,"base64").buffer,mimeType:LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_WAV}}catch(t){return this.logger.child("createSpeech").error("Error creating speech",{error:t,options:e}),{error:t}}}}exports.GoogleGenerativeAITextToSpeechService=GoogleGenerativeAITextToSpeechService;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GoogleGenerativeAITextToSpeechService=void 0;const genai_1=require("@google/genai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services");class GoogleGenerativeAITextToSpeechService extends services_1.LLMTextToSpeechService{#e=null;constructor(e,r){super(LLMService_typedefs_1.LLMProviders.GoogleGenerativeAI,e,r)}get instance(){return this.#e||(this.#e=new genai_1.GoogleGenAI(this.options)),this.#e}async createSpeech(e){try{const{text:r,model:t,instructions:o,speechOptions:i,abortSignal:n}=e,s=await this.instance.models.generateContent({model:t.name,contents:r,config:{...t.config,systemInstruction:o,responseModalities:["AUDIO"],speechConfig:i?.speechConfig,abortSignal:n}}),c=s.candidates?.[0]?.content?.parts?.[0]?.inlineData?.data;if(!c)throw new Error("No audio data received from the model");const a=Buffer.from(c,"base64").buffer;if(n?.aborted)throw new Error("Speech creation aborted");return{audio:a,mimeType:LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_WAV}}catch(r){return this.logger.child("createSpeech").error("Error creating speech",{error:r,options:e}),{error:r}}}}exports.GoogleGenerativeAITextToSpeechService=GoogleGenerativeAITextToSpeechService;
@@ -1 +1 @@
1
- {"version":3,"file":"GoogleGenerativeAITextToSpeech.service.js","sourceRoot":"","sources":["../../../../src/providers/GoogleGenerativeAI/services/GoogleGenerativeAITextToSpeech.service.ts"],"names":[],"mappings":";;;AACA,yCAA4C;AAC5C,+DAM+B;AAC/B,yCAAoD;AAEpD,MAAa,qCACX,SAAQ,iCAAuD;IAC/D,SAAS,GAAuB,IAAI,CAAC;IAErC,YACE,MAAc,EACd,OAA4D;QAE5D,KAAK,CAAC,kCAAY,CAAC,kBAAkB,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,IAAc,QAAQ;QACpB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,SAAS,GAAG,IAAI,mBAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,YAAY,CAChB,OAAqD;QAErD,IAAI,CAAC;YACH,MAAM,EACJ,IAAI,EACJ,KAAK,EACL,YAAY,EACZ,aAAa,GACd,GAAG,OAAO,CAAC;YAEZ,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,eAAe,CAAC;gBAC/D,KAAK,EAAE,KAAK,CAAC,IAAI;gBACjB,QAAQ,EAAE,IAAI;gBACd,MAAM,EAAE;oBACN,GAAG,KAAK,CAAC,MAAM;oBACf,iBAAiB,EAAE,YAAY;oBAC/B,kBAAkB,EAAE,CAAC,OAAO,CAAC;oBAC7B,YAAY,EAAE,aAAa,EAAE,YAAY;iBAC1C;aACF,CAAC,CAAC;YAEH,MAAM,IAAI,GAAG,aAAa,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC;YAElF,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;YAC3D,CAAC;YAED,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC;YAEvD,OAAO;gBACL,KAAK,EAAE,WAAW;gBAClB,QAAQ,EAAE,4CAAsB,CAAC,SAAS;aAC3C,CAAC;QAEJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM;iBACR,KAAK,CAAC,cAAc,CAAC;iBACrB,KAAK,CAAC,uBAAuB,EAAE;gBAC9B,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;YAEL,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AAjED,sFAiEC"}
1
+ {"version":3,"file":"GoogleGenerativeAITextToSpeech.service.js","sourceRoot":"","sources":["../../../../src/providers/GoogleGenerativeAI/services/GoogleGenerativeAITextToSpeech.service.ts"],"names":[],"mappings":";;;AACA,yCAA4C;AAC5C,+DAM+B;AAC/B,yCAAoD;AAEpD,MAAa,qCACX,SAAQ,iCAAuD;IAC/D,SAAS,GAAuB,IAAI,CAAC;IAErC,YACE,MAAc,EACd,OAA4D;QAE5D,KAAK,CAAC,kCAAY,CAAC,kBAAkB,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,IAAc,QAAQ;QACpB,IAAI,CAAC,IAA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AI,CAAC,MAAM;iBACR,KAAK,CAAC,cAAc,CAAC;iBACrB,KAAK,CAAC,uBAAuB,EAAE;gBAC9B,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;YAEL,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AAvED,sFAuEC"}
@@ -1,8 +1,14 @@
1
- import { type CombineMessagesOptions, type LLMCompletionMessage, type LLMCountTokensFunction, type LLMMessageContent, type LLMProviders, type LLMFileLimits } from '../../LLMService.typedefs';
2
- import { type ChatCompletionMessageParam } from 'openai/resources/chat';
1
+ import { type Logger } from '@mate-academy/core';
2
+ import { type CombineMessagesOptions, type LLMCompletionMessage, type LLMCountTokensFunction, type LLMCompletionsMessageContent, type LLMProviders, type LLMFileLimits, type LLMAssistanceMessageContent, type LLMAssistanceMessage } from '../../LLMService.typedefs';
3
+ import { type MessageContentPartParam } from 'openai/resources/beta/threads/messages';
4
+ import { type ThreadCreateParams } from 'openai/resources/beta/threads/threads';
5
+ import { type ChatCompletionAssistantMessageParam, type ChatCompletionUserMessageParam, type ChatCompletionContentPart } from 'openai/resources/chat';
3
6
  export declare class OpenAIEntity {
4
- static getCountTokensFn(): (messagesContents: LLMMessageContent[]) => Promise<number>;
5
- static getChatCompletionMessageParam(messages: LLMCompletionMessage[]): ChatCompletionMessageParam[];
6
- static combineMessagesWithLimit({ modelContext, history, message, model, countTokensFn, }: CombineMessagesOptions<LLMProviders.OpenAI, LLMCountTokensFunction<LLMProviders.OpenAI, LLMMessageContent[]>>): Promise<LLMCompletionMessage[]>;
7
+ static getCountTokensFn(): (messagesContents: (LLMCompletionsMessageContent | LLMAssistanceMessageContent)[]) => Promise<number>;
8
+ static getChatCompletionMessageParam(messages: LLMCompletionMessage[], logger: Logger): (ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam)[];
9
+ static getCompletionUserContentParameters(content: LLMCompletionsMessageContent[], logger: Logger): ChatCompletionContentPart[];
10
+ static getThreadAssistanceMessageParam(messages: LLMAssistanceMessage[]): ThreadCreateParams.Message[];
11
+ static getAssistanceContentParameters(content: LLMAssistanceMessageContent[]): MessageContentPartParam[];
12
+ static combineMessagesWithLimit({ modelContext, history, message, model, countTokensFn, }: CombineMessagesOptions<LLMProviders.OpenAI, LLMCountTokensFunction<LLMProviders.OpenAI, LLMCompletionsMessageContent[]>>): Promise<LLMCompletionMessage[]>;
7
13
  static get transcribeLimits(): LLMFileLimits;
8
14
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OpenAIEntity=void 0;const LLMService_constants_1=require("../../LLMService.constants"),LLMService_typedefs_1=require("../../LLMService.typedefs"),OpenAI_typedefs_1=require("../../providers/OpenAI/OpenAI.typedefs"),js_tiktoken_1=require("js-tiktoken");class OpenAIEntity{static getCountTokensFn(){return e=>{const t=(0,js_tiktoken_1.getEncoding)("o200k_base"),s=e.reduce((e,s)=>{switch(s.type){case LLMService_typedefs_1.LLMMessageContentType.IMAGE_URL:case LLMService_typedefs_1.LLMMessageContentType.IMAGE_FILE:return e+LLMService_constants_1.APPROXIMATE_TOKENS_COUNT_IN_IMAGE;case LLMService_typedefs_1.LLMMessageContentType.TEXT:return e+t.encode(s.text).length;default:return e}},0);return Promise.resolve(s)}}static getChatCompletionMessageParam(e){return e.map(e=>({role:e.role===LLMService_typedefs_1.LLMRoles.User?OpenAI_typedefs_1.OpenAIRoles.User:OpenAI_typedefs_1.OpenAIRoles.Assistant,content:e.content}))}static async combineMessagesWithLimit({modelContext:e=[],history:t=[],message:s,model:n,countTokensFn:i}){const r=[...e];if(t[0]){const e=t[0];r.push(e)}const o=[{role:LLMService_typedefs_1.LLMRoles.User,content:s.content},...t.slice(1).reverse()],p=r.flatMap(e=>e.content);let L=await(i?.(p,n))??0;for(const e of o){const t=L+(await(i?.(e.content,n))??0);if(!(t<=n.limits.maxInputTokens))break;r.push(e),L=t}return r}static get transcribeLimits(){return{maxFileSize:26214400,supportedMimeTypes:[LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_WAV,LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_MP3,LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_MPEG,LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_WEBM]}}}exports.OpenAIEntity=OpenAIEntity;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OpenAIEntity=void 0;const LLMService_constants_1=require("../../LLMService.constants"),LLMService_typedefs_1=require("../../LLMService.typedefs"),OpenAI_typedefs_1=require("../../providers/OpenAI/OpenAI.typedefs"),js_tiktoken_1=require("js-tiktoken");class OpenAIEntity{static getCountTokensFn(){return e=>{const t=(0,js_tiktoken_1.getEncoding)("o200k_base"),s=e.reduce((e,s)=>{switch(s.type){case LLMService_typedefs_1.LLMMessageContentType.IMAGE_URL:case LLMService_typedefs_1.LLMMessageContentType.IMAGE_FILE:return e+LLMService_constants_1.APPROXIMATE_TOKENS_COUNT_IN_IMAGE;case LLMService_typedefs_1.LLMMessageContentType.TEXT:return e+t.encode(s.text).length;default:return e}},0);return Promise.resolve(s)}}static getChatCompletionMessageParam(e,t){return e.map(e=>({role:e.role===LLMService_typedefs_1.LLMRoles.User?OpenAI_typedefs_1.OpenAIRoles.User:OpenAI_typedefs_1.OpenAIRoles.Assistant,content:OpenAIEntity.getCompletionUserContentParameters(e.content,t)}))}static getCompletionUserContentParameters(e,t){const s=[];for(const n of e)switch(n.type){case LLMService_typedefs_1.LLMMessageContentType.IMAGE_URL:{const e={type:"image_url",image_url:{url:n.image_url.url,detail:n.image_url.detail??"auto"}};s.push(e);break}case LLMService_typedefs_1.LLMMessageContentType.TEXT:{const e={type:"text",text:n.text};s.push(e);break}default:t.child("OpenAIEntity.getCompletionUserContentParameters").warn("Unsupported content type in message item",{contentItem:n})}return s}static getThreadAssistanceMessageParam(e){return e.map(e=>({role:e.role===LLMService_typedefs_1.LLMRoles.User?OpenAI_typedefs_1.OpenAIRoles.User:OpenAI_typedefs_1.OpenAIRoles.Assistant,content:OpenAIEntity.getAssistanceContentParameters(e.content)}))}static getAssistanceContentParameters(e){return e.map(e=>{if(e.type===LLMService_typedefs_1.LLMMessageContentType.IMAGE_URL){return{type:"image_url",image_url:{url:e.image_url.url,detail:e.image_url.detail??"auto"}}}if(e.type===LLMService_typedefs_1.LLMMessageContentType.IMAGE_FILE){return{type:"image_file",image_file:{file_id:e.image_file.file_id,detail:e.image_file.detail??"auto"}}}return{type:"text",text:e.text}})}static async combineMessagesWithLimit({modelContext:e=[],history:t=[],message:s,model:n,countTokensFn:r}){const i=[...e];if(t[0]){const e=t[0];i.push(e)}const a=[{role:LLMService_typedefs_1.LLMRoles.User,content:s.content},...t.slice(1).reverse()],o=i.flatMap(e=>e.content);let p=await(r?.(o,n))??0;for(const e of a){const t=p+(await(r?.(e.content,n))??0);if(!(t<=n.limits.maxInputTokens))break;i.push(e),p=t}return i}static get transcribeLimits(){return{maxFileSize:26214400,supportedMimeTypes:[LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_WAV,LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_MP3,LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_MPEG,LLMService_typedefs_1.LLMUploadFileMimeTypes.AUDIO_WEBM]}}}exports.OpenAIEntity=OpenAIEntity;
@@ -1 +1 @@
1
- {"version":3,"file":"OpenAI.entity.js","sourceRoot":"","sources":["../../../src/providers/OpenAI/OpenAI.entity.ts"],"names":[],"mappings":";;;AAAA,iEAA2E;AAC3E,+DAU+B;AAC/B,wEAAiE;AACjE,6CAA0C;AAG1C,MAAa,YAAY;IACvB,MAAM,CAAC,gBAAgB;QACrB,OAAO,CACL,gBAAqC,EACpB,EAAE;YACnB,MAAM,OAAO,GAAG,IAAA,yBAAW,EAAC,YAAY,CAAC,CAAC;YAC1C,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,CACpC,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE;gBAChB,QAAQ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ACnB,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB;YACD,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE;SAC9B,CAAC;QAEF,MAAM,QAAQ,GAAG,gBAAgB,CAAC,OAAO,CACvC,CAAC,eAAe,EAAE,EAAE,CAAC,eAAe,CAAC,OAAO,CAC7C,CAAC;QAEF,IAAI,UAAU,GAAG,MAAM,aAAa,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAE7D,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;YACrC,MAAM,cAAc,GAAG,UAAU,GAAG,CAClC,MAAM,aAAa,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,CAC/C,CAAC;YAEF,IAAI,cAAc,IAAI,KAAK,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;gBAClD,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAC3B,UAAU,GAAG,cAAc,CAAC;YAC9B,CAAC;iBAAM,CAAC;gBACN,MAAM;YACR,CAAC;QACH,CAAC;QAED,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED,MAAM,KAAK,gBAAgB;QACzB,OAAO;YACL,WAAW,EAAE,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,QAAQ;YACvC,kBAAkB,EAAE;gBAClB,4CAAsB,CAAC,SAAS;gBAChC,4CAAsB,CAAC,SAAS;gBAChC,4CAAsB,CAAC,UAAU;gBACjC,4CAAsB,CAAC,UAAU;aAClC;SACF,CAAC;IACJ,CAAC;CACF;AAnND,oCAmNC"}
@@ -1,13 +1,13 @@
1
1
  import { type Logger } from '@mate-academy/core';
2
2
  import { OpenAI } from 'openai';
3
- import { type LLMAssistanceOptions, type LLMAssistanceResult, type LLMCompletionMessage, type LLMCreateAssistantOptions, type LLMCreateAssistantResult, type LLMCreateChatOptions, type LLMCreateChatResult, type LLMCreateFileStorageOptions, type LLMCreateFileStorageResult, type LLMInstanceOptions, LLMProviders, type LLMUploadFile, type LLMUploadFileResult } from '../../../LLMService.typedefs';
3
+ import { type LLMAssistanceOptions, type LLMAssistanceResult, type LLMCompletionMessage, type LLMCreateAssistantOptions, type LLMCreateAssistantResult, type LLMCreateChatOptions, type LLMCreateChatResult, type LLMCreateFileStorageOptions, type LLMCreateFileStorageResult, type LLMInstanceOptions, LLMProviders, type LLMUploadFileOptions, type LLMUploadFileResult } from '../../../LLMService.typedefs';
4
4
  import { LLMAssistanceService } from '../../../services';
5
5
  export declare class OpenAIAssistanceService extends LLMAssistanceService<LLMProviders.OpenAI> {
6
6
  #private;
7
7
  private uploadedFiles;
8
8
  constructor(logger: Logger, options: LLMInstanceOptions[LLMProviders.OpenAI]);
9
9
  protected get instance(): OpenAI;
10
- uploadFile(file: LLMUploadFile): Promise<LLMUploadFileResult>;
10
+ uploadFile(fileOptions: LLMUploadFileOptions): Promise<LLMUploadFileResult>;
11
11
  deleteFile(fileId: string): Promise<void>;
12
12
  createFileStorage(options: LLMCreateFileStorageOptions<LLMProviders.OpenAI>): Promise<LLMCreateFileStorageResult>;
13
13
  deleteFileStorage(fileStorageId: string): Promise<void>;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OpenAIAssistanceService=void 0;const fs_1=require("fs"),openai_1=require("openai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services"),OpenAI_typedefs_1=require("../../../providers/OpenAI/OpenAI.typedefs"),OpenAI_entity_1=require("../../../providers/OpenAI/OpenAI.entity");class OpenAIAssistanceService extends services_1.LLMAssistanceService{#e=null;uploadedFiles=new Map;constructor(e,t){super(LLMService_typedefs_1.LLMProviders.OpenAI,e,t)}get instance(){return this.#e||(this.#e=new openai_1.OpenAI(this.options)),this.#e}async uploadFile(e){try{const{path:t}=e,s=this.uploadedFiles.get(t);if(s){if((await this.instance.files.retrieve(s)).id)return{...e,fileId:s}}const i=(0,fs_1.createReadStream)(t),r=await this.instance.files.create({purpose:"assistants",file:i});return await this.instance.files.waitForProcessing(r.id),this.uploadedFiles.set(t,r.id),{...e,fileId:r.id}}catch(t){return this.logger.child("uploadFile").error("Error uploading file",{error:t,file:e}),{error:t}}}async deleteFile(e){await this.instance.files.delete(e),this.uploadedFiles.delete(e)}async createFileStorage(e){const{uploadedFiles:t}=e;try{const e=await this.instance.vectorStores.create({expires_after:{anchor:"last_active_at",days:1}});return await this.instance.vectorStores.fileBatches.createAndPoll(e.id,{file_ids:t.map(({fileId:e})=>e)}),{storageId:e.id}}catch(e){return this.logger.child("createFileStorage").error("Error creating file storage",{error:e,uploadedFiles:t}),{error:e}}}async deleteFileStorage(e){await this.instance.vectorStores.delete(e)}async createChat(e){try{const{storageId:t,history:s,files:i}=e,r=t?{tool_resources:{file_search:{vector_store_ids:[t]}}}:{},a=s?.map(e=>({...e,content:e.content,role:e.role===LLMService_typedefs_1.LLMRoles.User?OpenAI_typedefs_1.OpenAIRoles.User:OpenAI_typedefs_1.OpenAIRoles.Assistant}))??[];if(i&&i.length>0){const e=i.filter(this.isImageFile);e.length>0&&a.push({role:OpenAI_typedefs_1.OpenAIRoles.User,content:e.map(e=>({type:LLMService_typedefs_1.LLMMessageContentType.IMAGE_FILE,image_file:{file_id:e.fileId,detail:"high"}}))})}return{chatId:(await this.instance.beta.threads.create({messages:a,...r})).id}}catch(t){return this.logger.child("createChat").error("Error creating chat",{error:t,options:e}),{error:t}}}async deleteChat(e){await this.instance.beta.threads.delete(e)}async createAssistant(e){try{const{model:t,instructions:s,storageIds:i,name:r}=e,a=i?.length?{tools:[{type:"file_search"}],tool_resources:{file_search:{vector_store_ids:i}}}:{};return{assistantId:(await this.instance.beta.assistants.create({model:t.name,instructions:s,temperature:t.config.temperature,top_p:t.config.top_p,name:r,...a})).id}}catch(t){return this.logger.child("createAssistant").error("Error creating assistant",{error:t,options:e}),{error:t}}}async deleteAssistant(e){await this.instance.beta.assistants.delete(e)}async assistInChat(e){try{const{message:t,chatId:s,assistantId:i,storageId:r}=e,{attachments:a,content:n,role:o}=t,c=[];a&&a.filter(this.isImageFile).forEach(e=>{c.push({type:"image_file",image_file:{file_id:e.fileId,detail:"high"}})}),c.push(...n);const l={role:o===LLMService_typedefs_1.LLMRoles.User?OpenAI_typedefs_1.OpenAIRoles.User:OpenAI_typedefs_1.OpenAIRoles.Assistant,content:c,attachments:a?a.filter(this.isNotImageFile).map(({fileId:e})=>({file_id:e,tools:[{type:"file_search"}]})):void 0},d=a&&a.some(this.isNotImageFile);await this.instance.beta.threads.messages.create(s,l);const p=await this.instance.beta.threads.runs.createAndPoll(s,{assistant_id:i,...d&&r?{tool_choice:{type:"file_search"}}:{tool_choice:"auto"}}),{status:h}=p;if("completed"!==h)throw new Error(`Thread run did not complete for message, status: ${h}`);const _=(await this.instance.beta.threads.messages.list(s,{run_id:p.id})).data.find(e=>e.role===OpenAI_typedefs_1.OpenAIRoles.Assistant),f=_?.content.find(e=>"text"===e.type&&"text"in e);return{text:f?.text?.value??""}}catch(t){return this.logger.child("assistInChat").error("Error assisting in chat",{error:t,options:e}),{error:t}}}async countTokens(e){return OpenAI_entity_1.OpenAIEntity.getCountTokensFn()(e.flatMap(e=>e.content))}}exports.OpenAIAssistanceService=OpenAIAssistanceService;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OpenAIAssistanceService=void 0;const fs_1=require("fs"),openai_1=require("openai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services"),OpenAI_typedefs_1=require("../../../providers/OpenAI/OpenAI.typedefs"),OpenAI_entity_1=require("../../../providers/OpenAI/OpenAI.entity");class OpenAIAssistanceService extends services_1.LLMAssistanceService{#e=null;uploadedFiles=new Map;constructor(e,t){super(LLMService_typedefs_1.LLMProviders.OpenAI,e,t)}get instance(){return this.#e||(this.#e=new openai_1.OpenAI(this.options)),this.#e}async uploadFile(e){try{const{path:t,abortSignal:s}=e,r=this.uploadedFiles.get(t);if(r){if((await this.instance.files.retrieve(r)).id)return{name:e.name,path:e.path,mimeType:e.mimeType,fileId:r}}const i=(0,fs_1.createReadStream)(t,{signal:s}),a=await this.instance.files.create({purpose:"assistants",file:i},{signal:s});if(await this.instance.files.waitForProcessing(a.id),s?.aborted)throw new Error("File upload aborted");return this.uploadedFiles.set(t,a.id),{...e,fileId:a.id}}catch(t){return this.logger.child("uploadFile").error("Error uploading file",{error:t,file:e}),{error:t}}}async deleteFile(e){await this.instance.files.delete(e),this.uploadedFiles.delete(e)}async createFileStorage(e){const{uploadedFiles:t,abortSignal:s}=e;try{const e=await this.instance.vectorStores.create({expires_after:{anchor:"last_active_at",days:1}},{signal:s});if(await this.instance.vectorStores.fileBatches.createAndPoll(e.id,{file_ids:t.map(({fileId:e})=>e)}),s?.aborted)throw new Error("File storage creation aborted");return{storageId:e.id}}catch(e){return this.logger.child("createFileStorage").error("Error creating file storage",{error:e,uploadedFiles:t}),{error:e}}}async deleteFileStorage(e){await this.instance.vectorStores.delete(e)}async createChat(e){try{const{storageId:t,history:s=[],files:r,abortSignal:i}=e,a=t?{tool_resources:{file_search:{vector_store_ids:[t]}}}:{},n=OpenAI_entity_1.OpenAIEntity.getThreadAssistanceMessageParam(s);if(r&&r.length>0){const e=r.filter(this.isImageFile);e.length>0&&n.push({role:OpenAI_typedefs_1.OpenAIRoles.User,content:e.map(e=>({type:LLMService_typedefs_1.LLMMessageContentType.IMAGE_FILE,image_file:{file_id:e.fileId,detail:"high"}}))})}const o=await this.instance.beta.threads.create({messages:n,...a},{signal:i});if(i?.aborted)throw new Error("Chat creation aborted");return{chatId:o.id}}catch(t){return this.logger.child("createChat").error("Error creating chat",{error:t,options:e}),{error:t}}}async deleteChat(e){await this.instance.beta.threads.delete(e)}async createAssistant(e){try{const{model:t,instructions:s,storageIds:r,name:i,abortSignal:a}=e,n=r?.length?{tools:[{type:"file_search"}],tool_resources:{file_search:{vector_store_ids:r}}}:{},o=await this.instance.beta.assistants.create({model:t.name,instructions:s,temperature:t.config.temperature,top_p:t.config.top_p,name:i,...n},{signal:a});if(a?.aborted)throw new Error("Assistant creation aborted");return{assistantId:o.id}}catch(t){return this.logger.child("createAssistant").error("Error creating assistant",{error:t,options:e}),{error:t}}}async deleteAssistant(e){await this.instance.beta.assistants.delete(e)}async assistInChat(e){try{const{message:t,chatId:s,assistantId:r,storageId:i,abortSignal:a}=e,{attachments:n,content:o,role:c}=t,l=[];n&&n.filter(this.isImageFile).forEach(e=>{l.push({type:"image_file",image_file:{file_id:e.fileId,detail:"high"}})}),l.push(...o);const d={role:c===LLMService_typedefs_1.LLMRoles.User?OpenAI_typedefs_1.OpenAIRoles.User:OpenAI_typedefs_1.OpenAIRoles.Assistant,content:l,attachments:n?n.filter(this.isNotImageFile).map(({fileId:e})=>({file_id:e,tools:[{type:"file_search"}]})):void 0},p=n&&n.some(this.isNotImageFile);await this.instance.beta.threads.messages.create(s,d,{signal:a});const h=await this.instance.beta.threads.runs.createAndPoll(s,{assistant_id:r,...p&&i?{tool_choice:{type:"file_search"}}:{tool_choice:"auto"}},{signal:a}),{status:f}=h;if("completed"!==f)throw new Error(`Thread run did not complete for message, status: ${f}`);const g=(await this.instance.beta.threads.messages.list(s,{run_id:h.id},{signal:a})).data.find(e=>e.role===OpenAI_typedefs_1.OpenAIRoles.Assistant),_=g?.content.find(e=>"text"===e.type&&"text"in e);if(a?.aborted)throw new Error("Assistant response retrieval aborted");return{text:_?.text?.value??""}}catch(t){return this.logger.child("assistInChat").error("Error assisting in chat",{error:t,options:e}),{error:t}}}async countTokens(e){return OpenAI_entity_1.OpenAIEntity.getCountTokensFn()(e.flatMap(e=>e.content))}}exports.OpenAIAssistanceService=OpenAIAssistanceService;
@@ -1 +1 @@
1
- {"version":3,"file":"OpenAIAssistance.service.js","sourceRoot":"","sources":["../../../../src/providers/OpenAI/services/OpenAIAssistance.service.ts"],"names":[],"mappings":";;;AAAA,2BAAsC;AAEtC,mCAAgC;AAChC,+DAgB+B;A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AED,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CACtE,MAAM,EACN;gBACE,MAAM,EAAE,SAAS,CAAC,EAAE;aACrB,CACF,CAAC;YAEF,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CACnD,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,6BAAW,CAAC,SAAS,CACpD,CAAC;YAEF,MAAM,WAAW,GAAG,iBAAiB,EAAE,OAAO;iBAC3C,IAAI,CACH,CAAC,OAAO,EAAmD,EAAE,CAAC,CAC5D,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,MAAM,IAAI,OAAO,CAC7C,CACF,CAAC;YAEJ,OAAO;gBACL,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE;aACrC,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM;iBACR,KAAK,CAAC,cAAc,CAAC;iBACrB,KAAK,CAAC,yBAAyB,EAAE;gBAChC,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;YAEL,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,WAAW,CACf,QAAgC;QAEhC,MAAM,aAAa,GAAG,4BAAY;aAC/B,gBAAgB,EAAE,CAAC;QAEtB,MAAM,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CACvC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAC7B,CAAC;QAEF,OAAO,aAAa,CAAC,gBAAgB,CAAC,CAAC;IACzC,CAAC;CACF;AAzXD,0DAyXC"}
1
+ {"version":3,"file":"OpenAIAssistance.service.js","sourceRoot":"","sources":["../../../../src/providers/OpenAI/services/OpenAIAssistance.service.ts"],"names":[],"mappings":";;;AAAA,2BAAsC;AAEtC,mCAAgC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AAsC,CAAC,CAAC;YAC1D,CAAC;YAED,OAAO;gBACL,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE;aACrC,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM;iBACR,KAAK,CAAC,cAAc,CAAC;iBACrB,KAAK,CAAC,yBAAyB,EAAE;gBAChC,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;YAEL,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,WAAW,CACf,QAAgC;QAEhC,MAAM,aAAa,GAAG,4BAAY;aAC/B,gBAAgB,EAAE,CAAC;QAEtB,MAAM,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CACvC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAC7B,CAAC;QAEF,OAAO,aAAa,CAAC,gBAAgB,CAAC,CAAC;IACzC,CAAC;CACF;AA3ZD,0DA2ZC"}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OpenAICompletionService=void 0;const openai_1=require("openai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services"),OpenAI_entity_1=require("../../../providers/OpenAI/OpenAI.entity");class OpenAICompletionService extends services_1.LLMCompletionService{#e=null;constructor(e,n){super(LLMService_typedefs_1.LLMProviders.OpenAI,e,n)}get instance(){return this.#e||(this.#e=new openai_1.OpenAI(this.options)),this.#e}async sendMessage(e){try{const{model:n,message:t,history:s=[]}=e,i=OpenAI_entity_1.OpenAIEntity.getCountTokensFn(),r=await OpenAI_entity_1.OpenAIEntity.combineMessagesWithLimit({history:s,message:t,model:n,countTokensFn:i,instance:this.instance}),o=OpenAI_entity_1.OpenAIEntity.getChatCompletionMessageParam(r),c=await this.instance.chat.completions.create({model:n.name,messages:o,n:1,...n.config});return{text:c.choices[0]?.message.content??""}}catch(n){return this.logger.child("sendMessage").error("Error sending message",{error:n,options:e}),{error:n}}}}exports.OpenAICompletionService=OpenAICompletionService;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OpenAICompletionService=void 0;const openai_1=require("openai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services"),OpenAI_entity_1=require("../../../providers/OpenAI/OpenAI.entity");class OpenAICompletionService extends services_1.LLMCompletionService{#e=null;constructor(e,t){super(LLMService_typedefs_1.LLMProviders.OpenAI,e,t)}get instance(){return this.#e||(this.#e=new openai_1.OpenAI(this.options)),this.#e}async sendMessage(e){try{const{model:t,message:n,history:s=[],abortSignal:i}=e,r=OpenAI_entity_1.OpenAIEntity.getCountTokensFn(),o=await OpenAI_entity_1.OpenAIEntity.combineMessagesWithLimit({history:s,message:n,model:t,countTokensFn:r,instance:this.instance,logger:this.logger}),a=OpenAI_entity_1.OpenAIEntity.getChatCompletionMessageParam(o,this.logger),c=await this.instance.chat.completions.create({model:t.name,messages:a,n:1,...t.config},{signal:i});if(i?.aborted)throw new Error("Message sending aborted");return{text:c.choices[0]?.message.content??""}}catch(t){return this.logger.child("sendMessage").error("Error sending message",{error:t,options:e}),{error:t}}}}exports.OpenAICompletionService=OpenAICompletionService;
@@ -1 +1 @@
1
- {"version":3,"file":"OpenAICompletion.service.js","sourceRoot":"","sources":["../../../../src/providers/OpenAI/services/OpenAICompletion.service.ts"],"names":[],"mappings":";;;AACA,mCAAgC;AAChC,+DAK+B;AAC/B,yCAEoB;AACpB,oEAAgE;AAEhE,MAAa,uBACX,SAAQ,+BAAyC;IACjD,SAAS,GAAkB,IAAI,CAAC;IAEhC,YACE,MAAc,EACd,OAAgD;QAEhD,KAAK,CAAC,kCAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,IAAc,QAAQ;QACpB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,SAAS,GAAG,IAAI,eAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,WAAW,CACf,OAAoD;QAEpD,IAAI,CAAC;YACH,MAAM,EACJ,KAAK,EACL,OAAO,EACP,OAAO,GAAG,EAAE,GACb,GAAG,OAAO,CAAC;YAEZ,MAAM,aAAa,GAAG,4BAAY,CAAC,gBAAgB,EAAE,CAAC;YAEtD,MAAM,gBAAgB,GAAG,MAAM,4BAAY,CAAC,wBAAwB,CAAC;gBACnE,OAAO;gBACP,OAAO;gBACP,KAAK;gBACL,aAAa;gBACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACxB,CAAC,CAAC;YAEH,MAAM,0BAA0B,GAAG,4BAAY;iBAC5C,6BAA6B,CAAC,gBAAgB,CAAC,CAAC;YAEnD,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;gBAC7D,KAAK,EAAE,KAAK,CAAC,IAAI;gBACjB,QAAQ,EAAE,0BAA0B;gBACpC,CAAC,EAAE,CAAC;gBACJ,GAAG,KAAK,CAAC,MAAM;aAChB,CAAC,CAAC;YAEH,OAAO;gBACL,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;aACnD,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM;iBACR,KAAK,CAAC,aAAa,CAAC;iBACpB,KAAK,CAAC,uBAAuB,EAAE;gBAC9B,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;YAEL,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AA/DD,0DA+DC"}
1
+ {"version":3,"file":"OpenAICompletion.service.js","sourceRoot":"","sources":["../../../../src/providers/OpenAI/services/OpenAICompletion.service.ts"],"names":[],"m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AC;YAEH,IAAI,WAAW,EAAE,OAAO,EAAE,CAAC;gBACzB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;YAC7C,CAAC;YAED,OAAO;gBACL,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;aACnD,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM;iBACR,KAAK,CAAC,aAAa,CAAC;iBACpB,KAAK,CAAC,uBAAuB,EAAE;gBAC9B,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;YAEL,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AAvED,0DAuEC"}
@@ -1 +1 @@
1
- "use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.OpenAISpeechToTextService=void 0;const fs_1=require("fs"),openai_1=require("openai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services"),OpenAI_entity_1=require("../../../providers/OpenAI/OpenAI.entity"),mime_types_1=__importDefault(require("mime-types"));class OpenAISpeechToTextService extends services_1.LLMSpeechToTextService{#e=null;constructor(e,t){super(LLMService_typedefs_1.LLMProviders.OpenAI,e,t)}get instance(){return this.#e||(this.#e=new openai_1.OpenAI(this.options)),this.#e}async transcribe(e){try{const{model:t,pathToAudio:r,mimeType:i}=e,{maxFileSize:s,supportedMimeTypes:n}=OpenAI_entity_1.OpenAIEntity.transcribeLimits;if((0,fs_1.statSync)(r).size>s)throw new Error(`File size exceeds the limit of ${s} bytes`);const o=i??mime_types_1.default.lookup(r);if(!o||!n.includes(o))throw new Error(`Unsupported audio file type: ${o}. Supported types are: ${n.join(", ")}`);const p=(0,fs_1.createReadStream)(r);return{text:await this.instance.audio.transcriptions.create({model:t.name,file:p,response_format:"text"})}}catch(t){return this.logger.child("transcribe").error("Error transcribing audio",{error:t,options:e}),{error:t}}}}exports.OpenAISpeechToTextService=OpenAISpeechToTextService;
1
+ "use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.OpenAISpeechToTextService=void 0;const fs_1=require("fs"),openai_1=require("openai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services"),OpenAI_entity_1=require("../../../providers/OpenAI/OpenAI.entity"),mime_types_1=__importDefault(require("mime-types"));class OpenAISpeechToTextService extends services_1.LLMSpeechToTextService{#e=null;constructor(e,t){super(LLMService_typedefs_1.LLMProviders.OpenAI,e,t)}get instance(){return this.#e||(this.#e=new openai_1.OpenAI(this.options)),this.#e}async transcribe(e){try{const{model:t,pathToAudio:r,mimeType:i,abortSignal:s}=e,{maxFileSize:n,supportedMimeTypes:o}=OpenAI_entity_1.OpenAIEntity.transcribeLimits;if((0,fs_1.statSync)(r).size>n)throw new Error(`File size exceeds the limit of ${n} bytes`);const p=i??mime_types_1.default.lookup(r);if(!p||!o.includes(p))throw new Error(`Unsupported audio file type: ${p}. Supported types are: ${o.join(", ")}`);const c=(0,fs_1.createReadStream)(r,{signal:s}),a=await this.instance.audio.transcriptions.create({model:t.name,file:c,response_format:"text"},{signal:s});if(s?.aborted)throw new Error("Transcription aborted");return{text:a}}catch(t){return this.logger.child("transcribe").error("Error transcribing audio",{error:t,options:e}),{error:t}}}}exports.OpenAISpeechToTextService=OpenAISpeechToTextService;
@@ -1 +1 @@
1
- {"version":3,"file":"OpenAISpeechToText.service.js","sourceRoot":"","sources":["../../../../src/providers/OpenAI/services/OpenAISpeechToText.service.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAgD;AAEhD,mCAAgC;AAChC,+DAK+B;AAC/B,yCAAoD;AACpD,oEAAgE;AAChE,4DAA8B;AAE9B,MAAa,yBACX,SAAQ,iCAA2C;IACnD,SAAS,GAAkB,IAAI,CAAC;IAEhC,YACE,MAAc,EAC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AAE,MAAM;aACxB,CAAC,CAAC;YAEH,OAAO,EAAE,IAAI,EAAE,CAAC;QAClB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM;iBACR,KAAK,CAAC,YAAY,CAAC;iBACnB,KAAK,CAAC,0BAA0B,EAAE;gBACjC,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;YAEL,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AAtED,8DAsEC"}
1
+ {"version":3,"file":"OpenAISpeechToText.service.js","sourceRoot":"","sources":["../../../../src/providers/OpenAI/services/OpenAISpeechToText.service.ts"],"names":[],"mappings":";;;;;;AAAA,2BAAgD;AAEhD,mCAAgC;AAChC,+DAK+B;AAC/B,yCAAoD;AACpD,oEAAgE;AAChE,4DAA8B;AAE9B,MAAa,yBACX,SAAQ,iCAA2C;IACnD,SAAS,GAAkB,IAAI,CAAC;IAEhC,YACE,MAAc,EACd,OAAgD;QAEhD,KAAK,CAAC,kCAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,IAAc,QAAQ;QACpB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,SAAS,GAAG,IAAI,eAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,UAAU,CACd,OAAmD;QAEnD,IAAI,CAAC;YACH,MAAM,EACJ,KAAK,EACL,WAAW,EACX,QAAQ,EACR,WAAW,GACZ,GAAG,OAAO,CAAC;YAEZ,MAAM,EACJ,WAAW,EACX,kBAAkB,GACnB,GAAG,4BAAY,CAAC,gBAAgB,CAAC;YAElC,MAAM,QAAQ,GAAG,IAAA,aAAQ,EAAC,WAAW,CAAC,CAAC,IAAI,CAAC;YAE5C,IAAI,QAAQ,GAAG,WAAW,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CACb,kCAAkC,WAAW,QAAQ,CACtD,CAAC;YACJ,CAAC;YAED,MAAM,gBAAgB,GAAG,QAAQ,IAAI,oBAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YAE9D,IAAI,CAAC,gBAAgB,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,gBAAuB,CAAC,EAAE,CAAC;gBAC/E,MAAM,IAAI,KAAK,CACb,gCAAgC,gBAAgB,0BAA0B,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC1G,CAAC;YACJ,CAAC;YAED,MAAM,SAAS,GAAG,IAAA,qBAAgB,EAAC,WAAW,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;YAEzE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC;gBAC3D,KAAK,EAAE,KAAK,CAAC,IAAI;gBACjB,IAAI,EAAE,SAAS;gBACf,eAAe,EAAE,MAAM;aACxB,EAAE;gBACD,MAAM,EAAE,WAAW;aACpB,CAAC,CAAC;YAEH,IAAI,WAAW,EAAE,OAAO,EAAE,CAAC;gBACzB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC3C,CAAC;YAED,OAAO,EAAE,IAAI,EAAE,CAAC;QAClB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM;iBACR,KAAK,CAAC,YAAY,CAAC;iBACnB,KAAK,CAAC,0BAA0B,EAAE;gBACjC,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;YAEL,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AA7ED,8DA6EC"}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OpenAITextToSpeechService=void 0;const openai_1=require("openai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services");class OpenAITextToSpeechService extends services_1.LLMTextToSpeechService{#e=null;constructor(e,r){super(LLMService_typedefs_1.LLMProviders.OpenAI,e,r)}get instance(){return this.#e||(this.#e=new openai_1.OpenAI(this.options)),this.#e}async createSpeech(e){try{const{text:r,model:t,instructions:s,speechOptions:i}=e,c=await this.instance.audio.speech.create({model:t.name,input:r,instructions:s,voice:i?.voice||"alloy",response_format:i?.response_format,speed:i?.speed});return{audio:await c.arrayBuffer(),mimeType:c.headers.get("Content-Type")}}catch(r){return this.logger.child("createSpeech").error("Error creating speech",{error:r,options:e}),{error:r}}}}exports.OpenAITextToSpeechService=OpenAITextToSpeechService;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OpenAITextToSpeechService=void 0;const openai_1=require("openai"),LLMService_typedefs_1=require("../../../LLMService.typedefs"),services_1=require("../../../services");class OpenAITextToSpeechService extends services_1.LLMTextToSpeechService{#e=null;constructor(e,r){super(LLMService_typedefs_1.LLMProviders.OpenAI,e,r)}get instance(){return this.#e||(this.#e=new openai_1.OpenAI(this.options)),this.#e}async createSpeech(e){try{const{text:r,model:t,instructions:i,speechOptions:s,abortSignal:n}=e,o=await this.instance.audio.speech.create({model:t.name,input:r,instructions:i,voice:s?.voice||"alloy",response_format:s?.response_format,speed:s?.speed},{signal:n});if(n?.aborted)throw new Error("Speech creation aborted");return{audio:await o.arrayBuffer(),mimeType:o.headers.get("Content-Type")}}catch(r){return this.logger.child("createSpeech").error("Error creating speech",{error:r,options:e}),{error:r}}}}exports.OpenAITextToSpeechService=OpenAITextToSpeechService;
@@ -1 +1 @@
1
- {"version":3,"file":"OpenAITextToSpeech.service.js","sourceRoot":"","sources":["../../../../src/providers/OpenAI/services/OpenAITextToSpeech.service.ts"],"names":[],"mappings":";;;AACA,mCAAgC;AAChC,+DAK+B;AAC/B,yCAAoD;AAEpD,MAAa,yBACX,SAAQ,iCAA2C;IACnD,SAAS,GAAkB,IAAI,CAAC;IAEhC,Y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AAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;aACpD,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM;iBACR,KAAK,CAAC,cAAc,CAAC;iBACrB,KAAK,CAAC,uBAAuB,EAAE;gBAC9B,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;YAEL,OAAO,EAAE,KAAK,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AAhED,8DAgEC"}
@@ -1,9 +1,9 @@
1
1
  import { type Logger } from '@mate-academy/core';
2
- import { type LLMAssistanceOptions, type LLMAssistanceResult, type LLMCompletionMessage, type LLMCreateAssistantOptions, type LLMCreateAssistantResult, type LLMCreateChatOptions, type LLMCreateChatResult, type LLMCreateFileStorageOptions, type LLMCreateFileStorageResult, type LLMInstanceOptions, type LLMModel, type LLMProviders, LLMPurposes, type LLMUploadFile, type LLMUploadFileResult } from '../LLMService.typedefs';
2
+ import { type LLMAssistanceOptions, type LLMAssistanceResult, type LLMCompletionMessage, type LLMCreateAssistantOptions, type LLMCreateAssistantResult, type LLMCreateChatOptions, type LLMCreateChatResult, type LLMCreateFileStorageOptions, type LLMCreateFileStorageResult, type LLMInstanceOptions, type LLMModel, type LLMProviders, LLMPurposes, type LLMUploadFileOptions, type LLMUploadFileResult } from '../LLMService.typedefs';
3
3
  import { LLMBaseService } from '../services';
4
4
  export declare abstract class LLMAssistanceService<Provider extends LLMProviders> extends LLMBaseService<LLMPurposes.Assistance, Provider> {
5
5
  constructor(provider: Provider, logger: Logger, options: LLMInstanceOptions[Provider]);
6
- abstract uploadFile(file: LLMUploadFile): Promise<LLMUploadFileResult>;
6
+ abstract uploadFile(options: LLMUploadFileOptions): Promise<LLMUploadFileResult>;
7
7
  abstract deleteFile(fileId: string): Promise<void>;
8
8
  abstract createFileStorage(options: LLMCreateFileStorageOptions<Provider>): Promise<LLMCreateFileStorageResult>;
9
9
  abstract deleteFileStorage(fileStorageId: string): Promise<void>;
@@ -13,6 +13,6 @@ export declare abstract class LLMAssistanceService<Provider extends LLMProviders
13
13
  abstract deleteChat(chatId: string): Promise<void>;
14
14
  abstract assistInChat(options: LLMAssistanceOptions): Promise<LLMAssistanceResult>;
15
15
  abstract countTokens(messages: LLMCompletionMessage[], model: LLMModel<Provider>): Promise<number>;
16
- protected isImageFile(file: LLMUploadFile): boolean;
17
- protected isNotImageFile: (file: LLMUploadFile) => boolean;
16
+ protected isImageFile(file: LLMUploadFileOptions): boolean;
17
+ protected isNotImageFile: (file: LLMUploadFileOptions) => boolean;
18
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"LLMAssistanceService.abstract.js","sourceRoot":"","sources":["../../src/services/LLMAssistanceService.abstract.ts"],"names":[],"mappings":";;;AACA,+DAgB+B;AAC/B,yCAA4C;AAC5C,iEAA8D;AAE9D,MAAsB,oBACpB,SAAQ,yBAGP;IACD,YACE,QAAkB,EAClB,MAAc,EACd,OAAqC;QAErC,KAAK,CACH,QAAQ,EACR,mBAAmB,EACnB,iCAAW,CAAC,UAAU,EACtB,MAAM,EACN,OAAO,CACR,CAAC;IACJ,CAAC;IA2CS,WAAW,CAAC,IAAmB;QACvC,OAAO,2CAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC;IAES,cAAc,GAAG,CAAC,IAAmB,EAAW,EAAE;QAC1D,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC,CAAA;CACF;AAnED,oDAmEC"}
1
+ {"version":3,"file":"LLMAssistanceService.abstract.js","sourceRoot":"","sources":["../../src/services/LLMAssistanceService.abstract.ts"],"names":[],"mappings":";;;AACA,+DAgB+B;AAC/B,yCAA4C;AAC5C,iEAA8D;AAE9D,MAAsB,oBACpB,SAAQ,yBAGP;IACD,YACE,QAAkB,EAClB,MAAc,EACd,OAAqC;QAErC,KAAK,CACH,QAAQ,EACR,mBAAmB,EACnB,iCAAW,CAAC,UAAU,EACtB,MAAM,EACN,OAAO,CACR,CAAC;IACJ,CAAC;IA2CS,WAAW,CAAC,IAA0B;QAC9C,OAAO,2CAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC;IAES,cAAc,GAAG,CAAC,IAA0B,EAAW,EAAE;QACjE,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC,CAAA;CACF;AAnED,oDAmEC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mate-academy/llm-gateway",
3
- "version": "2.1.7",
3
+ "version": "2.2.0",
4
4
  "description": "A gateway package for LLM services.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -54,7 +54,7 @@
54
54
  "@types/jest": "^30.0.0",
55
55
  "@types/mime-types": "^3.0.1",
56
56
  "@typescript-eslint/eslint-plugin": "^8.36.0",
57
- "dotenv": "^17.1.0",
57
+ "dotenv": "^17.2.0",
58
58
  "eslint": "^9.30.1",
59
59
  "eslint-plugin-no-only-tests": "^3.3.0",
60
60
  "glob": "^11.0.3",
@@ -67,12 +67,12 @@
67
67
  "typescript-eslint": "^8.36.0"
68
68
  },
69
69
  "dependencies": {
70
- "@google/genai": "^1.8.0",
70
+ "@google/genai": "^1.9.0",
71
71
  "@mate-academy/core": "^1.10.4",
72
72
  "axios": "^1.10.0",
73
73
  "js-tiktoken": "^1.0.20",
74
74
  "mime-types": "^3.0.1",
75
- "openai": "^5.8.2",
75
+ "openai": "^5.9.0",
76
76
  "uuid": "^11.1.0"
77
77
  }
78
78
  }