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