@xuda.io/ai_module 1.1.4768 → 1.1.4769
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 +59 -58
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -7519,6 +7519,65 @@ Category:`;
|
|
|
7519
7519
|
};
|
|
7520
7520
|
|
|
7521
7521
|
export const categorize_ai_prompt = async function (uid, prompt_text, account_profile_info) {
|
|
7522
|
+
// Helper functions (would be defined elsewhere)
|
|
7523
|
+
async function hashPrompt(text) {
|
|
7524
|
+
// Simple hash function for deduplication
|
|
7525
|
+
const encoder = new TextEncoder();
|
|
7526
|
+
const data = encoder.encode(text);
|
|
7527
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
|
7528
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
7529
|
+
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
7530
|
+
}
|
|
7531
|
+
|
|
7532
|
+
async function analyzePromptComplexity(prompt, category) {
|
|
7533
|
+
// Analyze prompt complexity based on various factors
|
|
7534
|
+
const wordCount = prompt.split(/\s+/).length;
|
|
7535
|
+
const sentenceCount = prompt.split(/[.!?]+/).length;
|
|
7536
|
+
const hasTechnicalTerms = /(\bAPI\b|\balgorithm\b|\bdebug\b|\banalysis\b)/i.test(prompt);
|
|
7537
|
+
const hasMultipleSteps = /(first|then|next|finally|step 1|step 2)/i.test(prompt);
|
|
7538
|
+
const requiresResearch = /(research|find|look up|investigate)/i.test(prompt);
|
|
7539
|
+
|
|
7540
|
+
let complexity = 'Basic';
|
|
7541
|
+
let estimatedTokens = Math.ceil(wordCount * 1.3); // Rough estimation
|
|
7542
|
+
|
|
7543
|
+
if (wordCount > 100 || hasTechnicalTerms || hasMultipleSteps) {
|
|
7544
|
+
complexity = 'Intermediate';
|
|
7545
|
+
}
|
|
7546
|
+
if (wordCount > 300 || requiresResearch || category.includes('Advanced') || category.includes('Expert')) {
|
|
7547
|
+
complexity = 'Advanced';
|
|
7548
|
+
}
|
|
7549
|
+
if (wordCount > 500 || category.includes('Research') || category.includes('Analysis')) {
|
|
7550
|
+
complexity = 'Expert';
|
|
7551
|
+
}
|
|
7552
|
+
|
|
7553
|
+
return {
|
|
7554
|
+
complexity,
|
|
7555
|
+
estimated_tokens: estimatedTokens,
|
|
7556
|
+
requires_specialized_knowledge: hasTechnicalTerms || requiresResearch,
|
|
7557
|
+
word_count: wordCount,
|
|
7558
|
+
sentence_count: sentenceCount,
|
|
7559
|
+
};
|
|
7560
|
+
}
|
|
7561
|
+
|
|
7562
|
+
function getDomainFromCategory(category) {
|
|
7563
|
+
// Map categories to broader domains
|
|
7564
|
+
const domainMap = {
|
|
7565
|
+
Creative: /writing|story|poetry|creative|art|design/i,
|
|
7566
|
+
Technical: /code|programming|technical|software|api|database/i,
|
|
7567
|
+
Business: /business|marketing|sales|strategy|management/i,
|
|
7568
|
+
Academic: /research|study|homework|academic|education/i,
|
|
7569
|
+
Personal: /advice|personal|relationship|health|fitness/i,
|
|
7570
|
+
Analytical: /analysis|data|statistical|trend|forecast/i,
|
|
7571
|
+
};
|
|
7572
|
+
|
|
7573
|
+
for (const [domain, pattern] of Object.entries(domainMap)) {
|
|
7574
|
+
if (pattern.test(category)) {
|
|
7575
|
+
return domain;
|
|
7576
|
+
}
|
|
7577
|
+
}
|
|
7578
|
+
return 'General';
|
|
7579
|
+
}
|
|
7580
|
+
|
|
7522
7581
|
const ai_prompt_categories = [
|
|
7523
7582
|
// Creative & Content Generation (1-15)
|
|
7524
7583
|
'Creative Writing',
|
|
@@ -7845,64 +7904,6 @@ Category:`;
|
|
|
7845
7904
|
}
|
|
7846
7905
|
};
|
|
7847
7906
|
|
|
7848
|
-
// Helper functions (would be defined elsewhere)
|
|
7849
|
-
async function hashPrompt(text) {
|
|
7850
|
-
// Simple hash function for deduplication
|
|
7851
|
-
const encoder = new TextEncoder();
|
|
7852
|
-
const data = encoder.encode(text);
|
|
7853
|
-
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
|
7854
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
7855
|
-
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
7856
|
-
}
|
|
7857
|
-
|
|
7858
|
-
async function analyzePromptComplexity(prompt, category) {
|
|
7859
|
-
// Analyze prompt complexity based on various factors
|
|
7860
|
-
const wordCount = prompt.split(/\s+/).length;
|
|
7861
|
-
const sentenceCount = prompt.split(/[.!?]+/).length;
|
|
7862
|
-
const hasTechnicalTerms = /(\bAPI\b|\balgorithm\b|\bdebug\b|\banalysis\b)/i.test(prompt);
|
|
7863
|
-
const hasMultipleSteps = /(first|then|next|finally|step 1|step 2)/i.test(prompt);
|
|
7864
|
-
const requiresResearch = /(research|find|look up|investigate)/i.test(prompt);
|
|
7865
|
-
|
|
7866
|
-
let complexity = 'Basic';
|
|
7867
|
-
let estimatedTokens = Math.ceil(wordCount * 1.3); // Rough estimation
|
|
7868
|
-
|
|
7869
|
-
if (wordCount > 100 || hasTechnicalTerms || hasMultipleSteps) {
|
|
7870
|
-
complexity = 'Intermediate';
|
|
7871
|
-
}
|
|
7872
|
-
if (wordCount > 300 || requiresResearch || category.includes('Advanced') || category.includes('Expert')) {
|
|
7873
|
-
complexity = 'Advanced';
|
|
7874
|
-
}
|
|
7875
|
-
if (wordCount > 500 || category.includes('Research') || category.includes('Analysis')) {
|
|
7876
|
-
complexity = 'Expert';
|
|
7877
|
-
}
|
|
7878
|
-
|
|
7879
|
-
return {
|
|
7880
|
-
complexity,
|
|
7881
|
-
estimated_tokens: estimatedTokens,
|
|
7882
|
-
requires_specialized_knowledge: hasTechnicalTerms || requiresResearch,
|
|
7883
|
-
word_count: wordCount,
|
|
7884
|
-
sentence_count: sentenceCount,
|
|
7885
|
-
};
|
|
7886
|
-
}
|
|
7887
|
-
|
|
7888
|
-
function getDomainFromCategory(category) {
|
|
7889
|
-
// Map categories to broader domains
|
|
7890
|
-
const domainMap = {
|
|
7891
|
-
Creative: /writing|story|poetry|creative|art|design/i,
|
|
7892
|
-
Technical: /code|programming|technical|software|api|database/i,
|
|
7893
|
-
Business: /business|marketing|sales|strategy|management/i,
|
|
7894
|
-
Academic: /research|study|homework|academic|education/i,
|
|
7895
|
-
Personal: /advice|personal|relationship|health|fitness/i,
|
|
7896
|
-
Analytical: /analysis|data|statistical|trend|forecast/i,
|
|
7897
|
-
};
|
|
7898
|
-
|
|
7899
|
-
for (const [domain, pattern] of Object.entries(domainMap)) {
|
|
7900
|
-
if (pattern.test(category)) {
|
|
7901
|
-
return domain;
|
|
7902
|
-
}
|
|
7903
|
-
}
|
|
7904
|
-
return 'General';
|
|
7905
|
-
}
|
|
7906
7907
|
export const categorize_text_message = async function (uid, text_message, account_profile_info) {
|
|
7907
7908
|
const text_message_categories = [
|
|
7908
7909
|
// Personal Communication (1-20)
|