@xuda.io/ai_module 1.1.4649 → 1.1.4651
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 +361 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -4217,7 +4217,7 @@ export const create_conversation = async function (req, job_id, headers) {
|
|
|
4217
4217
|
await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
|
|
4218
4218
|
}
|
|
4219
4219
|
}
|
|
4220
|
-
|
|
4220
|
+
/// categorize prompt
|
|
4221
4221
|
let category_info = {};
|
|
4222
4222
|
switch (conversation_type) {
|
|
4223
4223
|
case 'ai': {
|
|
@@ -4240,6 +4240,7 @@ export const create_conversation = async function (req, job_id, headers) {
|
|
|
4240
4240
|
}
|
|
4241
4241
|
|
|
4242
4242
|
conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_doc._id);
|
|
4243
|
+
contact_doc.category_info = category_info;
|
|
4243
4244
|
await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
|
|
4244
4245
|
|
|
4245
4246
|
if (perform_ai_execution) {
|
|
@@ -8120,3 +8121,362 @@ Category:`;
|
|
|
8120
8121
|
};
|
|
8121
8122
|
}
|
|
8122
8123
|
};
|
|
8124
|
+
|
|
8125
|
+
export const categorize_contact_note = async function (uid, note_text, account_profile_info) {
|
|
8126
|
+
const note_categories = [
|
|
8127
|
+
// Personal & Relationship Notes (1-20)
|
|
8128
|
+
'Personal Update',
|
|
8129
|
+
'Life Milestone',
|
|
8130
|
+
'Family News',
|
|
8131
|
+
'Relationship Update',
|
|
8132
|
+
'Romantic Expression',
|
|
8133
|
+
'Friendship Note',
|
|
8134
|
+
'Apology Letter',
|
|
8135
|
+
'Thank You Note',
|
|
8136
|
+
'Appreciation Message',
|
|
8137
|
+
'Encouragement Note',
|
|
8138
|
+
'Sympathy Message',
|
|
8139
|
+
'Condolences',
|
|
8140
|
+
'Congratulations',
|
|
8141
|
+
'Birthday Wish',
|
|
8142
|
+
'Anniversary Note',
|
|
8143
|
+
'Holiday Greeting',
|
|
8144
|
+
'Miss You Note',
|
|
8145
|
+
'Thinking of You',
|
|
8146
|
+
'Love Letter',
|
|
8147
|
+
'Reconciliation Request',
|
|
8148
|
+
|
|
8149
|
+
// Professional & Work Notes (21-40)
|
|
8150
|
+
'Work Update',
|
|
8151
|
+
'Project Status',
|
|
8152
|
+
'Meeting Follow-up',
|
|
8153
|
+
'Professional Thank You',
|
|
8154
|
+
'Colleague Recognition',
|
|
8155
|
+
'Business Proposal',
|
|
8156
|
+
'Partnership Interest',
|
|
8157
|
+
'Networking Introduction',
|
|
8158
|
+
'Reference Request',
|
|
8159
|
+
'Recommendation Letter',
|
|
8160
|
+
'Resignation Notice',
|
|
8161
|
+
'Job Offer',
|
|
8162
|
+
'Contract Discussion',
|
|
8163
|
+
'Client Update',
|
|
8164
|
+
'Team Announcement',
|
|
8165
|
+
'Performance Feedback',
|
|
8166
|
+
'Career Advice',
|
|
8167
|
+
'Mentorship Request',
|
|
8168
|
+
'Professional Inquiry',
|
|
8169
|
+
'Business Idea Sharing',
|
|
8170
|
+
|
|
8171
|
+
// Informational & Educational (41-60)
|
|
8172
|
+
'Knowledge Sharing',
|
|
8173
|
+
'Research Findings',
|
|
8174
|
+
'Article Summary',
|
|
8175
|
+
'Book Recommendation',
|
|
8176
|
+
'Educational Resource',
|
|
8177
|
+
'Study Notes',
|
|
8178
|
+
'Learning Insights',
|
|
8179
|
+
'Tutorial Guide',
|
|
8180
|
+
'How-to Instructions',
|
|
8181
|
+
'Technical Explanation',
|
|
8182
|
+
'Scientific Discovery',
|
|
8183
|
+
'Historical Fact',
|
|
8184
|
+
'Cultural Insight',
|
|
8185
|
+
'Language Lesson',
|
|
8186
|
+
'Skill Sharing',
|
|
8187
|
+
'Workshop Notes',
|
|
8188
|
+
'Conference Takeaways',
|
|
8189
|
+
'Lecture Summary',
|
|
8190
|
+
'Expert Advice',
|
|
8191
|
+
'Field Report',
|
|
8192
|
+
|
|
8193
|
+
// Creative & Artistic (61-75)
|
|
8194
|
+
'Creative Writing',
|
|
8195
|
+
'Poetry Share',
|
|
8196
|
+
'Story Excerpt',
|
|
8197
|
+
'Script Draft',
|
|
8198
|
+
'Song Lyrics',
|
|
8199
|
+
'Art Description',
|
|
8200
|
+
'Creative Idea',
|
|
8201
|
+
'Inspiration Share',
|
|
8202
|
+
'Design Concept',
|
|
8203
|
+
'Photography Note',
|
|
8204
|
+
'Craft Instructions',
|
|
8205
|
+
'Recipe Share',
|
|
8206
|
+
'Musical Composition',
|
|
8207
|
+
'Art Critique',
|
|
8208
|
+
'Creative Feedback',
|
|
8209
|
+
|
|
8210
|
+
// Planning & Organization (76-90)
|
|
8211
|
+
'Event Planning',
|
|
8212
|
+
'Travel Itinerary',
|
|
8213
|
+
'Meeting Agenda',
|
|
8214
|
+
'Project Plan',
|
|
8215
|
+
'Task List',
|
|
8216
|
+
'Schedule Coordination',
|
|
8217
|
+
'Goal Setting',
|
|
8218
|
+
'Budget Planning',
|
|
8219
|
+
'Checklist Share',
|
|
8220
|
+
'Timeline Update',
|
|
8221
|
+
'Resource Planning',
|
|
8222
|
+
'Strategy Outline',
|
|
8223
|
+
'Action Plan',
|
|
8224
|
+
'Roadmap Share',
|
|
8225
|
+
'Calendar Coordination',
|
|
8226
|
+
|
|
8227
|
+
// Health & Wellness (91-100)
|
|
8228
|
+
'Health Update',
|
|
8229
|
+
'Medical Information',
|
|
8230
|
+
'Wellness Tips',
|
|
8231
|
+
'Fitness Progress',
|
|
8232
|
+
'Diet Notes',
|
|
8233
|
+
'Mental Health Share',
|
|
8234
|
+
'Recovery Update',
|
|
8235
|
+
'Self-care Reminder',
|
|
8236
|
+
'Healthcare Advice',
|
|
8237
|
+
'Medication Notes',
|
|
8238
|
+
|
|
8239
|
+
// Financial & Legal (101-110)
|
|
8240
|
+
'Financial Update',
|
|
8241
|
+
'Investment Advice',
|
|
8242
|
+
'Budget Share',
|
|
8243
|
+
'Expense Report',
|
|
8244
|
+
'Tax Information',
|
|
8245
|
+
'Legal Notice',
|
|
8246
|
+
'Contract Review',
|
|
8247
|
+
'Documentation',
|
|
8248
|
+
'Compliance Note',
|
|
8249
|
+
'Insurance Information',
|
|
8250
|
+
|
|
8251
|
+
// Household & Property (111-120)
|
|
8252
|
+
'Home Update',
|
|
8253
|
+
'Property Information',
|
|
8254
|
+
'Maintenance Notes',
|
|
8255
|
+
'Renovation Plans',
|
|
8256
|
+
'Gardening Tips',
|
|
8257
|
+
'Pet Care Notes',
|
|
8258
|
+
'Childcare Update',
|
|
8259
|
+
'Household Instructions',
|
|
8260
|
+
'Neighborhood News',
|
|
8261
|
+
'Community Update',
|
|
8262
|
+
|
|
8263
|
+
// Spiritual & Philosophical (121-130)
|
|
8264
|
+
'Spiritual Reflection',
|
|
8265
|
+
'Religious Teaching',
|
|
8266
|
+
'Meditation Guide',
|
|
8267
|
+
'Prayer Request',
|
|
8268
|
+
'Philosophical Thought',
|
|
8269
|
+
'Ethical Consideration',
|
|
8270
|
+
'Life Philosophy',
|
|
8271
|
+
'Moral Dilemma',
|
|
8272
|
+
'Faith Journey',
|
|
8273
|
+
'Enlightenment Share',
|
|
8274
|
+
|
|
8275
|
+
// Travel & Adventure (131-140)
|
|
8276
|
+
'Travel Journal',
|
|
8277
|
+
'Adventure Story',
|
|
8278
|
+
'Destination Review',
|
|
8279
|
+
'Travel Tips',
|
|
8280
|
+
'Cultural Experience',
|
|
8281
|
+
'Vacation Plans',
|
|
8282
|
+
'Trip Report',
|
|
8283
|
+
'Exploration Notes',
|
|
8284
|
+
'Backpacking Guide',
|
|
8285
|
+
'Souvenir Story',
|
|
8286
|
+
|
|
8287
|
+
// Technology & Digital (141-150)
|
|
8288
|
+
'Tech Tips',
|
|
8289
|
+
'Software Review',
|
|
8290
|
+
'App Recommendation',
|
|
8291
|
+
'Gadget Review',
|
|
8292
|
+
'Coding Notes',
|
|
8293
|
+
'Security Alert',
|
|
8294
|
+
'Digital How-to',
|
|
8295
|
+
'Online Resource',
|
|
8296
|
+
'Website Review',
|
|
8297
|
+
'Tech Support Note',
|
|
8298
|
+
|
|
8299
|
+
// Social & Community (151-160)
|
|
8300
|
+
'Community News',
|
|
8301
|
+
'Event Announcement',
|
|
8302
|
+
'Volunteer Opportunity',
|
|
8303
|
+
'Social Cause',
|
|
8304
|
+
'Fundraising Update',
|
|
8305
|
+
'Club News',
|
|
8306
|
+
'Group Activity',
|
|
8307
|
+
'Team Building',
|
|
8308
|
+
'Social Gathering',
|
|
8309
|
+
'Public Announcement',
|
|
8310
|
+
|
|
8311
|
+
// Memory & Reflection (161-170)
|
|
8312
|
+
'Memory Share',
|
|
8313
|
+
'Childhood Story',
|
|
8314
|
+
'Life Reflection',
|
|
8315
|
+
'Lessons Learned',
|
|
8316
|
+
'Personal Growth',
|
|
8317
|
+
'Turning Point',
|
|
8318
|
+
'Nostalgic Memory',
|
|
8319
|
+
'Historical Personal',
|
|
8320
|
+
'Legacy Planning',
|
|
8321
|
+
'Life Summary',
|
|
8322
|
+
|
|
8323
|
+
// Advice & Guidance (171-180)
|
|
8324
|
+
'Personal Advice',
|
|
8325
|
+
'Relationship Advice',
|
|
8326
|
+
'Career Guidance',
|
|
8327
|
+
'Parenting Tips',
|
|
8328
|
+
'Financial Advice',
|
|
8329
|
+
'Health Guidance',
|
|
8330
|
+
'Educational Advice',
|
|
8331
|
+
'Legal Counsel',
|
|
8332
|
+
'Technical Advice',
|
|
8333
|
+
'Life Coaching',
|
|
8334
|
+
|
|
8335
|
+
// Urgent & Important (181-190)
|
|
8336
|
+
'Urgent Update',
|
|
8337
|
+
'Emergency Information',
|
|
8338
|
+
'Critical Notice',
|
|
8339
|
+
'Important Announcement',
|
|
8340
|
+
'Safety Alert',
|
|
8341
|
+
'Time-sensitive Info',
|
|
8342
|
+
'Immediate Action',
|
|
8343
|
+
'Priority Message',
|
|
8344
|
+
'Breaking News',
|
|
8345
|
+
'Crisis Update',
|
|
8346
|
+
|
|
8347
|
+
// Miscellaneous (191-200)
|
|
8348
|
+
'Random Thought',
|
|
8349
|
+
'Interesting Fact',
|
|
8350
|
+
'Question Posing',
|
|
8351
|
+
'Hypothesis Share',
|
|
8352
|
+
'Dream Description',
|
|
8353
|
+
'Observation Note',
|
|
8354
|
+
'Idea Brainstorm',
|
|
8355
|
+
'Problem Statement',
|
|
8356
|
+
'Solution Proposal',
|
|
8357
|
+
'General Update',
|
|
8358
|
+
];
|
|
8359
|
+
const prompt = `Categorize this note text into one of the 200 note categories based only on the note content.
|
|
8360
|
+
|
|
8361
|
+
Note Text: "${note_text}"
|
|
8362
|
+
|
|
8363
|
+
INSTRUCTIONS:
|
|
8364
|
+
1. Analyze ONLY the note content - no external context
|
|
8365
|
+
2. Choose ONE category that best fits the note's primary purpose
|
|
8366
|
+
3. Consider: What type of information is being shared?
|
|
8367
|
+
4. Return the exact category name from the list
|
|
8368
|
+
5. If truly ambiguous, choose "General Update"
|
|
8369
|
+
|
|
8370
|
+
Think step by step:
|
|
8371
|
+
1. What is the main purpose of this note? (Inform, update, request, share, etc.)
|
|
8372
|
+
2. What domain does it belong to? (Personal, professional, creative, etc.)
|
|
8373
|
+
3. What is the tone and formality level?
|
|
8374
|
+
4. What kind of response or action might it expect?
|
|
8375
|
+
|
|
8376
|
+
Category:`;
|
|
8377
|
+
|
|
8378
|
+
try {
|
|
8379
|
+
const note_category_ret = await submit_chat_gpt_prompt({
|
|
8380
|
+
uid,
|
|
8381
|
+
prompt: prompt,
|
|
8382
|
+
model: 'gpt-4o-mini',
|
|
8383
|
+
response_format: z.object({
|
|
8384
|
+
note_category: z.enum(note_categories),
|
|
8385
|
+
confidence_score: z.number().min(0).max(100),
|
|
8386
|
+
primary_purpose: z.string(),
|
|
8387
|
+
tone: z.enum(['Formal', 'Semi-formal', 'Casual', 'Professional', 'Personal', 'Academic', 'Creative', 'Urgent']),
|
|
8388
|
+
note_type: z.enum(['Informational', 'Emotional', 'Transactional', 'Creative', 'Reflective', 'Instructional', 'Request-based', 'Update']),
|
|
8389
|
+
}),
|
|
8390
|
+
metadata: {
|
|
8391
|
+
func: 'categorize_contact_note',
|
|
8392
|
+
note_length: note_text.length,
|
|
8393
|
+
timestamp: new Date().toISOString(),
|
|
8394
|
+
},
|
|
8395
|
+
account_profile_info,
|
|
8396
|
+
});
|
|
8397
|
+
|
|
8398
|
+
if (note_category_ret && note_category_ret.code > -1) {
|
|
8399
|
+
const data = typeof note_category_ret.data === 'string' ? JSON.parse(note_category_ret.data) : note_category_ret.data;
|
|
8400
|
+
|
|
8401
|
+
// Local note analysis
|
|
8402
|
+
const note_analysis = {
|
|
8403
|
+
word_count: note_text.split(/\s+/).filter((w) => w.length > 0).length,
|
|
8404
|
+
paragraph_count: (note_text.match(/\n\s*\n/g) || []).length + 1,
|
|
8405
|
+
has_questions: /[?]|(what|how|why|when|where|who|can|could|would)/i.test(note_text),
|
|
8406
|
+
has_requests: /(please|request|ask|need|want|require)/i.test(note_text),
|
|
8407
|
+
has_dates: /\b(\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}|\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2})\b/.test(note_text),
|
|
8408
|
+
has_numbers: /\b\d+\b/.test(note_text),
|
|
8409
|
+
is_structured: /(\d+\.|•|- \[|\d{1,2}\/\d{1,2})/.test(note_text.substring(0, 100)),
|
|
8410
|
+
};
|
|
8411
|
+
|
|
8412
|
+
// Determine importance level based on category and tone
|
|
8413
|
+
let importance = 3; // Medium by default
|
|
8414
|
+
if (data.tone === 'Urgent' || data.note_category.includes('Urgent') || data.note_category.includes('Emergency')) {
|
|
8415
|
+
importance = 1;
|
|
8416
|
+
} else if (data.tone === 'Professional' || data.note_category.includes('Important') || data.note_category.includes('Critical')) {
|
|
8417
|
+
importance = 2;
|
|
8418
|
+
} else if (data.note_category.includes('Casual') || data.note_category.includes('Personal') || data.note_category.includes('Random')) {
|
|
8419
|
+
importance = 4;
|
|
8420
|
+
}
|
|
8421
|
+
|
|
8422
|
+
// Estimate reading time (average reading speed: 200-250 words per minute)
|
|
8423
|
+
const reading_time_minutes = Math.ceil(note_analysis.word_count / 225);
|
|
8424
|
+
|
|
8425
|
+
// Determine if note requires follow-up
|
|
8426
|
+
const requires_follow_up = note_analysis.has_questions || note_analysis.has_requests || data.note_type === 'Request-based' || data.note_type === 'Transactional';
|
|
8427
|
+
|
|
8428
|
+
return {
|
|
8429
|
+
success: true,
|
|
8430
|
+
category: data.note_category,
|
|
8431
|
+
confidence: data.confidence_score,
|
|
8432
|
+
primary_purpose: data.primary_purpose,
|
|
8433
|
+
tone: data.tone,
|
|
8434
|
+
note_type: data.note_type,
|
|
8435
|
+
importance: importance,
|
|
8436
|
+
|
|
8437
|
+
// Note analysis
|
|
8438
|
+
word_count: note_analysis.word_count,
|
|
8439
|
+
paragraph_count: note_analysis.paragraph_count,
|
|
8440
|
+
has_questions: note_analysis.has_questions,
|
|
8441
|
+
has_requests: note_analysis.has_requests,
|
|
8442
|
+
is_structured: note_analysis.is_structured,
|
|
8443
|
+
|
|
8444
|
+
// Practical info
|
|
8445
|
+
estimated_reading_time: `${reading_time_minutes} min`,
|
|
8446
|
+
requires_follow_up: requires_follow_up,
|
|
8447
|
+
is_formal: data.tone === 'Formal' || data.tone === 'Professional',
|
|
8448
|
+
|
|
8449
|
+
// Metadata
|
|
8450
|
+
timestamp: new Date().toISOString(),
|
|
8451
|
+
note_preview: note_text.substring(0, 150) + (note_text.length > 150 ? '...' : ''),
|
|
8452
|
+
};
|
|
8453
|
+
} else {
|
|
8454
|
+
return {
|
|
8455
|
+
success: false,
|
|
8456
|
+
category: 'General Update',
|
|
8457
|
+
confidence: 0,
|
|
8458
|
+
primary_purpose: 'Unknown',
|
|
8459
|
+
tone: 'Casual',
|
|
8460
|
+
note_type: 'Informational',
|
|
8461
|
+
importance: 3,
|
|
8462
|
+
note_preview: note_text.substring(0, 150),
|
|
8463
|
+
error: note_category_ret?.message || 'API call failed',
|
|
8464
|
+
timestamp: new Date().toISOString(),
|
|
8465
|
+
};
|
|
8466
|
+
}
|
|
8467
|
+
} catch (error) {
|
|
8468
|
+
console.error('Error in categorize_contact_note:', error);
|
|
8469
|
+
return {
|
|
8470
|
+
success: false,
|
|
8471
|
+
category: 'General Update',
|
|
8472
|
+
confidence: 0,
|
|
8473
|
+
primary_purpose: 'Error',
|
|
8474
|
+
tone: 'Casual',
|
|
8475
|
+
note_type: 'Informational',
|
|
8476
|
+
importance: 3,
|
|
8477
|
+
note_preview: note_text.substring(0, 150),
|
|
8478
|
+
error: error.message,
|
|
8479
|
+
timestamp: new Date().toISOString(),
|
|
8480
|
+
};
|
|
8481
|
+
}
|
|
8482
|
+
};
|