@xuda.io/ai_module 1.1.4139 → 1.1.4141

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.
Files changed (2) hide show
  1. package/index.mjs +10 -8
  2. 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 };
@@ -4227,12 +4227,12 @@ export const create_conversation = async function (req, job_id, headers) {
4227
4227
 
4228
4228
  setTimeout(async () => {
4229
4229
  // Ask GPT for title
4230
- const title = await submit_chat_gpt_prompt({ uid, prompt: `create title for the prompt return 5 words result maximum text only without options : ${prompt}`, model: 'gpt-5-nano', metadata: { conversation_id: conversation_doc._id, func: 'create_conversation' } });
4230
+ const title = await submit_chat_gpt_prompt({ uid, prompt: `create title for the prompt return 5 words result maximum text only without options : ${prompt}`, model: 'gpt-5-nano', metadata: { conversation_id: conversation_doc._id, func: 'create_conversation' }, account_profile_info });
4231
4231
 
4232
- conversation_doc = await db_module.get_app_couch_doc_native(app_id, conversation_obj.id);
4232
+ conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_obj.id);
4233
4233
  conversation_doc.title = title.data;
4234
4234
 
4235
- await db_module.save_app_couch_doc_native(app_id, conversation_doc);
4235
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
4236
4236
 
4237
4237
  await update_thumbnail('conversation', conversation_doc, app_id, uid, job_id, headers);
4238
4238
 
@@ -4241,7 +4241,7 @@ export const create_conversation = async function (req, job_id, headers) {
4241
4241
  // write conversation to host after thumbnail update
4242
4242
  // get sender conversation
4243
4243
 
4244
- const sender_conversation_doc = await db_module.get_app_couch_doc_native(app_id, conversation_obj.id);
4244
+ const sender_conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_obj.id);
4245
4245
  const receiver_app_id = await account_module.get_account_default_project_id(contact_uid_chat_conversation);
4246
4246
 
4247
4247
  let receiver_conversation_doc = await db_module.get_app_couch_doc_native(receiver_app_id, conversation_obj.id);
@@ -6310,8 +6310,9 @@ const create_ai_agent_image = async function (req, job_id, headers) {
6310
6310
  }
6311
6311
  };
6312
6312
 
6313
- const record_chat_usage = async function (uid, input_tokens, output_tokens, source, prompt, model, metadata = {}) {
6313
+ const record_chat_usage = async function (uid, input_tokens, output_tokens, source, prompt, model, metadata = {}, account_profile_info) {
6314
6314
  try {
6315
+ if (!account_profile_info) throw new Error('missing account_profile_info');
6315
6316
  const app_id = await account_module.get_account_default_project_id(uid);
6316
6317
 
6317
6318
  const cost = _conf?.ai_models?.[model] || {
@@ -6333,8 +6334,9 @@ const record_chat_usage = async function (uid, input_tokens, output_tokens, sour
6333
6334
  metadata,
6334
6335
  model,
6335
6336
  cost,
6337
+ account_profile_info,
6336
6338
  };
6337
- const save_ret = await db_module.save_app_couch_doc(app_id, usage_doc);
6339
+ const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, usage_doc);
6338
6340
  // console.log(save_ret);
6339
6341
  } catch (err) {
6340
6342
  console.error(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4139",
3
+ "version": "1.1.4141",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",