@learning-commons/evaluators 0.1.0
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/README.md +318 -0
- package/dist/index.cjs +1899 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1142 -0
- package/dist/index.d.ts +1142 -0
- package/dist/index.js +1866 -0
- package/dist/index.js.map +1 -0
- package/package.json +84 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Learning Commons
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
# @learning-commons/evaluators
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for Learning Commons educational text complexity evaluators.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @learning-commons/evaluators ai
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The SDK uses the [Vercel AI SDK](https://sdk.vercel.ai) (`ai`) as its LLM interface. You also need to install the provider adapter(s) for the LLM(s) you use:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @ai-sdk/openai # for OpenAI
|
|
15
|
+
npm install @ai-sdk/google # for Google Gemini
|
|
16
|
+
npm install @ai-sdk/anthropic # for Anthropic
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { VocabularyEvaluator } from '@learning-commons/evaluators';
|
|
23
|
+
|
|
24
|
+
const evaluator = new VocabularyEvaluator({
|
|
25
|
+
googleApiKey: process.env.GOOGLE_API_KEY,
|
|
26
|
+
openaiApiKey: process.env.OPENAI_API_KEY
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const result = await evaluator.evaluate("Your text here", "5");
|
|
30
|
+
console.log(result.score); // "moderately complex"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Evaluators
|
|
36
|
+
|
|
37
|
+
### 1. Vocabulary Evaluator
|
|
38
|
+
|
|
39
|
+
Evaluates vocabulary complexity using the Qual Text Complexity rubric (SAP).
|
|
40
|
+
|
|
41
|
+
**Supported Grades:** 3-12
|
|
42
|
+
|
|
43
|
+
**Uses:** OpenAI GPT-4o (background knowledge) + Google Gemini 2.5 Pro (grades 3–4) / OpenAI GPT-4.1 (grades 5–12)
|
|
44
|
+
|
|
45
|
+
**Constructor:**
|
|
46
|
+
```typescript
|
|
47
|
+
const evaluator = new VocabularyEvaluator({
|
|
48
|
+
googleApiKey?: string; // Google API key (required by this evaluator)
|
|
49
|
+
openaiApiKey?: string; // OpenAI API key (required by this evaluator)
|
|
50
|
+
maxRetries?: number; // Optional - Max retry attempts (default: 2)
|
|
51
|
+
telemetry?: boolean | TelemetryOptions; // Optional (default: true)
|
|
52
|
+
logger?: Logger; // Optional - Custom logger
|
|
53
|
+
logLevel?: LogLevel; // Optional - SILENT | ERROR | WARN | INFO | DEBUG (default: WARN)
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**API:**
|
|
58
|
+
```typescript
|
|
59
|
+
await evaluator.evaluate(text: string, grade: string)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Returns:**
|
|
63
|
+
```typescript
|
|
64
|
+
{
|
|
65
|
+
score: 'slightly complex' | 'moderately complex' | 'very complex' | 'exceedingly complex';
|
|
66
|
+
reasoning: string;
|
|
67
|
+
metadata: {
|
|
68
|
+
model: string;
|
|
69
|
+
processingTimeMs: number;
|
|
70
|
+
};
|
|
71
|
+
_internal: VocabularyComplexity; // Detailed analysis
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
### 2. Sentence Structure Evaluator
|
|
78
|
+
|
|
79
|
+
Evaluates sentence structure complexity based on grammatical features.
|
|
80
|
+
|
|
81
|
+
**Supported Grades:** 3-12
|
|
82
|
+
|
|
83
|
+
**Uses:** OpenAI GPT-4o
|
|
84
|
+
|
|
85
|
+
**Constructor:**
|
|
86
|
+
```typescript
|
|
87
|
+
const evaluator = new SentenceStructureEvaluator({
|
|
88
|
+
openaiApiKey?: string; // OpenAI API key (required by this evaluator)
|
|
89
|
+
maxRetries?: number; // Optional - Max retry attempts (default: 2)
|
|
90
|
+
telemetry?: boolean | TelemetryOptions; // Optional (default: true)
|
|
91
|
+
logger?: Logger; // Optional - Custom logger
|
|
92
|
+
logLevel?: LogLevel; // Optional - Logging verbosity (default: WARN)
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**API:**
|
|
97
|
+
```typescript
|
|
98
|
+
await evaluator.evaluate(text: string, grade: string)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Returns:**
|
|
102
|
+
```typescript
|
|
103
|
+
{
|
|
104
|
+
score: 'Slightly Complex' | 'Moderately Complex' | 'Very Complex' | 'Exceedingly Complex';
|
|
105
|
+
reasoning: string;
|
|
106
|
+
metadata: {
|
|
107
|
+
model: string;
|
|
108
|
+
processingTimeMs: number;
|
|
109
|
+
};
|
|
110
|
+
_internal: {
|
|
111
|
+
sentenceAnalysis: SentenceAnalysis;
|
|
112
|
+
features: SentenceFeatures;
|
|
113
|
+
complexity: ComplexityClassification;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
### 3. Text Complexity Evaluator
|
|
121
|
+
|
|
122
|
+
Composite evaluator that analyzes both vocabulary and sentence structure complexity in parallel.
|
|
123
|
+
|
|
124
|
+
**Supported Grades:** 3-12
|
|
125
|
+
|
|
126
|
+
**Uses:** Google Gemini 2.5 Pro + OpenAI GPT-4o (composite)
|
|
127
|
+
|
|
128
|
+
**Constructor:**
|
|
129
|
+
```typescript
|
|
130
|
+
const evaluator = new TextComplexityEvaluator({
|
|
131
|
+
googleApiKey?: string; // Google API key (required by this evaluator)
|
|
132
|
+
openaiApiKey?: string; // OpenAI API key (required by this evaluator)
|
|
133
|
+
maxRetries?: number; // Optional - Max retry attempts (default: 2)
|
|
134
|
+
telemetry?: boolean | TelemetryOptions; // Optional (default: true)
|
|
135
|
+
logger?: Logger; // Optional - Custom logger
|
|
136
|
+
logLevel?: LogLevel; // Optional - Logging verbosity (default: WARN)
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**API:**
|
|
141
|
+
```typescript
|
|
142
|
+
await evaluator.evaluate(text: string, grade: string)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Returns:**
|
|
146
|
+
```typescript
|
|
147
|
+
{
|
|
148
|
+
score: {
|
|
149
|
+
overall: string; // Overall complexity (highest of the two)
|
|
150
|
+
vocabulary: string; // Vocabulary complexity score
|
|
151
|
+
sentenceStructure: string; // Sentence structure complexity score
|
|
152
|
+
};
|
|
153
|
+
reasoning: string; // Combined reasoning from both evaluators
|
|
154
|
+
metadata: EvaluationMetadata;
|
|
155
|
+
_internal: {
|
|
156
|
+
vocabulary: EvaluationResult | { error: Error };
|
|
157
|
+
sentenceStructure: EvaluationResult | { error: Error };
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
### 4. Grade Level Appropriateness Evaluator
|
|
165
|
+
|
|
166
|
+
Determines appropriate grade level for text.
|
|
167
|
+
|
|
168
|
+
**No grade parameter required** - evaluates what grade the text is appropriate for.
|
|
169
|
+
|
|
170
|
+
**Uses:** Google Gemini 2.5 Pro
|
|
171
|
+
|
|
172
|
+
**Constructor:**
|
|
173
|
+
```typescript
|
|
174
|
+
const evaluator = new GradeLevelAppropriatenessEvaluator({
|
|
175
|
+
googleApiKey?: string; // Google API key (required by this evaluator)
|
|
176
|
+
maxRetries?: number; // Optional - Max retry attempts (default: 2)
|
|
177
|
+
telemetry?: boolean | TelemetryOptions; // Optional (default: true)
|
|
178
|
+
logger?: Logger; // Optional - Custom logger
|
|
179
|
+
logLevel?: LogLevel; // Optional - Logging verbosity (default: WARN)
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
**API:**
|
|
184
|
+
```typescript
|
|
185
|
+
await evaluator.evaluate(text: string)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**Returns:**
|
|
189
|
+
```typescript
|
|
190
|
+
{
|
|
191
|
+
score: string; // e.g., 'K-1', '2-3', '4-5', '6-8', '9-10', '11-CCR'
|
|
192
|
+
reasoning: string;
|
|
193
|
+
metadata: {
|
|
194
|
+
model: string;
|
|
195
|
+
processingTimeMs: number;
|
|
196
|
+
};
|
|
197
|
+
_internal: {
|
|
198
|
+
grade: string;
|
|
199
|
+
alternative_grade: string;
|
|
200
|
+
scaffolding_needed: string;
|
|
201
|
+
reasoning: string;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Error Handling
|
|
209
|
+
|
|
210
|
+
The SDK provides specific error types to help you handle different scenarios:
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
import {
|
|
214
|
+
ConfigurationError,
|
|
215
|
+
ValidationError,
|
|
216
|
+
APIError,
|
|
217
|
+
AuthenticationError,
|
|
218
|
+
RateLimitError,
|
|
219
|
+
NetworkError,
|
|
220
|
+
TimeoutError,
|
|
221
|
+
} from '@learning-commons/evaluators';
|
|
222
|
+
|
|
223
|
+
try {
|
|
224
|
+
const evaluator = new VocabularyEvaluator({ googleApiKey, openaiApiKey });
|
|
225
|
+
const result = await evaluator.evaluate(text, grade);
|
|
226
|
+
} catch (error) {
|
|
227
|
+
if (error instanceof ConfigurationError) {
|
|
228
|
+
// Missing or invalid API keys — fix your config
|
|
229
|
+
console.error('Configuration error:', error.message);
|
|
230
|
+
} else if (error instanceof ValidationError) {
|
|
231
|
+
// Invalid input (text too short, invalid grade, etc.)
|
|
232
|
+
console.error('Invalid input:', error.message);
|
|
233
|
+
} else if (error instanceof AuthenticationError) {
|
|
234
|
+
// Invalid API keys
|
|
235
|
+
console.error('Check your API keys:', error.message);
|
|
236
|
+
} else if (error instanceof RateLimitError) {
|
|
237
|
+
// Rate limit exceeded - wait and retry
|
|
238
|
+
console.error('Rate limited. Retry after:', error.retryAfter);
|
|
239
|
+
} else if (error instanceof NetworkError) {
|
|
240
|
+
// Network connectivity issues
|
|
241
|
+
console.error('Network error:', error.message);
|
|
242
|
+
} else if (error instanceof APIError) {
|
|
243
|
+
// Other API errors
|
|
244
|
+
console.error('API error:', error.message, 'Status:', error.statusCode);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## Logging
|
|
252
|
+
|
|
253
|
+
Control logging verbosity with `logLevel`:
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
import { VocabularyEvaluator, LogLevel } from '@learning-commons/evaluators';
|
|
257
|
+
|
|
258
|
+
const evaluator = new VocabularyEvaluator({
|
|
259
|
+
googleApiKey: '...',
|
|
260
|
+
openaiApiKey: '...',
|
|
261
|
+
logLevel: LogLevel.INFO, // SILENT | ERROR | WARN | INFO | DEBUG
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Or provide a custom logger:
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
import type { Logger } from '@learning-commons/evaluators';
|
|
269
|
+
|
|
270
|
+
const customLogger: Logger = {
|
|
271
|
+
debug: (msg, ctx) => myLogger.debug(msg, ctx),
|
|
272
|
+
info: (msg, ctx) => myLogger.info(msg, ctx),
|
|
273
|
+
warn: (msg, ctx) => myLogger.warn(msg, ctx),
|
|
274
|
+
error: (msg, ctx) => myLogger.error(msg, ctx),
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const evaluator = new VocabularyEvaluator({
|
|
278
|
+
googleApiKey: '...',
|
|
279
|
+
openaiApiKey: '...',
|
|
280
|
+
logger: customLogger,
|
|
281
|
+
});
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Telemetry & Privacy
|
|
287
|
+
|
|
288
|
+
See [docs/telemetry.md](./docs/telemetry.md) for telemetry configuration and privacy information.
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## Configuration Options
|
|
293
|
+
|
|
294
|
+
All evaluators use the same `BaseEvaluatorConfig` interface:
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
interface BaseEvaluatorConfig {
|
|
298
|
+
googleApiKey?: string; // Google API key (required by some evaluators)
|
|
299
|
+
openaiApiKey?: string; // OpenAI API key (required by some evaluators)
|
|
300
|
+
maxRetries?: number; // Max API retry attempts (default: 2)
|
|
301
|
+
telemetry?: boolean | TelemetryOptions; // Telemetry config (default: true)
|
|
302
|
+
logger?: Logger; // Custom logger (optional)
|
|
303
|
+
logLevel?: LogLevel; // Console log level (default: WARN)
|
|
304
|
+
partnerKey?: string; // Learning Commons partner key for authenticated telemetry (optional)
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
**Note:** Which API keys are required depends on the evaluator. The SDK validates required keys at runtime based on the evaluator's metadata:
|
|
309
|
+
- **Vocabulary**: Requires both `googleApiKey` and `openaiApiKey`
|
|
310
|
+
- **Sentence Structure**: Requires `openaiApiKey` only
|
|
311
|
+
- **Text Complexity**: Requires both `googleApiKey` and `openaiApiKey`
|
|
312
|
+
- **Grade Level Appropriateness**: Requires `googleApiKey` only
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## License
|
|
317
|
+
|
|
318
|
+
MIT
|