@xuda.io/ai_module 1.1.4828 → 1.1.4829

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/old.mjs +226 -4
  2. package/package.json +1 -1
package/old.mjs CHANGED
@@ -4789,11 +4789,8 @@ for await (let account_profile of profile_requests_from_res.docs) {
4789
4789
  // return normalizedBuffer.toString('base64'); // Return normalized base64 string
4790
4790
  // }
4791
4791
 
4792
-
4793
4792
  /////////////////////
4794
4793
 
4795
-
4796
-
4797
4794
  // export const submit_agentic_studio_chat_gpt_prompt = async function (req) {
4798
4795
  // try {
4799
4796
  // const { user_prompt, object_unit = 'app', uid, app_id } = req;
@@ -5442,4 +5439,229 @@ for await (let account_profile of profile_requests_from_res.docs) {
5442
5439
  // } catch (err) {
5443
5440
  // return { code: -15, data: err.message };
5444
5441
  // }
5445
- // };
5442
+ // };
5443
+
5444
+ ////////////////////////////
5445
+
5446
+ // export const upload_prompt_attachment2 = async function (req, job_id, headers, file_obj) {
5447
+ // try {
5448
+ // if (!file_obj?.['originalname']) {
5449
+ // throw new Error('file data missing');
5450
+ // }
5451
+
5452
+ // const file_name = file_obj?.['originalname'];
5453
+
5454
+ // const validation_ret = file_upload_validator(file_name);
5455
+
5456
+ // if (!validation_ret.valid) {
5457
+ // throw new Error(validation_ret.error);
5458
+ // }
5459
+
5460
+ // const tempPath = file_obj.path;
5461
+
5462
+ // // Create the stream from the temp path
5463
+ // const fileStream = fs.createReadStream(tempPath);
5464
+ // let file;
5465
+ // let transcript;
5466
+ // switch (validation_ret.category) {
5467
+ // case 'audio':
5468
+ // case 'video': {
5469
+ // transcript = await transcribe(fileStream);
5470
+ // file = new File([Buffer.from(transcript, 'utf8')], file_name, {
5471
+ // type: 'text/plain',
5472
+ // });
5473
+
5474
+ // break;
5475
+ // }
5476
+
5477
+ // case 'image': {
5478
+ // const base64Image = encodeImage(tempPath);
5479
+ // const ret = await submit_chat_gpt_prompt({
5480
+ // prompt: [
5481
+ // {
5482
+ // role: 'user',
5483
+ // content: [
5484
+ // {
5485
+ // type: 'input_text',
5486
+ // text: `1. describe the image in detail. 2. Extract the text from this image into a clean markdown format `,
5487
+ // },
5488
+ // {
5489
+ // type: 'input_image',
5490
+ // image_url: `data:${validation_ret.mime};base64,${base64Image}`,
5491
+ // },
5492
+ // ],
5493
+ // },
5494
+ // ],
5495
+ // });
5496
+ // if (ret.code < 0) {
5497
+ // throw new Error('something went wrong try again later');
5498
+ // }
5499
+ // transcript = ret.data;
5500
+ // file = new File([Buffer.from(transcript, 'utf8')], file_name + '.txt', {
5501
+ // type: 'text/plain',
5502
+ // });
5503
+
5504
+ // break;
5505
+ // }
5506
+
5507
+ // case 'document':
5508
+ // case 'text': {
5509
+ // // async function streamToText(stream) {
5510
+ // // const chunks = [];
5511
+ // // for await (const chunk of stream) {
5512
+ // // chunks.push(chunk);
5513
+ // // }
5514
+ // // return Buffer.concat(chunks).toString('utf8');
5515
+ // // }
5516
+
5517
+ // // async function transcript_file(Buffer, fileName) {
5518
+ // // try {
5519
+ // // const ret = await submit_chat_gpt_prompt({
5520
+ // // prompt: [
5521
+ // // {
5522
+ // // role: 'user',
5523
+ // // content: [
5524
+ // // {
5525
+ // // type: 'input_text',
5526
+ // // text: 'Please extract all text from this document. Maintain the structure and formatting as much as possible.',
5527
+ // // },
5528
+ // // {
5529
+ // // type: 'input_file',
5530
+ // // source: {
5531
+ // // type: 'base64',
5532
+ // // // media_type: validation_ret.mime,
5533
+ // // // data: Buffer.toString('base64'),
5534
+ // // url: `data:${validation_ret.mime};base64,${Buffer.toString('base64')}`,
5535
+ // // },
5536
+ // // },
5537
+ // // ],
5538
+ // // },
5539
+ // // ],
5540
+ // // });
5541
+ // // debugger;
5542
+ // // return ret;
5543
+ // // } catch (error) {
5544
+ // // console.error('Error transcribing PDF:', error);
5545
+ // // throw error;
5546
+ // // }
5547
+ // // }
5548
+
5549
+ // // // file = await toFile(fileStream, file_name);
5550
+ // // // transcript = await streamToText(fileStream);
5551
+
5552
+ // async function streamToBuffer(fileStream) {
5553
+ // const chunks = [];
5554
+ // for await (const chunk of fileStream) {
5555
+ // chunks.push(chunk);
5556
+ // }
5557
+ // return Buffer.concat(chunks);
5558
+ // }
5559
+ // // transcript = await transcript_file(await streamToBuffer(fileStream));
5560
+
5561
+ // // async function transcript_file(fileBuffer, fileName) {
5562
+ // // try {
5563
+ // // const ret = await submit_chat_gpt_prompt({
5564
+ // // prompt: [
5565
+ // // {
5566
+ // // role: 'user',
5567
+ // // content: [
5568
+ // // {
5569
+ // // type: 'input_text',
5570
+ // // text: 'Please extract all text from this document. Maintain the structure and formatting as much as possible.',
5571
+ // // },
5572
+ // // {
5573
+ // // type: 'input_file',
5574
+ // // // FIX: Flattened structure. Do NOT use 'source'.
5575
+ // // // Place these properties directly at the content item level.
5576
+ // // media_type: validation_ret.mime,
5577
+ // // data: fileBuffer.toString('base64'),
5578
+ // // },
5579
+ // // ],
5580
+ // // },
5581
+ // // ],
5582
+ // // });
5583
+ // // debugger;
5584
+ // // return ret;
5585
+ // // } catch (error) {
5586
+ // // console.error('Error transcribing PDF:', error);
5587
+ // // throw error;
5588
+ // // }
5589
+ // // }
5590
+
5591
+ // // // Helper to convert stream to buffer
5592
+ // // async function streamToBuffer(fileStream) {
5593
+ // // const chunks = [];
5594
+ // // for await (const chunk of fileStream) {
5595
+ // // chunks.push(chunk);
5596
+ // // }
5597
+ // // return Buffer.concat(chunks);
5598
+ // // }
5599
+
5600
+ // // // Execution
5601
+ // // // Note: This consumes the stream completely.
5602
+ // // // If you uncomment 'toFile' later, you must use the PassThrough logic discussed previously.
5603
+ // // const buffer = await streamToBuffer(fileStream);
5604
+ // // transcript = await transcript_file(buffer);
5605
+
5606
+ // async function transcript_file(fileBuffer, fileName, mimeType) {
5607
+ // try {
5608
+ // const base64 = fileBuffer.toString('base64');
5609
+
5610
+ // const ret = await submit_chat_gpt_prompt({
5611
+ // // assuming your wrapper maps this to `input` for responses.create
5612
+ // prompt: [
5613
+ // {
5614
+ // role: 'user',
5615
+ // content: [
5616
+ // {
5617
+ // type: 'input_text',
5618
+ // text: 'Please extract all text from this document. Maintain the structure and formatting as much as possible.',
5619
+ // },
5620
+ // {
5621
+ // type: 'input_file',
5622
+ // filename: fileName || 'document.pdf',
5623
+ // // IMPORTANT: file_data is a *data URI* with mime type + base64
5624
+ // file_data: `data:${mimeType || 'application/pdf'};base64,${base64}`,
5625
+ // },
5626
+ // ],
5627
+ // },
5628
+ // ],
5629
+ // });
5630
+
5631
+ // debugger;
5632
+ // return ret;
5633
+ // } catch (error) {
5634
+ // console.error('Error transcribing PDF:', error);
5635
+ // throw error;
5636
+ // }
5637
+ // }
5638
+ // const buffer = await streamToBuffer(fileStream);
5639
+ // transcript = await transcript_file(buffer, file_name, validation_ret.mime);
5640
+
5641
+ // break;
5642
+ // }
5643
+
5644
+ // default:
5645
+ // break;
5646
+ // }
5647
+
5648
+ // // // Convert stream to an OpenAI-friendly file object with the specific name
5649
+ // // const convertedFile = await toFile(fileStream, file_name);
5650
+
5651
+ // // const uploadedFile = await client.files.create({
5652
+ // // file,
5653
+ // // purpose: 'assistants',
5654
+ // // });
5655
+
5656
+ // // const vector_ret = await client.vectorStores.files.create(_conf.OPENAI_VECTOR_STORE_ID, {
5657
+ // // file_id: uploadedFile.id,
5658
+ // // });
5659
+
5660
+ // // return { code: 1, data: { id: vector_ret.id, vector_store_id: vector_ret.vector_store_id, file_name: file_name, transcript } };
5661
+ // return { code: 1, data: { file_name: file_name, transcript } };
5662
+ // } catch (err) {
5663
+ // // It is good practice to log the specific error for debugging
5664
+ // console.error('Upload Error:', err);
5665
+ // return { code: -1, data: err.message };
5666
+ // }
5667
+ // };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4828",
3
+ "version": "1.1.4829",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",