@xuda.io/ai_module 1.1.5526 → 1.1.5527
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/index.mjs +4 -123
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -4023,15 +4023,8 @@ const chat_email = async function (req, job_id, headers) {
|
|
|
4023
4023
|
}
|
|
4024
4024
|
let item;
|
|
4025
4025
|
try {
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
{
|
|
4029
|
-
type: 'message',
|
|
4030
|
-
role: 'user',
|
|
4031
|
-
content: [{ type: 'input_text', text: body || '' }],
|
|
4032
|
-
},
|
|
4033
|
-
],
|
|
4034
|
-
});
|
|
4026
|
+
add_conversation_item(uid, profile_id, conversation_id, body, 'email', conversation_doc.reference_id, { direction });
|
|
4027
|
+
|
|
4035
4028
|
report_ai_status('conversations');
|
|
4036
4029
|
} catch (err) {
|
|
4037
4030
|
report_ai_status('conversations', err);
|
|
@@ -6648,15 +6641,8 @@ export const get_transcript = async function (uid, app_id, conversation_id, acco
|
|
|
6648
6641
|
|
|
6649
6642
|
export const add_transcript_conversation_item = async function (reference_conversation_id, filename, transcript) {
|
|
6650
6643
|
try {
|
|
6651
|
-
|
|
6652
|
-
|
|
6653
|
-
{
|
|
6654
|
-
type: 'message',
|
|
6655
|
-
role: 'system',
|
|
6656
|
-
content: [{ type: 'input_text', text: `the user attached file name: ${filename} with content: ${transcript?.data || transcript || ''}` }],
|
|
6657
|
-
},
|
|
6658
|
-
],
|
|
6659
|
-
});
|
|
6644
|
+
add_conversation_item(uid, profile_id, conversation_id, `File name: ${filename} with content: ${transcript?.data || transcript || ''}`, 'attachment', conversation_doc.reference_id, {});
|
|
6645
|
+
|
|
6660
6646
|
report_ai_status('conversations');
|
|
6661
6647
|
return items;
|
|
6662
6648
|
} catch (err) {
|
|
@@ -6669,111 +6655,6 @@ const attachment_handler = async function (uid, app_id, conversation_id, attachm
|
|
|
6669
6655
|
if (!attachments?.length) return;
|
|
6670
6656
|
let conversation_doc = await db_module.get_app_couch_doc_native(app_id, conversation_id);
|
|
6671
6657
|
|
|
6672
|
-
// const get_transcript = async function (filename) {
|
|
6673
|
-
// async function streamToBuffer(fileStream) {
|
|
6674
|
-
// const chunks = [];
|
|
6675
|
-
// for await (const chunk of fileStream) {
|
|
6676
|
-
// chunks.push(chunk);
|
|
6677
|
-
// }
|
|
6678
|
-
// return Buffer.concat(chunks);
|
|
6679
|
-
// }
|
|
6680
|
-
|
|
6681
|
-
// const validation_ret = await drive_ms.file_upload_validator(filename);
|
|
6682
|
-
// if (!validation_ret.valid) {
|
|
6683
|
-
// throw new Error(validation_ret.error);
|
|
6684
|
-
// }
|
|
6685
|
-
|
|
6686
|
-
// const fileStream = await get_drive_file_stream('user', app_id, uid, path.join('/', 'Chat Attachments', filename));
|
|
6687
|
-
|
|
6688
|
-
// let transcript;
|
|
6689
|
-
// switch (validation_ret.category) {
|
|
6690
|
-
// case 'audio':
|
|
6691
|
-
// case 'video': {
|
|
6692
|
-
// transcript = await transcribe(uid, fileStream, { conversation_id, func: 'attachment_handler - ' + validation_ret.category }, account_profile_info);
|
|
6693
|
-
|
|
6694
|
-
// break;
|
|
6695
|
-
// }
|
|
6696
|
-
|
|
6697
|
-
// case 'image': {
|
|
6698
|
-
// const fileBuffer = await streamToBuffer(fileStream);
|
|
6699
|
-
// const base64 = fileBuffer.toString('base64');
|
|
6700
|
-
|
|
6701
|
-
// const ret = await submit_chat_gpt_prompt({
|
|
6702
|
-
// uid,
|
|
6703
|
-
// prompt: [
|
|
6704
|
-
// {
|
|
6705
|
-
// role: 'user',
|
|
6706
|
-
// content: [
|
|
6707
|
-
// {
|
|
6708
|
-
// type: 'input_text',
|
|
6709
|
-
// text: `1. describe the image in detail. 2. Extract the text from this image into a clean markdown format `,
|
|
6710
|
-
// },
|
|
6711
|
-
// {
|
|
6712
|
-
// type: 'input_image',
|
|
6713
|
-
// image_url: `data:${validation_ret.mime};base64,${base64}`,
|
|
6714
|
-
// },
|
|
6715
|
-
// ],
|
|
6716
|
-
// },
|
|
6717
|
-
// ],
|
|
6718
|
-
// metadata: { conversation_id, func: 'attachment_handler' },
|
|
6719
|
-
// account_profile_info,
|
|
6720
|
-
// });
|
|
6721
|
-
// if (ret.code < 0) {
|
|
6722
|
-
// throw new Error('something went wrong try again later');
|
|
6723
|
-
// }
|
|
6724
|
-
// transcript = ret.data;
|
|
6725
|
-
|
|
6726
|
-
// break;
|
|
6727
|
-
// }
|
|
6728
|
-
|
|
6729
|
-
// case 'document':
|
|
6730
|
-
// case 'text': {
|
|
6731
|
-
// async function transcript_file(fileBuffer, fileName, mimeType) {
|
|
6732
|
-
// try {
|
|
6733
|
-
// const base64 = fileBuffer.toString('base64');
|
|
6734
|
-
|
|
6735
|
-
// const ret = await submit_chat_gpt_prompt({
|
|
6736
|
-
// uid,
|
|
6737
|
-
// prompt: [
|
|
6738
|
-
// {
|
|
6739
|
-
// role: 'user',
|
|
6740
|
-
// content: [
|
|
6741
|
-
// {
|
|
6742
|
-
// type: 'input_text',
|
|
6743
|
-
// text: 'extract all text from this document. Maintain the structure and formatting as much as possible.',
|
|
6744
|
-
// },
|
|
6745
|
-
// {
|
|
6746
|
-
// type: 'input_file',
|
|
6747
|
-
// filename: fileName || 'document.pdf',
|
|
6748
|
-
|
|
6749
|
-
// file_data: `data:${mimeType || 'application/pdf'};base64,${base64}`,
|
|
6750
|
-
// },
|
|
6751
|
-
// ],
|
|
6752
|
-
// },
|
|
6753
|
-
// ],
|
|
6754
|
-
// metadata: { conversation_id, func: 'attachment_handler' },
|
|
6755
|
-
// account_profile_info,
|
|
6756
|
-
// });
|
|
6757
|
-
|
|
6758
|
-
// return ret;
|
|
6759
|
-
// } catch (error) {
|
|
6760
|
-
// console.error('Error transcribing PDF:', error);
|
|
6761
|
-
// throw error;
|
|
6762
|
-
// }
|
|
6763
|
-
// }
|
|
6764
|
-
// const buffer = await streamToBuffer(fileStream);
|
|
6765
|
-
// transcript = await transcript_file(buffer, filename, validation_ret.mime);
|
|
6766
|
-
|
|
6767
|
-
// break;
|
|
6768
|
-
// }
|
|
6769
|
-
|
|
6770
|
-
// default:
|
|
6771
|
-
// break;
|
|
6772
|
-
// }
|
|
6773
|
-
|
|
6774
|
-
// return transcript;
|
|
6775
|
-
// };
|
|
6776
|
-
|
|
6777
6658
|
// let file_names = [];
|
|
6778
6659
|
let process_stat = 'full';
|
|
6779
6660
|
let system_message_items = [];
|