@xuda.io/ai_module 1.1.4003 → 1.1.4005

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 +14 -5
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -4920,10 +4920,10 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4920
4920
  }
4921
4921
  // if (!tools.length) continue;
4922
4922
  // console.log('tool', tools);
4923
- const agent_name = `${ai_agent_doc._id} ${ai_agent_doc?.properties?.menuName || ''}`;
4924
- // const agent_name = `${ai_agent_doc._id} `;
4923
+ // const agent_name = `${ai_agent_doc._id} ${ai_agent_doc?.properties?.menuName || ''}`;
4924
+ const agent_name = `${ai_agent_doc._id}`;
4925
4925
  const agent = new Agent({
4926
- name: agent_name.substring(0, 60),
4926
+ name: agent_name.substring(0, 55),
4927
4927
  instructions: ai_agent_doc.agentConfig.agent_instructions + (reference_type === 'ai_agents' ? get_agent_instructions() : ''),
4928
4928
  model,
4929
4929
  tools,
@@ -5116,7 +5116,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
5116
5116
  await attachment_handler();
5117
5117
  }
5118
5118
  ////////////
5119
- debugger;
5119
+
5120
5120
  if (reference_type === 'ai_agents') {
5121
5121
  _agent = agents[0];
5122
5122
 
@@ -5150,8 +5150,17 @@ const ai_chat_conversation = async function (req, job_id, headers) {
5150
5150
  conversation_doc.ts = Date.now();
5151
5151
  conversation_doc.stat = 3;
5152
5152
  conversation_doc.messages.push(obj);
5153
+
5154
+ let inputTokens = output.state?._context.usage?.inputTokens || 0;
5155
+ let outputTokens = output.state?._context?.usage?.outputTokens || 0;
5156
+
5157
+ for (const item of output?._modelResponses) {
5158
+ inputTokens += item.usage.inputTokens;
5159
+ outputTokens += item.usage.outputTokens;
5160
+ }
5161
+
5153
5162
  await db_module.save_app_couch_doc_native(app_id, conversation_doc);
5154
- record_chat_usage(uid, output.state._context.usage.inputTokens, output.state._context.usage.outputTokens, 'conversation chat', prompt, model, { conversation_id, ai_agent_id: obj.ai_agent_id, item_id: obj.id });
5163
+ record_chat_usage(uid, inputTokens, outputTokens, 'conversation chat', prompt, model, { conversation_id, ai_agent_id: obj.ai_agent_id, item_id: obj.id });
5155
5164
  // if (!conversation_doc.chat_image && (!conversation_doc.thumbnail_request_ts || Date.now() - conversation_doc.thumbnail_request_ts > 120000)) {
5156
5165
  // update_thumbnail('conversation', conversation_doc, app_id, uid, job_id, headers);
5157
5166
  // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4003",
3
+ "version": "1.1.4005",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",