myavana-bot-test-core 1.0.1 → 1.0.3
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/.env +19 -0
- package/index.js +3 -0
- package/package.json +1 -1
- package/src/postResponseProcessing.js +140 -1
- package/src/utils.js +39 -5
package/.env
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# PostgreSQL
|
|
2
|
+
DB_HOST=34.55.140.120
|
|
3
|
+
DB_USER=myavana
|
|
4
|
+
DB_PASSWORD=higibertigibet
|
|
5
|
+
DB_NAME=sienna-naturals-custom-bot
|
|
6
|
+
DB_PORT=5432
|
|
7
|
+
|
|
8
|
+
# Redis
|
|
9
|
+
REDIS_HOST=redis-15330.c1.us-central1-2.gce.redns.redis-cloud.com
|
|
10
|
+
REDIS_PORT=15330
|
|
11
|
+
REDIS_PASSWORD=OyLRjkTPuCGzQ2mNzA3Uhx5HIqWza8QC
|
|
12
|
+
REDIS_USERNAME=default
|
|
13
|
+
|
|
14
|
+
#GENKIT
|
|
15
|
+
GENKIT_API_KEY=AIzaSyBB5ZYwktOFI3R3j_vs8U7CxwKgS3XNgM0
|
|
16
|
+
|
|
17
|
+
#OpenAI
|
|
18
|
+
OPENAI_API_KEY=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
|
|
19
|
+
|
package/index.js
CHANGED
|
@@ -25,4 +25,7 @@ module.exports = {
|
|
|
25
25
|
// Utilities
|
|
26
26
|
getAllProducts: require('./src/utils').getAllProducts,
|
|
27
27
|
getAllFaqs: require('./src/utils').getAllFaqs,
|
|
28
|
+
getAllYoutubeVideos: require('./src/utils').getAllYoutubeVideos,
|
|
29
|
+
getAllTestimonials: require('./src/utils').getAllTestimonials,
|
|
30
|
+
getAdditionalInstructions: require('./src/utils').getAdditionalInstructions
|
|
28
31
|
};
|
package/package.json
CHANGED
|
@@ -5,7 +5,146 @@ const DatabaseSessionStore = require("./session");
|
|
|
5
5
|
const { pgClient, redisClient } = require('./database');
|
|
6
6
|
const {generateAndSaveSummary, saveConversationSummary, saveConversation} = require("./conversation");
|
|
7
7
|
const {saveHairIssue} = require("./hairIssues");
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
const postProcessingPrompt = (chatHistory, message) => {
|
|
10
|
+
return `
|
|
11
|
+
You are a Sienna Naturals expert AI assistant designed to analyze user conversations and user's name and extract structured information related to hair care.
|
|
12
|
+
|
|
13
|
+
**Task:** Analyze the following conversation history and the user's latest message to:
|
|
14
|
+
|
|
15
|
+
1. **Extract User Profile Parameters:** Identify any mentions of the user's name, hair characteristics, concerns, goals, habits, and preferences. Extract these as structured parameters based on the provided Zod schema for UserProfileUpdateSchema. If a parameter is not mentioned or cannot be inferred, leave it as null or optional as defined in the schema. **Specifically, try to identify and extract the user's name if they mention it during the conversation.**
|
|
16
|
+
|
|
17
|
+
2. **Extract Hair Issues:** Identify any specific hair issues the user mentions in their latest message. List these issues as an array of strings in the "hair_issues_reported" field, as defined in the HairIssueExtractionSchema. If no issues are mentioned, return an empty array or null for this field as defined in the schema.
|
|
18
|
+
|
|
19
|
+
**Conversation History:**
|
|
20
|
+
${JSON.stringify(chatHistory)}
|
|
21
|
+
|
|
22
|
+
**User's Latest Message:**
|
|
23
|
+
"${message}"
|
|
24
|
+
|
|
25
|
+
**Response Schema**
|
|
26
|
+
{
|
|
27
|
+
"type": "OBJECT",
|
|
28
|
+
"properties": {
|
|
29
|
+
"user_profile_updates": {
|
|
30
|
+
"type": "OBJECT",
|
|
31
|
+
"properties": {
|
|
32
|
+
"name": {
|
|
33
|
+
"type": "STRING",
|
|
34
|
+
"nullable": true
|
|
35
|
+
},
|
|
36
|
+
"hair_type": {
|
|
37
|
+
"type": "STRING",
|
|
38
|
+
"nullable": true
|
|
39
|
+
},
|
|
40
|
+
"hair_texture": {
|
|
41
|
+
"type": "STRING",
|
|
42
|
+
"nullable": true
|
|
43
|
+
},
|
|
44
|
+
"porosity": {
|
|
45
|
+
"type": "STRING",
|
|
46
|
+
"nullable": true
|
|
47
|
+
},
|
|
48
|
+
"elasticity": {
|
|
49
|
+
"type": "STRING",
|
|
50
|
+
"nullable": true
|
|
51
|
+
},
|
|
52
|
+
"density": {
|
|
53
|
+
"type": "STRING",
|
|
54
|
+
"nullable": true
|
|
55
|
+
},
|
|
56
|
+
"curl_pattern": {
|
|
57
|
+
"type": "STRING",
|
|
58
|
+
"nullable": true
|
|
59
|
+
},
|
|
60
|
+
"hair_color_natural": {
|
|
61
|
+
"type": "STRING",
|
|
62
|
+
"nullable": true
|
|
63
|
+
},
|
|
64
|
+
"hair_color_treated": {
|
|
65
|
+
"type": "STRING",
|
|
66
|
+
"nullable": true
|
|
67
|
+
},
|
|
68
|
+
"hair_concerns": {
|
|
69
|
+
"type": "ARRAY",
|
|
70
|
+
"items": {
|
|
71
|
+
"type": "STRING"
|
|
72
|
+
},
|
|
73
|
+
"nullable": true
|
|
74
|
+
},
|
|
75
|
+
"hair_goals": {
|
|
76
|
+
"type": "ARRAY",
|
|
77
|
+
"items": {
|
|
78
|
+
"type": "STRING"
|
|
79
|
+
},
|
|
80
|
+
"nullable": true
|
|
81
|
+
},
|
|
82
|
+
"hair_history_treatments": {
|
|
83
|
+
"type": "ARRAY",
|
|
84
|
+
"items": {
|
|
85
|
+
"type": "STRING"
|
|
86
|
+
},
|
|
87
|
+
"nullable": true
|
|
88
|
+
},
|
|
89
|
+
"hair_styling_habits": {
|
|
90
|
+
"type": "STRING",
|
|
91
|
+
"nullable": true
|
|
92
|
+
},
|
|
93
|
+
"product_preferences_brands": {
|
|
94
|
+
"type": "ARRAY",
|
|
95
|
+
"items": {
|
|
96
|
+
"type": "STRING"
|
|
97
|
+
},
|
|
98
|
+
"nullable": true
|
|
99
|
+
},
|
|
100
|
+
"product_preferences_ingredients": {
|
|
101
|
+
"type": "STRING",
|
|
102
|
+
"nullable": true
|
|
103
|
+
},
|
|
104
|
+
"journey_stage_intent": {
|
|
105
|
+
"type": "STRING",
|
|
106
|
+
"nullable": true
|
|
107
|
+
},
|
|
108
|
+
"damage_level_self_reported": {
|
|
109
|
+
"type": "STRING",
|
|
110
|
+
"nullable": true
|
|
111
|
+
},
|
|
112
|
+
"experimenting_interest": {
|
|
113
|
+
"type": "BOOLEAN",
|
|
114
|
+
"nullable": true
|
|
115
|
+
},
|
|
116
|
+
"boredom_expression": {
|
|
117
|
+
"type": "BOOLEAN",
|
|
118
|
+
"nullable": true
|
|
119
|
+
},
|
|
120
|
+
"confidence_level_inferred": {
|
|
121
|
+
"type": "STRING",
|
|
122
|
+
"nullable": true
|
|
123
|
+
},
|
|
124
|
+
"desperation_level_inferred": {
|
|
125
|
+
"type": "STRING",
|
|
126
|
+
"nullable": true
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"nullable": true
|
|
130
|
+
},
|
|
131
|
+
"hair_issue_extractions": {
|
|
132
|
+
"type": "OBJECT",
|
|
133
|
+
"properties": {
|
|
134
|
+
"hair_issues_reported": {
|
|
135
|
+
"type": "ARRAY",
|
|
136
|
+
"items": {
|
|
137
|
+
"type": "STRING"
|
|
138
|
+
},
|
|
139
|
+
"nullable": true
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
"nullable": true
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
`;
|
|
147
|
+
};
|
|
9
148
|
|
|
10
149
|
|
|
11
150
|
const processBotResponse = (botResponse) => {
|
package/src/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// app/api/utils.js
|
|
2
|
+
const { pgClient } = require('./database'); // Or your DB connection
|
|
2
3
|
|
|
3
4
|
async function getAllProducts() {
|
|
4
5
|
try {
|
|
@@ -20,13 +21,46 @@ async function getAllFaqs() {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
async function
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
async function getAllYoutubeVideos() { // New function to get ALL YouTube Videos
|
|
25
|
+
try {
|
|
26
|
+
const result = await pgClient.query('SELECT * FROM youtube_videos');
|
|
27
|
+
return result.rows;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error("Error fetching all YouTube videos:", error);
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
26
32
|
}
|
|
27
33
|
|
|
34
|
+
async function getAllTestimonials() { // New function to get ALL Testimonials
|
|
35
|
+
try {
|
|
36
|
+
const result = await pgClient.query('SELECT * FROM testimonials');
|
|
37
|
+
return result.rows;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error("Error fetching all testimonials:", error);
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function getAdditionalInstructions() { // New function to get ALL Bot Instructions
|
|
45
|
+
try {
|
|
46
|
+
const result = await pgClient.query('SELECT * FROM bot_instructions');
|
|
47
|
+
return result.rows;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error("Error fetching bot instructions:", error);
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function getHairIssuesForUser(userId){
|
|
54
|
+
//return empty for now
|
|
55
|
+
return []
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
28
59
|
module.exports = {
|
|
29
60
|
getAllProducts,
|
|
30
61
|
getAllFaqs,
|
|
31
|
-
|
|
62
|
+
getAllYoutubeVideos,
|
|
63
|
+
getAllTestimonials,
|
|
64
|
+
getAdditionalInstructions,
|
|
65
|
+
getHairIssuesForUser
|
|
32
66
|
};
|