goblin-agents 2.2.3 → 2.3.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.
@@ -183,6 +183,8 @@ const defaultValues = {
183
183
 
184
184
  class AiAgentLogic extends Elf.Archetype {
185
185
  static db = 'agents';
186
+ static indices = ['role'];
187
+
186
188
  state = new AiAgentState({
187
189
  id: undefined,
188
190
  version: 1,
@@ -433,13 +435,13 @@ class AiAgent extends Elf {
433
435
  }
434
436
  }
435
437
 
436
- async readPDFpages(pdfPath) {
438
+ async readPDFpages(pdfPath, pages) {
437
439
  await this._mutex.lock(this.id);
438
440
  this.quest.defer(() => this._mutex.unlock(this.id));
439
441
 
440
442
  await this._loadProvider();
441
443
 
442
- const images = await getPDFImages(pdfPath);
444
+ const images = await getPDFImages(pdfPath, pages);
443
445
  const descriptions = [];
444
446
  for (const image of images) {
445
447
  const messages = [
@@ -448,7 +450,7 @@ class AiAgent extends Elf {
448
450
  content: [
449
451
  {
450
452
  type: 'text',
451
- text: OCR_SYSTEM_PROMPT,
453
+ text: this.state.prompt || OCR_SYSTEM_PROMPT,
452
454
  },
453
455
  {
454
456
  type: 'image_url',
@@ -469,6 +471,37 @@ class AiAgent extends Elf {
469
471
  return descriptions;
470
472
  }
471
473
 
474
+ async vision(context, image) {
475
+ await this._mutex.lock(this.id);
476
+ this.quest.defer(() => this._mutex.unlock(this.id));
477
+
478
+ await this._loadProvider();
479
+ const messages = [
480
+ {role: 'system', content: this.state.prompt},
481
+ {
482
+ role: 'user',
483
+ content: [
484
+ {
485
+ type: 'image_url',
486
+ image_url: {
487
+ url: image,
488
+ },
489
+ },
490
+ {
491
+ type: 'text',
492
+ text: context,
493
+ },
494
+ ],
495
+ },
496
+ ];
497
+ const result = await this._provider.chat({
498
+ model: this.state.model,
499
+ reasoning: this.state.reasoning,
500
+ messages,
501
+ });
502
+ return result.message.content;
503
+ }
504
+
472
505
  async embed(rawText) {
473
506
  if (!rawText) {
474
507
  return null;
@@ -522,7 +555,7 @@ class AiAgent extends Elf {
522
555
  await this._loadProvider();
523
556
  const contextMessages = this.state.messages[contextId] || [];
524
557
  const messages = [
525
- {role: 'system', content: this.state.prompt},
558
+ {role: 'system', content: this.state.prompt || ''},
526
559
  ...Array.from(contextMessages).map((m) => m._state.toJS()), //history
527
560
  ];
528
561
 
package/lib/llm/utils.js CHANGED
@@ -24,7 +24,7 @@ Ignore les artefacts visuels inutiles.
24
24
  Corrige les erreurs évidentes et restitue un texte propre et fidèle à l'original.
25
25
  Ta réponse contient uniquement le texte lisible.`;
26
26
 
27
- const getPDFImages = async (pdfPath) => {
27
+ const getPDFImages = async (pdfPath, pagesToProcess) => {
28
28
  const {pdfToPng} = loadPdfToPngConverter();
29
29
  // The function accepts PDF file path or a Buffer
30
30
  const pages = await pdfToPng(pdfPath, {
@@ -35,7 +35,7 @@ const getPDFImages = async (pdfPath) => {
35
35
  //outputFolder: 'output/folder', // Folder to write output PNG files. If not specified, PNG output will be available only as a Buffer content, without saving to a file.
36
36
  //outputFileMaskFunc: (pageNumber) => `page_${pageNumber}.png`, // Output filename mask function. Example: (pageNumber) => `page_${pageNumber}.png`
37
37
  //pdfFilePassword: password, // Password for encrypted PDF.
38
- //pagesToProcess: [1, 3, 11], // Subset of pages to convert (first page = 1), other pages will be skipped if specified.
38
+ pagesToProcess, // Subset of pages to convert (first page = 1), other pages will be skipped if specified.
39
39
  //strictPagesToProcess: false, // When `true`, will throw an error if specified page number in pagesToProcess is invalid, otherwise will skip invalid page. Default value is false.
40
40
  verbosityLevel: 0, // Verbosity level. ERRORS: 0, WARNINGS: 1, INFOS: 5. Default value is 0.
41
41
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goblin-agents",
3
- "version": "2.2.3",
3
+ "version": "2.3.0",
4
4
  "description": "AI Agents framework",
5
5
  "author": "Epsitec SA",
6
6
  "contributors": [