llm-exe 1.0.2 → 2.0.0-beta.10
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/LICENSE +21 -0
- package/dist/index.d.mts +1224 -0
- package/dist/index.d.ts +1207 -46
- package/dist/index.js +4188 -80
- package/dist/index.mjs +4150 -0
- package/package.json +35 -29
- package/readme.md +79 -2
- package/dist/embedding/base.d.ts +0 -8
- package/dist/embedding/base.js +0 -43
- package/dist/embedding/base.js.map +0 -1
- package/dist/embedding/openai.d.ts +0 -11
- package/dist/embedding/openai.js +0 -73
- package/dist/embedding/openai.js.map +0 -1
- package/dist/executor/_base.d.ts +0 -68
- package/dist/executor/_base.js +0 -229
- package/dist/executor/_base.js.map +0 -1
- package/dist/executor/_functions.d.ts +0 -25
- package/dist/executor/_functions.js +0 -30
- package/dist/executor/_functions.js.map +0 -1
- package/dist/executor/_metadata.d.ts +0 -8
- package/dist/executor/_metadata.js +0 -59
- package/dist/executor/_metadata.js.map +0 -1
- package/dist/executor/core.d.ts +0 -10
- package/dist/executor/core.js +0 -28
- package/dist/executor/core.js.map +0 -1
- package/dist/executor/index.d.ts +0 -5
- package/dist/executor/index.js +0 -15
- package/dist/executor/index.js.map +0 -1
- package/dist/executor/llm-openai-function.d.ts +0 -13
- package/dist/executor/llm-openai-function.js +0 -23
- package/dist/executor/llm-openai-function.js.map +0 -1
- package/dist/executor/llm.d.ts +0 -32
- package/dist/executor/llm.js +0 -82
- package/dist/executor/llm.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/interfaces/chat.d.ts +0 -74
- package/dist/interfaces/chat.js +0 -3
- package/dist/interfaces/chat.js.map +0 -1
- package/dist/interfaces/functions.d.ts +0 -67
- package/dist/interfaces/functions.js +0 -4
- package/dist/interfaces/functions.js.map +0 -1
- package/dist/interfaces/index.d.ts +0 -7
- package/dist/interfaces/index.js +0 -23
- package/dist/interfaces/index.js.map +0 -1
- package/dist/interfaces/openai.d.ts +0 -46
- package/dist/interfaces/openai.js +0 -3
- package/dist/interfaces/openai.js.map +0 -1
- package/dist/interfaces/parser.d.ts +0 -8
- package/dist/interfaces/parser.js +0 -3
- package/dist/interfaces/parser.js.map +0 -1
- package/dist/interfaces/prompt.d.ts +0 -22
- package/dist/interfaces/prompt.js +0 -3
- package/dist/interfaces/prompt.js.map +0 -1
- package/dist/interfaces/utils.d.ts +0 -18
- package/dist/interfaces/utils.js +0 -3
- package/dist/interfaces/utils.js.map +0 -1
- package/dist/llm/_base.d.ts +0 -84
- package/dist/llm/_base.js +0 -184
- package/dist/llm/_base.js.map +0 -1
- package/dist/llm/index.d.ts +0 -2
- package/dist/llm/index.js +0 -9
- package/dist/llm/index.js.map +0 -1
- package/dist/llm/openai.d.ts +0 -96
- package/dist/llm/openai.js +0 -259
- package/dist/llm/openai.js.map +0 -1
- package/dist/llm/output/base.d.ts +0 -12
- package/dist/llm/output/base.js +0 -45
- package/dist/llm/output/base.js.map +0 -1
- package/dist/llm/output/index.d.ts +0 -9
- package/dist/llm/output/index.js +0 -30
- package/dist/llm/output/index.js.map +0 -1
- package/dist/llm/output/openai.d.ts +0 -17
- package/dist/llm/output/openai.js +0 -58
- package/dist/llm/output/openai.js.map +0 -1
- package/dist/parser/_base.d.ts +0 -33
- package/dist/parser/_base.js +0 -62
- package/dist/parser/_base.js.map +0 -1
- package/dist/parser/_functions.d.ts +0 -109
- package/dist/parser/_functions.js +0 -55
- package/dist/parser/_functions.js.map +0 -1
- package/dist/parser/_utils.d.ts +0 -3
- package/dist/parser/_utils.js +0 -24
- package/dist/parser/_utils.js.map +0 -1
- package/dist/parser/index.d.ts +0 -15
- package/dist/parser/index.js +0 -34
- package/dist/parser/index.js.map +0 -1
- package/dist/parser/parsers/BooleanParser.d.ts +0 -8
- package/dist/parser/parsers/BooleanParser.js +0 -20
- package/dist/parser/parsers/BooleanParser.js.map +0 -1
- package/dist/parser/parsers/CustomParser.d.ts +0 -28
- package/dist/parser/parsers/CustomParser.js +0 -42
- package/dist/parser/parsers/CustomParser.js.map +0 -1
- package/dist/parser/parsers/JsonParser.d.ts +0 -7
- package/dist/parser/parsers/JsonParser.js +0 -27
- package/dist/parser/parsers/JsonParser.js.map +0 -1
- package/dist/parser/parsers/ListToArrayParser.d.ts +0 -5
- package/dist/parser/parsers/ListToArrayParser.js +0 -17
- package/dist/parser/parsers/ListToArrayParser.js.map +0 -1
- package/dist/parser/parsers/ListToJsonParser.d.ts +0 -7
- package/dist/parser/parsers/ListToJsonParser.js +0 -34
- package/dist/parser/parsers/ListToJsonParser.js.map +0 -1
- package/dist/parser/parsers/ListToKeyValueParser.d.ts +0 -14
- package/dist/parser/parsers/ListToKeyValueParser.js +0 -24
- package/dist/parser/parsers/ListToKeyValueParser.js.map +0 -1
- package/dist/parser/parsers/MarkdownCodeBlock.d.ts +0 -14
- package/dist/parser/parsers/MarkdownCodeBlock.js +0 -16
- package/dist/parser/parsers/MarkdownCodeBlock.js.map +0 -1
- package/dist/parser/parsers/MarkdownCodeBlocks.d.ts +0 -14
- package/dist/parser/parsers/MarkdownCodeBlocks.js +0 -25
- package/dist/parser/parsers/MarkdownCodeBlocks.js.map +0 -1
- package/dist/parser/parsers/NumberParser.d.ts +0 -8
- package/dist/parser/parsers/NumberParser.js +0 -16
- package/dist/parser/parsers/NumberParser.js.map +0 -1
- package/dist/parser/parsers/OpenAiFunctionParser.d.ts +0 -16
- package/dist/parser/parsers/OpenAiFunctionParser.js +0 -32
- package/dist/parser/parsers/OpenAiFunctionParser.js.map +0 -1
- package/dist/parser/parsers/ReplaceStringTemplateParser.d.ts +0 -8
- package/dist/parser/parsers/ReplaceStringTemplateParser.js +0 -15
- package/dist/parser/parsers/ReplaceStringTemplateParser.js.map +0 -1
- package/dist/parser/parsers/StringExtractParser.d.ts +0 -12
- package/dist/parser/parsers/StringExtractParser.js +0 -42
- package/dist/parser/parsers/StringExtractParser.js.map +0 -1
- package/dist/parser/parsers/StringParser.d.ts +0 -8
- package/dist/parser/parsers/StringParser.js +0 -17
- package/dist/parser/parsers/StringParser.js.map +0 -1
- package/dist/plugins/callable/callable.d.ts +0 -87
- package/dist/plugins/callable/callable.js +0 -149
- package/dist/plugins/callable/callable.js.map +0 -1
- package/dist/plugins/callable/index.d.ts +0 -21
- package/dist/plugins/callable/index.js +0 -29
- package/dist/plugins/callable/index.js.map +0 -1
- package/dist/prompt/_base.d.ts +0 -61
- package/dist/prompt/_base.js +0 -164
- package/dist/prompt/_base.js.map +0 -1
- package/dist/prompt/_functions.d.ts +0 -19
- package/dist/prompt/_functions.js +0 -24
- package/dist/prompt/_functions.js.map +0 -1
- package/dist/prompt/chat.d.ts +0 -103
- package/dist/prompt/chat.js +0 -328
- package/dist/prompt/chat.js.map +0 -1
- package/dist/prompt/index.d.ts +0 -4
- package/dist/prompt/index.js +0 -13
- package/dist/prompt/index.js.map +0 -1
- package/dist/prompt/text.d.ts +0 -10
- package/dist/prompt/text.js +0 -16
- package/dist/prompt/text.js.map +0 -1
- package/dist/state/_base.d.ts +0 -29
- package/dist/state/_base.js +0 -96
- package/dist/state/_base.js.map +0 -1
- package/dist/state/_functions.d.ts +0 -7
- package/dist/state/_functions.js +0 -34
- package/dist/state/_functions.js.map +0 -1
- package/dist/state/dialogue.d.ts +0 -24
- package/dist/state/dialogue.js +0 -111
- package/dist/state/dialogue.js.map +0 -1
- package/dist/state/index.d.ts +0 -4
- package/dist/state/index.js +0 -16
- package/dist/state/index.js.map +0 -1
- package/dist/state/item.d.ts +0 -22
- package/dist/state/item.js +0 -63
- package/dist/state/item.js.map +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +0 -18
- package/dist/types/index.js.map +0 -1
- package/dist/utils/const.d.ts +0 -16
- package/dist/utils/const.js +0 -20
- package/dist/utils/const.js.map +0 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -18
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/modules/asyncCallWithTimeout.d.ts +0 -1
- package/dist/utils/modules/asyncCallWithTimeout.js +0 -17
- package/dist/utils/modules/asyncCallWithTimeout.js.map +0 -1
- package/dist/utils/modules/handlebars/hbs.d.ts +0 -11
- package/dist/utils/modules/handlebars/hbs.js +0 -65
- package/dist/utils/modules/handlebars/hbs.js.map +0 -1
- package/dist/utils/modules/handlebars/helpers/index.d.ts +0 -11
- package/dist/utils/modules/handlebars/helpers/index.js +0 -108
- package/dist/utils/modules/handlebars/helpers/index.js.map +0 -1
- package/dist/utils/modules/handlebars/index.d.ts +0 -2
- package/dist/utils/modules/handlebars/index.js +0 -79
- package/dist/utils/modules/handlebars/index.js.map +0 -1
- package/dist/utils/modules/handlebars/templates/index.d.ts +0 -12
- package/dist/utils/modules/handlebars/templates/index.js +0 -46
- package/dist/utils/modules/handlebars/templates/index.js.map +0 -1
- package/dist/utils/modules/index.d.ts +0 -73
- package/dist/utils/modules/index.js +0 -190
- package/dist/utils/modules/index.js.map +0 -1
- package/dist/utils/modules/json-schema-filter.d.ts +0 -2
- package/dist/utils/modules/json-schema-filter.js +0 -90
- package/dist/utils/modules/json-schema-filter.js.map +0 -1
- package/dist/utils/modules/json.d.ts +0 -3
- package/dist/utils/modules/json.js +0 -57
- package/dist/utils/modules/json.js.map +0 -1
- package/dist/utils/modules/openai.d.ts +0 -12
- package/dist/utils/modules/openai.js +0 -31
- package/dist/utils/modules/openai.js.map +0 -1
- package/dist/utils/modules/replaceTemplateString.d.ts +0 -2
- package/dist/utils/modules/replaceTemplateString.js +0 -21
- package/dist/utils/modules/replaceTemplateString.js.map +0 -1
- package/dist/vector/base.d.ts +0 -11
- package/dist/vector/base.js +0 -23
- package/dist/vector/base.js.map +0 -1
- package/dist/vector/index.d.ts +0 -2
- package/dist/vector/index.js +0 -8
- package/dist/vector/index.js.map +0 -1
- package/dist/vector/pinecone.d.ts +0 -6
- package/dist/vector/pinecone.js +0 -23
- package/dist/vector/pinecone.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"src/","sources":["interfaces/parser.ts"],"names":[],"mappings":""}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export type TextPromptType = "text";
|
|
2
|
-
export type ChatPromptType = "chat";
|
|
3
|
-
export type PromptType = TextPromptType | ChatPromptType;
|
|
4
|
-
export type PromptHelper = {
|
|
5
|
-
name: string;
|
|
6
|
-
handler: (args: any) => any;
|
|
7
|
-
};
|
|
8
|
-
export type PromptPartial = {
|
|
9
|
-
name: string;
|
|
10
|
-
template: string;
|
|
11
|
-
};
|
|
12
|
-
export interface PromptTemplateOptions {
|
|
13
|
-
partials?: PromptPartial[];
|
|
14
|
-
helpers?: PromptHelper[];
|
|
15
|
-
}
|
|
16
|
-
export interface PromptOptions extends PromptTemplateOptions {
|
|
17
|
-
preFilters?: ((prompt: string) => string)[];
|
|
18
|
-
postFilters?: ((prompt: string) => string)[];
|
|
19
|
-
}
|
|
20
|
-
export interface ChatPromptOptions extends PromptOptions {
|
|
21
|
-
allowUnsafeUserTemplate?: boolean;
|
|
22
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"src/","sources":["interfaces/prompt.ts"],"names":[],"mappings":""}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export type PrimitiveValue = bigint | boolean | null | number | string | symbol | undefined;
|
|
2
|
-
export type ObjectValue = PrimitiveValue | PlainObject | ObjectArray;
|
|
3
|
-
export interface PlainObject {
|
|
4
|
-
[key: string]: ObjectValue;
|
|
5
|
-
}
|
|
6
|
-
export interface ObjectArray extends Array<ObjectValue> {
|
|
7
|
-
}
|
|
8
|
-
export interface ResultAttributes<R = any, A = Record<string, any>> {
|
|
9
|
-
result: R;
|
|
10
|
-
attributes: A;
|
|
11
|
-
}
|
|
12
|
-
export interface Serializable {
|
|
13
|
-
serialize?(): Record<string, any>;
|
|
14
|
-
deserialize?(): void;
|
|
15
|
-
}
|
|
16
|
-
export interface EmptyObject {
|
|
17
|
-
[key: string]: never;
|
|
18
|
-
}
|
package/dist/interfaces/utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"src/","sources":["interfaces/utils.ts"],"names":[],"mappings":""}
|
package/dist/llm/_base.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { BaseLlmOptions, PromptType } from "../types";
|
|
2
|
-
import { BaseLlmOutput } from "../llm/output";
|
|
3
|
-
/**
|
|
4
|
-
* BaseLlm is an abstract class that provides a base structure for implementing
|
|
5
|
-
* specific Low Latency Models (LLMs). It handles retries, timeouts, and metrics
|
|
6
|
-
* for the calls made to the LLM.
|
|
7
|
-
*/
|
|
8
|
-
export declare abstract class BaseLlm<C = any> {
|
|
9
|
-
/**
|
|
10
|
-
* A property to hold the client instance for the specific LLM.
|
|
11
|
-
*/
|
|
12
|
-
protected client: C;
|
|
13
|
-
/**
|
|
14
|
-
* The type of prompt to create. Options are "text" or "chat"
|
|
15
|
-
*/
|
|
16
|
-
protected promptType: PromptType;
|
|
17
|
-
/**
|
|
18
|
-
* The maximum time (in milliseconds) to wait for a response before timing out.
|
|
19
|
-
*/
|
|
20
|
-
protected timeout: number;
|
|
21
|
-
/**
|
|
22
|
-
* The maximum delay (in milliseconds) between retries.
|
|
23
|
-
*/
|
|
24
|
-
protected maxDelay: number;
|
|
25
|
-
/**
|
|
26
|
-
* The maximum number of retries before giving up.
|
|
27
|
-
*/
|
|
28
|
-
protected numOfAttempts: number;
|
|
29
|
-
/**
|
|
30
|
-
* The jitter strategy to use between retries. Options are "none" or "full".
|
|
31
|
-
*/
|
|
32
|
-
protected jitter: "none" | "full";
|
|
33
|
-
protected traceId: null | string;
|
|
34
|
-
/**
|
|
35
|
-
* An object to store metrics related to the LLM calls.
|
|
36
|
-
*/
|
|
37
|
-
protected metrics: any;
|
|
38
|
-
/**
|
|
39
|
-
* The BaseLlm constructor takes an options object and sets up the instance.
|
|
40
|
-
* @param {BaseLlmOptions} options - The options object for LLM configuration.
|
|
41
|
-
*/
|
|
42
|
-
constructor(options: BaseLlmOptions);
|
|
43
|
-
shouldRetry(_error: any, _stepNumber: number): boolean;
|
|
44
|
-
handleError(_error: any): void;
|
|
45
|
-
getPromptType(): PromptType;
|
|
46
|
-
/**
|
|
47
|
-
* getMetrics returns the metrics object for the LLM.
|
|
48
|
-
*/
|
|
49
|
-
getMetrics(): any;
|
|
50
|
-
/**
|
|
51
|
-
* getMetadata - Used to return metrics and data about executions.
|
|
52
|
-
*/
|
|
53
|
-
getMetadata(): {
|
|
54
|
-
traceId: string | null;
|
|
55
|
-
promptType: PromptType;
|
|
56
|
-
timeout: number;
|
|
57
|
-
jitter: "none" | "full";
|
|
58
|
-
maxDelay: number;
|
|
59
|
-
numOfAttempts: number;
|
|
60
|
-
metrics: any;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* call makes a call to the specific LLM with input and returns the output.
|
|
64
|
-
* It also handles retries and updates the metrics.
|
|
65
|
-
* @param _input - The input to the LLM.
|
|
66
|
-
* @return The output from the LLM.
|
|
67
|
-
*/
|
|
68
|
-
call(_input: any, ...args: any[]): Promise<BaseLlmOutput>;
|
|
69
|
-
/**
|
|
70
|
-
* _callWithRetry is a private method that handles retries and timeouts for the LLM call.
|
|
71
|
-
* @param _input - The input to the LLM.
|
|
72
|
-
* @return The result of the LLM call.
|
|
73
|
-
* @throws An error if the maximum number of retries is reached.
|
|
74
|
-
*/
|
|
75
|
-
_callWithRetry(_input: any, ...args: any[]): Promise<any>;
|
|
76
|
-
/**
|
|
77
|
-
* _call is an method that must be implemented by subclasses to make the actual LLM call.
|
|
78
|
-
* @param {any} _input - The input to the LLM.
|
|
79
|
-
* @return The output from the LLM.
|
|
80
|
-
*/
|
|
81
|
-
_call(_input: any, ..._args: any[]): Promise<BaseLlmOutput>;
|
|
82
|
-
withTraceId(traceId: string): this;
|
|
83
|
-
getTraceId(): string | null;
|
|
84
|
-
}
|
package/dist/llm/_base.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseLlm = void 0;
|
|
4
|
-
const exponential_backoff_1 = require("exponential-backoff");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
const output_1 = require("../llm/output");
|
|
7
|
-
/**
|
|
8
|
-
* BaseLlm is an abstract class that provides a base structure for implementing
|
|
9
|
-
* specific Low Latency Models (LLMs). It handles retries, timeouts, and metrics
|
|
10
|
-
* for the calls made to the LLM.
|
|
11
|
-
*/
|
|
12
|
-
class BaseLlm {
|
|
13
|
-
/**
|
|
14
|
-
* The BaseLlm constructor takes an options object and sets up the instance.
|
|
15
|
-
* @param {BaseLlmOptions} options - The options object for LLM configuration.
|
|
16
|
-
*/
|
|
17
|
-
constructor(options) {
|
|
18
|
-
/**
|
|
19
|
-
* A property to hold the client instance for the specific LLM.
|
|
20
|
-
*/
|
|
21
|
-
Object.defineProperty(this, "client", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: void 0
|
|
26
|
-
});
|
|
27
|
-
/**
|
|
28
|
-
* The type of prompt to create. Options are "text" or "chat"
|
|
29
|
-
*/
|
|
30
|
-
Object.defineProperty(this, "promptType", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
configurable: true,
|
|
33
|
-
writable: true,
|
|
34
|
-
value: void 0
|
|
35
|
-
});
|
|
36
|
-
/**
|
|
37
|
-
* The maximum time (in milliseconds) to wait for a response before timing out.
|
|
38
|
-
*/
|
|
39
|
-
Object.defineProperty(this, "timeout", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
configurable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
value: void 0
|
|
44
|
-
});
|
|
45
|
-
/**
|
|
46
|
-
* The maximum delay (in milliseconds) between retries.
|
|
47
|
-
*/
|
|
48
|
-
Object.defineProperty(this, "maxDelay", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
configurable: true,
|
|
51
|
-
writable: true,
|
|
52
|
-
value: void 0
|
|
53
|
-
});
|
|
54
|
-
/**
|
|
55
|
-
* The maximum number of retries before giving up.
|
|
56
|
-
*/
|
|
57
|
-
Object.defineProperty(this, "numOfAttempts", {
|
|
58
|
-
enumerable: true,
|
|
59
|
-
configurable: true,
|
|
60
|
-
writable: true,
|
|
61
|
-
value: void 0
|
|
62
|
-
});
|
|
63
|
-
/**
|
|
64
|
-
* The jitter strategy to use between retries. Options are "none" or "full".
|
|
65
|
-
*/
|
|
66
|
-
Object.defineProperty(this, "jitter", {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
configurable: true,
|
|
69
|
-
writable: true,
|
|
70
|
-
value: void 0
|
|
71
|
-
});
|
|
72
|
-
Object.defineProperty(this, "traceId", {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
configurable: true,
|
|
75
|
-
writable: true,
|
|
76
|
-
value: void 0
|
|
77
|
-
});
|
|
78
|
-
/**
|
|
79
|
-
* An object to store metrics related to the LLM calls.
|
|
80
|
-
*/
|
|
81
|
-
Object.defineProperty(this, "metrics", {
|
|
82
|
-
enumerable: true,
|
|
83
|
-
configurable: true,
|
|
84
|
-
writable: true,
|
|
85
|
-
value: {
|
|
86
|
-
total_calls: 0,
|
|
87
|
-
total_call_success: 0,
|
|
88
|
-
total_call_retry: 0,
|
|
89
|
-
total_call_error: 0,
|
|
90
|
-
history: [],
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
this.traceId = options?.traceId || null;
|
|
94
|
-
this.client = null;
|
|
95
|
-
this.promptType = options?.promptType || "text";
|
|
96
|
-
this.timeout = options.timeout || 30000;
|
|
97
|
-
this.jitter = options.jitter || "none";
|
|
98
|
-
this.maxDelay = options.maxDelay || 5000;
|
|
99
|
-
this.numOfAttempts = options.numOfAttempts || 5;
|
|
100
|
-
}
|
|
101
|
-
shouldRetry(_error, _stepNumber) {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
handleError(_error) {
|
|
105
|
-
throw _error;
|
|
106
|
-
}
|
|
107
|
-
getPromptType() {
|
|
108
|
-
return this.promptType;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* getMetrics returns the metrics object for the LLM.
|
|
112
|
-
*/
|
|
113
|
-
getMetrics() {
|
|
114
|
-
return { ...this.metrics };
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* getMetadata - Used to return metrics and data about executions.
|
|
118
|
-
*/
|
|
119
|
-
getMetadata() {
|
|
120
|
-
return {
|
|
121
|
-
traceId: this.getTraceId(),
|
|
122
|
-
promptType: this.promptType,
|
|
123
|
-
timeout: this.timeout,
|
|
124
|
-
jitter: this.jitter,
|
|
125
|
-
maxDelay: this.maxDelay,
|
|
126
|
-
numOfAttempts: this.numOfAttempts,
|
|
127
|
-
metrics: this.getMetrics(),
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* call makes a call to the specific LLM with input and returns the output.
|
|
132
|
-
* It also handles retries and updates the metrics.
|
|
133
|
-
* @param _input - The input to the LLM.
|
|
134
|
-
* @return The output from the LLM.
|
|
135
|
-
*/
|
|
136
|
-
async call(_input, ...args) {
|
|
137
|
-
return this._callWithRetry(_input, ...args);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* _callWithRetry is a private method that handles retries and timeouts for the LLM call.
|
|
141
|
-
* @param _input - The input to the LLM.
|
|
142
|
-
* @return The result of the LLM call.
|
|
143
|
-
* @throws An error if the maximum number of retries is reached.
|
|
144
|
-
*/
|
|
145
|
-
async _callWithRetry(_input, ...args) {
|
|
146
|
-
try {
|
|
147
|
-
this.metrics.total_calls++;
|
|
148
|
-
const result = await (0, exponential_backoff_1.backOff)(() => (0, utils_1.asyncCallWithTimeout)(this._call(_input, ...args), this.timeout), {
|
|
149
|
-
startingDelay: 0,
|
|
150
|
-
maxDelay: this.maxDelay,
|
|
151
|
-
numOfAttempts: this.numOfAttempts,
|
|
152
|
-
jitter: this.jitter,
|
|
153
|
-
retry: (_error, _stepNumber) => {
|
|
154
|
-
this.metrics.total_call_retry++;
|
|
155
|
-
console.log(`Handler timeout after ${this.timeout}. Retrying...`);
|
|
156
|
-
return true;
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
this.metrics.total_call_success++;
|
|
160
|
-
return result;
|
|
161
|
-
}
|
|
162
|
-
catch (error) {
|
|
163
|
-
this.metrics.total_call_error++;
|
|
164
|
-
this.handleError(error);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* _call is an method that must be implemented by subclasses to make the actual LLM call.
|
|
169
|
-
* @param {any} _input - The input to the LLM.
|
|
170
|
-
* @return The output from the LLM.
|
|
171
|
-
*/
|
|
172
|
-
async _call(_input, ..._args) {
|
|
173
|
-
return new output_1.OutputDefault(undefined);
|
|
174
|
-
}
|
|
175
|
-
withTraceId(traceId) {
|
|
176
|
-
this.traceId = traceId;
|
|
177
|
-
return this;
|
|
178
|
-
}
|
|
179
|
-
getTraceId() {
|
|
180
|
-
return this.traceId;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
exports.BaseLlm = BaseLlm;
|
|
184
|
-
//# sourceMappingURL=_base.js.map
|
package/dist/llm/_base.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_base.js","sourceRoot":"src/","sources":["llm/_base.ts"],"names":[],"mappings":";;;AAAA,6DAA8C;AAE9C,mCAA+C;AAC/C,yCAA4D;AAE5D;;;;GAIG;AACH,MAAsB,OAAO;IA2C3B;;;OAGG;IACH,YAAY,OAAuB;QA9CnC;;WAEG;QACH;;;;;WAAoB;QAEpB;;WAEG;QACH;;;;;WAAiC;QAEjC;;WAEG;QACH;;;;;WAA0B;QAE1B;;WAEG;QACH;;;;;WAA2B;QAE3B;;WAEG;QACH;;;;;WAAgC;QAEhC;;WAEG;QACH;;;;;WAAkC;QAElC;;;;;WAAkC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AG,OAAO,CAAA;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;CACF;AA1JD,0BA0JC"}
|
package/dist/llm/index.d.ts
DELETED
package/dist/llm/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpenAI = exports.createLlmOpenAi = exports.BaseLlm = void 0;
|
|
4
|
-
var _base_1 = require("./_base");
|
|
5
|
-
Object.defineProperty(exports, "BaseLlm", { enumerable: true, get: function () { return _base_1.BaseLlm; } });
|
|
6
|
-
var openai_1 = require("./openai");
|
|
7
|
-
Object.defineProperty(exports, "createLlmOpenAi", { enumerable: true, get: function () { return openai_1.createLlmOpenAi; } });
|
|
8
|
-
Object.defineProperty(exports, "OpenAI", { enumerable: true, get: function () { return openai_1.OpenAI; } });
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
package/dist/llm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["llm/index.ts"],"names":[],"mappings":";;;AAAA,iCAAkC;AAAzB,gGAAA,OAAO,OAAA;AAChB,mCAAmD;AAA1C,yGAAA,eAAe,OAAA;AAAE,gGAAA,MAAM,OAAA"}
|
package/dist/llm/openai.d.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { OpenAIApi } from "openai";
|
|
2
|
-
import { IChatMessages, OpenAIModelName, OpenAIOptions, OpenAiLlmExecutorOptions } from "../types";
|
|
3
|
-
import { BaseLlm } from "./_base";
|
|
4
|
-
import { OutputOpenAIChat } from "../llm/output";
|
|
5
|
-
import { OutputOpenAICompletion } from "./output/openai";
|
|
6
|
-
/**
|
|
7
|
-
* Create a new instance of the OpenAI API wrapper.
|
|
8
|
-
* @param options - Configuration options for the OpenAI API wrapper.
|
|
9
|
-
* @returns - A new instance of the OpenAI API wrapper class.
|
|
10
|
-
*/
|
|
11
|
-
export declare function createLlmOpenAi(options: OpenAIOptions): OpenAI;
|
|
12
|
-
/**
|
|
13
|
-
* A class that extends BaseLlm and provides functionality for the OpenAI API.
|
|
14
|
-
*/
|
|
15
|
-
export declare class OpenAI extends BaseLlm<OpenAIApi> {
|
|
16
|
-
private model;
|
|
17
|
-
private temperature;
|
|
18
|
-
private maxTokens;
|
|
19
|
-
private topP;
|
|
20
|
-
private n;
|
|
21
|
-
private stream;
|
|
22
|
-
private stop;
|
|
23
|
-
private presencePenalty;
|
|
24
|
-
private frequencyPenalty;
|
|
25
|
-
private logitBias;
|
|
26
|
-
private user;
|
|
27
|
-
/**
|
|
28
|
-
* Constructor for the OpenAI class.
|
|
29
|
-
* @param {OpenAIOptions} options - Configuration options for the OpenAI API wrapper.
|
|
30
|
-
*/
|
|
31
|
-
constructor(options: OpenAIOptions);
|
|
32
|
-
/**
|
|
33
|
-
* Get the total prompt and completion tokens across all calls to the API.
|
|
34
|
-
* @returns - An object with total prompt and completion tokens.
|
|
35
|
-
*/
|
|
36
|
-
getMetrics(): {
|
|
37
|
-
total_completionTokens: number;
|
|
38
|
-
total_promptTokens: number;
|
|
39
|
-
total_totalTokens: number;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Calculate the API call cost based on input and output tokens.
|
|
43
|
-
* @param input_tokens - The number of input tokens.
|
|
44
|
-
* @param output_tokens=0 - The number of output tokens (defaults to 0).
|
|
45
|
-
* @returns An object for input/output tokens and cost.
|
|
46
|
-
*/
|
|
47
|
-
calculatePrice(input_tokens: number, output_tokens?: number): {
|
|
48
|
-
input_cost: number;
|
|
49
|
-
output_cost: number;
|
|
50
|
-
total_cost: number;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Log a table containing usage metrics for the OpenAI API.
|
|
54
|
-
*/
|
|
55
|
-
logMetrics(): void;
|
|
56
|
-
/**
|
|
57
|
-
* Wrapper function to call chat/completion with the specified input.
|
|
58
|
-
* @private
|
|
59
|
-
* @param input - The input for the chat/completion API.
|
|
60
|
-
* @returns The chat/completion response from the API.
|
|
61
|
-
*/
|
|
62
|
-
_call(input: string | IChatMessages, arg2?: OpenAiLlmExecutorOptions): Promise<OutputOpenAIChat | OutputOpenAICompletion>;
|
|
63
|
-
/**
|
|
64
|
-
* Communicate with the OpenAI Chat API.
|
|
65
|
-
* @param messages - A list of message objects for the API call.
|
|
66
|
-
* @returns The chat response from the API.
|
|
67
|
-
*/
|
|
68
|
-
chat(messages: IChatMessages, _args?: OpenAiLlmExecutorOptions): Promise<OutputOpenAIChat>;
|
|
69
|
-
/**
|
|
70
|
-
* Communicate with the OpenAI Completion API.
|
|
71
|
-
* @param messages - A list of message objects for the API call.
|
|
72
|
-
* @returns The chat response from the API.
|
|
73
|
-
*/
|
|
74
|
-
completion(prompt: string): Promise<OutputOpenAICompletion>;
|
|
75
|
-
getMetadata(): {
|
|
76
|
-
traceId: string | null;
|
|
77
|
-
promptType: import("../types").PromptType;
|
|
78
|
-
timeout: number;
|
|
79
|
-
jitter: "none" | "full";
|
|
80
|
-
maxDelay: number;
|
|
81
|
-
numOfAttempts: number;
|
|
82
|
-
metrics: any;
|
|
83
|
-
} & {
|
|
84
|
-
model: OpenAIModelName;
|
|
85
|
-
temperature: number;
|
|
86
|
-
max_tokens: number;
|
|
87
|
-
topP: number | null;
|
|
88
|
-
n: number | null;
|
|
89
|
-
stream: boolean | null;
|
|
90
|
-
stop: any;
|
|
91
|
-
presencePenalty: number | null;
|
|
92
|
-
frequencyPenalty: number | null;
|
|
93
|
-
logitBias: object | null;
|
|
94
|
-
user: string;
|
|
95
|
-
};
|
|
96
|
-
}
|