@mate-academy/llm-gateway 2.1.1 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,6 +19,8 @@ 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
+ - Token counting functionality for precise context management
23
+ - Type-safe prompt templates with dynamic replacements
22
24
  - Factory pattern for easy provider selection
23
25
  - Consistent logging across all providers
24
26
  - Comprehensive testing suite with integration tests
@@ -38,6 +40,9 @@ import {
38
40
  LLMRoles,
39
41
  LLMMessageContentType,
40
42
  LLMUploadFileMimeTypes,
43
+ LLMCompletionMessage,
44
+ LLMModel,
45
+ createPromptTemplate,
41
46
  } from '@mate-academy/llm-gateway';
42
47
 
43
48
  // Define provider options
@@ -270,6 +275,61 @@ const speech = await textToSpeechService.createSpeech({
270
275
  fs.writeFileSync('output.mp3', speech.audio);
271
276
  ```
272
277
 
278
+ #### Token Counting for Context Management
279
+
280
+ ```typescript
281
+ // Count tokens in messages before sending to optimize context usage
282
+ const messages = [
283
+ {
284
+ role: LLMRoles.User,
285
+ content: [
286
+ {
287
+ type: LLMMessageContentType.TEXT,
288
+ text: 'Analyze this document and provide insights.',
289
+ },
290
+ {
291
+ type: LLMMessageContentType.TEXT,
292
+ text: longDocumentContent, // Large text content
293
+ },
294
+ // ... potentially more content including images
295
+ ],
296
+ }
297
+ ];
298
+
299
+ const tokenCount = await assistanceService.countTokens(messages, preferredModel);
300
+
301
+ console.log(`Total tokens: ${tokenCount}`);
302
+
303
+ // Make intelligent decisions based on token count
304
+ if (tokenCount > 50000) {
305
+ // Use file upload approach for large content
306
+ const uploadedFile = await assistanceService.uploadFile({
307
+ name: 'document.txt',
308
+ path: '/path/to/document.txt',
309
+ mimeType: LLMUploadFileMimeTypes.PLAIN_TEXT,
310
+ });
311
+
312
+ const storage = await assistanceService.createFileStorage({
313
+ uploadedFiles: [uploadedFile],
314
+ model: preferredModel,
315
+ });
316
+
317
+ const chat = await assistanceService.createChat({
318
+ storageId: storage.storageId,
319
+ model: preferredModel,
320
+ instructions: 'Analyze the uploaded document',
321
+ });
322
+ } else {
323
+ // Send content directly in messages
324
+ const result = await assistanceService.assistInChat({
325
+ chatId: existingChatId,
326
+ assistantId: existingAssistantId,
327
+ message: messages[0],
328
+ model: preferredModel,
329
+ });
330
+ }
331
+ ```
332
+
273
333
  ## API Reference
274
334
 
275
335
  ### LLMProviders
@@ -342,6 +402,9 @@ Interface for chat/assistance services with file handling capabilities.
342
402
  - `assistInChat(options)`: Send a message in an existing chat and get an assistant response
343
403
  - Parameters: `LLMAssistanceOptions` with `model`, `message`, `chatId`, and `assistantId`
344
404
  - Returns: `Promise<LLMAssistanceResult>`
405
+ - `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
345
408
 
346
409
  ### LLMSpeechToTextService
347
410
 
@@ -359,6 +422,147 @@ Interface for converting text to speech audio.
359
422
 
360
423
  - `createSpeech(options)`: Convert text to speech audio file
361
424
 
425
+ ### Prompt Builder
426
+
427
+ The LLM Gateway includes a powerful prompt template system that provides type-safe string templates with dynamic replacements. This allows you to create reusable prompt templates with placeholders that can be replaced with actual values at runtime.
428
+
429
+ #### Features
430
+
431
+ - **Type Safety**: Automatic extraction and validation of placeholder keys from template strings
432
+ - **Dynamic Replacements**: Replace placeholders like `{{variableName}}` with actual values
433
+ - **Template Reusability**: Create templates once and use them multiple times with different values
434
+ - **Zero Runtime Dependencies**: Pure TypeScript utility functions
435
+
436
+ #### Basic Usage
437
+
438
+ ```typescript
439
+ import { createPromptTemplate } from '@mate-academy/llm-gateway';
440
+
441
+ // Create a prompt template with placeholders
442
+ const welcomePrompt = createPromptTemplate(`
443
+ Generate a welcome message for a user who has just started their auto tech check attempt on {{topicTitle}}.
444
+ The user's experience level is {{experienceLevel}} and they prefer {{learningStyle}} learning.
445
+ `);
446
+
447
+ // Use the template with actual values
448
+ const instruction = welcomePrompt({
449
+ topicTitle: 'JavaScript Basics',
450
+ experienceLevel: 'beginner',
451
+ learningStyle: 'hands-on',
452
+ });
453
+
454
+ // Result: "Generate a welcome message for a user who has just started their auto tech check attempt on JavaScript Basics. The user's experience level is beginner and they prefer hands-on learning."
455
+ ```
456
+
457
+ #### Advanced Usage
458
+
459
+ ```typescript
460
+ // Template without placeholders (no parameters required)
461
+ const staticPrompt = createPromptTemplate(`
462
+ Please analyze the provided code and suggest improvements.
463
+ `);
464
+ const staticInstruction = staticPrompt(); // No parameters needed
465
+
466
+ // Template with multiple placeholders
467
+ const codeReviewPrompt = createPromptTemplate(`
468
+ Review the {{language}} code below for {{focusArea}}.
469
+ Pay special attention to {{criteria}} and provide {{outputFormat}} feedback.
470
+
471
+ Code:
472
+ {{codeSnippet}}
473
+ `);
474
+
475
+ const reviewInstruction = codeReviewPrompt({
476
+ language: 'TypeScript',
477
+ focusArea: 'performance optimization',
478
+ criteria: 'algorithmic efficiency and memory usage',
479
+ outputFormat: 'structured',
480
+ codeSnippet: 'function example() { /* code here */ }',
481
+ });
482
+ ```
483
+
484
+ #### Integration with LLM Services
485
+
486
+ ```typescript
487
+ import {
488
+ createPromptTemplate,
489
+ LLMServiceFactory,
490
+ LLMProviders,
491
+ LLMRoles,
492
+ } from '@mate-academy/llm-gateway';
493
+
494
+ // Define reusable prompt templates
495
+ const PROMPTS = {
496
+ codeExplanation: createPromptTemplate(`
497
+ Explain the following {{language}} code in simple terms for a {{level}} developer:
498
+ {{code}}
499
+ `),
500
+
501
+ bugFinding: createPromptTemplate(`
502
+ Find potential bugs in this {{language}} code and suggest fixes:
503
+ {{code}}
504
+ `),
505
+
506
+ optimization: createPromptTemplate(`
507
+ Optimize the following code for {{optimizationType}}:
508
+ {{code}}
509
+ `),
510
+ };
511
+
512
+ // Use with completion service
513
+ async function explainCode(code: string, language: string, level: string) {
514
+ const prompt = PROMPTS.codeExplanation({
515
+ code,
516
+ language,
517
+ level,
518
+ });
519
+
520
+ return await completionService.sendMessage({
521
+ message: {
522
+ role: LLMRoles.User,
523
+ content: [prompt],
524
+ },
525
+ model: preferredModel,
526
+ });
527
+ }
528
+ ```
529
+
530
+ #### Type Safety Features
531
+
532
+ The prompt builder provides compile-time type checking for template placeholders:
533
+
534
+ ```typescript
535
+ // This will show TypeScript errors for missing or incorrect parameters
536
+ const template = createPromptTemplate(`Hello {{name}}, welcome to {{platform}}!`);
537
+
538
+ // ✅ Correct usage
539
+ template({ name: 'John', platform: 'LLM Gateway' });
540
+
541
+ // ❌ TypeScript error: missing required parameter 'platform'
542
+ template({ name: 'John' });
543
+
544
+ // ❌ TypeScript error: unknown parameter 'age'
545
+ template({ name: 'John', platform: 'LLM Gateway', age: 25 });
546
+ ```
547
+
548
+ #### API Reference
549
+
550
+ **`createPromptTemplate<T extends string>(template: T)`**
551
+
552
+ Creates a prompt template function from a template string.
553
+
554
+ - **Parameters:**
555
+ - `template: T` - The template string with placeholders in `{{variableName}}` format
556
+ - **Returns:** A function that accepts replacement values and returns the processed string
557
+ - **Type Safety:** Automatically extracts placeholder names from the template string for type checking
558
+
559
+ **Template Placeholder Format**
560
+
561
+ - Placeholders must be enclosed in double curly braces: `{{variableName}}`
562
+ - Whitespace around variable names is ignored: `{{ variableName }}` works the same as `{{variableName}}`
563
+ - Variable names can contain letters, numbers, and underscores
564
+ - Replacement values can be strings or numbers (automatically converted to strings)
565
+
362
566
  ## Supported Providers
363
567
 
364
568
  ### OpenAI
@@ -1038,7 +1242,3 @@ export class LLMServiceFactory {
1038
1242
  }
1039
1243
  }
1040
1244
  ```
1041
-
1042
- ## License
1043
-
1044
- [MIT](LICENSE)
@@ -1,4 +1,4 @@
1
- import { type LLMProviderModelsByPurpose, LLMProviders, type LLMPurposes } from './LLMService.typedefs';
1
+ import { type LLMProviderModelsByPurpose, LLMProviders, type LLMPurposes, LLMUploadFileMimeTypes } from './LLMService.typedefs';
2
2
  import { type LLMServicePurposeFactory } from './services/LLMServicePurposeFactory.abstract';
3
3
  export declare const LLM_SERVICE_FACTORIES: {
4
4
  [provider in LLMProviders]: LLMServicePurposeFactory<provider>;
@@ -7,3 +7,4 @@ export declare const LLM_SERVICE_MODELS: {
7
7
  [provider in LLMProviders]: LLMProviderModelsByPurpose<LLMPurposes, provider>;
8
8
  };
9
9
  export declare const APPROXIMATE_TOKENS_COUNT_IN_IMAGE = 1000;
10
+ export declare const ALL_IMAGE_MIME_TYPES: LLMUploadFileMimeTypes[];
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.APPROXIMATE_TOKENS_COUNT_IN_IMAGE=exports.LLM_SERVICE_MODELS=exports.LLM_SERVICE_FACTORIES=void 0;const LLMService_typedefs_1=require("./LLMService.typedefs"),providers_1=require("./providers"),GoogleGenerativeAI_constants_1=require("./providers/GoogleGenerativeAI/GoogleGenerativeAI.constants"),OpenAI_constants_1=require("./providers/OpenAI/OpenAI.constants");exports.LLM_SERVICE_FACTORIES={[LLMService_typedefs_1.LLMProviders.OpenAI]:new providers_1.OpenAIServiceFactory,[LLMService_typedefs_1.LLMProviders.GoogleGenerativeAI]:new providers_1.GoogleGenerativeAIServiceFactory},exports.LLM_SERVICE_MODELS={[LLMService_typedefs_1.LLMProviders.OpenAI]:OpenAI_constants_1.OPEN_AI_MODELS,[LLMService_typedefs_1.LLMProviders.GoogleGenerativeAI]:GoogleGenerativeAI_constants_1.GOOGLE_AI_MODELS},exports.APPROXIMATE_TOKENS_COUNT_IN_IMAGE=1e3;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ALL_IMAGE_MIME_TYPES=exports.APPROXIMATE_TOKENS_COUNT_IN_IMAGE=exports.LLM_SERVICE_MODELS=exports.LLM_SERVICE_FACTORIES=void 0;const LLMService_typedefs_1=require("./LLMService.typedefs"),providers_1=require("./providers"),GoogleGenerativeAI_constants_1=require("./providers/GoogleGenerativeAI/GoogleGenerativeAI.constants"),OpenAI_constants_1=require("./providers/OpenAI/OpenAI.constants");exports.LLM_SERVICE_FACTORIES={[LLMService_typedefs_1.LLMProviders.OpenAI]:new providers_1.OpenAIServiceFactory,[LLMService_typedefs_1.LLMProviders.GoogleGenerativeAI]:new providers_1.GoogleGenerativeAIServiceFactory},exports.LLM_SERVICE_MODELS={[LLMService_typedefs_1.LLMProviders.OpenAI]:OpenAI_constants_1.OPEN_AI_MODELS,[LLMService_typedefs_1.LLMProviders.GoogleGenerativeAI]:GoogleGenerativeAI_constants_1.GOOGLE_AI_MODELS},exports.APPROXIMATE_TOKENS_COUNT_IN_IMAGE=1e3,exports.ALL_IMAGE_MIME_TYPES=[LLMService_typedefs_1.LLMUploadFileMimeTypes.IMAGE_PNG,LLMService_typedefs_1.LLMUploadFileMimeTypes.IMAGE_JPEG,LLMService_typedefs_1.LLMUploadFileMimeTypes.IMAGE_JPG,LLMService_typedefs_1.LLMUploadFileMimeTypes.IMAGE_GIF,LLMService_typedefs_1.LLMUploadFileMimeTypes.IMAGE_WEBP,LLMService_typedefs_1.LLMUploadFileMimeTypes.IMAGE_SVG_XML,LLMService_typedefs_1.LLMUploadFileMimeTypes.IMAGE_BMP];
@@ -1 +1 @@
1
- {"version":3,"file":"LLMService.constants.js","sourceRoot":"","sources":["../src/LLMService.constants.ts"],"names":[],"mappings":";;;AAAA,+DAI+B;AAC/B,2CAAqF;AACrF,8GAA+F;AAC/F,0EAAqE;AAGxD,QAAA,qBAAqB,GAE9B;IACF,CAAC,kCAAY,CAAC,MAAM,CAAC,EAAE,IAAI,gCAAoB,EAAE;IACjD,CAAC,kCAAY,CAAC,kBAAkB,CAAC,EAAE,IAAI,4CAAgC,EAAE;CAC1E,CAAC;AAEW,QAAA,kBAAkB,GAE3B;IACF,CAAC,kCAAY,CAAC,MAAM,CAAC,EAAE,iCAAc;IACrC,CAAC,kCAAY,CAAC,kBAAkB,CAAC,EAAE,+CAAgB;CACpD,CAAC;AAEW,QAAA,iCAAiC,GAAG,IAAI,CAAC"}
1
+ {"version":3,"file":"LLMService.constants.js","sourceRoot":"","sources":["../src/LLMService.constants.ts"],"names":[],"mappings":";;;AAAA,+DAK+B;AAC/B,2CAAqF;AACrF,8GAA+F;AAC/F,0EAAqE;AAGxD,QAAA,qBAAqB,GAE9B;IACF,CAAC,kCAAY,CAAC,MAAM,CAAC,EAAE,IAAI,gCAAoB,EAAE;IACjD,CAAC,kCAAY,CAAC,kBAAkB,CAAC,EAAE,IAAI,4CAAgC,EAAE;CAC1E,CAAC;AAEW,QAAA,kBAAkB,GAE3B;IACF,CAAC,kCAAY,CAAC,MAAM,CAAC,EAAE,iCAAc;IACrC,CAAC,kCAAY,CAAC,kBAAkB,CAAC,EAAE,+CAAgB;CACpD,CAAC;AAEW,QAAA,iCAAiC,GAAG,IAAI,CAAC;AAEzC,QAAA,oBAAoB,GAA6B;IAC5D,4CAAsB,CAAC,SAAS;IAChC,4CAAsB,CAAC,UAAU;IACjC,4CAAsB,CAAC,SAAS;IAChC,4CAAsB,CAAC,SAAS;IAChC,4CAAsB,CAAC,UAAU;IACjC,4CAAsB,CAAC,aAAa;IACpC,4CAAsB,CAAC,SAAS;CACjC,CAAC"}
@@ -201,6 +201,7 @@ export declare enum LLMUploadFileMimeTypes {
201
201
  IMAGE_SVG_XML = "image/svg+xml",
202
202
  IMAGE_BMP = "image/bmp",
203
203
  PLAIN_TEXT = "text/plain",
204
+ MARKDOWN = "text/markdown",
204
205
  AUDIO_MP3 = "audio/mp3",
205
206
  AUDIO_MPEG = "audio/mpeg",
206
207
  AUDIO_WAV = "audio/wav",
@@ -299,6 +300,7 @@ export interface LLMAssistanceOptions {
299
300
  message: LLMAssistanceMessage;
300
301
  chatId: string;
301
302
  assistantId: string;
303
+ storageId?: string;
302
304
  }
303
305
  /**
304
306
  * Result type for assistance requests.
@@ -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.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"}(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,CAAA;IACzB,wCAAyB,CAAA;IACzB,8CAA+B,CAAA;IAC/B,8CAA+B,CAAA;AACjC,CAAC,EALW,WAAW,2BAAX,WAAW,QAKtB;AAyFD;;GAEG;AACH,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,mCAAuB,CAAA;AACzB,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB;AAED;;GAEG;AACH,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,sCAAa,CAAA;IACb,gDAAuB,CAAA;IACvB,kDAAyB,CAAA;AAC3B,CAAC,EAJW,qBAAqB,qCAArB,qBAAqB,QAIhC;AAqFD;;GAEG;AACH,IAAY,sBAaX;AAbD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DAA0B,CAAA;IAC1B,iDAAuB,CAAA;IACvB,mDAAyB,CAAA;IACzB,iDAAuB,CAAA;IACvB,mDAAyB,CAAA;AAC3B,CAAC,EAdW,sBAAsB,sCAAtB,sBAAsB,QAcjC"}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GOOGLE_AI_SERVICE_BUILDERS=exports.GOOGLE_AI_MODELS=exports.MIN_CACHE_CONTENT_LENGTH=void 0;const LLMService_typedefs_1=require("../../LLMService.typedefs"),GoogleGenerativeAI_typedefs_1=require("./GoogleGenerativeAI.typedefs"),services_1=require("../../providers/GoogleGenerativeAI/services"),functional_utils_1=require("../../functional.utils");exports.MIN_CACHE_CONTENT_LENGTH=32768;const GOOGLE_AI_AVAILABLE_MODELS={[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_FLASH]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_FLASH,limits:{maxInputTokens:1048576,maxOutputTokens:8192},config:{temperature:.2}},[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_PRO]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_PRO,limits:{maxInputTokens:2097152,maxOutputTokens:8192},config:{temperature:.2}},[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_PRO_STABLE]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_PRO_STABLE,limits:{maxInputTokens:2097152,maxOutputTokens:8192},config:{temperature:.2}},[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_0_FLASH]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_0_FLASH,limits:{maxInputTokens:1048576,maxOutputTokens:8192},config:{temperature:.2}},[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_0_FLASH_STABLE]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_0_FLASH_STABLE,limits:{maxInputTokens:1048576,maxOutputTokens:8192},config:{temperature:.2}},[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO,limits:{maxInputTokens:1048576,maxOutputTokens:65536},config:{temperature:.2}},[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_FLASH_PREVIEW_TTS]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_FLASH_PREVIEW_TTS,limits:{maxInputTokens:8e3,maxOutputTokens:16e3},config:{temperature:.2}},[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO_PREVIEW_TTS]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO_PREVIEW_TTS,limits:{maxInputTokens:8e3,maxOutputTokens:16e3},config:{temperature:.2}}};exports.GOOGLE_AI_MODELS={[LLMService_typedefs_1.LLMPurposes.Completion]:(0,functional_utils_1.pick)(GOOGLE_AI_AVAILABLE_MODELS,[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_FLASH,GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_PRO,GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_0_FLASH,GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO]),[LLMService_typedefs_1.LLMPurposes.Assistance]:(0,functional_utils_1.pick)(GOOGLE_AI_AVAILABLE_MODELS,[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_PRO_STABLE,GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_0_FLASH_STABLE]),[LLMService_typedefs_1.LLMPurposes.SpeechToText]:(0,functional_utils_1.pick)(GOOGLE_AI_AVAILABLE_MODELS,[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_0_FLASH,GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO]),[LLMService_typedefs_1.LLMPurposes.TextToSpeech]:(0,functional_utils_1.pick)(GOOGLE_AI_AVAILABLE_MODELS,[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_FLASH_PREVIEW_TTS,GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO_PREVIEW_TTS])},exports.GOOGLE_AI_SERVICE_BUILDERS={[LLMService_typedefs_1.LLMPurposes.Completion]:(e,_)=>new services_1.GoogleGenerativeAICompletionService(e,_),[LLMService_typedefs_1.LLMPurposes.Assistance]:(e,_)=>new services_1.GoogleGenerativeAIAssistanceService(e,_),[LLMService_typedefs_1.LLMPurposes.SpeechToText]:(e,_)=>new services_1.GoogleGenerativeAISpeechToTextService(e,_),[LLMService_typedefs_1.LLMPurposes.TextToSpeech]:(e,_)=>new services_1.GoogleGenerativeAITextToSpeechService(e,_)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GOOGLE_AI_SERVICE_BUILDERS=exports.GOOGLE_AI_MODELS=exports.MIN_CACHE_CONTENT_LENGTH=void 0;const LLMService_typedefs_1=require("../../LLMService.typedefs"),GoogleGenerativeAI_typedefs_1=require("./GoogleGenerativeAI.typedefs"),services_1=require("../../providers/GoogleGenerativeAI/services"),functional_utils_1=require("../../functional.utils");exports.MIN_CACHE_CONTENT_LENGTH=32768;const GOOGLE_AI_AVAILABLE_MODELS={[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_FLASH]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_FLASH,limits:{maxInputTokens:1048576,maxOutputTokens:8192},config:{temperature:.2}},[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_PRO]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_PRO,limits:{maxInputTokens:2097152,maxOutputTokens:8192},config:{temperature:.2}},[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_PRO_STABLE]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_PRO_STABLE,limits:{maxInputTokens:2097152,maxOutputTokens:8192},config:{temperature:.2}},[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_0_FLASH]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_0_FLASH,limits:{maxInputTokens:1048576,maxOutputTokens:8192},config:{temperature:.2}},[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_0_FLASH_STABLE]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_0_FLASH_STABLE,limits:{maxInputTokens:1048576,maxOutputTokens:8192},config:{temperature:.2}},[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO,limits:{maxInputTokens:1048576,maxOutputTokens:65536},config:{temperature:.2}},[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_FLASH_PREVIEW_TTS]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_FLASH_PREVIEW_TTS,limits:{maxInputTokens:8e3,maxOutputTokens:16e3},config:{temperature:.2}},[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO_PREVIEW_TTS]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO_PREVIEW_TTS,limits:{maxInputTokens:8e3,maxOutputTokens:16e3},config:{temperature:.2}}};exports.GOOGLE_AI_MODELS={[LLMService_typedefs_1.LLMPurposes.Completion]:(0,functional_utils_1.pick)(GOOGLE_AI_AVAILABLE_MODELS,[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_FLASH,GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_PRO,GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_0_FLASH,GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO]),[LLMService_typedefs_1.LLMPurposes.Assistance]:(0,functional_utils_1.pick)(GOOGLE_AI_AVAILABLE_MODELS,[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_1_5_PRO_STABLE,GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_0_FLASH_STABLE,GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO]),[LLMService_typedefs_1.LLMPurposes.SpeechToText]:(0,functional_utils_1.pick)(GOOGLE_AI_AVAILABLE_MODELS,[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_0_FLASH,GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO]),[LLMService_typedefs_1.LLMPurposes.TextToSpeech]:(0,functional_utils_1.pick)(GOOGLE_AI_AVAILABLE_MODELS,[GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_FLASH_PREVIEW_TTS,GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO_PREVIEW_TTS])},exports.GOOGLE_AI_SERVICE_BUILDERS={[LLMService_typedefs_1.LLMPurposes.Completion]:(e,_)=>new services_1.GoogleGenerativeAICompletionService(e,_),[LLMService_typedefs_1.LLMPurposes.Assistance]:(e,_)=>new services_1.GoogleGenerativeAIAssistanceService(e,_),[LLMService_typedefs_1.LLMPurposes.SpeechToText]:(e,_)=>new services_1.GoogleGenerativeAISpeechToTextService(e,_),[LLMService_typedefs_1.LLMPurposes.TextToSpeech]:(e,_)=>new services_1.GoogleGenerativeAITextToSpeechService(e,_)};
@@ -1 +1 @@
1
- {"version":3,"file":"GoogleGenerativeAI.constants.js","sourceRoot":"","sources":["../../../src/providers/GoogleGenerativeAI/GoogleGenerativeAI.constants.ts"],"names":[],"mappings":";;;AAAA,+DAM+B;AAC/B,+EAA6E;AAC7E,sEAKiD;AACjD,yDAA0C;AAE7B,QAAA,wBAAwB,GAAG,MAAM,CAAC;AAE/C,MAAM,0BAA0B,GAE5B;IACF,CAAC,0DAA4B,CAAC,gBAAgB,CAAC,EAAE;QAC/C,IAAI,EAAE,0DAA4B,CAAC,gBAAgB;QACnD,MAAM,EAAE;YACN,cAAc,EAAE,SAAS;YACzB,eAAe,EAAE,KAAK;SACvB;QACD,MAAM,EAAE;YACN,WAAW,EAAE,GAAG;SACjB;KACF;IACD,CAAC,0DAA4B,CAAC,cAAc,CAAC,EAAE;QAC7C,IAAI,EAAE,0DAA4B,CAAC,cAAc;QACjD,MAAM,EAAE;YACN,cAAc,EAAE,SAAS;YACzB,eAAe,EAAE,KAAK;SACvB;QACD,MAAM,EAAE;YACN,WAAW,EAAE,GAAG;SACjB;KACF;IACD,CAAC,0DAA4B,CAAC,qBAAqB,CAAC,EAAE;QACpD,IAAI,EAAE,0DAA4B,CAAC,qBAAqB;QACxD,MAAM,EAAE;YACN,cAAc,EAAE,SAAS;YACzB,eAAe,EAAE,KAAK;SACvB;QACD,MAAM,EAAE;YACN,WAAW,EAAE,GAAG;SACjB;KACF;IACD,CAAC,0DAA4B,CAAC,gBAAgB,CAAC,EAAE;QAC/C,IAAI,EAAE,0DAA4B,CAAC,gBAAgB;QACnD,MAAM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CAAC,EAAE,IAAA,uBAAI,EAC5B,0BAA0B,EAC1B;QACE,0DAA4B,CAAC,qBAAqB;QAClD,0DAA4B,CAAC,uBAAuB;KACrD,CACF;IACD,CAAC,iCAAW,CAAC,YAAY,CAAC,EAAE,IAAA,uBAAI,EAC9B,0BAA0B,EAC1B;QACE,0DAA4B,CAAC,gBAAgB;QAC7C,0DAA4B,CAAC,cAAc;KAC5C,CACF;IACD,CAAC,iCAAW,CAAC,YAAY,CAAC,EAAE,IAAA,uBAAI,EAC9B,0BAA0B,EAC1B;QACE,0DAA4B,CAAC,4BAA4B;QACzD,0DAA4B,CAAC,0BAA0B;KACxD,CACF;CACF,CAAC;AAEW,QAAA,0BAA0B,GAInC;IACF,CAAC,iCAAW,CAAC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,CAC7C,IAAI,8CAAmC,CAAC,MAAM,EAAE,OAAO,CAAC,CACzD;IACD,CAAC,iCAAW,CAAC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,CAC7C,IAAI,8CAAmC,CAAC,MAAM,EAAE,OAAO,CAAC,CACzD;IACD,CAAC,iCAAW,CAAC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,CAC/C,IAAI,gDAAqC,CAAC,MAAM,EAAE,OAAO,CAAC,CAC3D;IACD,CAAC,iCAAW,CAAC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,CAC/C,IAAI,gDAAqC,CAAC,MAAM,EAAE,OAAO,CAAC,CAC3D;CACF,CAAC"}
1
+ {"version":3,"file":"GoogleGenerativeAI.constants.js","sourceRoot":"","sources":["../../../src/providers/GoogleGenerativeAI/GoogleGenerativeAI.constants.ts"],"names":[],"mappings":";;;AAAA,+DAM+B;AAC/B,+EAA6E;AAC7E,sEAKiD;AACjD,yDAA0C;AAE7B,QAAA,wBAAwB,GAAG,M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IACF,CAAC,iCAAW,CAAC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,CAC7C,IAAI,8CAAmC,CAAC,MAAM,EAAE,OAAO,CAAC,CACzD;IACD,CAAC,iCAAW,CAAC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,CAC7C,IAAI,8CAAmC,CAAC,MAAM,EAAE,OAAO,CAAC,CACzD;IACD,CAAC,iCAAW,CAAC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,CAC/C,IAAI,gDAAqC,CAAC,MAAM,EAAE,OAAO,CAAC,CAC3D;IACD,CAAC,iCAAW,CAAC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,CAC/C,IAAI,gDAAqC,CAAC,MAAM,EAAE,OAAO,CAAC,CAC3D;CACF,CAAC"}
@@ -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 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 LLMCreateAssistantResult, type LLMCreateChatOptions, type LLMCreateChatResult, type LLMCreateFileStorageOptions, type LLMCreateFileStorageResult, type LLMInstanceOptions, type LLMModel, LLMProviders, type LLMUploadFile, type LLMUploadFileResult } from '../../../LLMService.typedefs';
4
4
  import { LLMAssistanceService } from '../../../services';
5
5
  export declare class GoogleGenerativeAIAssistanceService extends LLMAssistanceService<LLMProviders.GoogleGenerativeAI> {
6
6
  #private;
@@ -19,4 +19,5 @@ export declare class GoogleGenerativeAIAssistanceService extends LLMAssistanceSe
19
19
  createAssistant(): Promise<LLMCreateAssistantResult>;
20
20
  deleteAssistant(): Promise<void>;
21
21
  assistInChat(options: LLMAssistanceOptions): Promise<LLMAssistanceResult>;
22
+ countTokens(messages: LLMCompletionMessage[], model: LLMModel<LLMProviders.GoogleGenerativeAI>): Promise<number>;
22
23
  }
@@ -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,s=this.uploadedFiles.get(t);if(s)return s;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 n={...e,fileId:o.name,path:o.uri};return this.uploadedFiles.set(t,n),n}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),s=GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getCountTokensFn(this.instance),o=await s(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 n=await this.instance.caches.create({model:r.name,config:{contents:[{role:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIRoles.User,parts:e}],systemInstruction:i,ttl:"1h"}});if(!n.name)throw new Error("Cache result did not return a name");return this.cachedContent.set(n.name,n),{storageId:n.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:s,files:o}=e,n=t?this.cachedContent.get(t):void 0,a=t?this.uncachedFileStorages.get(t):void 0,c=s?await Promise.all(s.map(e=>GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getContent(e,this.instance))):[];if(!n&&o){const e=GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getFileDataParts(o);c.push({role:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIRoles.User,parts:e})}if(!n&&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,...n&&{cachedContent:n.name}}}),d=(0,uuid_1.v4)();return this.chatSessions.set(d,l),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(){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 s=await GoogleGenerativeAI_entity_1.GoogleGenerativeAIEntity.getContent(t,this.instance);if(!s.parts)return{text:""};return{text:(await i.sendMessage({message:s.parts})).text??""}}catch(t){return this.logger.child("assistInChat").error("Error assisting in chat",{error:t,options:e}),{error: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: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 +1 @@
1
- {"version":3,"file":"GoogleGenerativeAIAssistance.service.js","sourceRoot":"","sources":["../../../../src/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.ts"],"names":[],"mappings":";;;AACA,+BAAoC;AACpC,yCAKuB;AACvB,+DAa+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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K,CAAC,wBAAwB,CAAC,CAAC;YAC5C,CAAC;YAED,MAAM,cAAc,GAAG,MAAM,oDAAwB,CAAC,UAAU,CAC9D,OAAO,EACP,IAAI,CAAC,QAAQ,CACd,CAAC;YAEF,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;gBAC1B,OAAO;oBACL,IAAI,EAAE,EAAE;iBACT,CAAC;YACJ,CAAC;YAED,MAAM,YAAY,GAAG,MAAM,WAAW,CAAC,WAAW,CAAC;gBACjD,OAAO,EAAE,cAAc,CAAC,KAAK;aAC9B,CAAC,CAAC;YAEH,OAAO;gBACL,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;CACF;AAvUD,kFAuUC"}
1
+ {"version":3,"file":"GoogleGenerativeAIAssistance.service.js","sourceRoot":"","sources":["../../../../src/providers/GoogleGenerativeAI/services/GoogleGenerativeAIAssistance.service.ts"],"names":[],"mappings":";;;AACA,+BAAoC;AACpC,yCAKuB;AACvB,+DAe+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,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AAG,OAAO,CAAC;YAEZ,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAElD,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;YAC5C,CAAC;YAED,MAAM,cAAc,GAAG,MAAM,oDAAwB,CAAC,UAAU,CAC9D,OAAO,EACP,IAAI,CAAC,QAAQ,CACd,CAAC;YAEF,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;gBAC1B,OAAO;oBACL,IAAI,EAAE,EAAE;iBACT,CAAC;YACJ,CAAC;YAED,MAAM,YAAY,GAAG,MAAM,WAAW,CAAC,WAAW,CAAC;gBACjD,OAAO,EAAE,cAAc,CAAC,KAAK;aAC9B,CAAC,CAAC;YAEH,OAAO;gBACL,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;AAjVD,kFAiVC"}
@@ -1,6 +1,6 @@
1
1
  import { type Logger } from '@mate-academy/core';
2
2
  import { OpenAI } from 'openai';
3
- import { type LLMAssistanceOptions, type LLMAssistanceResult, 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 LLMUploadFile, type LLMUploadFileResult } from '../../../LLMService.typedefs';
4
4
  import { LLMAssistanceService } from '../../../services';
5
5
  export declare class OpenAIAssistanceService extends LLMAssistanceService<LLMProviders.OpenAI> {
6
6
  #private;
@@ -16,4 +16,5 @@ export declare class OpenAIAssistanceService extends LLMAssistanceService<LLMPro
16
16
  createAssistant(options: LLMCreateAssistantOptions<LLMProviders.OpenAI>): Promise<LLMCreateAssistantResult>;
17
17
  deleteAssistant(assistantId: string): Promise<void>;
18
18
  assistInChat(options: LLMAssistanceOptions): Promise<LLMAssistanceResult>;
19
+ countTokens(messages: LLMCompletionMessage[]): Promise<number>;
19
20
  }
@@ -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");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 r=(0,fs_1.createReadStream)(t),i=await this.instance.files.create({purpose:"assistants",file:r});return await this.instance.files.waitForProcessing(i.id),this.uploadedFiles.set(t,i.id),{...e,fileId:i.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:r}=e,i=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}))??[];r&&r.length>0&&a.push({role:OpenAI_typedefs_1.OpenAIRoles.User,content:r.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,...i})).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}=e,a=r?.length?{tools:[{type:"file_search"}],tool_resources:{file_search:{vector_store_ids:r}}}:{};return{assistantId:(await this.instance.beta.assistants.create({model:t.name,instructions:s,temperature:t.config.temperature,top_p:t.config.top_p,name:i,...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:r}=e,{attachments:i,content:a,role:n}=t,o=[];i&&i.forEach(e=>{o.push({type:"image_file",image_file:{file_id:e.fileId,detail:"high"}})}),o.push(...a);const c={role:n===LLMService_typedefs_1.LLMRoles.User?OpenAI_typedefs_1.OpenAIRoles.User:OpenAI_typedefs_1.OpenAIRoles.Assistant,content:o};await this.instance.beta.threads.messages.create(s,c);const l=await this.instance.beta.threads.runs.createAndPoll(s,{assistant_id:r}),{status:d}=l;if("completed"!==d)throw new Error(`Thread run did not complete for message, status: ${d}`);const p=(await this.instance.beta.threads.messages.list(s,{run_id:l.id})).data.find(e=>e.role===OpenAI_typedefs_1.OpenAIRoles.Assistant),h=p?.content.find(e=>"text"===e.type&&"text"in e);return{text:h?.text?.value??""}}catch(t){return this.logger.child("assistInChat").error("Error assisting in chat",{error:t,options:e}),{error:t}}}}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}=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}))??[];i&&i.length>0&&a.push({role:OpenAI_typedefs_1.OpenAIRoles.User,content:i.filter(this.isImageFile).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 +1 @@
1
- {"version":3,"file":"OpenAIAssistance.service.js","sourceRoot":"","sources":["../../../../src/providers/OpenAI/services/OpenAIAssistance.service.ts"],"names":[],"mappings":";;;AAAA,2BAAsC;AAEtC,mCAAgC;AAChC,+DAe+B;AAC/B,yCAAkD;AAClD,wEAAiE;AAGjE,MAAa,uBACX,SAAQ,+BAAyC;IACjD,SAAS,GAAkB,IAAI,CAAC;IAExB,aAAa,GAAwB,IAAI,GAAG,EAAE,CAAC;IAEvD,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,CAAC,IAAmB;QAClC,IAAI,CAAC;YACH,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;YAEtB,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,GAA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;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;CACF;AA5UD,0DA4UC"}
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;AAC/B,yCAAkD;AAClD,wEAAiE;AAEjE,oEAAgE;AAEhE,MAAa,uBACX,SAAQ,+BAAyC;IACjD,SAAS,GAAkB,IAAI,CAAC;IAExB,aAAa,GAAwB,IAAI,GAAG,EAAE,CAAC;IAEvD,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,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AAO;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;AAtXD,0DAsXC"}
@@ -1,5 +1,5 @@
1
1
  import { type Logger } from '@mate-academy/core';
2
- import { type LLMAssistanceOptions, type LLMAssistanceResult, type LLMCreateAssistantOptions, type LLMCreateAssistantResult, type LLMCreateChatOptions, type LLMCreateChatResult, type LLMCreateFileStorageOptions, type LLMCreateFileStorageResult, type LLMInstanceOptions, 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 LLMUploadFile, 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]);
@@ -12,4 +12,7 @@ export declare abstract class LLMAssistanceService<Provider extends LLMProviders
12
12
  abstract createChat(options: LLMCreateChatOptions<Provider>): Promise<LLMCreateChatResult>;
13
13
  abstract deleteChat(chatId: string): Promise<void>;
14
14
  abstract assistInChat(options: LLMAssistanceOptions): Promise<LLMAssistanceResult>;
15
+ abstract countTokens(messages: LLMCompletionMessage[], model: LLMModel<Provider>): Promise<number>;
16
+ protected isImageFile(file: LLMUploadFile): boolean;
17
+ protected isNotImageFile: (file: LLMUploadFile) => boolean;
15
18
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LLMAssistanceService=void 0;const LLMService_typedefs_1=require("../LLMService.typedefs"),services_1=require("../services");class LLMAssistanceService extends services_1.LLMBaseService{constructor(e,s,r){super(e,"AssistanceService",LLMService_typedefs_1.LLMPurposes.Assistance,s,r)}}exports.LLMAssistanceService=LLMAssistanceService;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LLMAssistanceService=void 0;const LLMService_typedefs_1=require("../LLMService.typedefs"),services_1=require("../services"),LLMService_constants_1=require("../LLMService.constants");class LLMAssistanceService extends services_1.LLMBaseService{constructor(e,s,i){super(e,"AssistanceService",LLMService_typedefs_1.LLMPurposes.Assistance,s,i)}isImageFile(e){return LLMService_constants_1.ALL_IMAGE_MIME_TYPES.includes(e.mimeType)}isNotImageFile=e=>!this.isImageFile(e)}exports.LLMAssistanceService=LLMAssistanceService;
@@ -1 +1 @@
1
- {"version":3,"file":"LLMAssistanceService.abstract.js","sourceRoot":"","sources":["../../src/services/LLMAssistanceService.abstract.ts"],"names":[],"mappings":";;;AACA,+DAc+B;AAC/B,yCAA4C;AAE5C,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;CAqCF;AAtDD,oDAsDC"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mate-academy/llm-gateway",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "A gateway package for LLM services.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",