@xapp/stentor-service-generative-ai 1.62.43 → 1.62.44
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/GenerativeAIService.d.ts +14 -1
- package/lib/GenerativeAIService.js +23 -0
- package/lib/GenerativeAIService.js.map +1 -1
- package/lib/models/GenerativeAIService.d.ts +17 -2
- package/lib/prompts/ChatSummary.d.ts +22 -3
- package/lib/prompts/ChatSummary.js +21 -2
- package/lib/prompts/ChatSummary.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/*! Copyright (c) 2024, XAPP AI */
|
|
2
2
|
import type { ExternalLead } from "stentor-models";
|
|
3
|
-
import type { IGenerativeAIService, LeadAnalysis, LLMService } from "./models";
|
|
3
|
+
import type { IGenerativeAIService, LeadAnalysis, LLMService, LLMServiceResponse, Prompt } from "./models";
|
|
4
|
+
import type { ChatSummary } from "./models/ChatSummary";
|
|
4
5
|
export interface AnalyzeLeadOptions {
|
|
5
6
|
businessDescription?: string;
|
|
6
7
|
highValueLeadDescription?: string;
|
|
@@ -8,10 +9,22 @@ export interface AnalyzeLeadOptions {
|
|
|
8
9
|
export declare class GenerativeAIService implements IGenerativeAIService {
|
|
9
10
|
private readonly llmService;
|
|
10
11
|
constructor(llmService: LLMService);
|
|
12
|
+
/**
|
|
13
|
+
* Executs a custom prompt that the user is responsible for creating and parsing.
|
|
14
|
+
*
|
|
15
|
+
* @param prompt
|
|
16
|
+
*/
|
|
17
|
+
customPrompt(prompt: Prompt): Promise<LLMServiceResponse>;
|
|
11
18
|
/**
|
|
12
19
|
* Can take in an external lead and help summarize and classify.
|
|
13
20
|
*
|
|
14
21
|
* @param lead
|
|
15
22
|
*/
|
|
16
23
|
analyzeLead(lead: ExternalLead, options?: AnalyzeLeadOptions): Promise<LeadAnalysis>;
|
|
24
|
+
/**
|
|
25
|
+
* Summarize a chat transcript
|
|
26
|
+
* @param transcript
|
|
27
|
+
* @returns Returns the summarized chat of a lead transcript
|
|
28
|
+
*/
|
|
29
|
+
summarizeChatFromTranscript(transcript: ExternalLead["transcript"]): Promise<ChatSummary>;
|
|
17
30
|
}
|
|
@@ -11,10 +11,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.GenerativeAIService = void 0;
|
|
13
13
|
const AnalyzeLead_1 = require("./prompts/AnalyzeLead");
|
|
14
|
+
const prompts_1 = require("./prompts");
|
|
14
15
|
class GenerativeAIService {
|
|
15
16
|
constructor(llmService) {
|
|
16
17
|
this.llmService = llmService;
|
|
17
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Executs a custom prompt that the user is responsible for creating and parsing.
|
|
21
|
+
*
|
|
22
|
+
* @param prompt
|
|
23
|
+
*/
|
|
24
|
+
customPrompt(prompt) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return this.llmService.generate(prompt);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
18
29
|
/**
|
|
19
30
|
* Can take in an external lead and help summarize and classify.
|
|
20
31
|
*
|
|
@@ -31,6 +42,18 @@ class GenerativeAIService {
|
|
|
31
42
|
return (0, AnalyzeLead_1.analyzeLeadResponseParse)(llmResponse.text);
|
|
32
43
|
});
|
|
33
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Summarize a chat transcript
|
|
47
|
+
* @param transcript
|
|
48
|
+
* @returns Returns the summarized chat of a lead transcript
|
|
49
|
+
*/
|
|
50
|
+
summarizeChatFromTranscript(transcript) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const prompt = (0, prompts_1.generateChatSummaryPromptFromLeadTranscript)({ transcript });
|
|
53
|
+
const llmResponse = yield this.llmService.generate(prompt);
|
|
54
|
+
return (0, prompts_1.chatSummaryResponseParse)(llmResponse.text);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
34
57
|
}
|
|
35
58
|
exports.GenerativeAIService = GenerativeAIService;
|
|
36
59
|
//# sourceMappingURL=GenerativeAIService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerativeAIService.js","sourceRoot":"","sources":["../src/GenerativeAIService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,uDAAsF;
|
|
1
|
+
{"version":3,"file":"GenerativeAIService.js","sourceRoot":"","sources":["../src/GenerativeAIService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,uDAAsF;AACtF,uCAAkG;AAQlG,MAAa,mBAAmB;IAI5B,YAAY,UAAsB;QAC9B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACG,YAAY,CAAC,MAAc;;YAC7B,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC5C,CAAC;KAAA;IAED;;;;OAIG;IACG,WAAW,CAAC,IAAkB,EAAE,OAA4B;;YAC9D,MAAM,MAAM,GAAG,IAAA,iCAAmB,EAAC;gBAC/B,mBAAmB,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,mBAAmB,KAAI,EAAE;gBACvD,wBAAwB,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,wBAAwB,KAAI,EAAE;gBACjE,UAAU,EAAE,IAAI,CAAC,UAAU;aAC9B,CAAC,CAAC;YAEH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAE3D,OAAO,IAAA,sCAAwB,EAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACtD,CAAC;KAAA;IAED;;;;OAIG;IACG,2BAA2B,CAAC,UAAsC;;YACpE,MAAM,MAAM,GAAG,IAAA,qDAA2C,EAAC,EAAE,UAAU,EAAE,CAAC,CAAC;YAC3E,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC3D,OAAO,IAAA,kCAAwB,EAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACtD,CAAC;KAAA;CACJ;AA5CD,kDA4CC"}
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
/*! Copyright (c) 2024, XAPP AI */
|
|
2
|
-
import { ExternalLead } from "stentor-models";
|
|
3
|
-
import { LeadAnalysis } from "./LeadAnalysis";
|
|
2
|
+
import type { ExternalLead } from "stentor-models";
|
|
3
|
+
import type { LeadAnalysis } from "./LeadAnalysis";
|
|
4
|
+
import type { ChatSummary } from "./ChatSummary";
|
|
5
|
+
import { Prompt } from "./Prompt";
|
|
6
|
+
import { LLMServiceResponse } from "./LLMService";
|
|
4
7
|
export interface IGenerativeAIService {
|
|
8
|
+
/**
|
|
9
|
+
* Executs a custom prompt that the user is responsible for creating and parsing.
|
|
10
|
+
*
|
|
11
|
+
* @param prompt
|
|
12
|
+
*/
|
|
13
|
+
customPrompt(prompt: Prompt): Promise<LLMServiceResponse>;
|
|
5
14
|
/**
|
|
6
15
|
* Analyze a lead to find summary
|
|
7
16
|
* @param lead
|
|
8
17
|
*/
|
|
9
18
|
analyzeLead(lead: ExternalLead): Promise<LeadAnalysis>;
|
|
19
|
+
/**
|
|
20
|
+
* Summarize a chat transcript
|
|
21
|
+
* @param transcript
|
|
22
|
+
* @returns Returns the summarized chat of a lead transcript
|
|
23
|
+
*/
|
|
24
|
+
summarizeChatFromTranscript(transcript: ExternalLead["transcript"]): Promise<ChatSummary>;
|
|
10
25
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/*! Copyright (c) 2024, XAPP AI */
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { ExternalLead } from "stentor-models";
|
|
3
|
+
import type { CompletionPrompt, PromptGenerator, ResponseParser } from "../models";
|
|
4
|
+
import type { ChatSummary } from "../models/ChatSummary";
|
|
4
5
|
/**
|
|
5
6
|
* A conversation line that was said by the user or system.
|
|
6
7
|
*/
|
|
@@ -23,7 +24,25 @@ export interface ChatSummaryPromptProps {
|
|
|
23
24
|
*/
|
|
24
25
|
summary: SummaryLine[];
|
|
25
26
|
}
|
|
27
|
+
export interface ChatSummaryFromLeadTranscriptProps {
|
|
28
|
+
/**
|
|
29
|
+
* The transcript of a found lead.
|
|
30
|
+
*/
|
|
31
|
+
transcript: ExternalLead["transcript"];
|
|
32
|
+
}
|
|
26
33
|
export type ChatSummaryLLMOverrides = Partial<Pick<CompletionPrompt, "model" | "max_tokens" | "temperature" | "top_p" | "frequency_penalty" | "presence_penalty">>;
|
|
34
|
+
/**
|
|
35
|
+
* Generate a prompt that can be used in an LLM to return a summary of a chat conversation from a lead transcript.
|
|
36
|
+
*
|
|
37
|
+
* The expected output format from the LLM will be:
|
|
38
|
+
*
|
|
39
|
+
* <Full summary of the text>
|
|
40
|
+
*
|
|
41
|
+
* @param transcript - The summary transcript of the chat.
|
|
42
|
+
* @param overrides
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
export declare const generateChatSummaryPromptFromLeadTranscript: PromptGenerator<ChatSummaryFromLeadTranscriptProps, ChatSummaryLLMOverrides, CompletionPrompt>;
|
|
27
46
|
/**
|
|
28
47
|
* Generates a prompt that can be used in an LLM to return a summary of a chat conversation.
|
|
29
48
|
*
|
|
@@ -31,7 +50,7 @@ export type ChatSummaryLLMOverrides = Partial<Pick<CompletionPrompt, "model" | "
|
|
|
31
50
|
*
|
|
32
51
|
* <Full summary of the text>
|
|
33
52
|
*
|
|
34
|
-
* @param
|
|
53
|
+
* @param summary - The summary transcript of the chat.
|
|
35
54
|
* @returns
|
|
36
55
|
*/
|
|
37
56
|
export declare const generateChatSummaryPrompt: PromptGenerator<ChatSummaryPromptProps, ChatSummaryLLMOverrides, CompletionPrompt>;
|
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*! Copyright (c) 2024, XAPP AI */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.chatSummaryResponseParse = exports.generateChatSummaryPrompt = void 0;
|
|
4
|
+
exports.chatSummaryResponseParse = exports.generateChatSummaryPrompt = exports.generateChatSummaryPromptFromLeadTranscript = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Generate a prompt that can be used in an LLM to return a summary of a chat conversation from a lead transcript.
|
|
7
|
+
*
|
|
8
|
+
* The expected output format from the LLM will be:
|
|
9
|
+
*
|
|
10
|
+
* <Full summary of the text>
|
|
11
|
+
*
|
|
12
|
+
* @param transcript - The summary transcript of the chat.
|
|
13
|
+
* @param overrides
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
const generateChatSummaryPromptFromLeadTranscript = ({ transcript }, overrides) => {
|
|
17
|
+
const summary = transcript.map(({ from, message }) => ({
|
|
18
|
+
user: (from === null || from === void 0 ? void 0 : from.name) || (from === null || from === void 0 ? void 0 : from.email) || (from === null || from === void 0 ? void 0 : from.phone) || (from === null || from === void 0 ? void 0 : from.id) || "Unknown",
|
|
19
|
+
line: message
|
|
20
|
+
}));
|
|
21
|
+
return (0, exports.generateChatSummaryPrompt)({ summary }, overrides);
|
|
22
|
+
};
|
|
23
|
+
exports.generateChatSummaryPromptFromLeadTranscript = generateChatSummaryPromptFromLeadTranscript;
|
|
5
24
|
/**
|
|
6
25
|
* Generates a prompt that can be used in an LLM to return a summary of a chat conversation.
|
|
7
26
|
*
|
|
@@ -9,7 +28,7 @@ exports.chatSummaryResponseParse = exports.generateChatSummaryPrompt = void 0;
|
|
|
9
28
|
*
|
|
10
29
|
* <Full summary of the text>
|
|
11
30
|
*
|
|
12
|
-
* @param
|
|
31
|
+
* @param summary - The summary transcript of the chat.
|
|
13
32
|
* @returns
|
|
14
33
|
*/
|
|
15
34
|
const generateChatSummaryPrompt = ({ summary }, overrides) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatSummary.js","sourceRoot":"","sources":["../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wFAAwF;wBAC1F,kLAAkL;wBAClL,yJAAyJ;wBACzJ,qRAAqR;wBACrR,gKAAgK;wBAChK,oDAAoD;wBACpD,kCAAkC;wBAClC,iGAAiG;wBACjG,IAAI;wBACJ,uGAAuG;iBAC9G;aACJ,EAAE;gBACC,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE;oBACL,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;iBAC9D;aACJ,CAAC,IACL;AACL,CAAC,CAAA;AApCY,QAAA,yBAAyB,6BAoCrC;AAED;;;;GAIG;AACI,MAAM,wBAAwB,GAAgC,CAAC,QAAQ,EAAE,EAAE;IAC9E,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;IAChC,OAAO;QACH,OAAO;KACV,CAAC;AACN,CAAC,CAAA;AALY,QAAA,wBAAwB,4BAKpC"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.62.
|
|
7
|
+
"version": "1.62.44",
|
|
8
8
|
"description": "Generative AI Service",
|
|
9
9
|
"types": "lib/index",
|
|
10
10
|
"main": "lib/index",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\"",
|
|
39
39
|
"local": "npm run test"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "af30f31dcdc358dd450b469698ab83315de1763a"
|
|
42
42
|
}
|