@rws-framework/ai-tools 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/.bin/add-v.sh +10 -0
- package/.bin/emerge.sh +11 -0
- package/.emerge-vis-output/rws-server/emerge-file_result_dependency_graph.graphml +2067 -0
- package/.emerge-vis-output/rws-server/emerge-filesystem_graph.graphml +1505 -0
- package/.emerge-vis-output/rws-server/emerge-statistics-and-metrics.json +1 -0
- package/.emerge-vis-output/rws-server/emerge-statistics-metrics.txt +1147 -0
- package/.emerge-vis-output/rws-server/html/emerge.html +501 -0
- package/.emerge-vis-output/rws-server/html/jsconfig.json +9 -0
- package/.emerge-vis-output/rws-server/html/resources/css/custom.css +211 -0
- package/.emerge-vis-output/rws-server/html/resources/js/emerge_common.js +45 -0
- package/.emerge-vis-output/rws-server/html/resources/js/emerge_data.js +13 -0
- package/.emerge-vis-output/rws-server/html/resources/js/emerge_git.js +1414 -0
- package/.emerge-vis-output/rws-server/html/resources/js/emerge_graph.js +539 -0
- package/.emerge-vis-output/rws-server/html/resources/js/emerge_heatmap.js +220 -0
- package/.emerge-vis-output/rws-server/html/resources/js/emerge_hull.js +180 -0
- package/.emerge-vis-output/rws-server/html/resources/js/emerge_main.js +1003 -0
- package/.emerge-vis-output/rws-server/html/resources/js/emerge_search.js +71 -0
- package/.emerge-vis-output/rws-server/html/resources/js/emerge_ui.js +199 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-grid.css +4124 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-grid.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-grid.min.css +7 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-grid.min.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-grid.rtl.css +4123 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-grid.rtl.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-grid.rtl.min.css +7 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-grid.rtl.min.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-reboot.css +488 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-reboot.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-reboot.min.css +7 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-reboot.min.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-reboot.rtl.css +485 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-reboot.rtl.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-reboot.rtl.min.css +7 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-reboot.rtl.min.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-utilities.css +4266 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-utilities.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-utilities.min.css +7 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-utilities.min.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-utilities.rtl.css +4257 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-utilities.rtl.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-utilities.rtl.min.css +7 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap-utilities.rtl.min.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap.css +10878 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap.min.css +7 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap.min.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap.rtl.css +10842 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap.rtl.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap.rtl.min.css +7 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/css/bootstrap.rtl.min.css.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/js/bootstrap.bundle.js +7075 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/js/bootstrap.bundle.js.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/js/bootstrap.bundle.min.js +7 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/js/bootstrap.bundle.min.js.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/js/bootstrap.esm.js +5202 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/js/bootstrap.esm.js.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/js/bootstrap.esm.min.js +7 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/js/bootstrap.esm.min.js.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/js/bootstrap.js +5249 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/js/bootstrap.js.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/js/bootstrap.min.js +7 -0
- package/.emerge-vis-output/rws-server/html/vendors/bootstrap/js/bootstrap.min.js.map +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/d3/d3.v7.8.4.min.js +2 -0
- package/.emerge-vis-output/rws-server/html/vendors/d3/d3.v7.min.js +2 -0
- package/.emerge-vis-output/rws-server/html/vendors/dark-mode-switch/css/dark-mode.css +148 -0
- package/.emerge-vis-output/rws-server/html/vendors/dark-mode-switch/js/dark-mode-switch.min.js +1 -0
- package/.emerge-vis-output/rws-server/html/vendors/daterangepicker/daterangepicker.css +410 -0
- package/.emerge-vis-output/rws-server/html/vendors/daterangepicker/daterangepicker.min.js +8 -0
- package/.emerge-vis-output/rws-server/html/vendors/daterangepicker/moment.min.js +7 -0
- package/.emerge-vis-output/rws-server/html/vendors/hull/hull.js +373 -0
- package/.emerge-vis-output/rws-server/html/vendors/jquery/jquery-3.6.0.min.js +2 -0
- package/.emerge-vis-output/rws-server/html/vendors/popper/popper.min.js +6 -0
- package/.emerge-vis-output/rws-server/html/vendors/simpleheat/simpleheat.js +141 -0
- package/.eslintrc.json +53 -0
- package/README.md +862 -0
- package/package.json +49 -0
- package/src/index.ts +22 -0
- package/src/models/convo/ConvoLoader.ts +415 -0
- package/src/models/convo/VectorStore.ts +33 -0
- package/src/models/prompts/_prompt.ts +388 -0
- package/src/services/VectorStoreService.ts +15 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
import { PromptTemplate } from '@langchain/core/prompts';
|
|
3
|
+
import ConvoLoader, { IChainCallOutput } from '../convo/ConvoLoader';
|
|
4
|
+
import { BedrockChat } from '@langchain/community/chat_models/bedrock/web';
|
|
5
|
+
import { IterableReadableStream } from '@langchain/core/utils/stream';
|
|
6
|
+
import { ChainValues } from '@langchain/core/utils/types';
|
|
7
|
+
|
|
8
|
+
import { IContextToken } from '../../types/IContextToken';
|
|
9
|
+
|
|
10
|
+
interface IPromptHyperParameters {
|
|
11
|
+
temperature: number,
|
|
12
|
+
top_k?: number,
|
|
13
|
+
top_p?: number,
|
|
14
|
+
[key: string]: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface IRWSHistoryMessage {
|
|
18
|
+
content: string, creator: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface ILLMChunk {
|
|
22
|
+
content: string
|
|
23
|
+
status: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface IPromptParams {
|
|
27
|
+
hyperParameters?: IPromptHyperParameters;
|
|
28
|
+
input?: string;
|
|
29
|
+
modelId: string;
|
|
30
|
+
modelType: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface IPromptEnchantment {
|
|
34
|
+
enhancementId: string,
|
|
35
|
+
enhancementName: string,
|
|
36
|
+
enhancementParams: any,
|
|
37
|
+
input: string
|
|
38
|
+
output: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type IPromptSender = (prompt: RWSPrompt) => Promise<void>;
|
|
42
|
+
|
|
43
|
+
interface IRWSPromptRequestExecutor {
|
|
44
|
+
promptRequest: (prompt: RWSPrompt, contextToken?: IContextToken | null, intruderPrompt?: string | null, debugVars?: any) => Promise<RWSPrompt>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
interface IRWSSinglePromptRequestExecutor {
|
|
49
|
+
singlePromptRequest: (prompt: RWSPrompt, contextToken?: IContextToken | null, intruderPrompt?: string | null, ensureJson?: boolean, debugVars?: any) => Promise<RWSPrompt>
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
interface IRWSPromptStreamExecutor {
|
|
54
|
+
promptStream: (prompt: RWSPrompt, read: (chunk: ILLMChunk) => void, end: () => void, debugVars?: any) => Promise<RWSPrompt>
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface IRWSPromptJSON {
|
|
58
|
+
input: string;
|
|
59
|
+
enhancedInput: IPromptEnchantment[];
|
|
60
|
+
sentInput: string;
|
|
61
|
+
originalInput: string;
|
|
62
|
+
output: string;
|
|
63
|
+
modelId: string;
|
|
64
|
+
modelType: string;
|
|
65
|
+
multiTemplate: PromptTemplate;
|
|
66
|
+
convo: { id: string };
|
|
67
|
+
hyperParameters: IPromptHyperParameters;
|
|
68
|
+
created_at: string;
|
|
69
|
+
var_storage: any;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type ChainStreamType = AsyncGenerator<IterableReadableStream<ChainValues>>;
|
|
73
|
+
|
|
74
|
+
class RWSPrompt {
|
|
75
|
+
public _stream: ChainStreamType;
|
|
76
|
+
private input: string = '';
|
|
77
|
+
private enhancedInput: IPromptEnchantment[];
|
|
78
|
+
private sentInput: string = '';
|
|
79
|
+
private originalInput: string = '';
|
|
80
|
+
private output: string = '';
|
|
81
|
+
private modelId: string;
|
|
82
|
+
private modelType: string;
|
|
83
|
+
private multiTemplate: PromptTemplate;
|
|
84
|
+
private convo: ConvoLoader<any>;
|
|
85
|
+
private hyperParameters: IPromptHyperParameters;
|
|
86
|
+
private created_at: Date;
|
|
87
|
+
|
|
88
|
+
private varStorage: any = {};
|
|
89
|
+
|
|
90
|
+
private onStream = (chunk: string) => {
|
|
91
|
+
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
constructor(params: IPromptParams){
|
|
95
|
+
this.input = params.input;
|
|
96
|
+
this.originalInput = params.input;
|
|
97
|
+
this.hyperParameters = params.hyperParameters;
|
|
98
|
+
this.modelId = params.modelId;
|
|
99
|
+
this.modelType = params.modelType;
|
|
100
|
+
|
|
101
|
+
this.created_at = new Date();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
listen(source: string, stream: boolean = true): RWSPrompt
|
|
105
|
+
{
|
|
106
|
+
this.output = '';
|
|
107
|
+
|
|
108
|
+
if (!stream) {
|
|
109
|
+
this.output = source;
|
|
110
|
+
} else {
|
|
111
|
+
this.output += source;
|
|
112
|
+
this.onStream(source);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
setStreamCallback(callback: (chunk: string) => void): void
|
|
119
|
+
{
|
|
120
|
+
this.onStream = callback;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
addEnchantment(enchantment: IPromptEnchantment): void
|
|
124
|
+
{
|
|
125
|
+
this.enhancedInput.push(enchantment);
|
|
126
|
+
this.input = enchantment.input;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
getEnchantedInput(): string | null
|
|
130
|
+
{
|
|
131
|
+
return this.enhancedInput[this.enhancedInput.length - 1].output;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
getModelId(): string
|
|
135
|
+
{
|
|
136
|
+
return this.modelId;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
readSentInput(): string
|
|
140
|
+
{
|
|
141
|
+
return this.sentInput;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
readInput(): string
|
|
145
|
+
{
|
|
146
|
+
return this.input;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
readBaseInput(): string
|
|
151
|
+
{
|
|
152
|
+
return this.originalInput;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
setBaseInput(input: string): RWSPrompt
|
|
156
|
+
{
|
|
157
|
+
this.originalInput = input;
|
|
158
|
+
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
injestOutput(content: string): RWSPrompt
|
|
163
|
+
{
|
|
164
|
+
this.output = content;
|
|
165
|
+
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
readOutput(): string
|
|
170
|
+
{
|
|
171
|
+
return this.output;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
getHyperParameters<T extends IPromptHyperParameters>(base: any = null): T
|
|
175
|
+
{
|
|
176
|
+
if(base){
|
|
177
|
+
this.hyperParameters = {...base, ...this.hyperParameters};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return this.hyperParameters as T;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
getHyperParameter<T>(key: keyof IPromptHyperParameters): T
|
|
184
|
+
{
|
|
185
|
+
if(!this.hyperParameters[key]){
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return this.hyperParameters[key] as T;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
setHyperParameter(key: string, value: any): RWSPrompt
|
|
193
|
+
{
|
|
194
|
+
this.hyperParameters[key] = value;
|
|
195
|
+
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
setHyperParameters(value: any): RWSPrompt
|
|
200
|
+
{
|
|
201
|
+
this.hyperParameters = value;
|
|
202
|
+
|
|
203
|
+
return this;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
setMultiTemplate(template: PromptTemplate): RWSPrompt
|
|
207
|
+
{
|
|
208
|
+
this.multiTemplate = template;
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
getMultiTemplate(): PromptTemplate
|
|
213
|
+
{
|
|
214
|
+
return this.multiTemplate;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
setConvo(convo: ConvoLoader<BedrockChat>): RWSPrompt
|
|
218
|
+
{
|
|
219
|
+
this.convo = convo.setPrompt(this);
|
|
220
|
+
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
getConvo<T extends BedrockChat>(): ConvoLoader<T>
|
|
225
|
+
{
|
|
226
|
+
return this.convo;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
replacePromptVar(key: string, val: string)
|
|
230
|
+
{
|
|
231
|
+
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
getModelMetadata(): [string, string]
|
|
235
|
+
{
|
|
236
|
+
return [this.modelType, this.modelId];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async requestWith(executor: IRWSPromptRequestExecutor, intruderPrompt: string = null, debugVars: any = {}): Promise<void>
|
|
240
|
+
{
|
|
241
|
+
this.sentInput = this.input;
|
|
242
|
+
const returnedRWS = await executor.promptRequest(this, null, intruderPrompt, debugVars);
|
|
243
|
+
this.output = returnedRWS.readOutput();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async singleRequestWith(executor: IRWSSinglePromptRequestExecutor, intruderPrompt: string = null, ensureJson: boolean = false): Promise<void>
|
|
247
|
+
{
|
|
248
|
+
await executor.singlePromptRequest(this, null, intruderPrompt, ensureJson);
|
|
249
|
+
this.sentInput = this.input;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
async streamWith(executor: IRWSPromptStreamExecutor, read: (chunk: ILLMChunk) => void, end: () => void = () => {}, debugVars: any = {}): Promise<RWSPrompt>
|
|
253
|
+
{
|
|
254
|
+
this.sentInput = this.input;
|
|
255
|
+
return executor.promptStream(this, read, end, debugVars);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
setInput(content: string): RWSPrompt
|
|
259
|
+
{
|
|
260
|
+
this.input = content;
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
getVar<T>(key: string): T
|
|
265
|
+
{
|
|
266
|
+
return Object.keys(this.varStorage).includes(key) ? this.varStorage[key] : null;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
setVar<T>(key: string, val: T): RWSPrompt {
|
|
270
|
+
this.varStorage[key] = val;
|
|
271
|
+
|
|
272
|
+
return this;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async _oldreadStream(stream: Readable, react: (chunk: string) => void): Promise<void>
|
|
276
|
+
{
|
|
277
|
+
let first = true;
|
|
278
|
+
const chunks: string[] = []; // Replace 'any' with the actual type of your chunks
|
|
279
|
+
|
|
280
|
+
for await (const event of stream) {
|
|
281
|
+
// Assuming 'event' has a specific structure. Adjust according to actual event structure.
|
|
282
|
+
if ('chunk' in event && event.chunk.bytes) {
|
|
283
|
+
const chunk = JSON.parse(Buffer.from(event.chunk.bytes).toString('utf-8'));
|
|
284
|
+
if(first){
|
|
285
|
+
console.log('chunk', chunk);
|
|
286
|
+
first = false;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
react(chunk.completion);
|
|
290
|
+
|
|
291
|
+
chunks.push(chunk.completion || chunk.generation ); // Use the actual property of 'chunk' you're interested in
|
|
292
|
+
} else if (
|
|
293
|
+
'internalServerException' in event ||
|
|
294
|
+
'modelStreamErrorException' in event ||
|
|
295
|
+
'throttlingException' in event ||
|
|
296
|
+
'validationException' in event
|
|
297
|
+
) {
|
|
298
|
+
console.error(event);
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
private async isChainStreamType(source: any): Promise<boolean> {
|
|
305
|
+
if (source && typeof source[Symbol.asyncIterator] === 'function') {
|
|
306
|
+
const asyncIterator = source[Symbol.asyncIterator]();
|
|
307
|
+
if (typeof asyncIterator.next === 'function' &&
|
|
308
|
+
typeof asyncIterator.throw === 'function' &&
|
|
309
|
+
typeof asyncIterator.return === 'function') {
|
|
310
|
+
try {
|
|
311
|
+
// Optionally check if the next method yields a value of the expected type
|
|
312
|
+
const { value, done } = await asyncIterator.next();
|
|
313
|
+
return !done && value instanceof ReadableStream; // or whatever check makes sense for IterableReadableStream<ChainValues>
|
|
314
|
+
} catch (error) {
|
|
315
|
+
// Handle or ignore error
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async readStreamAsText(readableStream: ReadableStream, callback: (txt: string) => void) {
|
|
323
|
+
const reader = readableStream.getReader();
|
|
324
|
+
|
|
325
|
+
let readResult: any;
|
|
326
|
+
|
|
327
|
+
// Continuously read from the stream
|
|
328
|
+
while (!(readResult = await reader.read()).done) {
|
|
329
|
+
|
|
330
|
+
if (readResult.value && readResult.value.response) {
|
|
331
|
+
// Emit each chunk text as it's read
|
|
332
|
+
callback(readResult.value.response);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
addHistory(messages: IRWSHistoryMessage[], historyPrompt: string, callback?: (messages: IRWSHistoryMessage[], prompt: string) => void){
|
|
339
|
+
const prompt = `
|
|
340
|
+
${messages.map(message => `
|
|
341
|
+
${message.creator}: ${message.content}
|
|
342
|
+
`).join('\n\n')}
|
|
343
|
+
${historyPrompt}
|
|
344
|
+
` ;
|
|
345
|
+
|
|
346
|
+
if(callback){
|
|
347
|
+
callback(messages, prompt);
|
|
348
|
+
}else{
|
|
349
|
+
this.input = prompt + this.input;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
toJSON(): IRWSPromptJSON
|
|
354
|
+
{
|
|
355
|
+
return {
|
|
356
|
+
input: this.input,
|
|
357
|
+
enhancedInput: this.enhancedInput,
|
|
358
|
+
sentInput: this.sentInput,
|
|
359
|
+
originalInput: this.originalInput,
|
|
360
|
+
output: this.output,
|
|
361
|
+
modelId: this.modelId,
|
|
362
|
+
modelType: this.modelType,
|
|
363
|
+
multiTemplate: this.multiTemplate,
|
|
364
|
+
convo: {
|
|
365
|
+
id: this.convo.getId()
|
|
366
|
+
},
|
|
367
|
+
hyperParameters: this.hyperParameters,
|
|
368
|
+
var_storage: this.varStorage,
|
|
369
|
+
created_at: this.created_at.toISOString()
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export default RWSPrompt;
|
|
375
|
+
|
|
376
|
+
export {
|
|
377
|
+
IPromptSender,
|
|
378
|
+
IPromptEnchantment,
|
|
379
|
+
IPromptParams,
|
|
380
|
+
IPromptHyperParameters,
|
|
381
|
+
IRWSPromptRequestExecutor,
|
|
382
|
+
IRWSPromptStreamExecutor,
|
|
383
|
+
IRWSSinglePromptRequestExecutor,
|
|
384
|
+
IRWSPromptJSON,
|
|
385
|
+
IChainCallOutput,
|
|
386
|
+
ChainStreamType,
|
|
387
|
+
ILLMChunk
|
|
388
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EmbeddingsInterface } from '@langchain/core/embeddings';
|
|
2
|
+
import { Injectable } from '@rws-framework/server/nest';
|
|
3
|
+
|
|
4
|
+
import RWSVectorStore, { VectorDocType } from '../models/convo/VectorStore';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
class VectorStoreService
|
|
8
|
+
{
|
|
9
|
+
async createStore(docs: VectorDocType, embeddings: EmbeddingsInterface): Promise<RWSVectorStore>
|
|
10
|
+
{
|
|
11
|
+
return await (new RWSVectorStore(docs, embeddings)).init();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { VectorStoreService };
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": "./",
|
|
4
|
+
"experimentalDecorators": true,
|
|
5
|
+
"emitDecoratorMetadata": true,
|
|
6
|
+
"target": "ES2018",
|
|
7
|
+
"module": "commonjs",
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"strictNullChecks": false,
|
|
14
|
+
"allowSyntheticDefaultImports": true,
|
|
15
|
+
"sourceMap": true,
|
|
16
|
+
"declaration": true,
|
|
17
|
+
},
|
|
18
|
+
"include": [
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"exclude": [
|
|
22
|
+
"node_modules"
|
|
23
|
+
]
|
|
24
|
+
}
|