@xuda.io/ai_module 1.1.3795 → 1.1.3798
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 +45 -4
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -4045,6 +4045,9 @@ export const create_conversation = async function (req, job_id, headers) {
|
|
|
4045
4045
|
const save_ret = await db_module.save_app_couch_doc(app_id, { ...conversation_doc, ...{ uid: receiver_contact_doc.contact_uid, reference_id: sender_contact_id } });
|
|
4046
4046
|
contact_uid_chat_conversation = receiver_contact_doc.contact_uid;
|
|
4047
4047
|
}
|
|
4048
|
+
|
|
4049
|
+
if (conversation_type === 'note') {
|
|
4050
|
+
}
|
|
4048
4051
|
}
|
|
4049
4052
|
|
|
4050
4053
|
setTimeout(async () => {
|
|
@@ -4126,11 +4129,14 @@ export const submit_chat_conversation = async function (req, job_id, headers) {
|
|
|
4126
4129
|
const app_id = await account_module.get_account_default_project_id(uid);
|
|
4127
4130
|
let conversation_doc = await db_module.get_app_couch_doc_native(app_id, conversation_id);
|
|
4128
4131
|
req.conversation_doc = conversation_doc;
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
return await contact_chat_conversation(req, job_id, headers);
|
|
4132
|
+
if (conversation_doc.conversation_type === 'note') {
|
|
4133
|
+
return await chat_note(req, job_id, header);
|
|
4132
4134
|
} else {
|
|
4133
|
-
|
|
4135
|
+
if (conversation_doc.reference_type === 'contacts') {
|
|
4136
|
+
return await contact_chat_conversation(req, job_id, headers);
|
|
4137
|
+
} else {
|
|
4138
|
+
return await ai_chat_conversation(req, job_id, headers);
|
|
4139
|
+
}
|
|
4134
4140
|
}
|
|
4135
4141
|
} catch (err) {
|
|
4136
4142
|
return { code: -14, data: err.message || String(err) };
|
|
@@ -4231,6 +4237,41 @@ const contact_chat_conversation = async function (req, job_id, headers) {
|
|
|
4231
4237
|
return { code: 15, data: item };
|
|
4232
4238
|
};
|
|
4233
4239
|
|
|
4240
|
+
const chat_note = async function (req, job_id, headers) {
|
|
4241
|
+
const { uid } = req;
|
|
4242
|
+
let { prompt, conversation_doc, attachments = [], ai_agents } = req;
|
|
4243
|
+
|
|
4244
|
+
const conversation_id = conversation_doc._id;
|
|
4245
|
+
|
|
4246
|
+
const receiver_contact_doc = await account_module.get_contact_info(uid, null, conversation_doc.reference_id);
|
|
4247
|
+
const receiver_app_id = await account_module.get_account_default_project_id(receiver_contact_doc.contact_uid);
|
|
4248
|
+
let receiver_conversation_doc = await db_module.get_app_couch_doc_native(receiver_app_id, conversation_id);
|
|
4249
|
+
|
|
4250
|
+
const sender_contact_doc = await account_module.get_contact_info(uid, null, conversation_doc.reference_id);
|
|
4251
|
+
const sender_app_id = await account_module.get_account_default_project_id(uid);
|
|
4252
|
+
let sender_conversation_doc = await db_module.get_app_couch_doc_native(sender_app_id, conversation_id);
|
|
4253
|
+
|
|
4254
|
+
const item = await client.conversations.items.create(conversation_id, {
|
|
4255
|
+
items: [
|
|
4256
|
+
{
|
|
4257
|
+
type: 'message',
|
|
4258
|
+
role: 'user',
|
|
4259
|
+
content: [{ type: 'input_text', text: prompt }],
|
|
4260
|
+
},
|
|
4261
|
+
],
|
|
4262
|
+
});
|
|
4263
|
+
|
|
4264
|
+
const obj = { id: item.data[0].id, ts: Date.now(), uid, read: true };
|
|
4265
|
+
receiver_conversation_doc.messages.push(obj);
|
|
4266
|
+
await db_module.save_app_couch_doc_native(receiver_app_id, receiver_conversation_doc);
|
|
4267
|
+
sender_conversation_doc.messages.push({ ...obj, ...{ read: false } });
|
|
4268
|
+
await db_module.save_app_couch_doc_native(sender_app_id, sender_conversation_doc);
|
|
4269
|
+
|
|
4270
|
+
update_conversation_mood_level(conversation_id, prompt, uid, receiver_contact_doc.contact_uid, conversation_doc.reference_type === 'contacts');
|
|
4271
|
+
|
|
4272
|
+
return { code: 15, data: item };
|
|
4273
|
+
};
|
|
4274
|
+
|
|
4234
4275
|
const ai_chat_conversation = async function (req, job_id, headers) {
|
|
4235
4276
|
const { uid, gtp_token } = req;
|
|
4236
4277
|
let { prompt, conversation_doc, attachments = [], ai_agents, output_format = 'md', stream = true, with_context = true } = req;
|