1
- import { Pipeline } from '../lib/module.js' ;
1
+ import { LLMPipeline } from '../lib/module.js' ;
2
2
3
3
import assert from 'node:assert/strict' ;
4
4
import { describe , it , before , after } from 'node:test' ;
@@ -11,7 +11,7 @@ describe('module', async () => {
11
11
let pipeline = null ;
12
12
13
13
await before ( async ( ) => {
14
- pipeline = await Pipeline . LLMPipeline ( MODEL_PATH , 'CPU' ) ;
14
+ pipeline = await LLMPipeline ( MODEL_PATH , 'CPU' ) ;
15
15
16
16
await pipeline . startChat ( ) ;
17
17
} ) ;
@@ -23,6 +23,7 @@ describe('module', async () => {
23
23
await it ( 'should generate non empty string' , async ( ) => {
24
24
const result = await pipeline . generate (
25
25
'Type something in English' ,
26
+ // eslint-disable-next-line camelcase
26
27
{ temperature : '0' , max_new_tokens : '4' } ,
27
28
( ) => { } ,
28
29
) ;
@@ -33,19 +34,19 @@ describe('module', async () => {
33
34
34
35
describe ( 'corner cases' , async ( ) => {
35
36
it ( 'should throw an error if pipeline is already initialized' , async ( ) => {
36
- const pipeline = await Pipeline . LLMPipeline ( MODEL_PATH , 'CPU' ) ;
37
+ const pipeline = await LLMPipeline ( MODEL_PATH , 'CPU' ) ;
37
38
38
39
await assert . rejects (
39
40
async ( ) => await pipeline . init ( ) ,
40
41
{
41
42
name : 'Error' ,
42
- message : 'Pipeline is already initialized' ,
43
+ message : 'LLMPipeline is already initialized' ,
43
44
} ,
44
45
) ;
45
46
} ) ;
46
47
47
48
it ( 'should throw an error if chat is already started' , async ( ) => {
48
- const pipeline = await Pipeline . LLMPipeline ( MODEL_PATH , 'CPU' ) ;
49
+ const pipeline = await LLMPipeline ( MODEL_PATH , 'CPU' ) ;
49
50
50
51
await pipeline . startChat ( ) ;
51
52
@@ -59,7 +60,7 @@ describe('corner cases', async () => {
59
60
} ) ;
60
61
61
62
it ( 'should throw an error if chat is not started' , async ( ) => {
62
- const pipeline = await Pipeline . LLMPipeline ( MODEL_PATH , 'CPU' ) ;
63
+ const pipeline = await LLMPipeline ( MODEL_PATH , 'CPU' ) ;
63
64
64
65
await assert . rejects (
65
66
( ) => pipeline . finishChat ( ) ,
@@ -75,7 +76,7 @@ describe('generation parameters validation', () => {
75
76
let pipeline = null ;
76
77
77
78
before ( async ( ) => {
78
- pipeline = await Pipeline . LLMPipeline ( MODEL_PATH , 'CPU' ) ;
79
+ pipeline = await LLMPipeline ( MODEL_PATH , 'CPU' ) ;
79
80
80
81
await pipeline . startChat ( ) ;
81
82
} ) ;
@@ -94,47 +95,54 @@ describe('generation parameters validation', () => {
94
95
) ;
95
96
} ) ;
96
97
97
- it ( 'should throw an error if generationCallback is not a function' , async ( ) => {
98
- const pipeline = await Pipeline . LLMPipeline ( MODEL_PATH , 'CPU' ) ;
98
+ it (
99
+ 'should throw an error if generationCallback is not a function' ,
100
+ async ( ) => {
101
+ const pipeline = await LLMPipeline ( MODEL_PATH , 'CPU' ) ;
99
102
100
- await pipeline . startChat ( ) ;
103
+ await pipeline . startChat ( ) ;
101
104
102
- await assert . rejects (
103
- async ( ) => await pipeline . generate ( 'prompt' , { } , false ) ,
104
- {
105
- name : 'Error' ,
106
- message : 'Generation callback must be a function' ,
107
- } ,
108
- ) ;
109
- } ) ;
105
+ await assert . rejects (
106
+ async ( ) => await pipeline . generate ( 'prompt' , { } , false ) ,
107
+ {
108
+ name : 'Error' ,
109
+ message : 'Generation callback must be a function' ,
110
+ } ,
111
+ ) ;
112
+ } ) ;
110
113
111
- it ( 'should throw an error if options specified but not an object' , async ( ) => {
112
- await assert . rejects (
113
- async ( ) => await pipeline . generate ( 'prompt' , 'options' , ( ) => { } ) ,
114
- {
115
- name : 'Error' ,
116
- message : 'Options must be an object' ,
117
- } ,
118
- ) ;
119
- } ) ;
114
+ it (
115
+ 'should throw an error if options specified but not an object' ,
116
+ async ( ) => {
117
+ await assert . rejects (
118
+ async ( ) => await pipeline . generate ( 'prompt' , 'options' , ( ) => { } ) ,
119
+ {
120
+ name : 'Error' ,
121
+ message : 'Options must be an object' ,
122
+ } ,
123
+ ) ;
124
+ } ) ;
120
125
121
126
it ( 'should perform generation with default options' , async ( ) => {
122
127
try {
128
+ // eslint-disable-next-line camelcase
123
129
await pipeline . generate ( 'prompt' , { max_new_tokens : 1 } ) ;
124
- } catch ( error ) {
130
+ } catch ( error ) {
125
131
assert . fail ( error ) ;
126
132
}
127
133
128
134
assert . ok ( true ) ;
129
135
} ) ;
130
136
131
137
it ( 'should return a string as generation result' , async ( ) => {
138
+ // eslint-disable-next-line camelcase
132
139
const reply = await pipeline . generate ( 'prompt' , { max_new_tokens : 1 } ) ;
133
140
134
141
assert . strictEqual ( typeof reply , 'string' ) ;
135
142
} ) ;
136
143
137
144
it ( 'should call generationCallback with string chunk' , async ( ) => {
145
+ // eslint-disable-next-line camelcase
138
146
await pipeline . generate ( 'prompt' , { max_new_tokens : 1 } , ( chunk ) => {
139
147
assert . strictEqual ( typeof chunk , 'string' ) ;
140
148
} ) ;
0 commit comments