@contentgrowth/llm-service 1.0.3 → 1.0.5
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/dist/index.cjs +87 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +87 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -200,6 +200,15 @@ declare class GeminiProvider extends BaseLLMProvider {
|
|
|
200
200
|
done: boolean;
|
|
201
201
|
error: any;
|
|
202
202
|
}>;
|
|
203
|
+
/**
|
|
204
|
+
* Extract structured data from a file (PDF, Image, etc.) using Gemini Multimodal capabilities.
|
|
205
|
+
* @param {Buffer|string} fileData - Base64 string or Buffer of the file
|
|
206
|
+
* @param {string} mimeType - Mime type (e.g., 'application/pdf', 'image/png')
|
|
207
|
+
* @param {string} prompt - Extraction prompt
|
|
208
|
+
* @param {Object} schema - JSON schema for the output
|
|
209
|
+
* @param {Object} options - Additional options
|
|
210
|
+
*/
|
|
211
|
+
extractWithLLM(fileData: Buffer | string, mimeType: string, prompt: string, schema?: any, options?: any): Promise<any>;
|
|
203
212
|
}
|
|
204
213
|
|
|
205
214
|
/**
|
|
@@ -331,6 +340,16 @@ declare class LLMService {
|
|
|
331
340
|
content?: string;
|
|
332
341
|
citations?: any[];
|
|
333
342
|
}>;
|
|
343
|
+
/**
|
|
344
|
+
* Extract structured data from a file (Multimodal)
|
|
345
|
+
* @param {Buffer|string} fileData - File content (base64 or buffer)
|
|
346
|
+
* @param {string} mimeType - File mime type (e.g. 'application/pdf')
|
|
347
|
+
* @param {string} prompt - Extraction instructions
|
|
348
|
+
* @param {string} tenantId - Tenant ID
|
|
349
|
+
* @param {Object} schema - Optional JSON schema
|
|
350
|
+
* @param {Object} options - Options
|
|
351
|
+
*/
|
|
352
|
+
extractWithLLM(fileData: Buffer | string, mimeType: string, prompt: string, tenantId: string, schema?: any, options?: any): Promise<any>;
|
|
334
353
|
}
|
|
335
354
|
declare class LLMServiceException extends Error {
|
|
336
355
|
constructor(message: any, statusCode?: number, details?: any);
|
package/dist/index.d.ts
CHANGED
|
@@ -200,6 +200,15 @@ declare class GeminiProvider extends BaseLLMProvider {
|
|
|
200
200
|
done: boolean;
|
|
201
201
|
error: any;
|
|
202
202
|
}>;
|
|
203
|
+
/**
|
|
204
|
+
* Extract structured data from a file (PDF, Image, etc.) using Gemini Multimodal capabilities.
|
|
205
|
+
* @param {Buffer|string} fileData - Base64 string or Buffer of the file
|
|
206
|
+
* @param {string} mimeType - Mime type (e.g., 'application/pdf', 'image/png')
|
|
207
|
+
* @param {string} prompt - Extraction prompt
|
|
208
|
+
* @param {Object} schema - JSON schema for the output
|
|
209
|
+
* @param {Object} options - Additional options
|
|
210
|
+
*/
|
|
211
|
+
extractWithLLM(fileData: Buffer | string, mimeType: string, prompt: string, schema?: any, options?: any): Promise<any>;
|
|
203
212
|
}
|
|
204
213
|
|
|
205
214
|
/**
|
|
@@ -331,6 +340,16 @@ declare class LLMService {
|
|
|
331
340
|
content?: string;
|
|
332
341
|
citations?: any[];
|
|
333
342
|
}>;
|
|
343
|
+
/**
|
|
344
|
+
* Extract structured data from a file (Multimodal)
|
|
345
|
+
* @param {Buffer|string} fileData - File content (base64 or buffer)
|
|
346
|
+
* @param {string} mimeType - File mime type (e.g. 'application/pdf')
|
|
347
|
+
* @param {string} prompt - Extraction instructions
|
|
348
|
+
* @param {string} tenantId - Tenant ID
|
|
349
|
+
* @param {Object} schema - Optional JSON schema
|
|
350
|
+
* @param {Object} options - Options
|
|
351
|
+
*/
|
|
352
|
+
extractWithLLM(fileData: Buffer | string, mimeType: string, prompt: string, tenantId: string, schema?: any, options?: any): Promise<any>;
|
|
334
353
|
}
|
|
335
354
|
declare class LLMServiceException extends Error {
|
|
336
355
|
constructor(message: any, statusCode?: number, details?: any);
|
package/dist/index.js
CHANGED
|
@@ -554,11 +554,13 @@ var GeminiProvider = class extends BaseLLMProvider {
|
|
|
554
554
|
return { text: response.content };
|
|
555
555
|
}
|
|
556
556
|
async chatCompletion(messages, systemPrompt, tools = null, options = {}) {
|
|
557
|
+
const tier = options.tier || "default";
|
|
558
|
+
const modelName = this.models[tier] || this.defaultModel;
|
|
557
559
|
return this._chatCompletionWithModel(
|
|
558
560
|
messages,
|
|
559
561
|
systemPrompt,
|
|
560
562
|
tools,
|
|
561
|
-
|
|
563
|
+
modelName,
|
|
562
564
|
this.config.maxTokens,
|
|
563
565
|
this.config.temperature,
|
|
564
566
|
options
|
|
@@ -1020,6 +1022,65 @@ ${prompt}` : prompt;
|
|
|
1020
1022
|
throw error;
|
|
1021
1023
|
}
|
|
1022
1024
|
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Extract structured data from a file (PDF, Image, etc.) using Gemini Multimodal capabilities.
|
|
1027
|
+
* @param {Buffer|string} fileData - Base64 string or Buffer of the file
|
|
1028
|
+
* @param {string} mimeType - Mime type (e.g., 'application/pdf', 'image/png')
|
|
1029
|
+
* @param {string} prompt - Extraction prompt
|
|
1030
|
+
* @param {Object} schema - JSON schema for the output
|
|
1031
|
+
* @param {Object} options - Additional options
|
|
1032
|
+
*/
|
|
1033
|
+
async extractWithLLM(fileData, mimeType, prompt, schema = null, options = {}) {
|
|
1034
|
+
var _a, _b, _c, _d;
|
|
1035
|
+
const tier = options.tier || "default";
|
|
1036
|
+
const modelName = this.models[tier] || this.defaultModel;
|
|
1037
|
+
const maxTokens = options.maxTokens || this.config.maxTokens;
|
|
1038
|
+
const temperature = options.temperature !== void 0 ? options.temperature : this.config.temperature;
|
|
1039
|
+
const generationConfig = this._buildGenerationConfig(
|
|
1040
|
+
{ ...options, responseFormat: schema ? { type: "json_schema", schema } : "json" },
|
|
1041
|
+
maxTokens,
|
|
1042
|
+
temperature
|
|
1043
|
+
);
|
|
1044
|
+
const parts = [
|
|
1045
|
+
{ text: prompt }
|
|
1046
|
+
];
|
|
1047
|
+
let base64Data = fileData;
|
|
1048
|
+
if (typeof fileData !== "string") {
|
|
1049
|
+
try {
|
|
1050
|
+
base64Data = Buffer.from(fileData).toString("base64");
|
|
1051
|
+
} catch (e) {
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
parts.push({
|
|
1055
|
+
inlineData: {
|
|
1056
|
+
data: base64Data,
|
|
1057
|
+
mimeType
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
1060
|
+
const requestOptions = {
|
|
1061
|
+
model: modelName,
|
|
1062
|
+
contents: [{
|
|
1063
|
+
role: "user",
|
|
1064
|
+
parts
|
|
1065
|
+
}],
|
|
1066
|
+
config: generationConfig
|
|
1067
|
+
};
|
|
1068
|
+
try {
|
|
1069
|
+
const response = await this.client.models.generateContent(requestOptions);
|
|
1070
|
+
const candidate = (_a = response.candidates) == null ? void 0 : _a[0];
|
|
1071
|
+
if (!candidate) {
|
|
1072
|
+
throw new LLMServiceException("No candidates returned from model during extraction", 500);
|
|
1073
|
+
}
|
|
1074
|
+
const textContent = ((_d = (_c = (_b = candidate.content) == null ? void 0 : _b.parts) == null ? void 0 : _c[0]) == null ? void 0 : _d.text) || "";
|
|
1075
|
+
if (this._shouldAutoParse(options)) {
|
|
1076
|
+
return this._safeJsonParse(textContent);
|
|
1077
|
+
}
|
|
1078
|
+
return textContent;
|
|
1079
|
+
} catch (error) {
|
|
1080
|
+
console.error(`[GeminiProvider] extractWithLLM failed (API Key: ${this._getMaskedApiKey()}):`, error);
|
|
1081
|
+
throw error;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1023
1084
|
};
|
|
1024
1085
|
|
|
1025
1086
|
// src/llm-service.js
|
|
@@ -1247,6 +1308,22 @@ var LLMService = class {
|
|
|
1247
1308
|
const provider = await this._getProvider(tenantId);
|
|
1248
1309
|
return provider.getDeepResearchStatus(operationId);
|
|
1249
1310
|
}
|
|
1311
|
+
/**
|
|
1312
|
+
* Extract structured data from a file (Multimodal)
|
|
1313
|
+
* @param {Buffer|string} fileData - File content (base64 or buffer)
|
|
1314
|
+
* @param {string} mimeType - File mime type (e.g. 'application/pdf')
|
|
1315
|
+
* @param {string} prompt - Extraction instructions
|
|
1316
|
+
* @param {string} tenantId - Tenant ID
|
|
1317
|
+
* @param {Object} schema - Optional JSON schema
|
|
1318
|
+
* @param {Object} options - Options
|
|
1319
|
+
*/
|
|
1320
|
+
async extractWithLLM(fileData, mimeType, prompt, tenantId, schema = null, options = {}) {
|
|
1321
|
+
const provider = await this._getProvider(tenantId);
|
|
1322
|
+
if (!provider.extractWithLLM) {
|
|
1323
|
+
throw new LLMServiceException(`Provider ${provider.config.provider} does not support extractWithLLM (Multimodal extraction)`, 400);
|
|
1324
|
+
}
|
|
1325
|
+
return provider.extractWithLLM(fileData, mimeType, prompt, schema, options);
|
|
1326
|
+
}
|
|
1250
1327
|
};
|
|
1251
1328
|
var LLMServiceException = class extends Error {
|
|
1252
1329
|
constructor(message, statusCode = 500, details = null) {
|
|
@@ -1495,9 +1572,17 @@ var TranscriptionService = class {
|
|
|
1495
1572
|
const apiEndpoint = location === "global" ? "https://speech.googleapis.com" : `https://${location}-speech.googleapis.com`;
|
|
1496
1573
|
const url = `${apiEndpoint}/v2/${recognizer}:recognize`;
|
|
1497
1574
|
const languageCodes = language ? [language] : ["en-US"];
|
|
1575
|
+
let decodingConfig = { autoDecodingConfig: {} };
|
|
1576
|
+
if (audioFile.type && audioFile.type.includes("webm")) {
|
|
1577
|
+
decodingConfig = {
|
|
1578
|
+
explicitDecodingConfig: {
|
|
1579
|
+
encoding: "WEBM_OPUS"
|
|
1580
|
+
}
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1498
1583
|
const body = {
|
|
1499
1584
|
config: {
|
|
1500
|
-
|
|
1585
|
+
...decodingConfig,
|
|
1501
1586
|
languageCodes,
|
|
1502
1587
|
// Sanitize model: Strict allowlist for Google v2 models
|
|
1503
1588
|
model: model || "chirp_3"
|