@xapp/stentor-service-generative-ai 1.62.41 → 1.62.43
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/OpenAIService.d.ts +11 -1
- package/lib/OpenAIService.js +3 -2
- package/lib/OpenAIService.js.map +1 -1
- 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/prompts/ChatSummary.d.ts +43 -0
- package/lib/prompts/ChatSummary.js +54 -0
- package/lib/prompts/ChatSummary.js.map +1 -0
- package/lib/prompts/index.d.ts +1 -0
- package/lib/prompts/index.js +1 -0
- package/lib/prompts/index.js.map +1 -1
- package/package.json +2 -2
package/lib/OpenAIService.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
/*! Copyright (c) 2024, XAPP AI */
|
|
2
2
|
import type { LLMService, LLMServiceResponse, Prompt } from "./models";
|
|
3
3
|
import type { HTTPService } from "./http/HTTPService";
|
|
4
|
+
export declare const DEFAULT_OPEN_AI_URL = "https://api.openai.com";
|
|
4
5
|
export type APIKeyGetter = () => string | Promise<string>;
|
|
5
6
|
export interface OpenAIServiceProps {
|
|
7
|
+
/**
|
|
8
|
+
* Returns the API key to use for the OpenAI service authorization
|
|
9
|
+
*/
|
|
6
10
|
keyGetter: APIKeyGetter;
|
|
7
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The HTTP service to use for making requests
|
|
13
|
+
*/
|
|
8
14
|
httpService: Pick<HTTPService, "post">;
|
|
15
|
+
/**
|
|
16
|
+
* The base URL for the OpenAI service
|
|
17
|
+
*/
|
|
18
|
+
openAIUrl?: string;
|
|
9
19
|
}
|
|
10
20
|
export declare class InvalidPromptTypeError extends Error {
|
|
11
21
|
constructor(type: string);
|
package/lib/OpenAIService.js
CHANGED
|
@@ -10,7 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.OpenAIService = exports.InvalidPromptTypeError = void 0;
|
|
13
|
+
exports.OpenAIService = exports.InvalidPromptTypeError = exports.DEFAULT_OPEN_AI_URL = void 0;
|
|
14
|
+
exports.DEFAULT_OPEN_AI_URL = "https://api.openai.com";
|
|
14
15
|
class InvalidPromptTypeError extends Error {
|
|
15
16
|
constructor(type) {
|
|
16
17
|
super(`Unknown prompt type: ${type}`);
|
|
@@ -21,7 +22,7 @@ exports.InvalidPromptTypeError = InvalidPromptTypeError;
|
|
|
21
22
|
class OpenAIService {
|
|
22
23
|
constructor(props) {
|
|
23
24
|
this.keyGetter = props.keyGetter;
|
|
24
|
-
this.openAIUrl = props.openAIUrl;
|
|
25
|
+
this.openAIUrl = props.openAIUrl || exports.DEFAULT_OPEN_AI_URL;
|
|
25
26
|
this.httpService = props.httpService;
|
|
26
27
|
}
|
|
27
28
|
generate(prompt) {
|
package/lib/OpenAIService.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAIService.js","sourceRoot":"","sources":["../src/OpenAIService.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"OpenAIService.js","sourceRoot":"","sources":["../src/OpenAIService.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;AAKrB,QAAA,mBAAmB,GAAG,wBAAwB,CAAC;AAkB5D,MAAa,sBAAuB,SAAQ,KAAK;IAE7C,YAAY,IAAY;QACpB,KAAK,CAAC,wBAAwB,IAAI,EAAE,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACzC,CAAC;CACJ;AAND,wDAMC;AAED,MAAa,aAAa;IAMtB,YAAY,KAAyB;QACjC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,2BAAmB,CAAC;QACxD,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;IACzC,CAAC;IAEK,QAAQ,CAAC,MAAc;;YACzB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;YACxB,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YACpC,CAAC;YACD,MAAM,IAAI,sBAAsB,CAAC,IAAI,CAAC,CAAC;QAC3C,CAAC;KAAA;IAEK,WAAW,CAAC,MAAc;;YAC5B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC;gBAC7B,IAAI,EAAE,qBAAqB;gBAC3B,IAAI,oBACG,MAAM,CACZ;aACJ,CAAC,CAAC;YACH,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,CAAC;KAAA;IAEa,IAAI,CAAC,KAAiD;;YAChE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;gBACzC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,IAAI,KAAK,CAAC,IAAI,EAAE;gBACtC,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,OAAO,EAAE;oBACL,eAAe,EAAE,UAAU,MAAM,EAAE;iBACtC;aACJ,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC;QACpB,CAAC;KAAA;CACJ;AAzCD,sCAyCC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*! Copyright (c) 2024, XAPP AI */
|
|
2
|
+
/**
|
|
3
|
+
* A quick summary returned by the LLM which summerizes the a chat widget transcript.
|
|
4
|
+
*/
|
|
5
|
+
export interface ChatSummary {
|
|
6
|
+
/**
|
|
7
|
+
* The summary that is returned by the LLM or undefined if the LLM failed.
|
|
8
|
+
*/
|
|
9
|
+
summary: string | undefined;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatSummary.js","sourceRoot":"","sources":["../../src/models/ChatSummary.ts"],"names":[],"mappings":";AAAA,kCAAkC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*! Copyright (c) 2024, XAPP AI */
|
|
2
|
+
import { CompletionPrompt, PromptGenerator, ResponseParser } from "../models";
|
|
3
|
+
import { ChatSummary } from "../models/ChatSummary";
|
|
4
|
+
/**
|
|
5
|
+
* A conversation line that was said by the user or system.
|
|
6
|
+
*/
|
|
7
|
+
export interface SummaryLine {
|
|
8
|
+
/**
|
|
9
|
+
* The user that said the line.
|
|
10
|
+
*/
|
|
11
|
+
user: string;
|
|
12
|
+
/**
|
|
13
|
+
* The content that was said by the user.
|
|
14
|
+
*/
|
|
15
|
+
line: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The properties that are required to generate a chat summary prompt.
|
|
19
|
+
*/
|
|
20
|
+
export interface ChatSummaryPromptProps {
|
|
21
|
+
/**
|
|
22
|
+
* The lines that were said in the conversation.
|
|
23
|
+
*/
|
|
24
|
+
summary: SummaryLine[];
|
|
25
|
+
}
|
|
26
|
+
export type ChatSummaryLLMOverrides = Partial<Pick<CompletionPrompt, "model" | "max_tokens" | "temperature" | "top_p" | "frequency_penalty" | "presence_penalty">>;
|
|
27
|
+
/**
|
|
28
|
+
* Generates a prompt that can be used in an LLM to return a summary of a chat conversation.
|
|
29
|
+
*
|
|
30
|
+
* The expected output format from the LLM will be:
|
|
31
|
+
*
|
|
32
|
+
* <Full summary of the text>
|
|
33
|
+
*
|
|
34
|
+
* @param lead - The lead to analyze with the business description and other options to customize the prompt.
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
export declare const generateChatSummaryPrompt: PromptGenerator<ChatSummaryPromptProps, ChatSummaryLLMOverrides, CompletionPrompt>;
|
|
38
|
+
/**
|
|
39
|
+
* Parser for the Chat Summary response.
|
|
40
|
+
* @param response
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
export declare const chatSummaryResponseParse: ResponseParser<ChatSummary>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*! Copyright (c) 2024, XAPP AI */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.chatSummaryResponseParse = exports.generateChatSummaryPrompt = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Generates a prompt that can be used in an LLM to return a summary of a chat conversation.
|
|
7
|
+
*
|
|
8
|
+
* The expected output format from the LLM will be:
|
|
9
|
+
*
|
|
10
|
+
* <Full summary of the text>
|
|
11
|
+
*
|
|
12
|
+
* @param lead - The lead to analyze with the business description and other options to customize the prompt.
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
const generateChatSummaryPrompt = ({ summary }, overrides) => {
|
|
16
|
+
return Object.assign(Object.assign({ model: "gpt-4o-mini", max_tokens: 256, frequency_penalty: 0, temperature: 1, top_p: 1, presence_penalty: 0 }, overrides), { response_format: {
|
|
17
|
+
type: "text"
|
|
18
|
+
}, type: "completions", messages: [{
|
|
19
|
+
role: "system",
|
|
20
|
+
content: {
|
|
21
|
+
type: "text",
|
|
22
|
+
text: "Summarize the transcript of a chat between a business's bot on a website and a person." +
|
|
23
|
+
"Please summarize as if you are the bot in the transcript and you are taking notes for somebody that will be able to help the person with their query. You may use first person." +
|
|
24
|
+
"Do not call the user, \"user\" but instead use \"Someone\", \"Somebody\" or if they give their name you can use their first name however not last name." +
|
|
25
|
+
"If the transcript contains additional identifying information from the user, such as last name, phone number, email address, or addresses then do not include theses in the summary. If the bot provided contact information for the business, you may include it in your summary." +
|
|
26
|
+
"The summary will be then be provided to the business owner so they are aware somebody will be in touch soon with the request they mentioned in the transcript." +
|
|
27
|
+
"Keep the summary to one sentence around 100 words." +
|
|
28
|
+
"An example of a good summary is:" +
|
|
29
|
+
"\"Somebody reached out looking for a quote and I provided them with your contact information.\"" +
|
|
30
|
+
"or" +
|
|
31
|
+
"\"John reached out looking to schedule an appointment and I provided them with the scheduling link.\""
|
|
32
|
+
}
|
|
33
|
+
}, {
|
|
34
|
+
role: "user",
|
|
35
|
+
content: {
|
|
36
|
+
type: "text",
|
|
37
|
+
text: summary.map((s) => `${s.user}: ${s.line}`).join("\n")
|
|
38
|
+
}
|
|
39
|
+
}] });
|
|
40
|
+
};
|
|
41
|
+
exports.generateChatSummaryPrompt = generateChatSummaryPrompt;
|
|
42
|
+
/**
|
|
43
|
+
* Parser for the Chat Summary response.
|
|
44
|
+
* @param response
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
const chatSummaryResponseParse = (response) => {
|
|
48
|
+
const summary = response.trim();
|
|
49
|
+
return {
|
|
50
|
+
summary
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
exports.chatSummaryResponseParse = chatSummaryResponseParse;
|
|
54
|
+
//# sourceMappingURL=ChatSummary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatSummary.js","sourceRoot":"","sources":["../../src/prompts/ChatSummary.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;AA+BlC;;;;;;;;;GASG;AACI,MAAM,yBAAyB,GAAuF,CAAC,EAAE,OAAO,EAAE,EAAE,SAAS,EAAoB,EAAE;IACtK,qCACI,KAAK,EAAE,aAAa,EACpB,UAAU,EAAE,GAAG,EACf,iBAAiB,EAAE,CAAC,EACpB,WAAW,EAAE,CAAC,EACd,KAAK,EAAE,CAAC,EACR,gBAAgB,EAAE,CAAC,IAChB,SAAS,KACZ,eAAe,EAAE;YACb,IAAI,EAAE,MAAM;SACf,EACD,IAAI,EAAE,aAAa,EACnB,QAAQ,EAAE,CAAC;gBACP,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE;oBACL,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,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/lib/prompts/index.d.ts
CHANGED
package/lib/prompts/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
__exportStar(require("./AnalyzeLead"), exports);
|
|
19
|
+
__exportStar(require("./ChatSummary"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
package/lib/prompts/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/prompts/index.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;;;;;AAElC,gDAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/prompts/index.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;;;;;AAElC,gDAA8B;AAC9B,gDAA8B"}
|
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.43",
|
|
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": "a997c80519e50a8c7d0253618bdfedf7e4037c62"
|
|
42
42
|
}
|