llm-exe 0.0.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/dist/embedding/base.d.ts +8 -0
- package/dist/embedding/base.js +43 -0
- package/dist/embedding/base.js.map +1 -0
- package/dist/embedding/openai.d.ts +11 -0
- package/dist/embedding/openai.js +72 -0
- package/dist/embedding/openai.js.map +1 -0
- package/dist/executor/_base.d.ts +54 -0
- package/dist/executor/_base.js +173 -0
- package/dist/executor/_base.js.map +1 -0
- package/dist/executor/_functions.d.ts +25 -0
- package/dist/executor/_functions.js +30 -0
- package/dist/executor/_functions.js.map +1 -0
- package/dist/executor/_metadata.d.ts +8 -0
- package/dist/executor/_metadata.js +69 -0
- package/dist/executor/_metadata.js.map +1 -0
- package/dist/executor/core.d.ts +10 -0
- package/dist/executor/core.js +28 -0
- package/dist/executor/core.js.map +1 -0
- package/dist/executor/index.d.ts +4 -0
- package/dist/executor/index.js +13 -0
- package/dist/executor/index.js.map +1 -0
- package/dist/executor/llm.d.ts +29 -0
- package/dist/executor/llm.js +73 -0
- package/dist/executor/llm.js.map +1 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +88 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/chat.d.ts +19 -0
- package/dist/interfaces/chat.js +3 -0
- package/dist/interfaces/chat.js.map +1 -0
- package/dist/interfaces/functions.d.ts +72 -0
- package/dist/interfaces/functions.js +3 -0
- package/dist/interfaces/functions.js.map +1 -0
- package/dist/interfaces/index.d.ts +6 -0
- package/dist/interfaces/index.js +23 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/openai.d.ts +33 -0
- package/dist/interfaces/openai.js +3 -0
- package/dist/interfaces/openai.js.map +1 -0
- package/dist/interfaces/parser.d.ts +11 -0
- package/dist/interfaces/parser.js +3 -0
- package/dist/interfaces/parser.js.map +1 -0
- package/dist/interfaces/prompt.d.ts +20 -0
- package/dist/interfaces/prompt.js +3 -0
- package/dist/interfaces/prompt.js.map +1 -0
- package/dist/interfaces/utils.d.ts +15 -0
- package/dist/interfaces/utils.js +3 -0
- package/dist/interfaces/utils.js.map +1 -0
- package/dist/llm/_base.d.ts +78 -0
- package/dist/llm/_base.js +164 -0
- package/dist/llm/_base.js.map +1 -0
- package/dist/llm/index.d.ts +2 -0
- package/dist/llm/index.js +9 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/openai.d.ts +95 -0
- package/dist/llm/openai.js +274 -0
- package/dist/llm/openai.js.map +1 -0
- package/dist/llm/output/base.d.ts +12 -0
- package/dist/llm/output/base.js +45 -0
- package/dist/llm/output/base.js.map +1 -0
- package/dist/llm/output/index.d.ts +9 -0
- package/dist/llm/output/index.js +29 -0
- package/dist/llm/output/index.js.map +1 -0
- package/dist/llm/output/openai-chat.d.ts +13 -0
- package/dist/llm/output/openai-chat.js +51 -0
- package/dist/llm/output/openai-chat.js.map +1 -0
- package/dist/parser/_base.d.ts +33 -0
- package/dist/parser/_base.js +64 -0
- package/dist/parser/_base.js.map +1 -0
- package/dist/parser/_functions.d.ts +94 -0
- package/dist/parser/_functions.js +52 -0
- package/dist/parser/_functions.js.map +1 -0
- package/dist/parser/index.d.ts +14 -0
- package/dist/parser/index.js +31 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/parsers/BooleanParser.d.ts +8 -0
- package/dist/parser/parsers/BooleanParser.js +20 -0
- package/dist/parser/parsers/BooleanParser.js.map +1 -0
- package/dist/parser/parsers/CustomParser.d.ts +27 -0
- package/dist/parser/parsers/CustomParser.js +41 -0
- package/dist/parser/parsers/CustomParser.js.map +1 -0
- package/dist/parser/parsers/JsonParser.d.ts +7 -0
- package/dist/parser/parsers/JsonParser.js +15 -0
- package/dist/parser/parsers/JsonParser.js.map +1 -0
- package/dist/parser/parsers/ListToArrayParser.d.ts +5 -0
- package/dist/parser/parsers/ListToArrayParser.js +17 -0
- package/dist/parser/parsers/ListToArrayParser.js.map +1 -0
- package/dist/parser/parsers/ListToJsonParser.d.ts +7 -0
- package/dist/parser/parsers/ListToJsonParser.js +25 -0
- package/dist/parser/parsers/ListToJsonParser.js.map +1 -0
- package/dist/parser/parsers/ListToKeyValueParser.d.ts +14 -0
- package/dist/parser/parsers/ListToKeyValueParser.js +24 -0
- package/dist/parser/parsers/ListToKeyValueParser.js.map +1 -0
- package/dist/parser/parsers/MarkdownCodeBlock.d.ts +14 -0
- package/dist/parser/parsers/MarkdownCodeBlock.js +16 -0
- package/dist/parser/parsers/MarkdownCodeBlock.js.map +1 -0
- package/dist/parser/parsers/MarkdownCodeBlocks.d.ts +14 -0
- package/dist/parser/parsers/MarkdownCodeBlocks.js +25 -0
- package/dist/parser/parsers/MarkdownCodeBlocks.js.map +1 -0
- package/dist/parser/parsers/NumberParser.d.ts +8 -0
- package/dist/parser/parsers/NumberParser.js +16 -0
- package/dist/parser/parsers/NumberParser.js.map +1 -0
- package/dist/parser/parsers/ReplaceStringTemplateParser.d.ts +8 -0
- package/dist/parser/parsers/ReplaceStringTemplateParser.js +15 -0
- package/dist/parser/parsers/ReplaceStringTemplateParser.js.map +1 -0
- package/dist/parser/parsers/StringParser.d.ts +8 -0
- package/dist/parser/parsers/StringParser.js +17 -0
- package/dist/parser/parsers/StringParser.js.map +1 -0
- package/dist/plugins/callable/callable.d.ts +72 -0
- package/dist/plugins/callable/callable.js +107 -0
- package/dist/plugins/callable/callable.js.map +1 -0
- package/dist/plugins/callable/index.d.ts +26 -0
- package/dist/plugins/callable/index.js +28 -0
- package/dist/plugins/callable/index.js.map +1 -0
- package/dist/prompt/_base.d.ts +56 -0
- package/dist/prompt/_base.js +139 -0
- package/dist/prompt/_base.js.map +1 -0
- package/dist/prompt/_functions.d.ts +19 -0
- package/dist/prompt/_functions.js +24 -0
- package/dist/prompt/_functions.js.map +1 -0
- package/dist/prompt/chat.d.ts +68 -0
- package/dist/prompt/chat.js +136 -0
- package/dist/prompt/chat.js.map +1 -0
- package/dist/prompt/index.d.ts +4 -0
- package/dist/prompt/index.js +13 -0
- package/dist/prompt/index.js.map +1 -0
- package/dist/prompt/text.d.ts +9 -0
- package/dist/prompt/text.js +16 -0
- package/dist/prompt/text.js.map +1 -0
- package/dist/state/_base.d.ts +29 -0
- package/dist/state/_base.js +92 -0
- package/dist/state/_base.js.map +1 -0
- package/dist/state/_functions.d.ts +6 -0
- package/dist/state/_functions.js +19 -0
- package/dist/state/_functions.js.map +1 -0
- package/dist/state/dialogue.d.ts +17 -0
- package/dist/state/dialogue.js +66 -0
- package/dist/state/dialogue.js.map +1 -0
- package/dist/state/index.d.ts +4 -0
- package/dist/state/index.js +16 -0
- package/dist/state/index.js.map +1 -0
- package/dist/state/item.d.ts +23 -0
- package/dist/state/item.js +64 -0
- package/dist/state/item.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +18 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +18 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/modules/asyncCallWithTimeout.d.ts +1 -0
- package/dist/utils/modules/asyncCallWithTimeout.js +17 -0
- package/dist/utils/modules/asyncCallWithTimeout.js.map +1 -0
- package/dist/utils/modules/handlebars/helpers/index.d.ts +7 -0
- package/dist/utils/modules/handlebars/helpers/index.js +71 -0
- package/dist/utils/modules/handlebars/helpers/index.js.map +1 -0
- package/dist/utils/modules/handlebars/index.d.ts +2 -0
- package/dist/utils/modules/handlebars/index.js +105 -0
- package/dist/utils/modules/handlebars/index.js.map +1 -0
- package/dist/utils/modules/handlebars/templates/index.d.ts +9 -0
- package/dist/utils/modules/handlebars/templates/index.js +34 -0
- package/dist/utils/modules/handlebars/templates/index.js.map +1 -0
- package/dist/utils/modules/index.d.ts +42 -0
- package/dist/utils/modules/index.js +133 -0
- package/dist/utils/modules/index.js.map +1 -0
- package/dist/utils/modules/json-schema-filter.d.ts +1 -0
- package/dist/utils/modules/json-schema-filter.js +69 -0
- package/dist/utils/modules/json-schema-filter.js.map +1 -0
- package/dist/utils/modules/json.d.ts +3 -0
- package/dist/utils/modules/json.js +57 -0
- package/dist/utils/modules/json.js.map +1 -0
- package/dist/utils/modules/replaceTemplateString.d.ts +2 -0
- package/dist/utils/modules/replaceTemplateString.js +21 -0
- package/dist/utils/modules/replaceTemplateString.js.map +1 -0
- package/dist/vector/base.d.ts +11 -0
- package/dist/vector/base.js +23 -0
- package/dist/vector/base.js.map +1 -0
- package/dist/vector/index.d.ts +2 -0
- package/dist/vector/index.js +8 -0
- package/dist/vector/index.js.map +1 -0
- package/dist/vector/pinecone.d.ts +6 -0
- package/dist/vector/pinecone.js +22 -0
- package/dist/vector/pinecone.js.map +1 -0
- package/package.json +67 -0
- package/readme.md +12 -0
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
/**
|
|
73
|
+
* An object to store metrics related to the LLM calls.
|
|
74
|
+
*/
|
|
75
|
+
Object.defineProperty(this, "metrics", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
configurable: true,
|
|
78
|
+
writable: true,
|
|
79
|
+
value: {
|
|
80
|
+
total_calls: 0,
|
|
81
|
+
total_call_success: 0,
|
|
82
|
+
total_call_retry: 0,
|
|
83
|
+
total_call_error: 0,
|
|
84
|
+
history: [],
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
this.client = null;
|
|
88
|
+
this.promptType = options?.promptType || "text";
|
|
89
|
+
this.timeout = options.timeout || 30000;
|
|
90
|
+
this.jitter = options.jitter || "none";
|
|
91
|
+
this.maxDelay = options.maxDelay || 5000;
|
|
92
|
+
this.numOfAttempts = options.numOfAttempts || 5;
|
|
93
|
+
}
|
|
94
|
+
getPromptType() {
|
|
95
|
+
return this.promptType;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* getMetrics returns the metrics object for the LLM.
|
|
99
|
+
*/
|
|
100
|
+
getMetrics() {
|
|
101
|
+
return { ...this.metrics };
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* getMetadata - Used to return metrics and data about executions.
|
|
105
|
+
*/
|
|
106
|
+
getMetadata() {
|
|
107
|
+
return {
|
|
108
|
+
promptType: this.promptType,
|
|
109
|
+
timeout: this.timeout,
|
|
110
|
+
jitter: this.jitter,
|
|
111
|
+
maxDelay: this.maxDelay,
|
|
112
|
+
numOfAttempts: this.numOfAttempts,
|
|
113
|
+
metrics: this.getMetrics(),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* call makes a call to the specific LLM with input and returns the output.
|
|
118
|
+
* It also handles retries and updates the metrics.
|
|
119
|
+
* @param _input - The input to the LLM.
|
|
120
|
+
* @return The output from the LLM.
|
|
121
|
+
*/
|
|
122
|
+
async call(_input, attributes) {
|
|
123
|
+
const called = await this._callWithRetry(_input, attributes);
|
|
124
|
+
return called;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* _callWithRetry is a private method that handles retries and timeouts for the LLM call.
|
|
128
|
+
* @param _input - The input to the LLM.
|
|
129
|
+
* @return The result of the LLM call.
|
|
130
|
+
* @throws An error if the maximum number of retries is reached.
|
|
131
|
+
*/
|
|
132
|
+
async _callWithRetry(_input, attributes) {
|
|
133
|
+
try {
|
|
134
|
+
this.metrics.total_calls++;
|
|
135
|
+
const result = await (0, exponential_backoff_1.backOff)(() => (0, utils_1.asyncCallWithTimeout)(this._call(_input, attributes), this.timeout), {
|
|
136
|
+
startingDelay: 0,
|
|
137
|
+
maxDelay: this.maxDelay,
|
|
138
|
+
numOfAttempts: this.numOfAttempts,
|
|
139
|
+
jitter: this.jitter,
|
|
140
|
+
retry: () => {
|
|
141
|
+
this.metrics.total_call_retry++;
|
|
142
|
+
console.log(`Handler timeout after ${this.timeout}. Retrying...`);
|
|
143
|
+
return true;
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
this.metrics.total_call_success++;
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
this.metrics.total_call_error++;
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* _call is an abstract method that must be implemented by subclasses to make the actual LLM call.
|
|
156
|
+
* @param {any} _input - The input to the LLM.
|
|
157
|
+
* @return The output from the LLM.
|
|
158
|
+
*/
|
|
159
|
+
async _call(_input, _attributes) {
|
|
160
|
+
return new output_1.OutputDefault(undefined);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.BaseLlm = BaseLlm;
|
|
164
|
+
//# sourceMappingURL=_base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;IA0C3B;;;OAGG;IACH,YAAY,OAAuB;QA7CnC;;WAEG;QACH;;;;;WAAoB;QAEpB;;WAEG;QACH;;;;;WAAiC;QAEjC;;WAEG;QACH;;;;;WAA0B;QAE1B;;WAEG;QACH;;;;;WAA2B;QAE3B;;WAEG;QACH;;;;;WAAgC;QAEhC;;WAEG;QACH;;;;;WAAkC;QAElC;;WAEG;QACH;;;;mBAAyB;gBACvB,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OAAO,CAAC,WAAW,EAAE,CAAC;YAC3B,MAAM,MAAM,GAAG,MAAM,IAAA,6BAAO,EAC1B,GAAG,EAAE,CACH,IAAA,4BAAoB,EAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,EACpE;gBACE,aAAa,EAAE,CAAC;gBAChB,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,aAAa,EAAE,IAAI,CAAC,aAAa;gBACjC,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,KAAK,EAAE,GAAG,EAAE;oBACV,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;oBAChC,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,CAAC,OAAO,eAAe,CAAC,CAAC;oBAClE,OAAO,IAAI,CAAC;gBACd,CAAC;aACF,CACF,CAAC;YACF,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC;YAClC,OAAO,MAAM,CAAC;SACf;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAChC,MAAM,KAAK,CAAC;SACb;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK,CACT,MAAW,EACX,WAAiC;QAEjC,OAAO,IAAI,sBAAa,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;CACF;AAzID,0BAyIC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { OpenAIApi } from "openai";
|
|
2
|
+
import { OpenAIModelName, OpenAIOptions } from "../types";
|
|
3
|
+
import { BaseLlm } from "./_base";
|
|
4
|
+
import { OutputOpenAIChat } from "../llm/output";
|
|
5
|
+
import { OutputOpenAICompletion } from "./output/openai-chat";
|
|
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: any): 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: any[]): 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
|
+
promptType: import("../types").PromptType;
|
|
77
|
+
timeout: number;
|
|
78
|
+
jitter: "none" | "full";
|
|
79
|
+
maxDelay: number;
|
|
80
|
+
numOfAttempts: number;
|
|
81
|
+
metrics: any;
|
|
82
|
+
} & {
|
|
83
|
+
model: OpenAIModelName;
|
|
84
|
+
temperature: number;
|
|
85
|
+
max_tokens: number;
|
|
86
|
+
topP: number | null;
|
|
87
|
+
n: number | null;
|
|
88
|
+
stream: boolean | null;
|
|
89
|
+
stop: any;
|
|
90
|
+
presencePenalty: number | null;
|
|
91
|
+
frequencyPenalty: number | null;
|
|
92
|
+
logitBias: object | null;
|
|
93
|
+
user: string;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenAI = exports.createLlmOpenAi = void 0;
|
|
4
|
+
const openai_1 = require("openai");
|
|
5
|
+
const _base_1 = require("./_base");
|
|
6
|
+
const output_1 = require("../llm/output");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const openai_chat_1 = require("./output/openai-chat");
|
|
9
|
+
/**
|
|
10
|
+
* Create a new instance of the OpenAI API wrapper.
|
|
11
|
+
* @param options - Configuration options for the OpenAI API wrapper.
|
|
12
|
+
* @returns - A new instance of the OpenAI API wrapper class.
|
|
13
|
+
*/
|
|
14
|
+
function createLlmOpenAi(options) {
|
|
15
|
+
return new OpenAI(options);
|
|
16
|
+
}
|
|
17
|
+
exports.createLlmOpenAi = createLlmOpenAi;
|
|
18
|
+
/**
|
|
19
|
+
* A class that extends BaseLlm and provides functionality for the OpenAI API.
|
|
20
|
+
*/
|
|
21
|
+
class OpenAI extends _base_1.BaseLlm {
|
|
22
|
+
/**
|
|
23
|
+
* Constructor for the OpenAI class.
|
|
24
|
+
* @param {OpenAIOptions} options - Configuration options for the OpenAI API wrapper.
|
|
25
|
+
*/
|
|
26
|
+
constructor(options) {
|
|
27
|
+
const { openAIApiKey, modelName, temperature, maxTokens, topP = null, n = null, stream = null, stop, presencePenalty = null, frequencyPenalty = null, logitBias = null, user = "", ...restOfOptions } = options;
|
|
28
|
+
super(restOfOptions);
|
|
29
|
+
Object.defineProperty(this, "model", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: void 0
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(this, "temperature", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: void 0
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(this, "maxTokens", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true,
|
|
45
|
+
value: void 0
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(this, "topP", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: void 0
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(this, "n", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: null
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(this, "stream", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true,
|
|
63
|
+
value: void 0
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(this, "stop", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: null
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(this, "presencePenalty", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
configurable: true,
|
|
74
|
+
writable: true,
|
|
75
|
+
value: void 0
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(this, "frequencyPenalty", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true,
|
|
81
|
+
value: void 0
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(this, "logitBias", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
configurable: true,
|
|
86
|
+
writable: true,
|
|
87
|
+
value: void 0
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(this, "user", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
configurable: true,
|
|
92
|
+
writable: true,
|
|
93
|
+
value: void 0
|
|
94
|
+
});
|
|
95
|
+
this.model = modelName || "gpt-3.5-turbo";
|
|
96
|
+
this.temperature = temperature || 0;
|
|
97
|
+
this.maxTokens = maxTokens || 500;
|
|
98
|
+
this.topP = topP;
|
|
99
|
+
this.n = n;
|
|
100
|
+
this.stream = stream;
|
|
101
|
+
this.stop = stop;
|
|
102
|
+
this.presencePenalty = presencePenalty;
|
|
103
|
+
this.frequencyPenalty = frequencyPenalty;
|
|
104
|
+
this.logitBias = logitBias;
|
|
105
|
+
this.user = user;
|
|
106
|
+
if (["gpt-3.5-turbo", "gpt-4"].includes(this.model)) {
|
|
107
|
+
this.promptType = "chat";
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
this.promptType = "text";
|
|
111
|
+
}
|
|
112
|
+
this.client = new openai_1.OpenAIApi(new openai_1.Configuration({
|
|
113
|
+
apiKey: openAIApiKey,
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get the total prompt and completion tokens across all calls to the API.
|
|
118
|
+
* @returns - An object with total prompt and completion tokens.
|
|
119
|
+
*/
|
|
120
|
+
getMetrics() {
|
|
121
|
+
let total_completionTokens = 0;
|
|
122
|
+
let total_promptTokens = 0;
|
|
123
|
+
let total_totalTokens = 0;
|
|
124
|
+
for (const item of this.metrics.history) {
|
|
125
|
+
const { completion_tokens = 0, prompt_tokens = 0, total_tokens = 0, } = item.usage;
|
|
126
|
+
total_completionTokens = total_completionTokens + completion_tokens;
|
|
127
|
+
total_promptTokens = total_promptTokens + prompt_tokens;
|
|
128
|
+
total_totalTokens = total_totalTokens + total_tokens;
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
total_completionTokens,
|
|
132
|
+
total_promptTokens,
|
|
133
|
+
total_totalTokens,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Calculate the API call cost based on input and output tokens.
|
|
138
|
+
* @param input_tokens - The number of input tokens.
|
|
139
|
+
* @param output_tokens=0 - The number of output tokens (defaults to 0).
|
|
140
|
+
* @returns An object for input/output tokens and cost.
|
|
141
|
+
*/
|
|
142
|
+
calculatePrice(input_tokens, output_tokens = 0) {
|
|
143
|
+
const cost = {
|
|
144
|
+
"gpt-3.5-turbo": [1000, 0.002, 0.002],
|
|
145
|
+
"gpt-4": [1000, 0.03, 0.06],
|
|
146
|
+
davinci: [1000, 0.02, 0.02],
|
|
147
|
+
"text-curie-001": [1000, 0.002, 0.002],
|
|
148
|
+
"text-babbage-001": [1000, 0.0005, 0.0005],
|
|
149
|
+
"text-ada-001": [1000, 0.0004, 0.0004],
|
|
150
|
+
"text-embedding-ada-002": [1000, 0.0004, 0.0004],
|
|
151
|
+
};
|
|
152
|
+
const out = {
|
|
153
|
+
input_cost: 0,
|
|
154
|
+
output_cost: 0,
|
|
155
|
+
total_cost: 0,
|
|
156
|
+
};
|
|
157
|
+
const price = cost[this.model];
|
|
158
|
+
/* istanbul ignore next */
|
|
159
|
+
if (price) {
|
|
160
|
+
const [amount, inputAmount, outputAmount] = price;
|
|
161
|
+
if (inputAmount && input_tokens) {
|
|
162
|
+
out["input_cost"] = (input_tokens / amount) * inputAmount;
|
|
163
|
+
}
|
|
164
|
+
if (outputAmount && output_tokens) {
|
|
165
|
+
out["output_cost"] = (output_tokens / amount) * outputAmount;
|
|
166
|
+
}
|
|
167
|
+
out["total_cost"] = out["input_cost"] + out["output_cost"];
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Log a table containing usage metrics for the OpenAI API.
|
|
173
|
+
*/
|
|
174
|
+
logMetrics() {
|
|
175
|
+
const metrics = this.getMetrics();
|
|
176
|
+
const { total_completionTokens = 0, total_promptTokens = 0, total_totalTokens = 0, } = metrics;
|
|
177
|
+
const cost = this.calculatePrice(total_promptTokens, total_completionTokens);
|
|
178
|
+
console.table([
|
|
179
|
+
{
|
|
180
|
+
["Total Calls"]: this.metrics.total_call_success,
|
|
181
|
+
["Total Completion Tokens"]: total_completionTokens,
|
|
182
|
+
["Total Completion Cost"]: cost.output_cost,
|
|
183
|
+
["Total Prompt Tokens"]: total_promptTokens,
|
|
184
|
+
["Total Prompt Cost"]: cost.input_cost,
|
|
185
|
+
["Total Tokens"]: total_totalTokens,
|
|
186
|
+
["Total Cost"]: cost.total_cost,
|
|
187
|
+
},
|
|
188
|
+
]);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Wrapper function to call chat/completion with the specified input.
|
|
192
|
+
* @private
|
|
193
|
+
* @param input - The input for the chat/completion API.
|
|
194
|
+
* @returns The chat/completion response from the API.
|
|
195
|
+
*/
|
|
196
|
+
async _call(input) {
|
|
197
|
+
console.log("???", this.model);
|
|
198
|
+
if (["gpt-3.5-turbo", "gpt-4"].includes(this.model)) {
|
|
199
|
+
return await this.chat(input);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
return await this.completion(input);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Communicate with the OpenAI Chat API.
|
|
207
|
+
* @param messages - A list of message objects for the API call.
|
|
208
|
+
* @returns The chat response from the API.
|
|
209
|
+
*/
|
|
210
|
+
async chat(messages) {
|
|
211
|
+
(0, utils_1.assert)(Array.isArray(messages), "Invalid prompt.");
|
|
212
|
+
const options = (0, utils_1.removeEmptyFromObject)({
|
|
213
|
+
messages,
|
|
214
|
+
model: this.model,
|
|
215
|
+
temperature: this.temperature,
|
|
216
|
+
max_tokens: this.maxTokens,
|
|
217
|
+
topP: this.topP,
|
|
218
|
+
n: this.n,
|
|
219
|
+
stream: this.stream,
|
|
220
|
+
stop: this.stop,
|
|
221
|
+
presencePenalty: this.presencePenalty,
|
|
222
|
+
frequencyPenalty: this.frequencyPenalty,
|
|
223
|
+
logitBias: this.logitBias,
|
|
224
|
+
user: this.user,
|
|
225
|
+
});
|
|
226
|
+
const response = await this.client.createChatCompletion(options);
|
|
227
|
+
const { data } = response;
|
|
228
|
+
this.metrics.history.push(data);
|
|
229
|
+
return new output_1.OutputOpenAIChat(data);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Communicate with the OpenAI Completion API.
|
|
233
|
+
* @param messages - A list of message objects for the API call.
|
|
234
|
+
* @returns The chat response from the API.
|
|
235
|
+
*/
|
|
236
|
+
async completion(prompt) {
|
|
237
|
+
(0, utils_1.assert)(typeof prompt === "string" && prompt !== "", "Missing prompt.");
|
|
238
|
+
const options = (0, utils_1.removeEmptyFromObject)({
|
|
239
|
+
prompt,
|
|
240
|
+
model: this.model,
|
|
241
|
+
temperature: this.temperature,
|
|
242
|
+
max_tokens: this.maxTokens,
|
|
243
|
+
topP: this.topP,
|
|
244
|
+
n: this.n,
|
|
245
|
+
stream: this.stream,
|
|
246
|
+
stop: this.stop,
|
|
247
|
+
presencePenalty: this.presencePenalty,
|
|
248
|
+
frequencyPenalty: this.frequencyPenalty,
|
|
249
|
+
logitBias: this.logitBias,
|
|
250
|
+
user: this.user,
|
|
251
|
+
});
|
|
252
|
+
const response = await this.client.createCompletion(options);
|
|
253
|
+
const { data } = response;
|
|
254
|
+
this.metrics.history.push(data);
|
|
255
|
+
return new openai_chat_1.OutputOpenAICompletion(data);
|
|
256
|
+
}
|
|
257
|
+
getMetadata() {
|
|
258
|
+
return Object.assign({}, super.getMetadata(), (0, utils_1.removeEmptyFromObject)({
|
|
259
|
+
model: this.model,
|
|
260
|
+
temperature: this.temperature,
|
|
261
|
+
max_tokens: this.maxTokens,
|
|
262
|
+
topP: this.topP,
|
|
263
|
+
n: this.n,
|
|
264
|
+
stream: this.stream,
|
|
265
|
+
stop: this.stop,
|
|
266
|
+
presencePenalty: this.presencePenalty,
|
|
267
|
+
frequencyPenalty: this.frequencyPenalty,
|
|
268
|
+
logitBias: this.logitBias,
|
|
269
|
+
user: this.user,
|
|
270
|
+
}));
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
exports.OpenAI = OpenAI;
|
|
274
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"src/","sources":["llm/openai.ts"],"names":[],"mappings":";;;AAAA,mCAAkD;AAElD,mCAAkC;AAClC,yCAAgD;AAChD,mCAAwD;AACxD,sDAA8D;AAE9D;;;;GAIG;AACH,SAAgB,eAAe,CAAC,OAAsB;IACpD,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC;AAFD,0CAEC;AAED;;GAEG;AACH,MAAa,MAAO,SAAQ,eAAkB;IAa5C;;;OAGG;IACH,YAAY,OAAsB;QAChC,MAAM,EACJ,YAAY,EACZ,SAAS,EACT,WAAW,EACX,SAAS,EACT,IAAI,GAAG,IAAI,EACX,CAAC,GAAG,IAAI,EACR,MAAM,GAAG,IAAI,EACb,IAAI,EACJ,eAAe,GAAG,IAAI,EACtB,gBAAgB,GAAG,IAAI,EACvB,SAAS,GAAG,IAAI,EAChB,IAAI,GAAG,EAAE,EACT,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;QAE/B,KAAK,CAAC,aAAa,CAAC,CAAC;QAhCvB;;;;;WAA+B;QAC/B;;;;;WAA4B;QAC5B;;;;;WAA0B;QAC1B;;;;;WAA4B;QAC5B;;;;mBAA2B,IAAI;WAAC;QAChC;;;;;WAA+B;QAC/B;;;;mBAAoB,IAAI;WAAC;QACzB;;;;;WAAuC;QACvC;;;;;WAAwC;QACxC;;;;;WAAiC;QACjC;;;;;WAAqB;QAwBnB,IAAI,CAAC,KAAK,GAAG,SAAS,IAAI,eAAe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AC,IAAI;YACf,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAE7D,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChC,OAAO,IAAI,oCAAsB,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,WAAW;QACT,OAAO,MAAM,CAAC,MAAM,CAClB,EAAE,EACF,KAAK,CAAC,WAAW,EAAE,EACnB,IAAA,6BAAqB,EAAC;YACpB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,UAAU,EAAE,IAAI,CAAC,SAAS;YAC1B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,CAAC,EAAE,IAAI,CAAC,CAAC;YACT,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CACH,CAAC;IACJ,CAAC;CACF;AArPD,wBAqPC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare abstract class BaseLlmOutput {
|
|
2
|
+
protected id: string;
|
|
3
|
+
protected name: string | undefined;
|
|
4
|
+
protected created: number | undefined;
|
|
5
|
+
protected results: any[];
|
|
6
|
+
protected usage: any;
|
|
7
|
+
constructor(result: any);
|
|
8
|
+
getResults(): any[];
|
|
9
|
+
abstract setResult(result: any): void;
|
|
10
|
+
abstract getResult(resultIndex: number): any;
|
|
11
|
+
abstract getResultContent(resultIndex?: number): any;
|
|
12
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseLlmOutput = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
class BaseLlmOutput {
|
|
6
|
+
constructor(result) {
|
|
7
|
+
Object.defineProperty(this, "id", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: void 0
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(this, "name", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: void 0
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "created", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "results", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: []
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(this, "usage", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: {}
|
|
36
|
+
});
|
|
37
|
+
this.id = (0, utils_1.uuid)();
|
|
38
|
+
this.setResult(result);
|
|
39
|
+
}
|
|
40
|
+
getResults() {
|
|
41
|
+
return [...this.results];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.BaseLlmOutput = BaseLlmOutput;
|
|
45
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"src/","sources":["llm/output/base.ts"],"names":[],"mappings":";;;AAAA,mCAA+B;AAE/B,MAAsB,aAAa;IAQjC,YAAY,MAAW;QAPvB;;;;;WAAqB;QACrB;;;;;WAAmC;QACnC;;;;;WAAsC;QACtC;;;;mBAA2B,EAAE;WAAC;QAE9B;;;;mBAAuB,EAAE;WAAC;QAGxB,IAAI,CAAC,EAAE,GAAG,IAAA,YAAI,GAAE,CAAC;QACjB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;IAED,UAAU;QACR,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;CAIF;AAnBD,sCAmBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseLlmOutput } from "./base";
|
|
2
|
+
export { BaseLlmOutput };
|
|
3
|
+
export { OutputOpenAIChat } from "./openai-chat";
|
|
4
|
+
export declare class OutputDefault extends BaseLlmOutput {
|
|
5
|
+
constructor(result: any);
|
|
6
|
+
setResult(result: any): void;
|
|
7
|
+
getResult(): any;
|
|
8
|
+
getResultContent(): any;
|
|
9
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OutputDefault = exports.OutputOpenAIChat = exports.BaseLlmOutput = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const base_1 = require("./base");
|
|
6
|
+
Object.defineProperty(exports, "BaseLlmOutput", { enumerable: true, get: function () { return base_1.BaseLlmOutput; } });
|
|
7
|
+
var openai_chat_1 = require("./openai-chat");
|
|
8
|
+
Object.defineProperty(exports, "OutputOpenAIChat", { enumerable: true, get: function () { return openai_chat_1.OutputOpenAIChat; } });
|
|
9
|
+
class OutputDefault extends base_1.BaseLlmOutput {
|
|
10
|
+
constructor(result) {
|
|
11
|
+
super(result);
|
|
12
|
+
}
|
|
13
|
+
setResult(result) {
|
|
14
|
+
this.id = `fn-${(0, utils_1.uuid)()}`;
|
|
15
|
+
this.name = `none`;
|
|
16
|
+
this.created = new Date().getTime();
|
|
17
|
+
this.usage = {};
|
|
18
|
+
this.results = [result];
|
|
19
|
+
}
|
|
20
|
+
getResult() {
|
|
21
|
+
const [result] = this.results;
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
getResultContent() {
|
|
25
|
+
return this.getResult();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.OutputDefault = OutputDefault;
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["llm/output/index.ts"],"names":[],"mappings":";;;AAAA,mCAA+B;AAC/B,iCAAuC;AAE9B,8FAFA,oBAAa,OAEA;AACtB,6CAAiD;AAAxC,+GAAA,gBAAgB,OAAA;AAEzB,MAAa,aAAc,SAAQ,oBAAa;IAC9C,YAAY,MAAW;QACrB,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED,SAAS,CAAC,MAAW;QACnB,IAAI,CAAC,EAAE,GAAG,MAAM,IAAA,YAAI,GAAE,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED,SAAS;QACP,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;QAC9B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;IAC1B,CAAC;CACF;AArBD,sCAqBC"}
|