@xapp/stentor-service-generative-ai 1.85.1 → 1.89.0
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/package.json +2 -2
- package/lib/AWSBedrockService.d.ts +0 -67
- package/lib/AWSBedrockService.js +0 -133
- package/lib/AWSBedrockService.js.map +0 -1
- package/lib/ClaudeService.d.ts +0 -77
- package/lib/ClaudeService.js +0 -142
- package/lib/ClaudeService.js.map +0 -1
- package/lib/FallbackLLMService.d.ts +0 -46
- package/lib/FallbackLLMService.js +0 -83
- package/lib/FallbackLLMService.js.map +0 -1
- package/lib/GenerativeAIService.d.ts +0 -40
- package/lib/GenerativeAIService.js +0 -108
- package/lib/GenerativeAIService.js.map +0 -1
- package/lib/OpenAIService.d.ts +0 -33
- package/lib/OpenAIService.js +0 -76
- package/lib/OpenAIService.js.map +0 -1
- package/lib/http/HTTPService.d.ts +0 -18
- package/lib/http/HTTPService.js +0 -4
- package/lib/http/HTTPService.js.map +0 -1
- package/lib/http/NodeHTTPService.d.ts +0 -8
- package/lib/http/NodeHTTPService.js +0 -70
- package/lib/http/NodeHTTPService.js.map +0 -1
- package/lib/http/index.d.ts +0 -3
- package/lib/http/index.js +0 -20
- package/lib/http/index.js.map +0 -1
- package/lib/index.d.ts +0 -10
- package/lib/index.js +0 -27
- package/lib/index.js.map +0 -1
- package/lib/models/ChatSummary.d.ts +0 -10
- package/lib/models/ChatSummary.js +0 -4
- package/lib/models/ChatSummary.js.map +0 -1
- package/lib/models/EmailAnalysis.d.ts +0 -73
- package/lib/models/EmailAnalysis.js +0 -4
- package/lib/models/EmailAnalysis.js.map +0 -1
- package/lib/models/GenerativeAIService.d.ts +0 -55
- package/lib/models/GenerativeAIService.js +0 -3
- package/lib/models/GenerativeAIService.js.map +0 -1
- package/lib/models/LLMService.d.ts +0 -24
- package/lib/models/LLMService.js +0 -4
- package/lib/models/LLMService.js.map +0 -1
- package/lib/models/LeadAnalysis.d.ts +0 -105
- package/lib/models/LeadAnalysis.js +0 -4
- package/lib/models/LeadAnalysis.js.map +0 -1
- package/lib/models/Prompt.d.ts +0 -37
- package/lib/models/Prompt.js +0 -8
- package/lib/models/Prompt.js.map +0 -1
- package/lib/models/PromptGenerator.d.ts +0 -6
- package/lib/models/PromptGenerator.js +0 -4
- package/lib/models/PromptGenerator.js.map +0 -1
- package/lib/models/ResponseParser.d.ts +0 -5
- package/lib/models/ResponseParser.js +0 -4
- package/lib/models/ResponseParser.js.map +0 -1
- package/lib/models/WebsiteAnalysis.d.ts +0 -48
- package/lib/models/WebsiteAnalysis.js +0 -4
- package/lib/models/WebsiteAnalysis.js.map +0 -1
- package/lib/models/errors.d.ts +0 -7
- package/lib/models/errors.js +0 -15
- package/lib/models/errors.js.map +0 -1
- package/lib/models/index.d.ts +0 -9
- package/lib/models/index.js +0 -26
- package/lib/models/index.js.map +0 -1
- package/lib/prompts/AnalyzeEmail.d.ts +0 -36
- package/lib/prompts/AnalyzeEmail.js +0 -385
- package/lib/prompts/AnalyzeEmail.js.map +0 -1
- package/lib/prompts/AnalyzeLead.d.ts +0 -59
- package/lib/prompts/AnalyzeLead.js +0 -396
- package/lib/prompts/AnalyzeLead.js.map +0 -1
- package/lib/prompts/AnalyzeWebsite.d.ts +0 -10
- package/lib/prompts/AnalyzeWebsite.js +0 -176
- package/lib/prompts/AnalyzeWebsite.js.map +0 -1
- package/lib/prompts/ChatSummary.d.ts +0 -62
- package/lib/prompts/ChatSummary.js +0 -67
- package/lib/prompts/ChatSummary.js.map +0 -1
- package/lib/prompts/index.d.ts +0 -4
- package/lib/prompts/index.js +0 -21
- package/lib/prompts/index.js.map +0 -1
- package/lib/utils/extractJSON.d.ts +0 -10
- package/lib/utils/extractJSON.js +0 -17
- package/lib/utils/extractJSON.js.map +0 -1
- package/lib/utils/standardizeTerms.d.ts +0 -15
- package/lib/utils/standardizeTerms.js +0 -53
- package/lib/utils/standardizeTerms.js.map +0 -1
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.
|
|
7
|
+
"version": "1.89.0",
|
|
8
8
|
"description": "Generative AI Service",
|
|
9
9
|
"types": "lib/index",
|
|
10
10
|
"main": "lib/index",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\"",
|
|
47
47
|
"ftest": "mocha --recursive -r ts-node/register \"./src/**/*.ftest.ts\""
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "9ca70c64befe97bf993832bf3648a2e4ce77e6c9"
|
|
50
50
|
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/*! Copyright (c) 2024, XAPP AI */
|
|
2
|
-
import type { LLMService, LLMServiceResponse, Prompt, CompletionPrompt } from "./models";
|
|
3
|
-
export interface AWSBedrockServiceProps {
|
|
4
|
-
/**
|
|
5
|
-
* The AWS region to use for Bedrock
|
|
6
|
-
* @default "us-east-1"
|
|
7
|
-
*/
|
|
8
|
-
region?: string;
|
|
9
|
-
/**
|
|
10
|
-
* AWS credentials configuration
|
|
11
|
-
*/
|
|
12
|
-
credentials?: {
|
|
13
|
-
accessKeyId: string;
|
|
14
|
-
secretAccessKey: string;
|
|
15
|
-
sessionToken?: string;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* The Bedrock model ID or inference profile to use.
|
|
19
|
-
* Newer models require inference profiles (prefixed with region, e.g., "us.").
|
|
20
|
-
* @default "us.anthropic.claude-haiku-4-5-20251001-v1:0"
|
|
21
|
-
*/
|
|
22
|
-
modelId?: string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* AWS Bedrock service for Anthropic Claude models
|
|
26
|
-
*
|
|
27
|
-
* This service implements the LLMService interface for AWS Bedrock,
|
|
28
|
-
* providing access to Anthropic Claude models hosted on Bedrock.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* const service = new AWSBedrockService({
|
|
33
|
-
* region: "us-east-1",
|
|
34
|
-
* modelId: "anthropic.claude-3-5-sonnet-20241022-v2:0"
|
|
35
|
-
* });
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare class AWSBedrockService implements LLMService {
|
|
39
|
-
private readonly client;
|
|
40
|
-
private readonly modelId;
|
|
41
|
-
private static readonly textDecoder;
|
|
42
|
-
constructor(props: AWSBedrockServiceProps);
|
|
43
|
-
/**
|
|
44
|
-
* Generate a response from the LLM based on the provided prompt
|
|
45
|
-
*
|
|
46
|
-
* @param prompt - The prompt to send to the LLM
|
|
47
|
-
* @param options - Optional configuration (Note: timeout is not supported for Bedrock and will be ignored with a warning)
|
|
48
|
-
* @returns The LLM service response
|
|
49
|
-
* @throws {InvalidPromptTypeError} If the prompt type is not supported
|
|
50
|
-
*/
|
|
51
|
-
generate(prompt: Prompt, options?: {
|
|
52
|
-
timeout?: number;
|
|
53
|
-
}): Promise<LLMServiceResponse>;
|
|
54
|
-
/**
|
|
55
|
-
* Generate completions using AWS Bedrock Claude models
|
|
56
|
-
*
|
|
57
|
-
* Note: The following CompletionPrompt parameters are not supported by Claude on Bedrock
|
|
58
|
-
* and will be ignored: frequency_penalty, presence_penalty, response_format
|
|
59
|
-
*
|
|
60
|
-
* System messages are extracted from the messages array and concatenated with double
|
|
61
|
-
* newlines to form a single system prompt, as Claude's API only accepts one system field.
|
|
62
|
-
*
|
|
63
|
-
* @param prompt - The completion prompt
|
|
64
|
-
* @returns The LLM service response
|
|
65
|
-
*/
|
|
66
|
-
completions(prompt: CompletionPrompt): Promise<LLMServiceResponse>;
|
|
67
|
-
}
|
package/lib/AWSBedrockService.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*! Copyright (c) 2024, XAPP AI */
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.AWSBedrockService = void 0;
|
|
14
|
-
const client_bedrock_runtime_1 = require("@aws-sdk/client-bedrock-runtime");
|
|
15
|
-
const models_1 = require("./models");
|
|
16
|
-
const BEDROCK_API_VERSION = "bedrock-2023-05-31";
|
|
17
|
-
/**
|
|
18
|
-
* AWS Bedrock service for Anthropic Claude models
|
|
19
|
-
*
|
|
20
|
-
* This service implements the LLMService interface for AWS Bedrock,
|
|
21
|
-
* providing access to Anthropic Claude models hosted on Bedrock.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const service = new AWSBedrockService({
|
|
26
|
-
* region: "us-east-1",
|
|
27
|
-
* modelId: "anthropic.claude-3-5-sonnet-20241022-v2:0"
|
|
28
|
-
* });
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
class AWSBedrockService {
|
|
32
|
-
constructor(props) {
|
|
33
|
-
this.client = new client_bedrock_runtime_1.BedrockRuntimeClient({
|
|
34
|
-
region: props.region || "us-east-1",
|
|
35
|
-
credentials: props.credentials,
|
|
36
|
-
});
|
|
37
|
-
this.modelId = props.modelId || "us.anthropic.claude-haiku-4-5-20251001-v1:0";
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Generate a response from the LLM based on the provided prompt
|
|
41
|
-
*
|
|
42
|
-
* @param prompt - The prompt to send to the LLM
|
|
43
|
-
* @param options - Optional configuration (Note: timeout is not supported for Bedrock and will be ignored with a warning)
|
|
44
|
-
* @returns The LLM service response
|
|
45
|
-
* @throws {InvalidPromptTypeError} If the prompt type is not supported
|
|
46
|
-
*/
|
|
47
|
-
generate(prompt, options) {
|
|
48
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
if ((options === null || options === void 0 ? void 0 : options.timeout) !== undefined) {
|
|
50
|
-
console.warn("AWSBedrockService: timeout option is not supported and will be ignored");
|
|
51
|
-
}
|
|
52
|
-
const { type } = prompt;
|
|
53
|
-
if (type === "completions") {
|
|
54
|
-
return this.completions(prompt);
|
|
55
|
-
}
|
|
56
|
-
throw new models_1.InvalidPromptTypeError(type);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Generate completions using AWS Bedrock Claude models
|
|
61
|
-
*
|
|
62
|
-
* Note: The following CompletionPrompt parameters are not supported by Claude on Bedrock
|
|
63
|
-
* and will be ignored: frequency_penalty, presence_penalty, response_format
|
|
64
|
-
*
|
|
65
|
-
* System messages are extracted from the messages array and concatenated with double
|
|
66
|
-
* newlines to form a single system prompt, as Claude's API only accepts one system field.
|
|
67
|
-
*
|
|
68
|
-
* @param prompt - The completion prompt
|
|
69
|
-
* @returns The LLM service response
|
|
70
|
-
*/
|
|
71
|
-
completions(prompt) {
|
|
72
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
// Extract and combine all system messages into a single prompt.
|
|
74
|
-
// Multiple system messages are joined with double newlines.
|
|
75
|
-
const systemMessages = prompt.messages
|
|
76
|
-
.filter((msg) => msg.role === "system")
|
|
77
|
-
.map((msg) => msg.content);
|
|
78
|
-
const systemPrompt = systemMessages.length > 0 ? systemMessages.join("\n\n") : undefined;
|
|
79
|
-
// Convert OpenAI-style messages to Claude format, excluding system messages
|
|
80
|
-
const messages = prompt.messages
|
|
81
|
-
.filter((msg) => msg.role !== "system")
|
|
82
|
-
.map((msg) => ({
|
|
83
|
-
role: msg.role,
|
|
84
|
-
content: msg.content,
|
|
85
|
-
}));
|
|
86
|
-
// Build the request payload for Claude
|
|
87
|
-
// Note: frequency_penalty, presence_penalty, and response_format are not supported by Bedrock
|
|
88
|
-
const requestBody = {
|
|
89
|
-
anthropic_version: BEDROCK_API_VERSION,
|
|
90
|
-
messages: messages,
|
|
91
|
-
max_tokens: prompt.max_tokens || 1024,
|
|
92
|
-
};
|
|
93
|
-
// Claude models do not allow both temperature and top_p simultaneously
|
|
94
|
-
if (prompt.temperature !== undefined) {
|
|
95
|
-
requestBody.temperature = prompt.temperature;
|
|
96
|
-
}
|
|
97
|
-
else if (prompt.top_p !== undefined) {
|
|
98
|
-
requestBody.top_p = prompt.top_p;
|
|
99
|
-
}
|
|
100
|
-
if (systemPrompt) {
|
|
101
|
-
requestBody.system = systemPrompt;
|
|
102
|
-
}
|
|
103
|
-
const input = {
|
|
104
|
-
modelId: this.modelId,
|
|
105
|
-
contentType: "application/json",
|
|
106
|
-
accept: "application/json",
|
|
107
|
-
body: JSON.stringify(requestBody),
|
|
108
|
-
};
|
|
109
|
-
const command = new client_bedrock_runtime_1.InvokeModelCommand(input);
|
|
110
|
-
const response = yield this.client.send(command);
|
|
111
|
-
// Parse the response
|
|
112
|
-
let responseBody;
|
|
113
|
-
try {
|
|
114
|
-
responseBody = JSON.parse(AWSBedrockService.textDecoder.decode(response.body));
|
|
115
|
-
}
|
|
116
|
-
catch (error) {
|
|
117
|
-
throw new Error(`Failed to parse Bedrock response: ${error instanceof Error ? error.message : String(error)}`);
|
|
118
|
-
}
|
|
119
|
-
// Check for error responses
|
|
120
|
-
if (responseBody.error || responseBody.message) {
|
|
121
|
-
throw new Error(`Bedrock API error: ${responseBody.message || responseBody.error}`);
|
|
122
|
-
}
|
|
123
|
-
// Extract content from Claude's response format
|
|
124
|
-
if (!responseBody.content || !Array.isArray(responseBody.content) || responseBody.content.length === 0) {
|
|
125
|
-
throw new Error(`Unexpected Bedrock response format: ${JSON.stringify(responseBody)}`);
|
|
126
|
-
}
|
|
127
|
-
return { text: responseBody.content[0].text };
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
exports.AWSBedrockService = AWSBedrockService;
|
|
132
|
-
AWSBedrockService.textDecoder = new TextDecoder();
|
|
133
|
-
//# sourceMappingURL=AWSBedrockService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AWSBedrockService.js","sourceRoot":"","sources":["../src/AWSBedrockService.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;AAElC,4EAIyC;AAEzC,qCAAkD;AA8ClD,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AAEjD;;;;;;;;;;;;;GAaG;AACH,MAAa,iBAAiB;IAK1B,YAAY,KAA6B;QACrC,IAAI,CAAC,MAAM,GAAG,IAAI,6CAAoB,CAAC;YACnC,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,WAAW;YACnC,WAAW,EAAE,KAAK,CAAC,WAAW;SACjC,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,6CAA6C,CAAC;IAClF,CAAC;IAED;;;;;;;OAOG;IACG,QAAQ,CAAC,MAAc,EAAE,OAA8B;;YACzD,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,MAAK,SAAS,EAAE,CAAC;gBACjC,OAAO,CAAC,IAAI,CAAC,wEAAwE,CAAC,CAAC;YAC3F,CAAC;YACD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;YACxB,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC,WAAW,CAAC,MAA0B,CAAC,CAAC;YACxD,CAAC;YACD,MAAM,IAAI,+BAAsB,CAAC,IAAI,CAAC,CAAC;QAC3C,CAAC;KAAA;IAED;;;;;;;;;;;OAWG;IACG,WAAW,CAAC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,IAAI,EAAE,CAAC;QAClD,CAAC;KAAA;;AA5GL,8CA6GC;AA1G2B,6BAAW,GAAG,IAAI,WAAW,EAAE,CAAC"}
|
package/lib/ClaudeService.d.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/*! Copyright (c) 2024, XAPP AI */
|
|
2
|
-
import type { APIKeyGetter, LLMService, LLMServiceResponse, Prompt, CompletionPrompt } from "./models";
|
|
3
|
-
import type { HTTPService } from "./http/HTTPService";
|
|
4
|
-
export declare const DEFAULT_CLAUDE_API_URL = "https://api.anthropic.com";
|
|
5
|
-
export declare const DEFAULT_CLAUDE_MODEL = "claude-3-5-haiku-20241022";
|
|
6
|
-
export declare const ANTHROPIC_API_VERSION = "2023-06-01";
|
|
7
|
-
export interface ClaudeServiceProps {
|
|
8
|
-
/**
|
|
9
|
-
* Returns the API key to use for the Anthropic Claude service authorization
|
|
10
|
-
*/
|
|
11
|
-
keyGetter: APIKeyGetter;
|
|
12
|
-
/**
|
|
13
|
-
* The HTTP service to use for making requests
|
|
14
|
-
*
|
|
15
|
-
* Defaults to a Node.js HTTP service if not provided.
|
|
16
|
-
*/
|
|
17
|
-
httpService?: Pick<HTTPService, "post">;
|
|
18
|
-
/**
|
|
19
|
-
* The base URL for the Claude API
|
|
20
|
-
* @default "https://api.anthropic.com"
|
|
21
|
-
*/
|
|
22
|
-
apiUrl?: string;
|
|
23
|
-
/**
|
|
24
|
-
* The model to use for completions
|
|
25
|
-
* @default "claude-3-5-haiku-20241022"
|
|
26
|
-
*/
|
|
27
|
-
model?: string;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Claude service for direct Anthropic API calls.
|
|
31
|
-
*
|
|
32
|
-
* This service implements the LLMService interface for the Anthropic Claude API,
|
|
33
|
-
* providing direct access to Claude models without going through AWS Bedrock.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```typescript
|
|
37
|
-
* const service = new ClaudeService({
|
|
38
|
-
* keyGetter: () => process.env.ANTHROPIC_API_KEY || "",
|
|
39
|
-
* model: "claude-3-5-haiku-20241022"
|
|
40
|
-
* });
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export declare class ClaudeService implements LLMService {
|
|
44
|
-
private readonly keyGetter;
|
|
45
|
-
private readonly apiUrl;
|
|
46
|
-
private readonly httpService;
|
|
47
|
-
private readonly model;
|
|
48
|
-
constructor(props: ClaudeServiceProps);
|
|
49
|
-
/**
|
|
50
|
-
* Generate a response from the LLM based on the provided prompt
|
|
51
|
-
*
|
|
52
|
-
* @param prompt - The prompt to send to the LLM
|
|
53
|
-
* @param options - Optional configuration including timeout
|
|
54
|
-
* @returns The LLM service response
|
|
55
|
-
* @throws {InvalidPromptTypeError} If the prompt type is not supported
|
|
56
|
-
*/
|
|
57
|
-
generate(prompt: Prompt, options?: {
|
|
58
|
-
timeout?: number;
|
|
59
|
-
}): Promise<LLMServiceResponse>;
|
|
60
|
-
/**
|
|
61
|
-
* Generate completions using the Anthropic Claude API
|
|
62
|
-
*
|
|
63
|
-
* Note: The following CompletionPrompt parameters are not supported by Claude
|
|
64
|
-
* and will be ignored: frequency_penalty, presence_penalty, response_format
|
|
65
|
-
*
|
|
66
|
-
* System messages are extracted from the messages array and concatenated with double
|
|
67
|
-
* newlines to form a single system prompt, as Claude's API only accepts one system field.
|
|
68
|
-
*
|
|
69
|
-
* @param prompt - The completion prompt
|
|
70
|
-
* @param options - Optional configuration including timeout
|
|
71
|
-
* @returns The LLM service response
|
|
72
|
-
*/
|
|
73
|
-
completions(prompt: CompletionPrompt, options?: {
|
|
74
|
-
timeout?: number;
|
|
75
|
-
}): Promise<LLMServiceResponse>;
|
|
76
|
-
private post;
|
|
77
|
-
}
|
package/lib/ClaudeService.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*! Copyright (c) 2024, XAPP AI */
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.ClaudeService = exports.ANTHROPIC_API_VERSION = exports.DEFAULT_CLAUDE_MODEL = exports.DEFAULT_CLAUDE_API_URL = void 0;
|
|
14
|
-
const models_1 = require("./models");
|
|
15
|
-
const http_1 = require("./http");
|
|
16
|
-
exports.DEFAULT_CLAUDE_API_URL = "https://api.anthropic.com";
|
|
17
|
-
exports.DEFAULT_CLAUDE_MODEL = "claude-3-5-haiku-20241022";
|
|
18
|
-
exports.ANTHROPIC_API_VERSION = "2023-06-01";
|
|
19
|
-
/**
|
|
20
|
-
* Claude service for direct Anthropic API calls.
|
|
21
|
-
*
|
|
22
|
-
* This service implements the LLMService interface for the Anthropic Claude API,
|
|
23
|
-
* providing direct access to Claude models without going through AWS Bedrock.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* const service = new ClaudeService({
|
|
28
|
-
* keyGetter: () => process.env.ANTHROPIC_API_KEY || "",
|
|
29
|
-
* model: "claude-3-5-haiku-20241022"
|
|
30
|
-
* });
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
class ClaudeService {
|
|
34
|
-
constructor(props) {
|
|
35
|
-
this.keyGetter = props.keyGetter;
|
|
36
|
-
this.apiUrl = props.apiUrl || exports.DEFAULT_CLAUDE_API_URL;
|
|
37
|
-
this.httpService = props.httpService || new http_1.NodeHttpService();
|
|
38
|
-
this.model = props.model || exports.DEFAULT_CLAUDE_MODEL;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Generate a response from the LLM based on the provided prompt
|
|
42
|
-
*
|
|
43
|
-
* @param prompt - The prompt to send to the LLM
|
|
44
|
-
* @param options - Optional configuration including timeout
|
|
45
|
-
* @returns The LLM service response
|
|
46
|
-
* @throws {InvalidPromptTypeError} If the prompt type is not supported
|
|
47
|
-
*/
|
|
48
|
-
generate(prompt, options) {
|
|
49
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const { type } = prompt;
|
|
51
|
-
if (type === "completions") {
|
|
52
|
-
return this.completions(prompt, options);
|
|
53
|
-
}
|
|
54
|
-
throw new models_1.InvalidPromptTypeError(type);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Generate completions using the Anthropic Claude API
|
|
59
|
-
*
|
|
60
|
-
* Note: The following CompletionPrompt parameters are not supported by Claude
|
|
61
|
-
* and will be ignored: frequency_penalty, presence_penalty, response_format
|
|
62
|
-
*
|
|
63
|
-
* System messages are extracted from the messages array and concatenated with double
|
|
64
|
-
* newlines to form a single system prompt, as Claude's API only accepts one system field.
|
|
65
|
-
*
|
|
66
|
-
* @param prompt - The completion prompt
|
|
67
|
-
* @param options - Optional configuration including timeout
|
|
68
|
-
* @returns The LLM service response
|
|
69
|
-
*/
|
|
70
|
-
completions(prompt, options) {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
// Extract and combine all system messages into a single prompt.
|
|
73
|
-
// Multiple system messages are joined with double newlines.
|
|
74
|
-
const systemMessages = prompt.messages
|
|
75
|
-
.filter((msg) => msg.role === "system")
|
|
76
|
-
.map((msg) => msg.content);
|
|
77
|
-
const systemPrompt = systemMessages.length > 0 ? systemMessages.join("\n\n") : undefined;
|
|
78
|
-
// Convert messages to Claude format, excluding system messages
|
|
79
|
-
const messages = prompt.messages
|
|
80
|
-
.filter((msg) => msg.role !== "system")
|
|
81
|
-
.map((msg) => ({
|
|
82
|
-
role: msg.role,
|
|
83
|
-
content: msg.content
|
|
84
|
-
}));
|
|
85
|
-
// Build the request payload for Claude
|
|
86
|
-
// Note: frequency_penalty, presence_penalty, and response_format are not supported
|
|
87
|
-
const requestBody = {
|
|
88
|
-
model: this.model,
|
|
89
|
-
messages: messages,
|
|
90
|
-
max_tokens: prompt.max_tokens || 1024,
|
|
91
|
-
temperature: prompt.temperature,
|
|
92
|
-
top_p: prompt.top_p
|
|
93
|
-
};
|
|
94
|
-
if (systemPrompt) {
|
|
95
|
-
requestBody.system = systemPrompt;
|
|
96
|
-
}
|
|
97
|
-
const response = yield this.post({
|
|
98
|
-
path: "v1/messages",
|
|
99
|
-
body: requestBody
|
|
100
|
-
}, options);
|
|
101
|
-
// Parse the response
|
|
102
|
-
let responseBody;
|
|
103
|
-
try {
|
|
104
|
-
responseBody = JSON.parse(response.body);
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
throw new Error(`Failed to parse Claude response: ${error instanceof Error ? error.message : String(error)}`);
|
|
108
|
-
}
|
|
109
|
-
// Check for error responses
|
|
110
|
-
if (responseBody.error) {
|
|
111
|
-
throw new Error(`Claude API error: ${responseBody.error.message}`);
|
|
112
|
-
}
|
|
113
|
-
// Extract content from Claude's response format
|
|
114
|
-
if (!responseBody.content || !Array.isArray(responseBody.content) || responseBody.content.length === 0) {
|
|
115
|
-
throw new Error(`Unexpected Claude response format: ${JSON.stringify(responseBody)}`);
|
|
116
|
-
}
|
|
117
|
-
const textContent = responseBody.content.find((c) => c.type === "text");
|
|
118
|
-
if (!textContent) {
|
|
119
|
-
throw new Error(`No text content in Claude response: ${JSON.stringify(responseBody)}`);
|
|
120
|
-
}
|
|
121
|
-
return { text: textContent.text };
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
post(props, options) {
|
|
125
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
-
const apiKey = yield this.keyGetter();
|
|
127
|
-
const response = yield this.httpService.post({
|
|
128
|
-
url: `${this.apiUrl}/${props.path}`,
|
|
129
|
-
body: props.body,
|
|
130
|
-
headers: {
|
|
131
|
-
"x-api-key": apiKey,
|
|
132
|
-
"anthropic-version": exports.ANTHROPIC_API_VERSION,
|
|
133
|
-
"content-type": "application/json"
|
|
134
|
-
},
|
|
135
|
-
timeout: options === null || options === void 0 ? void 0 : options.timeout
|
|
136
|
-
});
|
|
137
|
-
return response;
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
exports.ClaudeService = ClaudeService;
|
|
142
|
-
//# sourceMappingURL=ClaudeService.js.map
|
package/lib/ClaudeService.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ClaudeService.js","sourceRoot":"","sources":["../src/ClaudeService.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;AAGlC,qCAAkD;AAElD,iCAAyC;AAE5B,QAAA,sBAAsB,GAAG,2BAA2B,CAAC;AACrD,QAAA,oBAAoB,GAAG,2BAA2B,CAAC;AACnD,QAAA,qBAAqB,GAAG,YAAY,CAAC;AA8ClD;;;;;;;;;;;;;GAaG;AACH,MAAa,aAAa;IAMtB,YAAY,KAAyB;QACjC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,8BAAsB,CAAC;QACrD,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW,IAAI,IAAI,sBAAe,EAAE,CAAC;QAC9D,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,4BAAoB,CAAC;IACrD,CAAC;IAED;;;;;;;OAOG;IACG,QAAQ,CAAC,MAAc,EAAE,OAA8B;;YACzD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;YACxB,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;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AC;QACtC,CAAC;KAAA;IAEa,IAAI,CACd,KAAiD,EACjD,OAA8B;;YAE9B,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,MAAM,IAAI,KAAK,CAAC,IAAI,EAAE;gBACnC,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,OAAO,EAAE;oBACL,WAAW,EAAE,MAAM;oBACnB,mBAAmB,EAAE,6BAAqB;oBAC1C,cAAc,EAAE,kBAAkB;iBACrC;gBACD,OAAO,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO;aAC5B,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC;QACpB,CAAC;KAAA;CACJ;AA3HD,sCA2HC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/*! Copyright (c) 2024, XAPP AI */
|
|
2
|
-
import type { LLMService, LLMServiceResponse, Prompt } from "./models";
|
|
3
|
-
export interface FallbackLLMServiceProps {
|
|
4
|
-
/**
|
|
5
|
-
* The primary LLM service to use
|
|
6
|
-
*/
|
|
7
|
-
primary: LLMService;
|
|
8
|
-
/**
|
|
9
|
-
* The fallback LLM service to use when the primary is rate limited
|
|
10
|
-
*/
|
|
11
|
-
fallback: LLMService;
|
|
12
|
-
/**
|
|
13
|
-
* Optional callback when fallback is triggered
|
|
14
|
-
*/
|
|
15
|
-
onFallback?: (error: Error) => void;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* An LLM service that wraps a primary service with a fallback service.
|
|
19
|
-
* When the primary service returns a rate limit error, the fallback service is used.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* const service = new FallbackLLMService({
|
|
24
|
-
* primary: new AWSBedrockService({ region: "us-east-1" }),
|
|
25
|
-
* fallback: new OpenAIService({ keyGetter: () => process.env.OPENAI_API_KEY }),
|
|
26
|
-
* onFallback: (error) => console.warn("Falling back due to:", error.message)
|
|
27
|
-
* });
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export declare class FallbackLLMService implements LLMService {
|
|
31
|
-
private readonly primary;
|
|
32
|
-
private readonly fallback;
|
|
33
|
-
private readonly onFallback?;
|
|
34
|
-
constructor(props: FallbackLLMServiceProps);
|
|
35
|
-
/**
|
|
36
|
-
* Generate a response from the primary LLM service, falling back to the
|
|
37
|
-
* secondary service if the primary returns a rate limit error.
|
|
38
|
-
*
|
|
39
|
-
* @param prompt - The prompt to send to the LLM
|
|
40
|
-
* @param options - Optional configuration including timeout
|
|
41
|
-
* @returns The LLM service response
|
|
42
|
-
*/
|
|
43
|
-
generate(prompt: Prompt, options?: {
|
|
44
|
-
timeout?: number;
|
|
45
|
-
}): Promise<LLMServiceResponse>;
|
|
46
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*! Copyright (c) 2024, XAPP AI */
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.FallbackLLMService = void 0;
|
|
14
|
-
/**
|
|
15
|
-
* Error patterns that indicate rate limiting and should trigger fallback
|
|
16
|
-
*/
|
|
17
|
-
const RATE_LIMIT_PATTERNS = [
|
|
18
|
-
/rate limit/i,
|
|
19
|
-
/throttl/i,
|
|
20
|
-
/too many requests/i,
|
|
21
|
-
/429/,
|
|
22
|
-
/ThrottlingException/i,
|
|
23
|
-
/ServiceQuotaExceededException/i,
|
|
24
|
-
/ProvisionedThroughputExceededException/i
|
|
25
|
-
];
|
|
26
|
-
/**
|
|
27
|
-
* Check if an error is a rate limit error
|
|
28
|
-
*/
|
|
29
|
-
function isRateLimitError(error) {
|
|
30
|
-
if (error instanceof Error) {
|
|
31
|
-
return RATE_LIMIT_PATTERNS.some((pattern) => pattern.test(error.message));
|
|
32
|
-
}
|
|
33
|
-
if (typeof error === "string") {
|
|
34
|
-
return RATE_LIMIT_PATTERNS.some((pattern) => pattern.test(error));
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* An LLM service that wraps a primary service with a fallback service.
|
|
40
|
-
* When the primary service returns a rate limit error, the fallback service is used.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* const service = new FallbackLLMService({
|
|
45
|
-
* primary: new AWSBedrockService({ region: "us-east-1" }),
|
|
46
|
-
* fallback: new OpenAIService({ keyGetter: () => process.env.OPENAI_API_KEY }),
|
|
47
|
-
* onFallback: (error) => console.warn("Falling back due to:", error.message)
|
|
48
|
-
* });
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
class FallbackLLMService {
|
|
52
|
-
constructor(props) {
|
|
53
|
-
this.primary = props.primary;
|
|
54
|
-
this.fallback = props.fallback;
|
|
55
|
-
this.onFallback = props.onFallback;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Generate a response from the primary LLM service, falling back to the
|
|
59
|
-
* secondary service if the primary returns a rate limit error.
|
|
60
|
-
*
|
|
61
|
-
* @param prompt - The prompt to send to the LLM
|
|
62
|
-
* @param options - Optional configuration including timeout
|
|
63
|
-
* @returns The LLM service response
|
|
64
|
-
*/
|
|
65
|
-
generate(prompt, options) {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
try {
|
|
68
|
-
return yield this.primary.generate(prompt, options);
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
if (isRateLimitError(error)) {
|
|
72
|
-
if (this.onFallback && error instanceof Error) {
|
|
73
|
-
this.onFallback(error);
|
|
74
|
-
}
|
|
75
|
-
return this.fallback.generate(prompt, options);
|
|
76
|
-
}
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
exports.FallbackLLMService = FallbackLLMService;
|
|
83
|
-
//# sourceMappingURL=FallbackLLMService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FallbackLLMService.js","sourceRoot":"","sources":["../src/FallbackLLMService.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;AAIlC;;GAEG;AACH,MAAM,mBAAmB,GAAG;IACxB,aAAa;IACb,UAAU;IACV,oBAAoB;IACpB,KAAK;IACL,sBAAsB;IACtB,gCAAgC;IAChC,yCAAyC;CAC5C,CAAC;AAEF;;GAEG;AACH,SAAS,gBAAgB,CAAC,KAAc;IACpC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QACzB,OAAO,mBAAmB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9E,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,mBAAmB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAiBD;;;;;;;;;;;;GAYG;AACH,MAAa,kBAAkB;IAK3B,YAAY,KAA8B;QACtC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;IACvC,CAAC;IAED;;;;;;;OAOG;IACG,QAAQ,CAAC,MAAc,EAAE,OAA8B;;YACzD,IAAI,CAAC;gBACD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACxD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;oBAC1B,IAAI,IAAI,CAAC,UAAU,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;wBAC5C,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;oBAC3B,CAAC;oBACD,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBACnD,CAAC;gBACD,MAAM,KAAK,CAAC;YAChB,CAAC;QACL,CAAC;KAAA;CACJ;AAhCD,gDAgCC"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/*! Copyright (c) 2026, XAPP AI */
|
|
2
|
-
import type { ExternalLead } from "stentor-models";
|
|
3
|
-
import type { AnalyzeLeadOptions, AnalyzeWebsiteData, IGenerativeAIService, LeadAnalysis, LLMService, LLMServiceResponse, Prompt } from "./models";
|
|
4
|
-
import type { EmailAnalysisInput, EmailLeadAnalysis } from "./models/EmailAnalysis";
|
|
5
|
-
import type { ChatSummary } from "./models/ChatSummary";
|
|
6
|
-
import { WebsiteAnalysis } from "./models/WebsiteAnalysis";
|
|
7
|
-
export declare class GenerativeAIService implements IGenerativeAIService {
|
|
8
|
-
private readonly llmService;
|
|
9
|
-
constructor(llmService: LLMService);
|
|
10
|
-
/**
|
|
11
|
-
* Executes a custom prompt that the user is responsible for creating and parsing.
|
|
12
|
-
*
|
|
13
|
-
* @param prompt
|
|
14
|
-
*/
|
|
15
|
-
customPrompt(prompt: Prompt): Promise<LLMServiceResponse>;
|
|
16
|
-
/**
|
|
17
|
-
* Can take in an external lead and help summarize and classify.
|
|
18
|
-
*
|
|
19
|
-
* @param lead
|
|
20
|
-
*/
|
|
21
|
-
analyzeLead(lead: ExternalLead, options?: AnalyzeLeadOptions): Promise<LeadAnalysis>;
|
|
22
|
-
/**
|
|
23
|
-
* Analyze an inbound email (or email thread) to classify and extract lead information.
|
|
24
|
-
*
|
|
25
|
-
* Combines lead classification (contactType, serviceType, jobType, urgency) with
|
|
26
|
-
* structured contact extraction in a single LLM call. Handles direct customer emails,
|
|
27
|
-
* FSM/CRM lead notification emails, and multi-email threads.
|
|
28
|
-
*
|
|
29
|
-
* @param email - The email content and optional thread history to analyze.
|
|
30
|
-
* @param options - Optional business context and LLM call options.
|
|
31
|
-
*/
|
|
32
|
-
analyzeEmail(email: EmailAnalysisInput, options?: AnalyzeLeadOptions): Promise<EmailLeadAnalysis>;
|
|
33
|
-
/**
|
|
34
|
-
* Summarize a chat transcript
|
|
35
|
-
* @param transcript
|
|
36
|
-
* @returns Returns the summarized chat of a lead transcript
|
|
37
|
-
*/
|
|
38
|
-
summarizeChatFromTranscript(transcript: ExternalLead["transcript"]): Promise<ChatSummary>;
|
|
39
|
-
analyzeWebsite(markdown: string, data: AnalyzeWebsiteData): Promise<WebsiteAnalysis>;
|
|
40
|
-
}
|