@xuda.io/ai_module 1.1.4997 → 1.1.4999
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 +16 -15
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -70,6 +70,7 @@ const email_ms = await import(`${module_path}/email_module/index_ms.mjs`);
|
|
|
70
70
|
|
|
71
71
|
const ws_dashboard_msa = await import(`${module_path}/ws_dashboard_module/index_msa.mjs`);
|
|
72
72
|
const account_msa = await import(`${module_path}/account_module/index_msa.mjs`);
|
|
73
|
+
const drive_msa = await import(`${module_path}/drive_module/index_msa.mjs`);
|
|
73
74
|
|
|
74
75
|
var open_ai_status = {};
|
|
75
76
|
const report_ai_status = function (model, err) {
|
|
@@ -1404,7 +1405,7 @@ export const delete_ai_chat = async function (req) {
|
|
|
1404
1405
|
}
|
|
1405
1406
|
|
|
1406
1407
|
if (conversation_doc?.chat_image?.[0]) {
|
|
1407
|
-
|
|
1408
|
+
drive_msa.delete_drive_files({ uid, drive_type: 'user', files_arr: [{ type: 'file', file_path: path.join(conversation_doc.chat_image[0].file_path, conversation_doc.chat_image[0].filename) }] });
|
|
1408
1409
|
}
|
|
1409
1410
|
}
|
|
1410
1411
|
|
|
@@ -1525,7 +1526,7 @@ const create_image = async function (uid, prompt, model = 'gpt-image-1-mini', si
|
|
|
1525
1526
|
|
|
1526
1527
|
const thumbnailBase64 = resized.toString('base64');
|
|
1527
1528
|
|
|
1528
|
-
|
|
1529
|
+
account_msa.record_ai_usage(uid, response.usage.input_tokens, response.usage.output_tokens, 'create image', prompt, model, metadata, account_profile_info);
|
|
1529
1530
|
|
|
1530
1531
|
return thumbnailBase64;
|
|
1531
1532
|
} catch (err) {
|
|
@@ -2887,7 +2888,7 @@ export const update_thumbnail = async function (type, doc, app_id, uid, job_id,
|
|
|
2887
2888
|
images_arr = [cache];
|
|
2888
2889
|
if (!cache) {
|
|
2889
2890
|
images_arr = await create_and_upload_image_to_drive('user', 'Chat Thumbnails', doc._id, prompt, 1, uid, app_id, job_id, headers, true, tags, account_profile_info);
|
|
2890
|
-
|
|
2891
|
+
account_msa.save_xuda_cache(uid, 'chat_thumbnail', doc.title, images_arr[0], { tags });
|
|
2891
2892
|
}
|
|
2892
2893
|
db_doc = await get_db_doc();
|
|
2893
2894
|
db_doc.thumbnail_request_ts = Date.now();
|
|
@@ -2906,7 +2907,7 @@ export const update_thumbnail = async function (type, doc, app_id, uid, job_id,
|
|
|
2906
2907
|
images_arr = [cache];
|
|
2907
2908
|
if (!cache) {
|
|
2908
2909
|
images_arr = await create_and_upload_image_to_drive('user', 'Chat Thumbnails', doc._id, prompt, 1, uid, app_id, job_id, headers, true, tags, account_profile_info);
|
|
2909
|
-
|
|
2910
|
+
account_msa.save_xuda_cache(uid, 'chat_thumbnail', doc.category_info.category, images_arr[0], { tags });
|
|
2910
2911
|
}
|
|
2911
2912
|
db_doc = await get_db_doc();
|
|
2912
2913
|
db_doc.thumbnail_request_ts = Date.now();
|
|
@@ -3044,7 +3045,7 @@ const transcribe = async function (uid, stream, metadata, account_profile_info)
|
|
|
3044
3045
|
// temperature: 0 // lower = more literal
|
|
3045
3046
|
});
|
|
3046
3047
|
report_ai_status(model);
|
|
3047
|
-
|
|
3048
|
+
account_msa.record_ai_usage(uid, 0, resp.length || 0, 'transcribe', '', model, metadata, account_profile_info);
|
|
3048
3049
|
// console.log(resp); // or resp for JSON formats
|
|
3049
3050
|
return resp;
|
|
3050
3051
|
} catch (err) {
|
|
@@ -3364,7 +3365,7 @@ export const submit_chat_gpt_prompt = async function (req) {
|
|
|
3364
3365
|
report_ai_status(model, err);
|
|
3365
3366
|
throw err;
|
|
3366
3367
|
}
|
|
3367
|
-
|
|
3368
|
+
account_msa.record_ai_usage(uid, response.usage.input_tokens, response.usage.output_tokens, 'submit chat', prompt, model, metadata, account_profile_info, tools);
|
|
3368
3369
|
return { code: 5, data: response.output_text };
|
|
3369
3370
|
} catch (err) {
|
|
3370
3371
|
return { code: -5, data: err.message };
|
|
@@ -3605,7 +3606,7 @@ export const submit_chat_conversation = async function (req, job_id, headers) {
|
|
|
3605
3606
|
if (conversation_doc.reference_type === 'contacts') {
|
|
3606
3607
|
req._thread_reentry = Date.now() - conversation_doc.date_created_ts > 60000;
|
|
3607
3608
|
|
|
3608
|
-
|
|
3609
|
+
account_msa.ts_contact(uid, conversation_doc.reference_id);
|
|
3609
3610
|
|
|
3610
3611
|
switch (conversation_doc.conversation_type) {
|
|
3611
3612
|
case 'note': {
|
|
@@ -4636,7 +4637,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
|
|
|
4636
4637
|
out_conversation_item_doc.conversation_item_reference_id = conversation_items?.data?.[0]?.id;
|
|
4637
4638
|
await db_module.save_app_couch_doc_native(account_profile_info.app_id, out_conversation_item_doc);
|
|
4638
4639
|
|
|
4639
|
-
|
|
4640
|
+
account_msa.record_ai_usage(uid, inputTokens, outputTokens, 'conversation chat', prompt, model, { conversation_id, ai_agent_id: in_conversation_item_obj.ai_agent_id, item_id: in_conversation_item_obj._id }, account_profile_info);
|
|
4640
4641
|
// if (!conversation_doc.chat_image && (!conversation_doc.thumbnail_request_ts || Date.now() - conversation_doc.thumbnail_request_ts > 120000)) {
|
|
4641
4642
|
// update_thumbnail('conversation', conversation_doc, app_id, uid, job_id, headers);
|
|
4642
4643
|
// }
|
|
@@ -5213,7 +5214,7 @@ export const get_profile_avatar = async function (profile_picture, uid, prompt,
|
|
|
5213
5214
|
throw err;
|
|
5214
5215
|
}
|
|
5215
5216
|
imageBase64 = ai_avatar_response.data[0].b64_json;
|
|
5216
|
-
|
|
5217
|
+
account_msa.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
|
|
5217
5218
|
} else {
|
|
5218
5219
|
imageBase64 = Buffer.from(await image_blob_ret.image_blob.arrayBuffer()).toString('base64');
|
|
5219
5220
|
if (account_type === 'business') {
|
|
@@ -5305,7 +5306,7 @@ export const get_profile_avatar = async function (profile_picture, uid, prompt,
|
|
|
5305
5306
|
// The background should be fully removed, remove trees,clouds,sky or any landscape objects`,
|
|
5306
5307
|
// background: 'transparent',
|
|
5307
5308
|
// });
|
|
5308
|
-
//
|
|
5309
|
+
// account_msa.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
|
|
5309
5310
|
// imageBase64 = ai_avatar_response.data[0].b64_json;
|
|
5310
5311
|
if (is_user) {
|
|
5311
5312
|
if (business_has_person) {
|
|
@@ -5332,7 +5333,7 @@ export const get_profile_avatar = async function (profile_picture, uid, prompt,
|
|
|
5332
5333
|
report_ai_status(model, err);
|
|
5333
5334
|
throw err;
|
|
5334
5335
|
}
|
|
5335
|
-
|
|
5336
|
+
account_msa.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
|
|
5336
5337
|
imageBase64 = ai_avatar_response.data[0].b64_json;
|
|
5337
5338
|
}
|
|
5338
5339
|
} else {
|
|
@@ -5404,7 +5405,7 @@ export const get_profile_avatar = async function (profile_picture, uid, prompt,
|
|
|
5404
5405
|
report_ai_status(model, err);
|
|
5405
5406
|
throw err;
|
|
5406
5407
|
}
|
|
5407
|
-
|
|
5408
|
+
account_msa.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'profile avatar', prompt, model, { profile_picture }, account_profile_info);
|
|
5408
5409
|
imageBase64 = ai_avatar_response.data[0].b64_json;
|
|
5409
5410
|
avatar_source = 'ai profile';
|
|
5410
5411
|
};
|
|
@@ -5627,7 +5628,7 @@ export const get_profile_picture = async function (uid, account_type = 'business
|
|
|
5627
5628
|
}
|
|
5628
5629
|
|
|
5629
5630
|
imageBase64 = await normalizeBase64To1024(image_response.data[0].b64_json, resize);
|
|
5630
|
-
|
|
5631
|
+
account_msa.record_ai_usage(uid, image_response.usage.input_tokens, image_response.usage.output_tokens, 'profile image', prompt, model, { url }, account_profile_info);
|
|
5631
5632
|
}
|
|
5632
5633
|
|
|
5633
5634
|
const outputBuffer = Buffer.from(imageBase64, 'base64');
|
|
@@ -5943,7 +5944,7 @@ const create_ai_agent_image = async function (req, job_id, headers) {
|
|
|
5943
5944
|
throw err;
|
|
5944
5945
|
}
|
|
5945
5946
|
imageBase64 = ai_avatar_response.data[0].b64_json;
|
|
5946
|
-
|
|
5947
|
+
account_msa.record_ai_usage(uid, ai_avatar_response.usage.input_tokens, ai_avatar_response.usage.output_tokens, 'agent avatar', prompt, model, { ai_agent_id }, account_profile_info);
|
|
5947
5948
|
console.log('Normalizing final avatar to 1024 with transparent padding...');
|
|
5948
5949
|
imageBase64 = await normalizeBase64To1024(imageBase64);
|
|
5949
5950
|
|
|
@@ -6615,7 +6616,7 @@ const get_chat_picture_cache = async function (uid, docType, key) {
|
|
|
6615
6616
|
const ret = await db_module.find_couch_query('xuda_cache', query);
|
|
6616
6617
|
|
|
6617
6618
|
if (ret.docs.length > 0) {
|
|
6618
|
-
|
|
6619
|
+
account_msa.save_cache_hit(ret.docs[0]._id);
|
|
6619
6620
|
return ret.docs[0].file;
|
|
6620
6621
|
}
|
|
6621
6622
|
}
|