@xuda.io/ai_module 1.1.5526 → 1.1.5528
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 +12 -129
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -3855,8 +3855,9 @@ const contact_chat_conversation = async function (req, job_id, headers) {
|
|
|
3855
3855
|
const sender_app_id = account_profile_info.app_id;
|
|
3856
3856
|
let sender_conversation_doc = await db_module.get_app_couch_doc_native(sender_app_id, conversation_id);
|
|
3857
3857
|
|
|
3858
|
+
let
|
|
3858
3859
|
try {
|
|
3859
|
-
|
|
3860
|
+
const conversation_item_reference_id=await add_conversation_item(uid, profile_id, conversation_id, prompt, 'chat', conversation_doc.reference_id, { direction: 'out' });
|
|
3860
3861
|
|
|
3861
3862
|
report_ai_status('conversations');
|
|
3862
3863
|
} catch (err) {
|
|
@@ -3880,7 +3881,7 @@ const contact_chat_conversation = async function (req, job_id, headers) {
|
|
|
3880
3881
|
conversation_id,
|
|
3881
3882
|
text: body,
|
|
3882
3883
|
reference_id: conversation_doc.reference_id,
|
|
3883
|
-
conversation_item_reference_id
|
|
3884
|
+
conversation_item_reference_id,
|
|
3884
3885
|
direction: 'out',
|
|
3885
3886
|
role: 'user',
|
|
3886
3887
|
};
|
|
@@ -4023,24 +4024,15 @@ const chat_email = async function (req, job_id, headers) {
|
|
|
4023
4024
|
}
|
|
4024
4025
|
let item;
|
|
4025
4026
|
try {
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
{
|
|
4029
|
-
type: 'message',
|
|
4030
|
-
role: 'user',
|
|
4031
|
-
content: [{ type: 'input_text', text: body || '' }],
|
|
4032
|
-
},
|
|
4033
|
-
],
|
|
4034
|
-
});
|
|
4027
|
+
add_conversation_item(uid, profile_id, conversation_id, body, 'email', conversation_doc.reference_id, { direction });
|
|
4028
|
+
|
|
4035
4029
|
report_ai_status('conversations');
|
|
4036
4030
|
} catch (err) {
|
|
4037
4031
|
report_ai_status('conversations', err);
|
|
4038
4032
|
throw err;
|
|
4039
4033
|
}
|
|
4040
4034
|
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
// sender_conversation_doc.messages.push(obj);
|
|
4035
|
+
|
|
4044
4036
|
await db_module.save_app_couch_doc_native(sender_app_id, sender_conversation_doc);
|
|
4045
4037
|
|
|
4046
4038
|
let out_conversation_item_obj = {
|
|
@@ -5129,8 +5121,9 @@ const add_conversation_item = async function (uid, profile_id, conversation_id,
|
|
|
5129
5121
|
},
|
|
5130
5122
|
];
|
|
5131
5123
|
|
|
5124
|
+
let item
|
|
5132
5125
|
try {
|
|
5133
|
-
|
|
5126
|
+
item = await client.conversations.items.create(conversation_doc.reference_conversation_id, {
|
|
5134
5127
|
items,
|
|
5135
5128
|
});
|
|
5136
5129
|
} catch (err) {
|
|
@@ -5146,6 +5139,8 @@ const add_conversation_item = async function (uid, profile_id, conversation_id,
|
|
|
5146
5139
|
throw err;
|
|
5147
5140
|
}
|
|
5148
5141
|
}
|
|
5142
|
+
|
|
5143
|
+
return item.data[0].id
|
|
5149
5144
|
} catch (err) {
|
|
5150
5145
|
throw err;
|
|
5151
5146
|
}
|
|
@@ -6648,15 +6643,8 @@ export const get_transcript = async function (uid, app_id, conversation_id, acco
|
|
|
6648
6643
|
|
|
6649
6644
|
export const add_transcript_conversation_item = async function (reference_conversation_id, filename, transcript) {
|
|
6650
6645
|
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
|
-
});
|
|
6646
|
+
add_conversation_item(uid, profile_id, conversation_id, `File name: ${filename} with content: ${transcript?.data || transcript || ''}`, 'attachment', conversation_doc.reference_id, {});
|
|
6647
|
+
|
|
6660
6648
|
report_ai_status('conversations');
|
|
6661
6649
|
return items;
|
|
6662
6650
|
} catch (err) {
|
|
@@ -6669,111 +6657,6 @@ const attachment_handler = async function (uid, app_id, conversation_id, attachm
|
|
|
6669
6657
|
if (!attachments?.length) return;
|
|
6670
6658
|
let conversation_doc = await db_module.get_app_couch_doc_native(app_id, conversation_id);
|
|
6671
6659
|
|
|
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
6660
|
// let file_names = [];
|
|
6778
6661
|
let process_stat = 'full';
|
|
6779
6662
|
let system_message_items = [];
|