@xuda.io/ai_module 1.1.3795 → 1.1.3797
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 +44 -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,13 @@ 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
|
-
if (conversation_doc.reference_type === 'contacts') {
|
|
4131
|
-
return await contact_chat_conversation(req, job_id, headers);
|
|
4132
|
+
if (conversation_doc.conversation_type === 'note') {
|
|
4132
4133
|
} else {
|
|
4133
|
-
|
|
4134
|
+
if (conversation_doc.reference_type === 'contacts') {
|
|
4135
|
+
return await contact_chat_conversation(req, job_id, headers);
|
|
4136
|
+
} else {
|
|
4137
|
+
return await ai_chat_conversation(req, job_id, headers);
|
|
4138
|
+
}
|
|
4134
4139
|
}
|
|
4135
4140
|
} catch (err) {
|
|
4136
4141
|
return { code: -14, data: err.message || String(err) };
|
|
@@ -4231,6 +4236,41 @@ const contact_chat_conversation = async function (req, job_id, headers) {
|
|
|
4231
4236
|
return { code: 15, data: item };
|
|
4232
4237
|
};
|
|
4233
4238
|
|
|
4239
|
+
const contact_chat_note = async function (req, job_id, headers) {
|
|
4240
|
+
const { uid } = req;
|
|
4241
|
+
let { prompt, conversation_doc, attachments = [], ai_agents } = req;
|
|
4242
|
+
|
|
4243
|
+
const conversation_id = conversation_doc._id;
|
|
4244
|
+
|
|
4245
|
+
const receiver_contact_doc = await account_module.get_contact_info(uid, null, conversation_doc.reference_id);
|
|
4246
|
+
const receiver_app_id = await account_module.get_account_default_project_id(receiver_contact_doc.contact_uid);
|
|
4247
|
+
let receiver_conversation_doc = await db_module.get_app_couch_doc_native(receiver_app_id, conversation_id);
|
|
4248
|
+
|
|
4249
|
+
const sender_contact_doc = await account_module.get_contact_info(uid, null, conversation_doc.reference_id);
|
|
4250
|
+
const sender_app_id = await account_module.get_account_default_project_id(uid);
|
|
4251
|
+
let sender_conversation_doc = await db_module.get_app_couch_doc_native(sender_app_id, conversation_id);
|
|
4252
|
+
|
|
4253
|
+
const item = await client.conversations.items.create(conversation_id, {
|
|
4254
|
+
items: [
|
|
4255
|
+
{
|
|
4256
|
+
type: 'message',
|
|
4257
|
+
role: 'user',
|
|
4258
|
+
content: [{ type: 'input_text', text: prompt }],
|
|
4259
|
+
},
|
|
4260
|
+
],
|
|
4261
|
+
});
|
|
4262
|
+
|
|
4263
|
+
const obj = { id: item.data[0].id, ts: Date.now(), uid, read: true };
|
|
4264
|
+
receiver_conversation_doc.messages.push(obj);
|
|
4265
|
+
await db_module.save_app_couch_doc_native(receiver_app_id, receiver_conversation_doc);
|
|
4266
|
+
sender_conversation_doc.messages.push({ ...obj, ...{ read: false } });
|
|
4267
|
+
await db_module.save_app_couch_doc_native(sender_app_id, sender_conversation_doc);
|
|
4268
|
+
|
|
4269
|
+
update_conversation_mood_level(conversation_id, prompt, uid, receiver_contact_doc.contact_uid, conversation_doc.reference_type === 'contacts');
|
|
4270
|
+
|
|
4271
|
+
return { code: 15, data: item };
|
|
4272
|
+
};
|
|
4273
|
+
|
|
4234
4274
|
const ai_chat_conversation = async function (req, job_id, headers) {
|
|
4235
4275
|
const { uid, gtp_token } = req;
|
|
4236
4276
|
let { prompt, conversation_doc, attachments = [], ai_agents, output_format = 'md', stream = true, with_context = true } = req;
|