@learning-commons/evaluators 0.4.0 → 0.5.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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { B as BaseEvaluator, a as BaseEvaluatorConfig } from './base-Ced9oKKa.js';
3
- export { E as EvaluatorMetadata, b as LogContext, c as LogLevel, L as Logger, T as TelemetryOptions } from './base-Ced9oKKa.js';
2
+ import { B as BaseEvaluator, P as Provider, a as BaseEvaluatorConfig } from './base-DKcAYXfb.js';
3
+ export { E as EvaluatorMetadata, L as LLMProvider, b as LLMRequest, c as LLMResponse, d as LogContext, e as LogLevel, f as Logger, M as Message, g as ModelOverride, h as ProviderConfig, i as Providers, T as TelemetryOptions, j as TextGenerationResponse } from './base-DKcAYXfb.js';
4
4
 
5
5
  /**
6
6
  * Shared complexity levels used across all text complexity evaluators
@@ -62,6 +62,111 @@ declare const GradeLevelAppropriatenessSchema: z.ZodObject<{
62
62
  }>;
63
63
  type GradeLevelAppropriatenessInternal = z.infer<typeof GradeLevelAppropriatenessSchema>;
64
64
 
65
+ declare const PurposeOutputSchema: z.ZodObject<{
66
+ complexity_score: z.ZodEnum<["slightly_complex", "moderately_complex", "very_complex", "exceedingly_complex", "more_context_needed"]>;
67
+ reasoning: z.ZodString;
68
+ details: z.ZodObject<{
69
+ detailed_summary: z.ZodArray<z.ZodObject<{
70
+ factor: z.ZodString;
71
+ description: z.ZodString;
72
+ effect_on_complexity_dimension: z.ZodString;
73
+ }, "strict", z.ZodTypeAny, {
74
+ factor: string;
75
+ description: string;
76
+ effect_on_complexity_dimension: string;
77
+ }, {
78
+ factor: string;
79
+ description: string;
80
+ effect_on_complexity_dimension: string;
81
+ }>, "many">;
82
+ adjustment_and_scaffolding: z.ZodArray<z.ZodObject<{
83
+ scaffolding_need: z.ZodString;
84
+ suggestion: z.ZodString;
85
+ }, "strict", z.ZodTypeAny, {
86
+ scaffolding_need: string;
87
+ suggestion: string;
88
+ }, {
89
+ scaffolding_need: string;
90
+ suggestion: string;
91
+ }>, "many">;
92
+ recommended_use_cases: z.ZodArray<z.ZodObject<{
93
+ opportunity: z.ZodString;
94
+ suggestion: z.ZodString;
95
+ }, "strict", z.ZodTypeAny, {
96
+ suggestion: string;
97
+ opportunity: string;
98
+ }, {
99
+ suggestion: string;
100
+ opportunity: string;
101
+ }>, "many">;
102
+ }, "strict", z.ZodTypeAny, {
103
+ detailed_summary: {
104
+ factor: string;
105
+ description: string;
106
+ effect_on_complexity_dimension: string;
107
+ }[];
108
+ adjustment_and_scaffolding: {
109
+ scaffolding_need: string;
110
+ suggestion: string;
111
+ }[];
112
+ recommended_use_cases: {
113
+ suggestion: string;
114
+ opportunity: string;
115
+ }[];
116
+ }, {
117
+ detailed_summary: {
118
+ factor: string;
119
+ description: string;
120
+ effect_on_complexity_dimension: string;
121
+ }[];
122
+ adjustment_and_scaffolding: {
123
+ scaffolding_need: string;
124
+ suggestion: string;
125
+ }[];
126
+ recommended_use_cases: {
127
+ suggestion: string;
128
+ opportunity: string;
129
+ }[];
130
+ }>;
131
+ }, "strict", z.ZodTypeAny, {
132
+ reasoning: string;
133
+ complexity_score: "slightly_complex" | "moderately_complex" | "very_complex" | "exceedingly_complex" | "more_context_needed";
134
+ details: {
135
+ detailed_summary: {
136
+ factor: string;
137
+ description: string;
138
+ effect_on_complexity_dimension: string;
139
+ }[];
140
+ adjustment_and_scaffolding: {
141
+ scaffolding_need: string;
142
+ suggestion: string;
143
+ }[];
144
+ recommended_use_cases: {
145
+ suggestion: string;
146
+ opportunity: string;
147
+ }[];
148
+ };
149
+ }, {
150
+ reasoning: string;
151
+ complexity_score: "slightly_complex" | "moderately_complex" | "very_complex" | "exceedingly_complex" | "more_context_needed";
152
+ details: {
153
+ detailed_summary: {
154
+ factor: string;
155
+ description: string;
156
+ effect_on_complexity_dimension: string;
157
+ }[];
158
+ adjustment_and_scaffolding: {
159
+ scaffolding_need: string;
160
+ suggestion: string;
161
+ }[];
162
+ recommended_use_cases: {
163
+ suggestion: string;
164
+ opportunity: string;
165
+ }[];
166
+ };
167
+ }>;
168
+ type PurposeInternal = z.infer<typeof PurposeOutputSchema>;
169
+
65
170
  /**
66
171
  * Custom error types for the Evaluators SDK
67
172
  *
@@ -204,72 +309,6 @@ declare class TimeoutError extends APIError {
204
309
  constructor(message?: string);
205
310
  }
206
311
 
207
- /**
208
- * Message format for LLM conversations
209
- */
210
- interface Message {
211
- role: 'system' | 'user' | 'assistant';
212
- content: string;
213
- }
214
- /**
215
- * Request configuration for structured LLM generation
216
- */
217
- interface LLMRequest<T> {
218
- messages: Message[];
219
- schema: z.ZodSchema<T>;
220
- temperature?: number;
221
- maxTokens?: number;
222
- model?: string;
223
- }
224
- /**
225
- * Response from LLM with usage metadata
226
- */
227
- interface LLMResponse<T> {
228
- data: T;
229
- model: string;
230
- usage: {
231
- inputTokens: number;
232
- outputTokens: number;
233
- };
234
- latencyMs: number;
235
- }
236
- /**
237
- * Response from plain text generation
238
- */
239
- interface TextGenerationResponse {
240
- text: string;
241
- usage: {
242
- inputTokens: number;
243
- outputTokens: number;
244
- };
245
- latencyMs: number;
246
- }
247
- /**
248
- * Base interface for LLM provider implementations
249
- */
250
- interface LLMProvider {
251
- /**
252
- * Generate structured output from LLM using Zod schema
253
- */
254
- generateStructured<T>(request: LLMRequest<T>): Promise<LLMResponse<T>>;
255
- /**
256
- * Generate plain text from LLM
257
- */
258
- generateText(messages: Message[], temperature?: number): Promise<TextGenerationResponse>;
259
- }
260
- /**
261
- * Configuration for LLM provider
262
- */
263
- interface ProviderConfig {
264
- type: 'openai' | 'anthropic' | 'google' | 'custom';
265
- apiKey?: string;
266
- model?: string;
267
- temperature?: number;
268
- baseURL?: string;
269
- customProvider?: LLMProvider;
270
- maxRetries?: number;
271
- }
272
-
273
312
  /**
274
313
  * Stage 1: Detailed sentence analysis output (40+ metrics)
275
314
  * Ported from Python SentenceAnalysesEvaluatorOutput
@@ -461,18 +500,18 @@ declare const VocabularyComplexitySchema: z.ZodObject<{
461
500
  reasoning: z.ZodString;
462
501
  }, "strip", z.ZodTypeAny, {
463
502
  reasoning: string;
503
+ complexity_score: "Slightly complex" | "Moderately complex" | "Very complex" | "Exceedingly complex";
464
504
  tier_2_words: string;
465
505
  tier_3_words: string;
466
506
  archaic_words: string;
467
507
  other_complex_words: string;
468
- complexity_score: "Slightly complex" | "Moderately complex" | "Very complex" | "Exceedingly complex";
469
508
  }, {
470
509
  reasoning: string;
510
+ complexity_score: "Slightly complex" | "Moderately complex" | "Very complex" | "Exceedingly complex";
471
511
  tier_2_words: string;
472
512
  tier_3_words: string;
473
513
  archaic_words: string;
474
514
  other_complex_words: string;
475
- complexity_score: "Slightly complex" | "Moderately complex" | "Very complex" | "Exceedingly complex";
476
515
  }>;
477
516
  type VocabularyInternal = z.infer<typeof VocabularyComplexitySchema>;
478
517
 
@@ -559,8 +598,7 @@ declare class VocabularyEvaluator extends BaseEvaluator {
559
598
  name: string;
560
599
  description: string;
561
600
  supportedGrades: readonly ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
562
- requiresGoogleKey: boolean;
563
- requiresOpenAIKey: boolean;
601
+ defaultProviders: readonly [Provider.Google, Provider.OpenAI];
564
602
  };
565
603
  private grades34ComplexityProvider;
566
604
  private otherGradesComplexityProvider;
@@ -573,6 +611,7 @@ declare class VocabularyEvaluator extends BaseEvaluator {
573
611
  * @param grade - The target grade level (3-12)
574
612
  * @returns Evaluation result with complexity score and detailed analysis
575
613
  * @throws {ValidationError} If text is empty, too short/long, or grade is invalid
614
+ * @throws {ConfigurationError} If modelOverride specifies a model ID that the provider rejects
576
615
  * @throws {APIError} If LLM API calls fail (includes AuthenticationError, RateLimitError, NetworkError, TimeoutError)
577
616
  */
578
617
  evaluate(text: string, grade: string): Promise<EvaluationResult<TextComplexityLevel, VocabularyInternal>>;
@@ -639,11 +678,9 @@ declare class SentenceStructureEvaluator extends BaseEvaluator {
639
678
  name: string;
640
679
  description: string;
641
680
  supportedGrades: readonly ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
642
- requiresGoogleKey: boolean;
643
- requiresOpenAIKey: boolean;
681
+ defaultProviders: readonly [Provider.OpenAI];
644
682
  };
645
- private analysisProvider;
646
- private complexityProvider;
683
+ private provider;
647
684
  constructor(config: BaseEvaluatorConfig);
648
685
  /**
649
686
  * Evaluate sentence structure complexity for a given text and grade level
@@ -652,6 +689,7 @@ declare class SentenceStructureEvaluator extends BaseEvaluator {
652
689
  * @param grade - The target grade level (3-12)
653
690
  * @returns Evaluation result with complexity score and detailed analysis
654
691
  * @throws {ValidationError} If text is empty, too short/long, or grade is invalid
692
+ * @throws {ConfigurationError} If modelOverride specifies a model ID that the provider rejects
655
693
  * @throws {APIError} If LLM API calls fail (includes AuthenticationError, RateLimitError, NetworkError, TimeoutError)
656
694
  */
657
695
  evaluate(text: string, grade: string): Promise<EvaluationResult<TextComplexityLevel, SentenceStructureInternal>>;
@@ -717,8 +755,7 @@ declare class GradeLevelAppropriatenessEvaluator extends BaseEvaluator {
717
755
  name: string;
718
756
  description: string;
719
757
  supportedGrades: readonly [];
720
- requiresGoogleKey: boolean;
721
- requiresOpenAIKey: boolean;
758
+ defaultProviders: readonly [Provider.Google];
722
759
  };
723
760
  private provider;
724
761
  constructor(config: BaseEvaluatorConfig);
@@ -728,6 +765,7 @@ declare class GradeLevelAppropriatenessEvaluator extends BaseEvaluator {
728
765
  * @param text - The text to evaluate
729
766
  * @returns Evaluation result with grade recommendations and scaffolding suggestions
730
767
  * @throws {ValidationError} If text is empty or too short/long
768
+ * @throws {ConfigurationError} If modelOverride specifies a model ID that the provider rejects
731
769
  * @throws {APIError} If LLM API calls fail (includes AuthenticationError, RateLimitError, NetworkError, TimeoutError)
732
770
  */
733
771
  evaluate(text: string): Promise<EvaluationResult<GradeBand, GradeLevelAppropriatenessInternal>>;
@@ -776,8 +814,7 @@ declare class SmkEvaluator extends BaseEvaluator {
776
814
  name: string;
777
815
  description: string;
778
816
  supportedGrades: readonly ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
779
- requiresGoogleKey: boolean;
780
- requiresOpenAIKey: boolean;
817
+ defaultProviders: readonly [Provider.Google];
781
818
  };
782
819
  private provider;
783
820
  constructor(config: BaseEvaluatorConfig);
@@ -788,6 +825,7 @@ declare class SmkEvaluator extends BaseEvaluator {
788
825
  * @param grade - The target grade level (3-12)
789
826
  * @returns Evaluation result with complexity score and detailed analysis
790
827
  * @throws {ValidationError} If text is empty, too short/long, or grade is invalid
828
+ * @throws {ConfigurationError} If modelOverride specifies a model ID that the provider rejects
791
829
  * @throws {APIError} If LLM API calls fail (includes AuthenticationError, RateLimitError, NetworkError, TimeoutError)
792
830
  */
793
831
  evaluate(text: string, grade: string): Promise<EvaluationResult<TextComplexityLevel, SmkInternal>>;
@@ -839,8 +877,7 @@ declare class ConventionalityEvaluator extends BaseEvaluator {
839
877
  name: string;
840
878
  description: string;
841
879
  supportedGrades: readonly ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
842
- requiresGoogleKey: boolean;
843
- requiresOpenAIKey: boolean;
880
+ defaultProviders: readonly [Provider.Google];
844
881
  };
845
882
  private provider;
846
883
  constructor(config: BaseEvaluatorConfig);
@@ -851,6 +888,7 @@ declare class ConventionalityEvaluator extends BaseEvaluator {
851
888
  * @param grade - The target grade level (3-12)
852
889
  * @returns Evaluation result with complexity score and detailed analysis
853
890
  * @throws {ValidationError} If text is empty, too short/long, or grade is invalid
891
+ * @throws {ConfigurationError} If modelOverride specifies a model ID that the provider rejects
854
892
  * @throws {APIError} If LLM API calls fail (includes AuthenticationError, RateLimitError, NetworkError, TimeoutError)
855
893
  */
856
894
  evaluate(text: string, grade: string): Promise<EvaluationResult<TextComplexityLevel, ConventionalityInternal>>;
@@ -922,8 +960,7 @@ declare class TextComplexityEvaluator extends BaseEvaluator {
922
960
  name: string;
923
961
  description: string;
924
962
  supportedGrades: readonly ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
925
- requiresGoogleKey: boolean;
926
- requiresOpenAIKey: boolean;
963
+ defaultProviders: readonly [Provider.Google, Provider.OpenAI];
927
964
  };
928
965
  private vocabularyEvaluator;
929
966
  private sentenceStructureEvaluator;
@@ -941,7 +978,8 @@ declare class TextComplexityEvaluator extends BaseEvaluator {
941
978
  * @param text - The text to evaluate
942
979
  * @param grade - The target grade level (3-12)
943
980
  * @returns Map of sub-evaluator results
944
- * @throws {ValidationError} If text is empty or grade is invalid
981
+ * @throws {ValidationError} If text is empty, too short/long, or grade is invalid
982
+ * @throws {ConfigurationError} If modelOverride specifies a model ID that the provider rejects
945
983
  * @throws {Error} If all sub-evaluators fail
946
984
  */
947
985
  evaluate(text: string, grade: string): Promise<TextComplexityResult>;
@@ -968,6 +1006,35 @@ declare class TextComplexityEvaluator extends BaseEvaluator {
968
1006
  */
969
1007
  declare function evaluateTextComplexity(text: string, grade: string, config: BaseEvaluatorConfig): Promise<TextComplexityResult>;
970
1008
 
1009
+ type PurposeComplexityLevel = TextComplexityLevel | 'More context needed';
1010
+ declare class PurposeEvaluator extends BaseEvaluator {
1011
+ static readonly metadata: {
1012
+ id: string;
1013
+ name: string;
1014
+ description: string;
1015
+ supportedGrades: string[];
1016
+ defaultProviders: readonly [Provider.Google];
1017
+ };
1018
+ private static readonly TEMPERATURE;
1019
+ private static computeFkScore;
1020
+ private provider;
1021
+ constructor(config: BaseEvaluatorConfig);
1022
+ /**
1023
+ * Evaluate purpose complexity for a given text and grade level
1024
+ *
1025
+ * @param text - The text to evaluate
1026
+ * @param grade - The target grade level (3-12)
1027
+ * @returns Evaluation result with complexity score and detailed analysis
1028
+ * @throws {ValidationError} If text is empty, too short/long, or grade is invalid
1029
+ * @throws {ConfigurationError} If modelOverride specifies a model ID that the provider rejects
1030
+ * @throws {APIError} If LLM API calls fail (includes AuthenticationError, RateLimitError, NetworkError, TimeoutError)
1031
+ */
1032
+ evaluate(text: string, grade: string): Promise<EvaluationResult<PurposeComplexityLevel, PurposeInternal>>;
1033
+ private parseAndValidateGrade;
1034
+ private callLLM;
1035
+ }
1036
+ declare function evaluatePurpose(text: string, grade: string, config: BaseEvaluatorConfig): Promise<EvaluationResult<PurposeComplexityLevel, PurposeInternal>>;
1037
+
971
1038
  /**
972
1039
  * Calculate Flesch-Kincaid Grade Level
973
1040
  * Equivalent to Python's textstat.flesch_kincaid_grade()
@@ -998,4 +1065,4 @@ declare function addEngineeredFeatures(analysis: SentenceAnalysis): SentenceFeat
998
1065
  */
999
1066
  declare function featuresToJSON(features: SentenceFeatures, decimals?: number, castToInt?: boolean): string;
1000
1067
 
1001
- export { APIError, AuthenticationError, BaseEvaluatorConfig, type ComplexityClassification, ComplexityClassificationSchema, ConfigurationError, ConventionalityEvaluator, type ConventionalityInternal, type EvaluationError, type EvaluationMetadata, type EvaluationResult, EvaluatorError, GradeBand, GradeLevelAppropriatenessEvaluator, type GradeLevelAppropriatenessInternal, GradeLevelAppropriatenessSchema, type LLMProvider, type LLMRequest, type LLMResponse, type Message, NetworkError, type ProviderConfig, RateLimitError, type ReadabilityMetrics, type SentenceAnalysis, SentenceAnalysisSchema, type SentenceFeatures, SentenceStructureEvaluator, type SentenceStructureInternal, SmkEvaluator, type SmkInternal, TextComplexityEvaluator, TextComplexityLevel, type TextComplexityResult, type TextGenerationResponse, TimeoutError, ValidationError, VocabularyEvaluator, type VocabularyInternal, addEngineeredFeatures, calculateFleschKincaidGrade, calculateReadabilityMetrics, evaluateConventionality, evaluateGradeLevelAppropriateness, evaluateSentenceStructure, evaluateSmk, evaluateTextComplexity, evaluateVocabulary, featuresToJSON };
1068
+ export { APIError, AuthenticationError, BaseEvaluatorConfig, type ComplexityClassification, ComplexityClassificationSchema, ConfigurationError, ConventionalityEvaluator, type ConventionalityInternal, type EvaluationError, type EvaluationMetadata, type EvaluationResult, EvaluatorError, GradeBand, GradeLevelAppropriatenessEvaluator, type GradeLevelAppropriatenessInternal, GradeLevelAppropriatenessSchema, NetworkError, Provider, type PurposeComplexityLevel, PurposeEvaluator, type PurposeInternal, RateLimitError, type ReadabilityMetrics, type SentenceAnalysis, SentenceAnalysisSchema, type SentenceFeatures, SentenceStructureEvaluator, type SentenceStructureInternal, SmkEvaluator, type SmkInternal, TextComplexityEvaluator, TextComplexityLevel, type TextComplexityResult, TimeoutError, ValidationError, VocabularyEvaluator, type VocabularyInternal, addEngineeredFeatures, calculateFleschKincaidGrade, calculateReadabilityMetrics, evaluateConventionality, evaluateGradeLevelAppropriateness, evaluatePurpose, evaluateSentenceStructure, evaluateSmk, evaluateTextComplexity, evaluateVocabulary, featuresToJSON };