@xuda.io/ai_module 1.1.4639 → 1.1.4641

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 +386 -0
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -7363,3 +7363,389 @@ Category:`;
7363
7363
  };
7364
7364
  }
7365
7365
  };
7366
+
7367
+ export const categorize_ai_prompt = async function (uid, prompt_text, account_profile_info) {
7368
+ const ai_prompt_categories = [
7369
+ // Creative & Content Generation (1-15)
7370
+ 'Creative Writing',
7371
+ 'Poetry Generation',
7372
+ 'Storytelling / Narrative',
7373
+ 'Script Writing',
7374
+ 'Song Lyrics Creation',
7375
+ 'Blog Post Writing',
7376
+ 'Article Generation',
7377
+ 'Social Media Content',
7378
+ 'Marketing Copy',
7379
+ 'Advertising Slogans',
7380
+ 'Product Descriptions',
7381
+ 'Email Drafting',
7382
+ 'Resume / Cover Letter',
7383
+ 'Business Communication',
7384
+ 'Technical Documentation',
7385
+
7386
+ // Analysis & Research (16-30)
7387
+ 'Data Analysis Request',
7388
+ 'Research Assistance',
7389
+ 'Market Research',
7390
+ 'Competitive Analysis',
7391
+ 'Trend Analysis',
7392
+ 'Statistical Analysis',
7393
+ 'Academic Research',
7394
+ 'Literature Review',
7395
+ 'Case Study Analysis',
7396
+ 'SWOT Analysis',
7397
+ 'Financial Analysis',
7398
+ 'Code Review',
7399
+ 'Document Analysis',
7400
+ 'Text Summarization',
7401
+ 'Comparative Analysis',
7402
+
7403
+ // Technical & Programming (31-45)
7404
+ 'Code Generation',
7405
+ 'Bug Fixing',
7406
+ 'Algorithm Design',
7407
+ 'System Architecture',
7408
+ 'Database Query',
7409
+ 'API Development',
7410
+ 'Web Development',
7411
+ 'Mobile App Development',
7412
+ 'DevOps / Infrastructure',
7413
+ 'Software Testing',
7414
+ 'Code Optimization',
7415
+ 'Technical Explanation',
7416
+ 'Programming Tutorial',
7417
+ 'Code Translation',
7418
+ 'Technical Support',
7419
+
7420
+ // Learning & Education (46-60)
7421
+ 'Concept Explanation',
7422
+ 'Homework Help',
7423
+ 'Study Guide Creation',
7424
+ 'Test Preparation',
7425
+ 'Language Learning',
7426
+ 'Math Problem Solving',
7427
+ 'Science Explanation',
7428
+ 'History Research',
7429
+ 'Philosophy Discussion',
7430
+ 'Theory Explanation',
7431
+ 'Learning Plan Creation',
7432
+ 'Educational Content',
7433
+ 'Course Design',
7434
+ 'Teaching Material',
7435
+ 'Knowledge Assessment',
7436
+
7437
+ // Business & Strategy (61-75)
7438
+ 'Business Strategy',
7439
+ 'Marketing Strategy',
7440
+ 'Sales Strategy',
7441
+ 'Business Plan Development',
7442
+ 'Project Planning',
7443
+ 'Risk Assessment',
7444
+ 'Decision Support',
7445
+ 'Process Optimization',
7446
+ 'Workflow Design',
7447
+ 'Meeting Preparation',
7448
+ 'Presentation Creation',
7449
+ 'Proposal Writing',
7450
+ 'Negotiation Strategy',
7451
+ 'Leadership Advice',
7452
+ 'Management Consulting',
7453
+
7454
+ // Personal & Lifestyle (76-90)
7455
+ 'Personal Advice',
7456
+ 'Relationship Advice',
7457
+ 'Career Counseling',
7458
+ 'Health Advice',
7459
+ 'Fitness Planning',
7460
+ 'Nutrition Guidance',
7461
+ 'Travel Planning',
7462
+ 'Financial Planning',
7463
+ 'Life Coaching',
7464
+ 'Goal Setting',
7465
+ 'Time Management',
7466
+ 'Productivity Tips',
7467
+ 'Hobby Assistance',
7468
+ 'Recipe Creation',
7469
+ 'Event Planning',
7470
+
7471
+ // Analysis & Problem Solving (91-105)
7472
+ 'Problem Solving',
7473
+ 'Decision Making',
7474
+ 'Critical Thinking',
7475
+ 'Logical Reasoning',
7476
+ 'Brainstorming Session',
7477
+ 'Idea Generation',
7478
+ 'Innovation Request',
7479
+ 'Solution Design',
7480
+ 'Troubleshooting',
7481
+ 'Root Cause Analysis',
7482
+ 'Hypothesis Testing',
7483
+ 'Scenario Analysis',
7484
+ 'Prediction Request',
7485
+ 'Forecasting',
7486
+ 'Simulation Request',
7487
+
7488
+ // Specialized Domains (106-120)
7489
+ 'Legal Analysis',
7490
+ 'Medical Information',
7491
+ 'Scientific Research',
7492
+ 'Engineering Design',
7493
+ 'Artistic Creation',
7494
+ 'Music Composition',
7495
+ 'Game Design',
7496
+ 'UI/UX Design',
7497
+ 'SEO Optimization',
7498
+ 'Data Science',
7499
+ 'Machine Learning',
7500
+ 'Blockchain / Crypto',
7501
+ 'Cybersecurity',
7502
+ 'Climate / Environment',
7503
+ 'Public Policy',
7504
+
7505
+ // Interactive & Conversational (121-130)
7506
+ 'Roleplaying / Simulation',
7507
+ 'Debate / Discussion',
7508
+ 'Interview Practice',
7509
+ 'Language Practice',
7510
+ 'Therapy / Counseling',
7511
+ 'Entertainment',
7512
+ 'Game Playing',
7513
+ 'Trivia / Quiz',
7514
+ 'Joke Generation',
7515
+ 'Conversational Companion',
7516
+
7517
+ // Meta & System (131-140)
7518
+ 'Prompt Engineering',
7519
+ 'AI Capabilities Question',
7520
+ 'System Instruction',
7521
+ 'Model Evaluation',
7522
+ 'Feedback on AI Response',
7523
+ 'Ethics Discussion',
7524
+ 'Bias Detection',
7525
+ 'Fact Checking',
7526
+ 'Source Verification',
7527
+ 'Translation Request',
7528
+
7529
+ // Creative Arts (141-150)
7530
+ 'Visual Art Description',
7531
+ 'Art Style Analysis',
7532
+ 'Creative Direction',
7533
+ 'Character Design',
7534
+ 'World Building',
7535
+ 'Plot Development',
7536
+ 'Dialogue Writing',
7537
+ 'Creative Critique',
7538
+ 'Artistic Inspiration',
7539
+ 'Design Feedback',
7540
+
7541
+ // Analysis & Processing (151-160)
7542
+ 'Sentiment Analysis',
7543
+ 'Text Classification',
7544
+ 'Entity Extraction',
7545
+ 'Keyword Extraction',
7546
+ 'Topic Modeling',
7547
+ 'Content Moderation',
7548
+ 'Plagiarism Check',
7549
+ 'Grammar Correction',
7550
+ 'Style Improvement',
7551
+ 'Tone Adjustment',
7552
+
7553
+ // Planning & Organization (161-170)
7554
+ 'Schedule Planning',
7555
+ 'Task Management',
7556
+ 'Resource Allocation',
7557
+ 'Budget Planning',
7558
+ 'Timeline Creation',
7559
+ 'Milestone Setting',
7560
+ 'Priority Setting',
7561
+ 'Checklist Creation',
7562
+ 'Work Breakdown',
7563
+ 'Deadline Management',
7564
+
7565
+ // Communication & Social (171-180)
7566
+ 'Conflict Resolution',
7567
+ 'Communication Strategy',
7568
+ 'Public Speaking',
7569
+ 'Persuasive Writing',
7570
+ 'Negotiation Preparation',
7571
+ 'Networking Strategy',
7572
+ 'Social Media Strategy',
7573
+ 'Community Management',
7574
+ 'Crisis Communication',
7575
+ 'Reputation Management',
7576
+
7577
+ // Technical Support & Operations (181-190)
7578
+ 'IT Support',
7579
+ 'System Troubleshooting',
7580
+ 'Configuration Assistance',
7581
+ 'Installation Guide',
7582
+ 'User Manual Creation',
7583
+ 'FAQ Generation',
7584
+ 'Knowledge Base',
7585
+ 'Customer Support',
7586
+ 'Service Desk',
7587
+ 'Incident Response',
7588
+
7589
+ // Data & Analytics (191-200)
7590
+ 'Data Visualization',
7591
+ 'Report Generation',
7592
+ 'Dashboard Design',
7593
+ 'KPI Definition',
7594
+ 'Metric Analysis',
7595
+ 'A/B Testing Design',
7596
+ 'User Behavior Analysis',
7597
+ 'Conversion Optimization',
7598
+ 'Analytics Setup',
7599
+ 'Data Cleaning',
7600
+ ];
7601
+
7602
+ const prompt = `Categorize the AI prompt into one of these exact categories:
7603
+
7604
+ AI Prompt: "${prompt_text.substring(0, 500)}${prompt_text.length > 500 ? '...' : ''}"
7605
+
7606
+ Available Categories (200 total, showing first 20 as examples):
7607
+ ${ai_prompt_categories
7608
+ .slice(0, 20)
7609
+ .map((cat, index) => `${index + 1}. ${cat}`)
7610
+ .join('\n')}
7611
+ [Full list of 200 categories available to the system]
7612
+
7613
+ Instructions:
7614
+ 1. Analyze the prompt's intent and domain
7615
+ 2. Choose the single most relevant category
7616
+ 3. Return only the exact category name as it appears in the full list
7617
+ 4. Consider:
7618
+ - Primary task (writing, analysis, coding, etc.)
7619
+ - Domain (business, technical, creative, etc.)
7620
+ - Complexity level
7621
+ - Expected output format
7622
+ 5. If unsure, choose based on primary intent
7623
+ 6. If truly cannot categorize, choose "General Assistance"
7624
+
7625
+ Category:`;
7626
+
7627
+ try {
7628
+ const prompt_category_ret = await submit_chat_gpt_prompt({
7629
+ uid,
7630
+ prompt: prompt,
7631
+ model: 'gpt-4o', // Using GPT-4o for better understanding of AI prompts
7632
+ response_format: z.object({
7633
+ prompt_category: z.enum(ai_prompt_categories),
7634
+ confidence_score: z.number().min(0).max(100),
7635
+ primary_intent: z.string().max(100),
7636
+ secondary_category: z.string().optional(),
7637
+ complexity_level: z.enum(['Basic', 'Intermediate', 'Advanced', 'Expert']).optional(),
7638
+ }),
7639
+ metadata: {
7640
+ func: 'categorize_ai_prompt',
7641
+ prompt_length: prompt_text.length,
7642
+ prompt_hash: await hashPrompt(prompt_text), // Optional: hash for deduplication
7643
+ timestamp: new Date().toISOString(),
7644
+ },
7645
+ account_profile_info,
7646
+ });
7647
+
7648
+ if (prompt_category_ret && prompt_category_ret.code > -1) {
7649
+ const data = typeof prompt_category_ret.data === 'string' ? JSON.parse(prompt_category_ret.data) : prompt_category_ret.data;
7650
+
7651
+ // Additional analysis based on category
7652
+ const analysis = await analyzePromptComplexity(prompt_text, data.prompt_category);
7653
+
7654
+ return {
7655
+ success: true,
7656
+ category: data.prompt_category,
7657
+ confidence: data.confidence_score,
7658
+ primary_intent: data.primary_intent,
7659
+ secondary_category: data.secondary_category,
7660
+ complexity: data.complexity_level || analysis.complexity,
7661
+ estimated_tokens: analysis.estimated_tokens,
7662
+ domain: getDomainFromCategory(data.prompt_category),
7663
+ requires_specialized_knowledge: analysis.requires_specialized_knowledge,
7664
+ prompt_preview: prompt_text.substring(0, 200),
7665
+ timestamp: new Date().toISOString(),
7666
+ };
7667
+ } else {
7668
+ return {
7669
+ success: false,
7670
+ category: 'General Assistance',
7671
+ confidence: 0,
7672
+ primary_intent: 'Uncategorized',
7673
+ complexity: 'Basic',
7674
+ prompt_preview: prompt_text.substring(0, 200),
7675
+ error: prompt_category_ret?.message || 'API call failed',
7676
+ timestamp: new Date().toISOString(),
7677
+ };
7678
+ }
7679
+ } catch (error) {
7680
+ console.error('Error in categorize_ai_prompt:', error);
7681
+ return {
7682
+ success: false,
7683
+ category: 'General Assistance',
7684
+ confidence: 0,
7685
+ primary_intent: 'Error',
7686
+ complexity: 'Basic',
7687
+ prompt_preview: prompt_text.substring(0, 200),
7688
+ error: error.message,
7689
+ timestamp: new Date().toISOString(),
7690
+ };
7691
+ }
7692
+ };
7693
+
7694
+ // Helper functions (would be defined elsewhere)
7695
+ async function hashPrompt(text) {
7696
+ // Simple hash function for deduplication
7697
+ const encoder = new TextEncoder();
7698
+ const data = encoder.encode(text);
7699
+ const hashBuffer = await crypto.subtle.digest('SHA-256', data);
7700
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
7701
+ return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
7702
+ }
7703
+
7704
+ async function analyzePromptComplexity(prompt, category) {
7705
+ // Analyze prompt complexity based on various factors
7706
+ const wordCount = prompt.split(/\s+/).length;
7707
+ const sentenceCount = prompt.split(/[.!?]+/).length;
7708
+ const hasTechnicalTerms = /(\bAPI\b|\balgorithm\b|\bdebug\b|\banalysis\b)/i.test(prompt);
7709
+ const hasMultipleSteps = /(first|then|next|finally|step 1|step 2)/i.test(prompt);
7710
+ const requiresResearch = /(research|find|look up|investigate)/i.test(prompt);
7711
+
7712
+ let complexity = 'Basic';
7713
+ let estimatedTokens = Math.ceil(wordCount * 1.3); // Rough estimation
7714
+
7715
+ if (wordCount > 100 || hasTechnicalTerms || hasMultipleSteps) {
7716
+ complexity = 'Intermediate';
7717
+ }
7718
+ if (wordCount > 300 || requiresResearch || category.includes('Advanced') || category.includes('Expert')) {
7719
+ complexity = 'Advanced';
7720
+ }
7721
+ if (wordCount > 500 || category.includes('Research') || category.includes('Analysis')) {
7722
+ complexity = 'Expert';
7723
+ }
7724
+
7725
+ return {
7726
+ complexity,
7727
+ estimated_tokens: estimatedTokens,
7728
+ requires_specialized_knowledge: hasTechnicalTerms || requiresResearch,
7729
+ word_count: wordCount,
7730
+ sentence_count: sentenceCount,
7731
+ };
7732
+ }
7733
+
7734
+ function getDomainFromCategory(category) {
7735
+ // Map categories to broader domains
7736
+ const domainMap = {
7737
+ Creative: /writing|story|poetry|creative|art|design/i,
7738
+ Technical: /code|programming|technical|software|api|database/i,
7739
+ Business: /business|marketing|sales|strategy|management/i,
7740
+ Academic: /research|study|homework|academic|education/i,
7741
+ Personal: /advice|personal|relationship|health|fitness/i,
7742
+ Analytical: /analysis|data|statistical|trend|forecast/i,
7743
+ };
7744
+
7745
+ for (const [domain, pattern] of Object.entries(domainMap)) {
7746
+ if (pattern.test(category)) {
7747
+ return domain;
7748
+ }
7749
+ }
7750
+ return 'General';
7751
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4639",
3
+ "version": "1.1.4641",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",