@@ -12,7 +12,10 @@ import { runLLMStep, type RunLLMStepArgs } from './engine/step/runLLMStep';
12
12
import { testPipelineStep } from './engine/testStep' ;
13
13
import type { LLMModel , LLMProvider } from './llm/types' ;
14
14
import { OUTPUT_ID } from './output/Output' ;
15
- import { pipelineFromText } from './pipeline/fromText' ;
15
+ import {
16
+ pipelineFromText ,
17
+ type PipelineFromTextStatus ,
18
+ } from './pipeline/fromText' ;
16
19
import { generatePipeline } from './pipeline/generate' ;
17
20
import {
18
21
emptyPipeline ,
@@ -59,15 +62,15 @@ export interface LitLyticsConfig {
59
62
60
63
export class LitLytics {
61
64
// model config
62
- private _provider ?: LLMProviders ;
63
- private _model ?: LLMModel ;
65
+ provider ?: LLMProviders ;
66
+ model ?: LLMModel ;
64
67
#llmKey?: string ;
65
68
// local LLM engine
66
- private _engine ?: MLCEngine ;
69
+ engine ?: MLCEngine ;
67
70
68
71
// pipeline
69
- private _pipeline : Pipeline = emptyPipeline ;
70
- private _pipelineStatus : PipelineStatus = {
72
+ pipeline : Pipeline = emptyPipeline ;
73
+ pipelineStatus : PipelineStatus = {
71
74
status : 'init' ,
72
75
} ;
73
76
@@ -82,89 +85,66 @@ export class LitLytics {
82
85
key : string ;
83
86
engine ?: MLCEngine ;
84
87
} ) {
85
- this . _provider = provider ;
86
- this . _model = model ;
88
+ this . provider = provider ;
89
+ this . model = model ;
87
90
this . #llmKey = key ;
88
- this . _engine = engine ;
91
+ this . engine = engine ;
89
92
}
90
93
91
94
/**
92
95
* Config management
93
96
*/
94
- public get config ( ) : LitLyticsConfig {
95
- return {
96
- // model config
97
- provider : this . _provider ,
98
- model : this . _model ,
99
- // pipeline
100
- pipeline : this . _pipeline ,
101
- } ;
102
- }
103
-
104
97
exportConfig = ( ) : LitLyticsConfig => {
105
98
return {
106
99
// model config
107
- provider : this . _provider ,
108
- model : this . _model ,
100
+ provider : this . provider ,
101
+ model : this . model ,
109
102
llmKey : this . #llmKey,
110
103
// pipeline
111
- pipeline : this . _pipeline ,
104
+ pipeline : this . pipeline ,
112
105
} ;
113
106
} ;
114
107
115
108
importConfig = ( config : LitLyticsConfig ) => {
116
- this . _provider = config . provider ;
117
- this . _model = config . model ;
109
+ this . provider = config . provider ;
110
+ this . model = config . model ;
118
111
this . #llmKey = config . llmKey ;
119
- this . _pipeline = config . pipeline ?? this . _pipeline ?? emptyPipeline ;
120
- } ;
121
-
122
- getEngine = ( ) : MLCEngine | undefined => {
123
- return this . _engine ;
124
- } ;
125
-
126
- setWebEngine = ( engine ?: MLCEngine ) => {
127
- this . _engine = engine ;
112
+ this . pipeline = config . pipeline ?? this . pipeline ?? emptyPipeline ;
128
113
} ;
129
114
130
115
/**
131
116
* Pipeline management
132
117
*/
133
- public get pipeline ( ) : Pipeline {
134
- return this . _pipeline ;
135
- }
136
-
137
118
setPipeline = ( newPipeline : Partial < Pipeline > ) => {
138
- this . _pipeline = {
139
- ...this . _pipeline ,
119
+ this . pipeline = {
120
+ ...this . pipeline ,
140
121
...newPipeline ,
141
122
} ;
123
+ return this . pipeline ;
142
124
} ;
143
125
144
126
resetPipeline = ( ) => {
145
- this . _pipeline = emptyPipeline ;
146
- this . _pipelineStatus = { status : 'init' } ;
127
+ this . pipeline = structuredClone ( emptyPipeline ) ;
128
+ this . pipelineStatus = { status : 'init' } ;
129
+ return this . pipeline ;
147
130
} ;
148
131
149
132
/**
150
133
* Pipeline status
151
134
*/
152
- public get pipelineStatus ( ) : PipelineStatus {
153
- return this . _pipelineStatus ;
154
- }
155
-
156
135
setPipelineStatus = ( status : PipelineStatus ) => {
157
- this . _pipelineStatus = {
158
- ...this . _pipelineStatus ,
136
+ this . pipelineStatus = {
137
+ ...this . pipelineStatus ,
159
138
...status ,
160
139
} ;
140
+ return this . pipelineStatus ;
161
141
} ;
162
142
163
143
/**
164
144
* Document management
165
145
*/
166
146
public get docs ( ) : Doc [ ] {
167
- return this . _pipeline . source . docs ;
147
+ return this . pipeline . source . docs ;
168
148
}
169
149
170
150
setDocs = ( docs : Doc [ ] ) => {
@@ -186,18 +166,18 @@ export class LitLytics {
186
166
args,
187
167
} : Pick < RunPromptFromMessagesArgs , 'messages' | 'args' > ) => {
188
168
if (
189
- ! this . _provider ?. length ||
190
- ! this . _model ?. length ||
191
- ( ! this . #llmKey?. length && this . _provider !== 'local' )
169
+ ! this . provider ?. length ||
170
+ ! this . model ?. length ||
171
+ ( ! this . #llmKey?. length && this . provider !== 'local' )
192
172
) {
193
173
throw new Error ( 'No provider, model or key set!' ) ;
194
174
}
195
175
196
176
return await runPromptFromMessages ( {
197
- provider : this . _provider ,
177
+ provider : this . provider ,
198
178
key : this . #llmKey ?? 'local' ,
199
- model : this . _model ,
200
- engine : this . _engine ,
179
+ model : this . model ,
180
+ engine : this . engine ,
201
181
messages,
202
182
args,
203
183
} ) ;
@@ -209,18 +189,18 @@ export class LitLytics {
209
189
args,
210
190
} : Pick < RunPromptArgs , 'system' | 'user' | 'args' > ) => {
211
191
if (
212
- ! this . _provider ?. length ||
213
- ! this . _model ?. length ||
214
- ( ! this . #llmKey?. length && this . _provider !== 'local' )
192
+ ! this . provider ?. length ||
193
+ ! this . model ?. length ||
194
+ ( ! this . #llmKey?. length && this . provider !== 'local' )
215
195
) {
216
196
throw new Error ( 'No provider, model or key set!' ) ;
217
197
}
218
198
219
199
return await runPrompt ( {
220
- provider : this . _provider ,
200
+ provider : this . provider ,
221
201
key : this . #llmKey ?? 'local' ,
222
- model : this . _model ,
223
- engine : this . _engine ,
202
+ model : this . model ,
203
+ engine : this . engine ,
224
204
system,
225
205
user,
226
206
args,
@@ -231,19 +211,12 @@ export class LitLytics {
231
211
* Pipeline
232
212
*/
233
213
pipelineFromText = async (
234
- onStatus : ( {
235
- step,
236
- totalSteps,
237
- } : {
238
- step : number ;
239
- totalSteps : number ;
240
- } ) => void
214
+ onStatus : ( { step, totalSteps } : PipelineFromTextStatus ) => void
241
215
) => {
242
216
if ( ! this . pipeline . pipelinePlan ) {
243
217
return ;
244
218
}
245
219
246
- this . setPipelineStatus ( { status : 'sourcing' } ) ;
247
220
const newSteps = await pipelineFromText (
248
221
this ,
249
222
this . pipeline . pipelinePlan ,
@@ -254,7 +227,7 @@ export class LitLytics {
254
227
newSteps . at ( - 1 ) ! . connectsTo = [ OUTPUT_ID ] ;
255
228
256
229
// save
257
- this . setPipeline ( {
230
+ return this . setPipeline ( {
258
231
// assign input to first step
259
232
source : {
260
233
...this . pipeline . source ,
@@ -263,8 +236,6 @@ export class LitLytics {
263
236
// assign steps
264
237
steps : newSteps ,
265
238
} ) ;
266
-
267
- this . setPipelineStatus ( { status : 'done' } ) ;
268
239
} ;
269
240
270
241
generatePipeline = async ( ) => {
@@ -277,11 +248,9 @@ export class LitLytics {
277
248
description : this . pipeline . pipelineDescription ,
278
249
} ) ;
279
250
280
- this . setPipeline ( {
251
+ return this . setPipeline ( {
281
252
pipelinePlan : plan ?? '' ,
282
253
} ) ;
283
-
284
- return this . pipeline ;
285
254
} ;
286
255
287
256
refinePipeline = async ( { refineRequest } : { refineRequest : string } ) => {
@@ -290,8 +259,7 @@ export class LitLytics {
290
259
refineRequest,
291
260
pipeline : this . pipeline ,
292
261
} ) ;
293
- this . setPipeline ( {
294
- ...this . pipeline ,
262
+ return this . setPipeline ( {
295
263
pipelinePlan : plan ?? '' ,
296
264
} ) ;
297
265
} ;
@@ -308,8 +276,7 @@ export class LitLytics {
308
276
try {
309
277
setStatus ( { status : 'init' } ) ;
310
278
const newPipeline = await runPipeline ( this , setStatus ) ;
311
- this . setPipeline ( newPipeline ) ;
312
- return newPipeline ;
279
+ return this . setPipeline ( newPipeline ) ;
313
280
} catch ( err ) {
314
281
setStatus ( { status : 'error' , error : err as Error } ) ;
315
282
}
0 commit comments