@xuda.io/ai_module 1.1.4004 → 1.1.4006
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 +14 -5
- 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
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
+
debugger;
|
|
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,
|
|
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
|
// }
|