@mate-academy/llm-gateway 2.0.2 → 2.1.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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.pick=void 0;const pick=(e,c)=>c.reduce(((c,s)=>(Object.assign(c,{[s]:e[s]}),c)),{});exports.pick=pick;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.pick=void 0;const pick=(e,c)=>c.reduce((c,s)=>(Object.assign(c,{[s]:e[s]}),c),{});exports.pick=pick;
@@ -1 +1 @@
1
- "use strict";function promptBuilder(e,t){return t?Object.entries(t).reduce(((e,[t,r])=>e.replace(new RegExp(`{{\\s*${t}\\s*}}`,"g"),String(r))),e):e}function createPromptTemplate(e){const t=e.trim();return(...e)=>promptBuilder(t,...e)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.createPromptTemplate=createPromptTemplate;
1
+ "use strict";function promptBuilder(e,t){return t?Object.entries(t).reduce((e,[t,r])=>e.replace(new RegExp(`{{\\s*${t}\\s*}}`,"g"),String(r)),e):e}function createPromptTemplate(e){const t=e.trim();return(...e)=>promptBuilder(t,...e)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.createPromptTemplate=createPromptTemplate;
@@ -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_PREVIEW]:{name:GoogleGenerativeAI_typedefs_1.GoogleGenerativeAIModelNames.GEMINI_2_5_PRO_PREVIEW,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_PREVIEW]),[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_PREVIEW]),[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]),[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;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AC,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,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,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.__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: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;
@@ -4,7 +4,7 @@ export declare enum GoogleGenerativeAIModelNames {
4
4
  GEMINI_1_5_PRO_STABLE = "gemini-1.5-pro-002",
5
5
  GEMINI_2_0_FLASH = "gemini-2.0-flash",
6
6
  GEMINI_2_0_FLASH_STABLE = "gemini-2.0-flash-001",
7
- GEMINI_2_5_PRO_PREVIEW = "gemini-2.5-pro-preview-06-05",
7
+ GEMINI_2_5_PRO = "gemini-2.5-pro",
8
8
  GEMINI_2_5_FLASH_PREVIEW_TTS = "gemini-2.5-flash-preview-tts",
9
9
  GEMINI_2_5_PRO_PREVIEW_TTS = "gemini-2.5-pro-preview-tts"
10
10
  }
@@ -1 +1 @@
1
- "use strict";var GoogleGenerativeAIModelNames,GoogleGenerativeAIRoles;Object.defineProperty(exports,"__esModule",{value:!0}),exports.GoogleGenerativeAIRoles=exports.GoogleGenerativeAIModelNames=void 0,function(e){e.GEMINI_1_5_FLASH="gemini-1.5-flash",e.GEMINI_1_5_PRO="gemini-1.5-pro",e.GEMINI_1_5_PRO_STABLE="gemini-1.5-pro-002",e.GEMINI_2_0_FLASH="gemini-2.0-flash",e.GEMINI_2_0_FLASH_STABLE="gemini-2.0-flash-001",e.GEMINI_2_5_PRO_PREVIEW="gemini-2.5-pro-preview-06-05",e.GEMINI_2_5_FLASH_PREVIEW_TTS="gemini-2.5-flash-preview-tts",e.GEMINI_2_5_PRO_PREVIEW_TTS="gemini-2.5-pro-preview-tts"}(GoogleGenerativeAIModelNames||(exports.GoogleGenerativeAIModelNames=GoogleGenerativeAIModelNames={})),function(e){e.User="user",e.Model="model"}(GoogleGenerativeAIRoles||(exports.GoogleGenerativeAIRoles=GoogleGenerativeAIRoles={}));
1
+ "use strict";var GoogleGenerativeAIModelNames,GoogleGenerativeAIRoles;Object.defineProperty(exports,"__esModule",{value:!0}),exports.GoogleGenerativeAIRoles=exports.GoogleGenerativeAIModelNames=void 0,function(e){e.GEMINI_1_5_FLASH="gemini-1.5-flash",e.GEMINI_1_5_PRO="gemini-1.5-pro",e.GEMINI_1_5_PRO_STABLE="gemini-1.5-pro-002",e.GEMINI_2_0_FLASH="gemini-2.0-flash",e.GEMINI_2_0_FLASH_STABLE="gemini-2.0-flash-001",e.GEMINI_2_5_PRO="gemini-2.5-pro",e.GEMINI_2_5_FLASH_PREVIEW_TTS="gemini-2.5-flash-preview-tts",e.GEMINI_2_5_PRO_PREVIEW_TTS="gemini-2.5-pro-preview-tts"}(GoogleGenerativeAIModelNames||(exports.GoogleGenerativeAIModelNames=GoogleGenerativeAIModelNames={})),function(e){e.User="user",e.Model="model"}(GoogleGenerativeAIRoles||(exports.GoogleGenerativeAIRoles=GoogleGenerativeAIRoles={}));
@@ -1 +1 @@
1
- {"version":3,"file":"GoogleGenerativeAI.typedefs.js","sourceRoot":"","sources":["../../../src/providers/GoogleGenerativeAI/GoogleGenerativeAI.typedefs.ts"],"names":[],"mappings":";;;AAAA,IAAY,4BASX;AATD,WAAY,4BAA4B;IACtC,qEAAqC,CAAA;IACrC,iEAAiC,CAAA;IACjC,4EAA4C,CAAA;IAC5C,qEAAqC,CAAA;IACrC,gFAAgD,CAAA;IAChD,uFAAuD,CAAA;IACvD,6FAA6D,CAAA;IAC7D,yFAAyD,CAAA;AAC3D,CAAC,EATW,4BAA4B,4CAA5B,4BAA4B,QASvC;AAED,IAAY,uBAGX;AAHD,WAAY,uBAAuB;IACjC,wCAAa,CAAA;IACb,0CAAe,CAAA;AACjB,CAAC,EAHW,uBAAuB,uCAAvB,uBAAuB,QAGlC"}
1
+ {"version":3,"file":"GoogleGenerativeAI.typedefs.js","sourceRoot":"","sources":["../../../src/providers/GoogleGenerativeAI/GoogleGenerativeAI.typedefs.ts"],"names":[],"mappings":";;;AAAA,IAAY,4BASX;AATD,WAAY,4BAA4B;IACtC,qEAAqC,CAAA;IACrC,iEAAiC,CAAA;IACjC,4EAA4C,CAAA;IAC5C,qEAAqC,CAAA;IACrC,gFAAgD,CAAA;IAChD,iEAAiC,CAAA;IACjC,6FAA6D,CAAA;IAC7D,yFAAyD,CAAA;AAC3D,CAAC,EATW,4BAA4B,4CAA5B,4BAA4B,QASvC;AAED,IAAY,uBAGX;AAHD,WAAY,uBAAuB;IACjC,wCAAa,CAAA;IACb,0CAAe,CAAA;AACjB,CAAC,EAHW,uBAAuB,uCAAvB,uBAAuB,QAGlC"}
@@ -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,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 +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){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 +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");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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mate-academy/llm-gateway",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "A gateway package for LLM services.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,7 +11,9 @@
11
11
  "lint:fix": "eslint . --fix",
12
12
  "test": "ENABLE_LOGGING=true jest",
13
13
  "test:silent": "jest",
14
- "prepublishOnly": "npm run lint:fix && npm run type-check && npm run build",
14
+ "test:integration": "ENABLE_LOGGING=true jest src/tests/integration --verbose",
15
+ "prepublish-tests": "node scripts/prepublish-tests.js",
16
+ "prepublishOnly": "npm run prepublish-tests && npm run lint:fix && npm run type-check && npm run build",
15
17
  "type-check": "tsc --noEmit",
16
18
  "postpublish": "npm run clean",
17
19
  "clean": "rm -rf ./dist",
@@ -47,25 +49,29 @@
47
49
  },
48
50
  "devDependencies": {
49
51
  "@mate-academy/ts-config": "^1.0.5",
50
- "@types/jest": "^29.5.14",
52
+ "@types/glob": "^8.1.0",
53
+ "@types/inquirer": "^9.0.8",
54
+ "@types/jest": "^30.0.0",
51
55
  "@types/mime-types": "^3.0.1",
52
56
  "@typescript-eslint/eslint-plugin": "^8.33.1",
53
57
  "dotenv": "^16.5.0",
54
- "eslint": "^9.28.0",
55
- "jest": "^29.7.0",
56
- "terser": "^5.41.0",
57
- "ts-jest": "^29.3.4",
58
+ "eslint": "^9.29.0",
59
+ "glob": "^11.0.3",
60
+ "inquirer": "^12.6.3",
61
+ "jest": "^30.0.2",
62
+ "terser": "^5.43.1",
63
+ "ts-jest": "^29.4.0",
58
64
  "tsc-alias": "^1.8.16",
59
65
  "typescript": "^5.8.3",
60
- "typescript-eslint": "^8.33.1"
66
+ "typescript-eslint": "^8.34.1"
61
67
  },
62
68
  "dependencies": {
63
- "@google/genai": "^1.4.0",
69
+ "@google/genai": "^1.6.0",
64
70
  "@mate-academy/core": "^1.10.4",
65
- "axios": "^1.9.0",
71
+ "axios": "^1.10.0",
66
72
  "js-tiktoken": "^1.0.20",
67
73
  "mime-types": "^3.0.1",
68
- "openai": "^5.2.0",
74
+ "openai": "^5.6.0",
69
75
  "uuid": "^11.1.0"
70
76
  }
71
77
  }