@xuda.io/ai_module 1.1.4140 → 1.1.4142
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 +10 -7
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -4150,7 +4150,7 @@ export const delete_prompt_attachment = async function (req, job_id, headers, fi
|
|
|
4150
4150
|
};
|
|
4151
4151
|
|
|
4152
4152
|
export const submit_chat_gpt_prompt = async function (req) {
|
|
4153
|
-
const { model = 'gpt-5-nano', prompt, response_format, uid, metadata = {} } = req; //'gpt-5-mini
|
|
4153
|
+
const { model = 'gpt-5-nano', prompt, response_format, uid, metadata = {}, account_profile_info } = req; //'gpt-5-mini
|
|
4154
4154
|
|
|
4155
4155
|
let formattedParams;
|
|
4156
4156
|
if (response_format) {
|
|
@@ -4165,7 +4165,7 @@ export const submit_chat_gpt_prompt = async function (req) {
|
|
|
4165
4165
|
format: formattedParams,
|
|
4166
4166
|
},
|
|
4167
4167
|
});
|
|
4168
|
-
record_chat_usage(uid, response.usage.input_tokens, response.usage.output_tokens, 'submit chat', prompt, model, metadata);
|
|
4168
|
+
record_chat_usage(uid, response.usage.input_tokens, response.usage.output_tokens, 'submit chat', prompt, model, metadata, account_profile_info);
|
|
4169
4169
|
return { code: 5, data: response.output_text };
|
|
4170
4170
|
} catch (err) {
|
|
4171
4171
|
return { code: -5, data: err.message };
|
|
@@ -4251,10 +4251,10 @@ export const create_conversation = async function (req, job_id, headers) {
|
|
|
4251
4251
|
receiver_conversation_doc.chat_image = sender_conversation_doc.chat_image;
|
|
4252
4252
|
await db_module.save_app_couch_doc_native(receiver_app_id, receiver_conversation_doc);
|
|
4253
4253
|
|
|
4254
|
-
await update_conversation_mood_level(conversation_obj.id, prompt, uid, contact_uid_chat_conversation, true);
|
|
4254
|
+
await update_conversation_mood_level(conversation_obj.id, prompt, uid, contact_uid_chat_conversation, true, account_profile_info);
|
|
4255
4255
|
} else {
|
|
4256
4256
|
// other cases rather then chat
|
|
4257
|
-
await update_conversation_mood_level(conversation_obj.id, prompt, null, receiver_contact_doc.contact_uid, conversation_doc.reference_type === 'contacts');
|
|
4257
|
+
await update_conversation_mood_level(conversation_obj.id, prompt, null, receiver_contact_doc.contact_uid, conversation_doc.reference_type === 'contacts', account_profile_info);
|
|
4258
4258
|
}
|
|
4259
4259
|
}
|
|
4260
4260
|
}, 1000);
|
|
@@ -4342,7 +4342,7 @@ export const submit_chat_conversation = async function (req, job_id, headers) {
|
|
|
4342
4342
|
}
|
|
4343
4343
|
};
|
|
4344
4344
|
|
|
4345
|
-
const update_conversation_mood_level = async function (conversation_id, prompt, sender_uid, receiver_uid, update_contact) {
|
|
4345
|
+
const update_conversation_mood_level = async function (conversation_id, prompt, sender_uid, receiver_uid, update_contact, account_profile_info) {
|
|
4346
4346
|
try {
|
|
4347
4347
|
// analyze the mood of the conversation
|
|
4348
4348
|
const mood_level = await submit_chat_gpt_prompt({
|
|
@@ -4353,6 +4353,7 @@ const update_conversation_mood_level = async function (conversation_id, prompt,
|
|
|
4353
4353
|
mood_level: z.number().describe('mood level of interaction: -2: very negative,-1: negative 0:natural 1:positive 2: very positive'),
|
|
4354
4354
|
}),
|
|
4355
4355
|
metadata: { conversation_id, func: 'update_conversation_mood_level' },
|
|
4356
|
+
account_profile_info,
|
|
4356
4357
|
});
|
|
4357
4358
|
|
|
4358
4359
|
const mood_level_obj = JSON5.parse(mood_level.data);
|
|
@@ -6310,8 +6311,9 @@ const create_ai_agent_image = async function (req, job_id, headers) {
|
|
|
6310
6311
|
}
|
|
6311
6312
|
};
|
|
6312
6313
|
|
|
6313
|
-
const record_chat_usage = async function (uid, input_tokens, output_tokens, source, prompt, model, metadata = {}) {
|
|
6314
|
+
const record_chat_usage = async function (uid, input_tokens, output_tokens, source, prompt, model, metadata = {}, account_profile_info) {
|
|
6314
6315
|
try {
|
|
6316
|
+
if (!account_profile_info) throw new Error('missing account_profile_info');
|
|
6315
6317
|
const app_id = await account_module.get_account_default_project_id(uid);
|
|
6316
6318
|
|
|
6317
6319
|
const cost = _conf?.ai_models?.[model] || {
|
|
@@ -6333,8 +6335,9 @@ const record_chat_usage = async function (uid, input_tokens, output_tokens, sour
|
|
|
6333
6335
|
metadata,
|
|
6334
6336
|
model,
|
|
6335
6337
|
cost,
|
|
6338
|
+
account_profile_info,
|
|
6336
6339
|
};
|
|
6337
|
-
const save_ret = await db_module.save_app_couch_doc(app_id, usage_doc);
|
|
6340
|
+
const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, usage_doc);
|
|
6338
6341
|
// console.log(save_ret);
|
|
6339
6342
|
} catch (err) {
|
|
6340
6343
|
console.error(err);
|