@xapp/stentor-service-generative-ai 1.89.0 → 1.89.1
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/lib/AWSBedrockService.d.ts +67 -0
- package/lib/AWSBedrockService.js +133 -0
- package/lib/AWSBedrockService.js.map +1 -0
- package/lib/ClaudeService.d.ts +77 -0
- package/lib/ClaudeService.js +142 -0
- package/lib/ClaudeService.js.map +1 -0
- package/lib/FallbackLLMService.d.ts +46 -0
- package/lib/FallbackLLMService.js +83 -0
- package/lib/FallbackLLMService.js.map +1 -0
- package/lib/GenerativeAIService.d.ts +49 -0
- package/lib/GenerativeAIService.js +130 -0
- package/lib/GenerativeAIService.js.map +1 -0
- package/lib/OpenAIService.d.ts +33 -0
- package/lib/OpenAIService.js +76 -0
- package/lib/OpenAIService.js.map +1 -0
- package/lib/http/HTTPService.d.ts +18 -0
- package/lib/http/HTTPService.js +4 -0
- package/lib/http/HTTPService.js.map +1 -0
- package/lib/http/NodeHTTPService.d.ts +8 -0
- package/lib/http/NodeHTTPService.js +70 -0
- package/lib/http/NodeHTTPService.js.map +1 -0
- package/lib/http/index.d.ts +3 -0
- package/lib/http/index.js +20 -0
- package/lib/http/index.js.map +1 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +27 -0
- package/lib/index.js.map +1 -0
- package/lib/models/ChatSummary.d.ts +10 -0
- package/lib/models/ChatSummary.js +4 -0
- package/lib/models/ChatSummary.js.map +1 -0
- package/lib/models/EmailAnalysis.d.ts +73 -0
- package/lib/models/EmailAnalysis.js +4 -0
- package/lib/models/EmailAnalysis.js.map +1 -0
- package/lib/models/EngagementAnalysis.d.ts +93 -0
- package/lib/models/EngagementAnalysis.js +4 -0
- package/lib/models/EngagementAnalysis.js.map +1 -0
- package/lib/models/GenerativeAIService.d.ts +65 -0
- package/lib/models/GenerativeAIService.js +3 -0
- package/lib/models/GenerativeAIService.js.map +1 -0
- package/lib/models/LLMService.d.ts +24 -0
- package/lib/models/LLMService.js +4 -0
- package/lib/models/LLMService.js.map +1 -0
- package/lib/models/LeadAnalysis.d.ts +105 -0
- package/lib/models/LeadAnalysis.js +4 -0
- package/lib/models/LeadAnalysis.js.map +1 -0
- package/lib/models/Prompt.d.ts +37 -0
- package/lib/models/Prompt.js +8 -0
- package/lib/models/Prompt.js.map +1 -0
- package/lib/models/PromptGenerator.d.ts +6 -0
- package/lib/models/PromptGenerator.js +4 -0
- package/lib/models/PromptGenerator.js.map +1 -0
- package/lib/models/ResponseParser.d.ts +5 -0
- package/lib/models/ResponseParser.js +4 -0
- package/lib/models/ResponseParser.js.map +1 -0
- package/lib/models/WebsiteAnalysis.d.ts +48 -0
- package/lib/models/WebsiteAnalysis.js +4 -0
- package/lib/models/WebsiteAnalysis.js.map +1 -0
- package/lib/models/errors.d.ts +7 -0
- package/lib/models/errors.js +15 -0
- package/lib/models/errors.js.map +1 -0
- package/lib/models/index.d.ts +10 -0
- package/lib/models/index.js +27 -0
- package/lib/models/index.js.map +1 -0
- package/lib/prompts/AnalyzeEmail.d.ts +36 -0
- package/lib/prompts/AnalyzeEmail.js +385 -0
- package/lib/prompts/AnalyzeEmail.js.map +1 -0
- package/lib/prompts/AnalyzeLead.d.ts +59 -0
- package/lib/prompts/AnalyzeLead.js +396 -0
- package/lib/prompts/AnalyzeLead.js.map +1 -0
- package/lib/prompts/AnalyzeTranscript.d.ts +24 -0
- package/lib/prompts/AnalyzeTranscript.js +202 -0
- package/lib/prompts/AnalyzeTranscript.js.map +1 -0
- package/lib/prompts/AnalyzeWebsite.d.ts +10 -0
- package/lib/prompts/AnalyzeWebsite.js +176 -0
- package/lib/prompts/AnalyzeWebsite.js.map +1 -0
- package/lib/prompts/ChatSummary.d.ts +62 -0
- package/lib/prompts/ChatSummary.js +67 -0
- package/lib/prompts/ChatSummary.js.map +1 -0
- package/lib/prompts/index.d.ts +5 -0
- package/lib/prompts/index.js +22 -0
- package/lib/prompts/index.js.map +1 -0
- package/lib/utils/extractJSON.d.ts +10 -0
- package/lib/utils/extractJSON.js +17 -0
- package/lib/utils/extractJSON.js.map +1 -0
- package/lib/utils/standardizeTerms.d.ts +15 -0
- package/lib/utils/standardizeTerms.js +53 -0
- package/lib/utils/standardizeTerms.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.analyzeLeadResponseParse = exports.generateAnalyzeLead = void 0;
|
|
4
|
+
exports.translateTranscript = translateTranscript;
|
|
5
|
+
exports.transcriptToMessages = transcriptToMessages;
|
|
6
|
+
exports.parseFields = parseFields;
|
|
7
|
+
exports.getHighValueLeadDescription = getHighValueLeadDescription;
|
|
8
|
+
const stentor_utils_1 = require("stentor-utils");
|
|
9
|
+
const extractJSON_1 = require("../utils/extractJSON");
|
|
10
|
+
function getName(profile) {
|
|
11
|
+
// Sorting these based on priority.
|
|
12
|
+
return (profile === null || profile === void 0 ? void 0 : profile.name) || (profile === null || profile === void 0 ? void 0 : profile.email) || (profile === null || profile === void 0 ? void 0 : profile.phone) || "Unknown";
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Converts a transcript from an external lead in to a series of strings.
|
|
16
|
+
*
|
|
17
|
+
* @param transcript
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
function translateTranscript(transcript) {
|
|
21
|
+
if (!transcript || transcript.length === 0) {
|
|
22
|
+
return ["No transcript available."];
|
|
23
|
+
}
|
|
24
|
+
return transcript.map(({ from, message }) => `${getName(from)}: ${message}`);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Turns a transcript into a series of messages for OpenAI
|
|
28
|
+
*
|
|
29
|
+
* @param system
|
|
30
|
+
* @param transcript
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
function transcriptToMessages(system, transcript) {
|
|
34
|
+
const messages = [
|
|
35
|
+
{
|
|
36
|
+
role: "system",
|
|
37
|
+
content: system
|
|
38
|
+
}
|
|
39
|
+
];
|
|
40
|
+
// add the messages from the transcript
|
|
41
|
+
if ((0, stentor_utils_1.existsAndNotEmpty)(transcript)) {
|
|
42
|
+
// it will either be the appId, typically for single tenant runtimes,
|
|
43
|
+
// or "bot" for multi-tenant since we don't set this environment variable in multi-tenant
|
|
44
|
+
const botId = process.env["STUDIO_APP_ID"] || "bot";
|
|
45
|
+
// the transcript is in reverse order, so we need to reverse it
|
|
46
|
+
//const reversed = transcript.slice().reverse();
|
|
47
|
+
for (const message of transcript) {
|
|
48
|
+
const role = message.from.id === botId || message.from.id === "bot" ? "assistant" : "user";
|
|
49
|
+
messages.push({
|
|
50
|
+
role,
|
|
51
|
+
content: message.message
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return messages;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Parses the fields from an external lead and returns a string representation of them.
|
|
59
|
+
*
|
|
60
|
+
* @param fields
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
function parseFields(fields) {
|
|
64
|
+
if (!fields || fields.length === 0) {
|
|
65
|
+
return "";
|
|
66
|
+
}
|
|
67
|
+
const fieldStrings = fields.map((field) => {
|
|
68
|
+
if (field.value && field.value.length > 0) {
|
|
69
|
+
return `${field.name}: ${field.value}`;
|
|
70
|
+
}
|
|
71
|
+
return `${field.name}: No value provided`;
|
|
72
|
+
});
|
|
73
|
+
return fieldStrings.join("\n");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Generates a default High Value Lead Description if the business does not provide one.
|
|
77
|
+
*
|
|
78
|
+
* @param app
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
function getHighValueLeadDescription(highValueLeadDescription) {
|
|
82
|
+
return highValueLeadDescription || "No description was provided, do not return highValueLead.";
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Generates a prompt that can be used in an LLM to analyze a lead for a business.
|
|
86
|
+
*
|
|
87
|
+
* The expected output format from the LLM will be:
|
|
88
|
+
*
|
|
89
|
+
* <Contact Type>::<Urgency Type>::<High Value Lead (true/false)>::<Summary>
|
|
90
|
+
*
|
|
91
|
+
* @param lead - The lead to analyze with the business description and other options to customize the prompt.
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
94
|
+
const generateAnalyzeLead = ({ channel, businessDescription, highValueLeadDescription, transcript, fields }, overrides) => {
|
|
95
|
+
// determine max_tokens
|
|
96
|
+
// depending on if the lead is from chat or form, we provide different content.
|
|
97
|
+
// if form, we just put the gathered fields in the system message
|
|
98
|
+
// if chat, we add the chat transcript to the messages, bot is the system message and user is the chat transcript.
|
|
99
|
+
const isChat = channel === "widget" || (0, stentor_utils_1.existsAndNotEmpty)(transcript);
|
|
100
|
+
const hasBusinessDescription = !!businessDescription;
|
|
101
|
+
const hasHighValueLeadDescription = !!highValueLeadDescription;
|
|
102
|
+
let intro = `You are a knowledgeable employee of a business.`;
|
|
103
|
+
if (hasBusinessDescription) {
|
|
104
|
+
intro = `
|
|
105
|
+
You are a knowledgeable employee of a business with the following description:
|
|
106
|
+
|
|
107
|
+
===
|
|
108
|
+
${businessDescription}
|
|
109
|
+
===`;
|
|
110
|
+
}
|
|
111
|
+
const instructions = isChat
|
|
112
|
+
? `Your job is to analyze the following chat transcript that occurred between a customer or potential customer and an AI agent representing the business.`
|
|
113
|
+
: `Your job is to analyze the information provided by the customer or potential customer in a form submission.`;
|
|
114
|
+
let highValueLeadInstruction = "A high value lead description was not provided, do not return highValueLead.";
|
|
115
|
+
if (hasHighValueLeadDescription) {
|
|
116
|
+
highValueLeadInstruction = `A high value lead is defined as:
|
|
117
|
+
===
|
|
118
|
+
${getHighValueLeadDescription(highValueLeadDescription)}
|
|
119
|
+
===`;
|
|
120
|
+
}
|
|
121
|
+
let system = `
|
|
122
|
+
${intro}
|
|
123
|
+
|
|
124
|
+
${instructions}
|
|
125
|
+
|
|
126
|
+
You will return you analysis as a JSON object with the following properties:
|
|
127
|
+
|
|
128
|
+
- contactType
|
|
129
|
+
- serviceType
|
|
130
|
+
- jobType
|
|
131
|
+
- urgency
|
|
132
|
+
- analysis
|
|
133
|
+
- summary
|
|
134
|
+
- conciseSummary
|
|
135
|
+
|
|
136
|
+
Provide your analysis of why you made these decisions which will be placed in the value "analysis". Include why you made decisions for contactType, serviceType, jobType and urgency. The analysis should be concise and provide enough detail to understand your reasoning. The analysis should not exceed 500 characters.
|
|
137
|
+
|
|
138
|
+
"contactType" definitions are as follows:
|
|
139
|
+
BILLING_ISSUE: Concerns about charges, refunds, pricing discrepancies, or payments (e.g., “I was billed incorrectly”, “I want a refund”).
|
|
140
|
+
CANCELLATION: Asking to cancel an appointment, service, subscription, or contract.
|
|
141
|
+
COMPLAINT: Dissatisfaction with the business, product, or service quality, excluding billing or scheduling issues.
|
|
142
|
+
COMPLIMENT: Positive feedback about the business, staff, or product.
|
|
143
|
+
CONTACT_REQUEST: A request for someone to contact the customer, without describing any service need, issue, quote request, scheduling intent, problem, or other specific purpose. Use only when the customer gives no actionable details (e.g., “please call me”). Do NOT use if the message includes a request for service, repair, installation, inspection, maintenance, scheduling, rescheduling, a quote, or reporting an issue.
|
|
144
|
+
EMPLOYMENT_INQUIRY: Questions about jobs, openings, hiring, or how to apply.
|
|
145
|
+
MISSED_APPOINTMENT: Reporting a no-show, missed call/visit, or confusion about appointment status or confirmation.
|
|
146
|
+
QUESTION: A general question about the business, services, products, availability, or policies, without requesting service or a quote. Requires a human reply.
|
|
147
|
+
QUOTE_REQUEST: Requesting a price, cost, estimate, quote, or ballpark figure for a product or service.
|
|
148
|
+
RESCHEDULE_REQUEST: Asking to change, move, or adjust the date or time of an existing appointment or scheduled service.
|
|
149
|
+
SERVICE_REQUEST: Requesting service, repair, installation, maintenance, inspection, booking/scheduling, or any assistance with a problem or issue. Includes any request for someone to come out, fix something, inspect something, or schedule a visit.
|
|
150
|
+
SPAM: Unsolicited, irrelevant, deceptive, generic, or low-value content. Includes people offering cost estimation or takeoff services, marketing/multimedia/SEO vendors, people offering to buy the business, debt relief companies, generic copy-pasted messages, gibberish, or fake/incomplete contact info.
|
|
151
|
+
TEST: A test message, placeholder text, or internal system check (e.g., “test”, “asdf”).
|
|
152
|
+
OTHER: Content cannot be reasonably determined from the transcript.
|
|
153
|
+
|
|
154
|
+
When multiple could apply, prefer BILLING_ISSUE, RESCHEDULE_REQUEST, CANCELLATION, or MISSED_APPOINTMENT over COMPLAINT or CONTACT_REQUEST.
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
The definitions of each "serviceType" value are as follows:
|
|
158
|
+
CLEANING: Cleaning work (e.g., house, windows, ducts, carpet, gutters). Note: overlaps with jobType=cleaning but here describes the type of work performed.
|
|
159
|
+
CONSULTATION: Requesting advice or guidance only, not execution (e.g., legal, design, remodel planning).
|
|
160
|
+
INSPECTION: Evaluation or check to assess a condition or issue (e.g., termite, mold, roof, crawlspace, safety, pre-sale).
|
|
161
|
+
INSTALLATION: New install of a product or system.
|
|
162
|
+
MAINTENANCE: Routine or recurring upkeep (e.g., HVAC tune-up, landscaping, gutter service).
|
|
163
|
+
REFINISH: Refinishing surfaces (e.g., floors, cabinets). Can include painting, staining, or other surface treatments. Use with jobType=painting when applicable.
|
|
164
|
+
REMODEL: Renovating or improving an existing structure or space. Note: overlaps with jobType=remodeling but here describes the type of work performed.
|
|
165
|
+
REPAIR: Fixing an existing product or system.
|
|
166
|
+
SUPPORT: Help with an issue or appointment related to the service but not the work itself (e.g., service follow-up, account help).
|
|
167
|
+
TRANSPORT: Requests to move, haul, or deliver items (e.g., moving services, relocation, junk removal, large delivery).
|
|
168
|
+
TREATMENT: Active service to resolve or prevent an issue (e.g., pest treatment, mold remediation, lawn spraying, rodent removal, recurring pest plans).
|
|
169
|
+
OTHER: Anything not covered above. If multiple apply, pick the most specific.
|
|
170
|
+
|
|
171
|
+
jobType definitions are as follows:
|
|
172
|
+
appliance_repair: Appliance repair services.
|
|
173
|
+
blinds: Window blinds and shades installation services.
|
|
174
|
+
carpentry: Carpentry or woodworking services.
|
|
175
|
+
cleaning: General cleaning services (house, carpet, duct, etc.).
|
|
176
|
+
construction: General construction services.
|
|
177
|
+
contractor: General contracting services (same as construction).
|
|
178
|
+
drywall: Drywall installation or repair.
|
|
179
|
+
electrical: Electrical work or services.
|
|
180
|
+
electrician: Electrical work or services (same as electrical).
|
|
181
|
+
fencing: Fence installation or repair.
|
|
182
|
+
flooring: Flooring installation, refinishing, or repair (hardwood, tile, etc.).
|
|
183
|
+
gutter: Gutter installation, rerouting, or cleaning.
|
|
184
|
+
gutters: Gutter services (same as gutter).
|
|
185
|
+
handyman: General home repair and maintenance services.
|
|
186
|
+
house_cleaning: House cleaning services (same as cleaning).
|
|
187
|
+
hvac: Heating, ventilation, or air conditioning services.
|
|
188
|
+
junk_removal: Junk and debris removal services.
|
|
189
|
+
landscaping: Landscaping or yard services.
|
|
190
|
+
landscaper: Landscaping services (same as landscaping).
|
|
191
|
+
legal_services: Legal services.
|
|
192
|
+
masonry: Masonry, brick, stone, or tuckpointing work.
|
|
193
|
+
mold_remediation: Mold inspection, removal, or remediation services.
|
|
194
|
+
moving: Moving or relocation services.
|
|
195
|
+
painting: Painting services.
|
|
196
|
+
painter: Painting services (same as painting).
|
|
197
|
+
pest_control: Pest control services (insects, termites, rodents).
|
|
198
|
+
plumbing: Plumbing services.
|
|
199
|
+
pressure_washing: Pressure washing and power washing services.
|
|
200
|
+
remodeling: Remodeling or renovation (kitchen, bathroom, home).
|
|
201
|
+
restoration: Water, fire, or damage restoration services.
|
|
202
|
+
roofing: Roofing services.
|
|
203
|
+
roofer: Roofing services (same as roofing).
|
|
204
|
+
siding: Siding installation or repair services.
|
|
205
|
+
tree_services: Tree removal, trimming, and care services.
|
|
206
|
+
wildlife_control: Wildlife removal or exclusion services (e.g., raccoons, squirrels, bats).
|
|
207
|
+
window_cleaning: Window cleaning services.
|
|
208
|
+
window_installation: Window installation or replacement services.
|
|
209
|
+
windows_doors: Window or door installation or replacement.
|
|
210
|
+
other: Services that do not fit above.
|
|
211
|
+
|
|
212
|
+
The definitions of each "urgency" value are as follows:
|
|
213
|
+
LOW: The interaction requests a service that is not time sensitive at all and can be addressed at the business's convenience.
|
|
214
|
+
MEDIUM: The interaction requests a service that is not time sensitive and can be addressed within a couple weeks.
|
|
215
|
+
HIGH: The interaction requests some service that is not life threatening, but should be addressed within a few days. It may lead to property damage or other issues if not addressed in a timely manner.
|
|
216
|
+
URGENT: The interaction requests some service that is life threatening or is causing property damage. It should be addressed as soon as possible, potentially same day. The longer the business waits to address the issue, the more damage will occur.
|
|
217
|
+
NOT_SPECIFIED: The urgency of the lead could not be determined by the content of the transcript.
|
|
218
|
+
|
|
219
|
+
Note about "urgency": This isn't necessarily the customer stating that the issue is urgent, but rather the nature of the issue itself.
|
|
220
|
+
|
|
221
|
+
${highValueLeadInstruction}
|
|
222
|
+
|
|
223
|
+
Provide a summary of the conversation which will be placed in the value "summary". The summary should not exceed 250 characters.
|
|
224
|
+
|
|
225
|
+
Provide a concise 2–3 word phrase describing the main topic or service request of the lead. Use context from the business description, jobType, and serviceType if available. Use information from the message field and leverage the user's words as much as possible. Focus on meaningful keywords related to the issue or service, not greetings or filler words. Return this in the value "conciseSummary".
|
|
226
|
+
Examples:
|
|
227
|
+
- Message: "we need our backflow tested" → "backflow testing"
|
|
228
|
+
- Message: "scorpion and cricket issues" → "scorpion cricket issues"
|
|
229
|
+
- Message: "i'm interested in filing bankruptcy" → "bankruptcy filing"
|
|
230
|
+
- Message (pest control company): "this is only for small casita housing. not big main house" → "casita housing service"
|
|
231
|
+
`;
|
|
232
|
+
if (!isChat && (0, stentor_utils_1.existsAndNotEmpty)(fields)) {
|
|
233
|
+
const parsedFields = parseFields(fields);
|
|
234
|
+
system += `
|
|
235
|
+
The following fields were collected from the customer or potential customer in the form submission:
|
|
236
|
+
${parsedFields}
|
|
237
|
+
`;
|
|
238
|
+
}
|
|
239
|
+
// console.log(system);
|
|
240
|
+
const messages = transcriptToMessages(system, transcript);
|
|
241
|
+
// determine max_tokens based on the length of the system message
|
|
242
|
+
// const systemMessageLength = JSON.stringify(system).length;
|
|
243
|
+
// const tokens = getTokens(system);
|
|
244
|
+
// console.log("System message tokens:", tokens);
|
|
245
|
+
const max_tokens = 512;
|
|
246
|
+
return Object.assign(Object.assign({ model: "gpt-4o-mini",
|
|
247
|
+
// model: "gpt-4.1-mini",
|
|
248
|
+
max_tokens, frequency_penalty: 0, temperature: 1, top_p: 1, presence_penalty: 0 }, overrides), { response_format: {
|
|
249
|
+
type: "json_schema",
|
|
250
|
+
json_schema: {
|
|
251
|
+
name: "analyze_lead",
|
|
252
|
+
strict: false,
|
|
253
|
+
schema: {
|
|
254
|
+
type: "object",
|
|
255
|
+
additionalProperties: false,
|
|
256
|
+
required: [
|
|
257
|
+
"contactType",
|
|
258
|
+
"jobType",
|
|
259
|
+
"serviceType",
|
|
260
|
+
"urgency",
|
|
261
|
+
"highValueLead",
|
|
262
|
+
"conciseSummary",
|
|
263
|
+
"summary",
|
|
264
|
+
"analysis"
|
|
265
|
+
],
|
|
266
|
+
properties: {
|
|
267
|
+
contactType: {
|
|
268
|
+
type: "string",
|
|
269
|
+
enum: [
|
|
270
|
+
"BILLING_ISSUE",
|
|
271
|
+
"CANCELLATION",
|
|
272
|
+
"COMPLAINT",
|
|
273
|
+
"COMPLIMENT",
|
|
274
|
+
"CONTACT_REQUEST",
|
|
275
|
+
"EMPLOYMENT_INQUIRY",
|
|
276
|
+
"MISSED_APPOINTMENT",
|
|
277
|
+
"QUESTION",
|
|
278
|
+
"QUOTE_REQUEST",
|
|
279
|
+
"RESCHEDULE_REQUEST",
|
|
280
|
+
"SERVICE_REQUEST",
|
|
281
|
+
"SPAM",
|
|
282
|
+
"TEST",
|
|
283
|
+
"OTHER"
|
|
284
|
+
]
|
|
285
|
+
},
|
|
286
|
+
jobType: {
|
|
287
|
+
type: "string",
|
|
288
|
+
enum: [
|
|
289
|
+
"appliance_repair",
|
|
290
|
+
"blinds",
|
|
291
|
+
"carpentry",
|
|
292
|
+
"cleaning",
|
|
293
|
+
"construction",
|
|
294
|
+
"contractor",
|
|
295
|
+
"drywall",
|
|
296
|
+
"electrical",
|
|
297
|
+
"electrician",
|
|
298
|
+
"fencing",
|
|
299
|
+
"flooring",
|
|
300
|
+
"gutter",
|
|
301
|
+
"gutters",
|
|
302
|
+
"handyman",
|
|
303
|
+
"house_cleaning",
|
|
304
|
+
"hvac",
|
|
305
|
+
"junk_removal",
|
|
306
|
+
"landscaping",
|
|
307
|
+
"landscaper",
|
|
308
|
+
"legal_services",
|
|
309
|
+
"masonry",
|
|
310
|
+
"mold_remediation",
|
|
311
|
+
"moving",
|
|
312
|
+
"painting",
|
|
313
|
+
"painter",
|
|
314
|
+
"pest_control",
|
|
315
|
+
"plumbing",
|
|
316
|
+
"pressure_washing",
|
|
317
|
+
"remodeling",
|
|
318
|
+
"restoration",
|
|
319
|
+
"roofing",
|
|
320
|
+
"roofer",
|
|
321
|
+
"siding",
|
|
322
|
+
"tree_services",
|
|
323
|
+
"wildlife_control",
|
|
324
|
+
"window_cleaning",
|
|
325
|
+
"window_installation",
|
|
326
|
+
"windows_doors",
|
|
327
|
+
"other"
|
|
328
|
+
]
|
|
329
|
+
},
|
|
330
|
+
serviceType: {
|
|
331
|
+
type: "string",
|
|
332
|
+
enum: [
|
|
333
|
+
"CLEANING",
|
|
334
|
+
"CONSULTATION",
|
|
335
|
+
"INSPECTION",
|
|
336
|
+
"INSTALLATION",
|
|
337
|
+
"MAINTENANCE",
|
|
338
|
+
"REFINISH",
|
|
339
|
+
"REMODEL",
|
|
340
|
+
"REPAIR",
|
|
341
|
+
"SUPPORT",
|
|
342
|
+
"TRANSPORT",
|
|
343
|
+
"TREATMENT",
|
|
344
|
+
"OTHER"
|
|
345
|
+
]
|
|
346
|
+
},
|
|
347
|
+
urgency: {
|
|
348
|
+
type: "string",
|
|
349
|
+
enum: ["LOW", "MEDIUM", "HIGH", "URGENT", "NOT_SPECIFIED"]
|
|
350
|
+
},
|
|
351
|
+
highValueLead: {
|
|
352
|
+
type: "boolean"
|
|
353
|
+
},
|
|
354
|
+
summary: {
|
|
355
|
+
type: "string"
|
|
356
|
+
},
|
|
357
|
+
conciseSummary: {
|
|
358
|
+
type: "string"
|
|
359
|
+
},
|
|
360
|
+
analysis: {
|
|
361
|
+
type: "string"
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}, type: "completions", messages });
|
|
367
|
+
};
|
|
368
|
+
exports.generateAnalyzeLead = generateAnalyzeLead;
|
|
369
|
+
const defaultLeadAnalysis = {
|
|
370
|
+
contactType: "OTHER",
|
|
371
|
+
urgency: "NOT_SPECIFIED",
|
|
372
|
+
highValueLead: false,
|
|
373
|
+
summary: "A summary could not be generated.",
|
|
374
|
+
analysis: "An analysis could not be generated."
|
|
375
|
+
};
|
|
376
|
+
const analyzeLeadResponseParse = (response) => {
|
|
377
|
+
try {
|
|
378
|
+
const { contactType, jobType, serviceType, urgency, highValueLead, summary, analysis, conciseSummary } = JSON.parse((0, extractJSON_1.extractJSON)(response));
|
|
379
|
+
const draftAnalysis = Object.assign(Object.assign({}, defaultLeadAnalysis), { contactType: (contactType === null || contactType === void 0 ? void 0 : contactType.toUpperCase()) || defaultLeadAnalysis.contactType, urgency: (urgency === null || urgency === void 0 ? void 0 : urgency.toUpperCase()) || defaultLeadAnalysis.urgency, highValueLead: (highValueLead === null || highValueLead === void 0 ? void 0 : highValueLead.toString().toLocaleLowerCase()) === "true" || defaultLeadAnalysis.highValueLead, summary: summary || defaultLeadAnalysis.summary, analysis: analysis || defaultLeadAnalysis.analysis });
|
|
380
|
+
if (conciseSummary) {
|
|
381
|
+
draftAnalysis.conciseSummary = conciseSummary;
|
|
382
|
+
}
|
|
383
|
+
if (jobType) {
|
|
384
|
+
draftAnalysis.jobType = jobType.toLowerCase();
|
|
385
|
+
}
|
|
386
|
+
if (serviceType) {
|
|
387
|
+
draftAnalysis.serviceType = serviceType.toUpperCase();
|
|
388
|
+
}
|
|
389
|
+
return draftAnalysis;
|
|
390
|
+
}
|
|
391
|
+
catch (e) {
|
|
392
|
+
return Object.assign({}, defaultLeadAnalysis);
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
exports.analyzeLeadResponseParse = analyzeLeadResponseParse;
|
|
396
|
+
//# sourceMappingURL=AnalyzeLead.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnalyzeLead.js","sourceRoot":"","sources":["../../src/prompts/AnalyzeLead.ts"],"names":[],"mappings":";;;AAiCA,kDAMC;AASD,oDA8BC;AAOD,kCAaC;AAQD,kEAEC;AA1GD,iDAAkD;AAGlD,sDAAmD;AAiBnD,SAAS,OAAO,CAAC,OAA+C;IAC5D,mCAAmC;IACnC,OAAO,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,CAAA,KAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,CAAA,IAAI,SAAS,CAAC;AAC1E,CAAC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,UAAsC;IACtE,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzC,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC;AACjF,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAChC,MAAc,EACd,UAAqB;IAErB,MAAM,QAAQ,GAAiE;QAC3E;YACI,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,MAAM;SAClB;KACJ,CAAC;IAEF,uCAAuC;IACvC,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GAClG,IAAI,CAAC,KAAK,CAAC,IAAA,yBAAW,EAAC,QAAQ,CAAC,CAAC,CAAC;QACtC,MAAM,aAAa,mCACZ,mBAAmB,KACtB,WAAW,EAAE,CAAC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,WAAW,EAAkC,KAAI,mBAAmB,CAAC,WAAW,EAC3G,OAAO,EAAE,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAA8B,KAAI,mBAAmB,CAAC,OAAO,EAC3F,aAAa,EACT,CAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,QAAQ,GAAG,iBAAiB,EAAE,MAAK,MAAM,IAAI,mBAAmB,CAAC,aAAa,EACjG,OAAO,EAAE,OAAO,IAAI,mBAAmB,CAAC,OAAO,EAC/C,QAAQ,EAAE,QAAQ,IAAI,mBAAmB,CAAC,QAAQ,GACrD,CAAC;QAEF,IAAI,cAAc,EAAE,CAAC;YACjB,aAAa,CAAC,cAAc,GAAG,cAAc,CAAC;QAClD,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACV,aAAa,CAAC,OAAO,GAAG,OAAO,CAAC,WAAW,EAA6B,CAAC;QAC7E,CAAC;QAED,IAAI,WAAW,EAAE,CAAC;YACd,aAAa,CAAC,WAAW,GAAG,WAAW,CAAC,WAAW,EAAiC,CAAC;QACzF,CAAC;QAED,OAAO,aAAa,CAAC;IACzB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,yBAAY,mBAAmB,EAAG;IACtC,CAAC;AACL,CAAC,CAAC;AA9BW,QAAA,wBAAwB,4BA8BnC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*! Copyright (c) 2026, XAPP AI */
|
|
2
|
+
import type { Message } from "stentor-models";
|
|
3
|
+
import type { CompletionPrompt, EngagementAnalysis, EngagementAnalysisCategory, PromptGenerator, ResponseParser } from "../models";
|
|
4
|
+
export declare const ANALYZE_TRANSCRIPT_VERSION = "1.0.0";
|
|
5
|
+
/**
|
|
6
|
+
* Sensible default engagement categories used when a business does not provide its own
|
|
7
|
+
* `EngagementAnalysisConfig.categories`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_ENGAGEMENT_CATEGORIES: EngagementAnalysisCategory[];
|
|
10
|
+
export interface AnalyzeTranscriptProps {
|
|
11
|
+
transcript: Message[];
|
|
12
|
+
businessContext?: string;
|
|
13
|
+
categories?: EngagementAnalysisCategory[];
|
|
14
|
+
}
|
|
15
|
+
export type AnalyzeTranscriptLLMOverrides = Partial<Pick<CompletionPrompt, "model" | "max_tokens" | "temperature" | "top_p" | "frequency_penalty" | "presence_penalty">>;
|
|
16
|
+
/**
|
|
17
|
+
* Generates a prompt that can be used in an LLM to analyze a completed chat transcript between
|
|
18
|
+
* a customer and an AI agent representing a business, deriving engagement metadata.
|
|
19
|
+
*
|
|
20
|
+
* @param props - The transcript to analyze, along with optional categories and business context.
|
|
21
|
+
* @param overrides - Optional overrides for LLM call parameters.
|
|
22
|
+
*/
|
|
23
|
+
export declare const generateAnalyzeTranscript: PromptGenerator<AnalyzeTranscriptProps, AnalyzeTranscriptLLMOverrides, CompletionPrompt>;
|
|
24
|
+
export declare const analyzeTranscriptResponseParse: ResponseParser<EngagementAnalysis>;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.analyzeTranscriptResponseParse = exports.generateAnalyzeTranscript = exports.DEFAULT_ENGAGEMENT_CATEGORIES = exports.ANALYZE_TRANSCRIPT_VERSION = void 0;
|
|
4
|
+
const extractJSON_1 = require("../utils/extractJSON");
|
|
5
|
+
const AnalyzeLead_1 = require("./AnalyzeLead");
|
|
6
|
+
exports.ANALYZE_TRANSCRIPT_VERSION = "1.0.0";
|
|
7
|
+
/**
|
|
8
|
+
* Sensible default engagement categories used when a business does not provide its own
|
|
9
|
+
* `EngagementAnalysisConfig.categories`.
|
|
10
|
+
*/
|
|
11
|
+
exports.DEFAULT_ENGAGEMENT_CATEGORIES = [
|
|
12
|
+
{
|
|
13
|
+
key: "GENERAL_INQUIRY",
|
|
14
|
+
description: "A general question about the business, its products, or services."
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
key: "SUPPORT_REQUEST",
|
|
18
|
+
description: "The customer needed help with an existing product, service, or account issue."
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
key: "COMPLAINT",
|
|
22
|
+
description: "The customer expressed dissatisfaction with the business, product, or service."
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
key: "COMPLIMENT",
|
|
26
|
+
description: "The customer gave positive feedback about the business, staff, or product."
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: "SALES_INQUIRY",
|
|
30
|
+
description: "The customer was interested in purchasing a product or service, or requested pricing."
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "TECHNICAL_ISSUE",
|
|
34
|
+
description: "The customer reported a bug, error, or something not working as expected."
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
key: "OTHER",
|
|
38
|
+
description: "The conversation does not fit any of the other categories."
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
/**
|
|
42
|
+
* Generates a prompt that can be used in an LLM to analyze a completed chat transcript between
|
|
43
|
+
* a customer and an AI agent representing a business, deriving engagement metadata.
|
|
44
|
+
*
|
|
45
|
+
* @param props - The transcript to analyze, along with optional categories and business context.
|
|
46
|
+
* @param overrides - Optional overrides for LLM call parameters.
|
|
47
|
+
*/
|
|
48
|
+
const generateAnalyzeTranscript = ({ transcript, businessContext, categories }, overrides) => {
|
|
49
|
+
const resolvedCategories = categories && categories.length > 0 ? categories : exports.DEFAULT_ENGAGEMENT_CATEGORIES;
|
|
50
|
+
let intro = `You are a knowledgeable employee of a business.`;
|
|
51
|
+
if (businessContext) {
|
|
52
|
+
intro = `
|
|
53
|
+
You are a knowledgeable employee of a business with the following context:
|
|
54
|
+
|
|
55
|
+
===
|
|
56
|
+
${businessContext}
|
|
57
|
+
===`;
|
|
58
|
+
}
|
|
59
|
+
const categoryDefinitions = resolvedCategories.map(({ key, description }) => `${key}: ${description}`).join("\n");
|
|
60
|
+
const categoryKeys = resolvedCategories.map(({ key }) => key);
|
|
61
|
+
const system = `
|
|
62
|
+
${intro}
|
|
63
|
+
|
|
64
|
+
Your job is to analyze the following chat transcript that occurred between a customer or potential customer and an AI agent representing the business.
|
|
65
|
+
|
|
66
|
+
You will return your analysis as a JSON object with the following properties:
|
|
67
|
+
|
|
68
|
+
- sentiment
|
|
69
|
+
- topics
|
|
70
|
+
- containment
|
|
71
|
+
- resolved
|
|
72
|
+
- escalation
|
|
73
|
+
- categories
|
|
74
|
+
- summary
|
|
75
|
+
- conciseSummary
|
|
76
|
+
- analysis
|
|
77
|
+
|
|
78
|
+
"sentiment" definitions are as follows:
|
|
79
|
+
POSITIVE: The customer expressed satisfaction, gratitude, or an overall positive tone.
|
|
80
|
+
NEUTRAL: The customer's tone was neutral or transactional, or sentiment could not be determined.
|
|
81
|
+
NEGATIVE: The customer expressed frustration, dissatisfaction, or an overall negative tone.
|
|
82
|
+
|
|
83
|
+
Provide the main topics discussed in the conversation as an array of short (2-4 word) strings in the value "topics".
|
|
84
|
+
|
|
85
|
+
"containment" is true if the AI agent was able to fully address the customer's need without any human handoff being requested or required. It is false if a human needed to be, or was, involved at any point.
|
|
86
|
+
|
|
87
|
+
"resolved" is true if the customer's issue or question was addressed by the end of the conversation, regardless of whether it was the AI agent or a human who resolved it. It is false if the conversation ended without resolution.
|
|
88
|
+
|
|
89
|
+
"escalation" is true if the conversation was escalated, or should be escalated, to a human agent.
|
|
90
|
+
|
|
91
|
+
For "categories", return an array of objects with a "key" property containing every category below that applies to this conversation. Include at least one category. The definitions of each category are as follows:
|
|
92
|
+
${categoryDefinitions}
|
|
93
|
+
|
|
94
|
+
Provide a summary of the conversation which will be placed in the value "summary". The summary should not exceed 250 characters.
|
|
95
|
+
|
|
96
|
+
Provide a concise 2–3 word phrase describing the main topic of the conversation. Return this in the value "conciseSummary".
|
|
97
|
+
|
|
98
|
+
Provide your analysis of why you made these decisions which will be placed in the value "analysis". Include why you made decisions for sentiment, containment, resolved, escalation, and categories. The analysis should be concise and provide enough detail to understand your reasoning. The analysis should not exceed 500 characters.
|
|
99
|
+
`;
|
|
100
|
+
const messages = (0, AnalyzeLead_1.transcriptToMessages)(system, transcript);
|
|
101
|
+
const max_tokens = 768;
|
|
102
|
+
return Object.assign(Object.assign({ model: "claude-haiku-4-5-20251001", max_tokens, frequency_penalty: 0, temperature: 1, top_p: 1, presence_penalty: 0 }, overrides), { response_format: {
|
|
103
|
+
type: "json_schema",
|
|
104
|
+
json_schema: {
|
|
105
|
+
name: "analyze_transcript",
|
|
106
|
+
strict: false,
|
|
107
|
+
schema: {
|
|
108
|
+
type: "object",
|
|
109
|
+
additionalProperties: false,
|
|
110
|
+
required: [
|
|
111
|
+
"sentiment",
|
|
112
|
+
"topics",
|
|
113
|
+
"containment",
|
|
114
|
+
"resolved",
|
|
115
|
+
"escalation",
|
|
116
|
+
"categories",
|
|
117
|
+
"summary",
|
|
118
|
+
"conciseSummary",
|
|
119
|
+
"analysis"
|
|
120
|
+
],
|
|
121
|
+
properties: {
|
|
122
|
+
sentiment: {
|
|
123
|
+
type: "string",
|
|
124
|
+
enum: ["POSITIVE", "NEUTRAL", "NEGATIVE"]
|
|
125
|
+
},
|
|
126
|
+
topics: {
|
|
127
|
+
type: "array",
|
|
128
|
+
items: {
|
|
129
|
+
type: "string"
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
containment: {
|
|
133
|
+
type: "boolean"
|
|
134
|
+
},
|
|
135
|
+
resolved: {
|
|
136
|
+
type: "boolean"
|
|
137
|
+
},
|
|
138
|
+
escalation: {
|
|
139
|
+
type: "boolean"
|
|
140
|
+
},
|
|
141
|
+
categories: {
|
|
142
|
+
type: "array",
|
|
143
|
+
items: {
|
|
144
|
+
type: "object",
|
|
145
|
+
additionalProperties: false,
|
|
146
|
+
required: ["key"],
|
|
147
|
+
properties: {
|
|
148
|
+
key: {
|
|
149
|
+
type: "string",
|
|
150
|
+
enum: categoryKeys
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
summary: {
|
|
156
|
+
type: "string"
|
|
157
|
+
},
|
|
158
|
+
conciseSummary: {
|
|
159
|
+
type: "string"
|
|
160
|
+
},
|
|
161
|
+
analysis: {
|
|
162
|
+
type: "string"
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}, type: "completions", messages });
|
|
168
|
+
};
|
|
169
|
+
exports.generateAnalyzeTranscript = generateAnalyzeTranscript;
|
|
170
|
+
const defaultEngagementAnalysis = {
|
|
171
|
+
sentiment: "NEUTRAL",
|
|
172
|
+
topics: [],
|
|
173
|
+
containment: false,
|
|
174
|
+
resolved: false,
|
|
175
|
+
escalation: false,
|
|
176
|
+
categories: [],
|
|
177
|
+
summary: "A summary could not be generated.",
|
|
178
|
+
analysis: "An analysis could not be generated."
|
|
179
|
+
};
|
|
180
|
+
const analyzeTranscriptResponseParse = (response) => {
|
|
181
|
+
try {
|
|
182
|
+
const { sentiment, topics, containment, resolved, escalation, categories, summary, conciseSummary, analysis } = JSON.parse((0, extractJSON_1.extractJSON)(response));
|
|
183
|
+
const draftAnalysis = Object.assign(Object.assign({}, defaultEngagementAnalysis), { sentiment: (sentiment === null || sentiment === void 0 ? void 0 : sentiment.toUpperCase()) || defaultEngagementAnalysis.sentiment, containment: (containment === null || containment === void 0 ? void 0 : containment.toString().toLocaleLowerCase()) === "true" || defaultEngagementAnalysis.containment, resolved: (resolved === null || resolved === void 0 ? void 0 : resolved.toString().toLocaleLowerCase()) === "true" || defaultEngagementAnalysis.resolved, escalation: (escalation === null || escalation === void 0 ? void 0 : escalation.toString().toLocaleLowerCase()) === "true" || defaultEngagementAnalysis.escalation, summary: summary || defaultEngagementAnalysis.summary, analysis: analysis || defaultEngagementAnalysis.analysis });
|
|
184
|
+
if (conciseSummary) {
|
|
185
|
+
draftAnalysis.conciseSummary = conciseSummary;
|
|
186
|
+
}
|
|
187
|
+
if (Array.isArray(topics)) {
|
|
188
|
+
draftAnalysis.topics = topics.filter((topic) => typeof topic === "string");
|
|
189
|
+
}
|
|
190
|
+
if (Array.isArray(categories)) {
|
|
191
|
+
// Preserve the exact key casing from the config's categories rather than normalizing it,
|
|
192
|
+
// since (unlike contactType/urgency) categories are business-defined, not a fixed enum.
|
|
193
|
+
draftAnalysis.categories = categories.filter((category) => category && typeof category.key === "string" && category.key.length > 0);
|
|
194
|
+
}
|
|
195
|
+
return draftAnalysis;
|
|
196
|
+
}
|
|
197
|
+
catch (e) {
|
|
198
|
+
return Object.assign({}, defaultEngagementAnalysis);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
exports.analyzeTranscriptResponseParse = analyzeTranscriptResponseParse;
|
|
202
|
+
//# sourceMappingURL=AnalyzeTranscript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnalyzeTranscript.js","sourceRoot":"","sources":["../../src/prompts/AnalyzeTranscript.ts"],"names":[],"mappings":";;;AAIA,sDAAmD;AACnD,+CAAqD;AAExC,QAAA,0BAA0B,GAAG,OAAO,CAAC;AAElD;;;GAGG;AACU,QAAA,6BAA6B,GAAiC;IACvE;QACI,GAAG,EAAE,iBAAiB;QACtB,WAAW,EAAE,mEAAmE;KACnF;IACD;QACI,GAAG,EAAE,iBAAiB;QACtB,WAAW,EAAE,+EAA+E;KAC/F;IACD;QACI,GAAG,EAAE,WAAW;QAChB,WAAW,EAAE,gFAAgF;KAChG;IACD;QACI,GAAG,EAAE,YAAY;QACjB,WAAW,EAAE,4EAA4E;KAC5F;IACD;QACI,GAAG,EAAE,eAAe;QACpB,WAAW,EAAE,uFAAuF;KACvG;IACD;QACI,GAAG,EAAE,iBAAiB;QACtB,WAAW,EAAE,2EAA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CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC;QAC/E,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YAC5B,yFAAyF;YACzF,wFAAwF;YACxF,aAAa,CAAC,UAAU,GAAG,UAAU,CAAC,MAAM,CACxC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,IAAI,OAAO,QAAQ,CAAC,GAAG,KAAK,QAAQ,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CACxF,CAAC;QACN,CAAC;QAED,OAAO,aAAa,CAAC;IACzB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,yBAAY,yBAAyB,EAAG;IAC5C,CAAC;AACL,CAAC,CAAC;AApCW,QAAA,8BAA8B,kCAoCzC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*! Copyright (c) 2025, XAPP AI */
|
|
2
|
+
import { CompletionPrompt, PromptGenerator, ResponseParser } from "../models";
|
|
3
|
+
import { WebsiteAnalysis } from "../models/WebsiteAnalysis";
|
|
4
|
+
export interface AnalyzeWebsiteProps {
|
|
5
|
+
markdown: string;
|
|
6
|
+
url: string;
|
|
7
|
+
}
|
|
8
|
+
export type AnalyzeWebsiteLLMOverrides = Partial<Pick<CompletionPrompt, "model" | "max_tokens" | "temperature" | "top_p" | "frequency_penalty" | "presence_penalty">>;
|
|
9
|
+
export declare const generateAnalyzeWebsite: PromptGenerator<AnalyzeWebsiteProps, AnalyzeWebsiteLLMOverrides, CompletionPrompt>;
|
|
10
|
+
export declare const parseAnalyzeWebsiteResponse: ResponseParser<WebsiteAnalysis>;
|