@learning-commons/evaluators 0.2.0 → 0.3.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/README.md +71 -4
- package/dist/index.cjs +224 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +94 -2
- package/dist/index.d.ts +94 -2
- package/dist/index.js +223 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -580,6 +580,30 @@ declare const SmkOutputSchema: z.ZodObject<{
|
|
|
580
580
|
}>;
|
|
581
581
|
type SmkInternal = z.infer<typeof SmkOutputSchema>;
|
|
582
582
|
|
|
583
|
+
/**
|
|
584
|
+
* Conventionality evaluation output schema
|
|
585
|
+
*/
|
|
586
|
+
declare const ConventionalityOutputSchema: z.ZodObject<{
|
|
587
|
+
conventionality_features: z.ZodArray<z.ZodString, "many">;
|
|
588
|
+
grade_context: z.ZodString;
|
|
589
|
+
instructional_insights: z.ZodString;
|
|
590
|
+
complexity_score: z.ZodEnum<["Slightly complex", "Moderately complex", "Very complex", "Exceedingly complex"]>;
|
|
591
|
+
reasoning: z.ZodString;
|
|
592
|
+
}, "strip", z.ZodTypeAny, {
|
|
593
|
+
reasoning: string;
|
|
594
|
+
complexity_score: "Slightly complex" | "Moderately complex" | "Very complex" | "Exceedingly complex";
|
|
595
|
+
conventionality_features: string[];
|
|
596
|
+
grade_context: string;
|
|
597
|
+
instructional_insights: string;
|
|
598
|
+
}, {
|
|
599
|
+
reasoning: string;
|
|
600
|
+
complexity_score: "Slightly complex" | "Moderately complex" | "Very complex" | "Exceedingly complex";
|
|
601
|
+
conventionality_features: string[];
|
|
602
|
+
grade_context: string;
|
|
603
|
+
instructional_insights: string;
|
|
604
|
+
}>;
|
|
605
|
+
type ConventionalityInternal = z.infer<typeof ConventionalityOutputSchema>;
|
|
606
|
+
|
|
583
607
|
/**
|
|
584
608
|
* Evaluation status
|
|
585
609
|
*/
|
|
@@ -1114,6 +1138,69 @@ declare class SmkEvaluator extends BaseEvaluator {
|
|
|
1114
1138
|
*/
|
|
1115
1139
|
declare function evaluateSmk(text: string, grade: string, config: BaseEvaluatorConfig): Promise<EvaluationResult<TextComplexityLevel, SmkInternal>>;
|
|
1116
1140
|
|
|
1141
|
+
/**
|
|
1142
|
+
* Conventionality Evaluator
|
|
1143
|
+
*
|
|
1144
|
+
* Evaluates how explicit, literal, and straightforward a text's meaning is versus
|
|
1145
|
+
* how abstract, ironic, figurative, or archaic it is for the target grade level.
|
|
1146
|
+
*
|
|
1147
|
+
* Based on the Common Core Qualitative Text Complexity Rubric with 4 levels:
|
|
1148
|
+
* - Slightly complex
|
|
1149
|
+
* - Moderately complex
|
|
1150
|
+
* - Very complex
|
|
1151
|
+
* - Exceedingly complex
|
|
1152
|
+
*
|
|
1153
|
+
* @example
|
|
1154
|
+
* ```typescript
|
|
1155
|
+
* const evaluator = new ConventionalityEvaluator({
|
|
1156
|
+
* googleApiKey: process.env.GOOGLE_API_KEY
|
|
1157
|
+
* });
|
|
1158
|
+
*
|
|
1159
|
+
* const result = await evaluator.evaluate(text, "6");
|
|
1160
|
+
* console.log(result.score); // "Moderately complex"
|
|
1161
|
+
* console.log(result.reasoning);
|
|
1162
|
+
* ```
|
|
1163
|
+
*/
|
|
1164
|
+
declare class ConventionalityEvaluator extends BaseEvaluator {
|
|
1165
|
+
static readonly metadata: {
|
|
1166
|
+
id: string;
|
|
1167
|
+
name: string;
|
|
1168
|
+
description: string;
|
|
1169
|
+
supportedGrades: readonly ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
|
|
1170
|
+
requiresGoogleKey: boolean;
|
|
1171
|
+
requiresOpenAIKey: boolean;
|
|
1172
|
+
};
|
|
1173
|
+
private provider;
|
|
1174
|
+
constructor(config: BaseEvaluatorConfig);
|
|
1175
|
+
/**
|
|
1176
|
+
* Evaluate conventionality complexity for a given text and grade level
|
|
1177
|
+
*
|
|
1178
|
+
* @param text - The text to evaluate
|
|
1179
|
+
* @param grade - The target grade level (3-12)
|
|
1180
|
+
* @returns Evaluation result with complexity score and detailed analysis
|
|
1181
|
+
* @throws {ValidationError} If text is empty, too short/long, or grade is invalid
|
|
1182
|
+
* @throws {APIError} If LLM API calls fail (includes AuthenticationError, RateLimitError, NetworkError, TimeoutError)
|
|
1183
|
+
*/
|
|
1184
|
+
evaluate(text: string, grade: string): Promise<EvaluationResult<TextComplexityLevel, ConventionalityInternal>>;
|
|
1185
|
+
/**
|
|
1186
|
+
* Run the Conventionality evaluation LLM call
|
|
1187
|
+
*/
|
|
1188
|
+
private evaluateConventionality;
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Functional API for Conventionality evaluation
|
|
1192
|
+
*
|
|
1193
|
+
* @example
|
|
1194
|
+
* ```typescript
|
|
1195
|
+
* const result = await evaluateConventionality(
|
|
1196
|
+
* "The author uses sustained irony to critique societal norms.",
|
|
1197
|
+
* "10",
|
|
1198
|
+
* { googleApiKey: process.env.GOOGLE_API_KEY }
|
|
1199
|
+
* );
|
|
1200
|
+
* ```
|
|
1201
|
+
*/
|
|
1202
|
+
declare function evaluateConventionality(text: string, grade: string, config: BaseEvaluatorConfig): Promise<EvaluationResult<TextComplexityLevel, ConventionalityInternal>>;
|
|
1203
|
+
|
|
1117
1204
|
/**
|
|
1118
1205
|
* Result map returned by TextComplexityEvaluator.
|
|
1119
1206
|
* Each key holds the full evaluation result from its sub-evaluator, or an error if it failed.
|
|
@@ -1128,17 +1215,21 @@ interface TextComplexityResult {
|
|
|
1128
1215
|
subjectMatterKnowledge: EvaluationResult<TextComplexityLevel, SmkInternal> | {
|
|
1129
1216
|
error: Error;
|
|
1130
1217
|
};
|
|
1218
|
+
conventionality: EvaluationResult<TextComplexityLevel, ConventionalityInternal> | {
|
|
1219
|
+
error: Error;
|
|
1220
|
+
};
|
|
1131
1221
|
}
|
|
1132
1222
|
/**
|
|
1133
1223
|
* Text Complexity Evaluator
|
|
1134
1224
|
*
|
|
1135
|
-
* Composite evaluator that analyzes vocabulary, sentence structure,
|
|
1225
|
+
* Composite evaluator that analyzes vocabulary, sentence structure, subject matter knowledge, and conventionality.
|
|
1136
1226
|
* Runs all evaluations in parallel with concurrency control to avoid rate limiting.
|
|
1137
1227
|
*
|
|
1138
1228
|
* Uses:
|
|
1139
1229
|
* - VocabularyEvaluator (Google Gemini 2.5 Pro + OpenAI GPT-4o)
|
|
1140
1230
|
* - SentenceStructureEvaluator (OpenAI GPT-4o)
|
|
1141
1231
|
* - SmkEvaluator (Google Gemini 3 Flash Preview)
|
|
1232
|
+
* - ConventionalityEvaluator (Google Gemini 3 Flash Preview)
|
|
1142
1233
|
*
|
|
1143
1234
|
* @example
|
|
1144
1235
|
* ```typescript
|
|
@@ -1165,6 +1256,7 @@ declare class TextComplexityEvaluator extends BaseEvaluator {
|
|
|
1165
1256
|
private vocabularyEvaluator;
|
|
1166
1257
|
private sentenceStructureEvaluator;
|
|
1167
1258
|
private smkEvaluator;
|
|
1259
|
+
private conventionalityEvaluator;
|
|
1168
1260
|
private limit;
|
|
1169
1261
|
constructor(config: BaseEvaluatorConfig);
|
|
1170
1262
|
/**
|
|
@@ -1234,4 +1326,4 @@ declare function addEngineeredFeatures(analysis: SentenceAnalysis): SentenceFeat
|
|
|
1234
1326
|
*/
|
|
1235
1327
|
declare function featuresToJSON(features: SentenceFeatures, decimals?: number, castToInt?: boolean): string;
|
|
1236
1328
|
|
|
1237
|
-
export { APIError, AuthenticationError, type BaseEvaluatorConfig, type ComplexityClassification, ComplexityClassificationSchema, ConfigurationError, type EvaluationError, type EvaluationMetadata, type EvaluationResult, EvaluatorError, type EvaluatorMetadata, GradeBand, GradeLevelAppropriatenessEvaluator, type GradeLevelAppropriatenessInternal, GradeLevelAppropriatenessSchema, type LLMProvider, type LLMRequest, type LLMResponse, type LogContext, LogLevel, type Logger, type Message, NetworkError, type ProviderConfig, RateLimitError, type ReadabilityMetrics, type SentenceAnalysis, SentenceAnalysisSchema, type SentenceFeatures, SentenceStructureEvaluator, type SentenceStructureInternal, SmkEvaluator, type SmkInternal, type TelemetryOptions, TextComplexityEvaluator, TextComplexityLevel, type TextComplexityResult, type TextGenerationResponse, TimeoutError, ValidationError, VocabularyEvaluator, type VocabularyInternal, addEngineeredFeatures, calculateFleschKincaidGrade, calculateReadabilityMetrics, evaluateGradeLevelAppropriateness, evaluateSentenceStructure, evaluateSmk, evaluateTextComplexity, evaluateVocabulary, featuresToJSON };
|
|
1329
|
+
export { APIError, AuthenticationError, type BaseEvaluatorConfig, type ComplexityClassification, ComplexityClassificationSchema, ConfigurationError, ConventionalityEvaluator, type ConventionalityInternal, type EvaluationError, type EvaluationMetadata, type EvaluationResult, EvaluatorError, type EvaluatorMetadata, GradeBand, GradeLevelAppropriatenessEvaluator, type GradeLevelAppropriatenessInternal, GradeLevelAppropriatenessSchema, type LLMProvider, type LLMRequest, type LLMResponse, type LogContext, LogLevel, type Logger, type Message, NetworkError, type ProviderConfig, RateLimitError, type ReadabilityMetrics, type SentenceAnalysis, SentenceAnalysisSchema, type SentenceFeatures, SentenceStructureEvaluator, type SentenceStructureInternal, SmkEvaluator, type SmkInternal, type TelemetryOptions, TextComplexityEvaluator, TextComplexityLevel, type TextComplexityResult, type TextGenerationResponse, TimeoutError, ValidationError, VocabularyEvaluator, type VocabularyInternal, addEngineeredFeatures, calculateFleschKincaidGrade, calculateReadabilityMetrics, evaluateConventionality, evaluateGradeLevelAppropriateness, evaluateSentenceStructure, evaluateSmk, evaluateTextComplexity, evaluateVocabulary, featuresToJSON };
|
package/dist/index.d.ts
CHANGED
|
@@ -580,6 +580,30 @@ declare const SmkOutputSchema: z.ZodObject<{
|
|
|
580
580
|
}>;
|
|
581
581
|
type SmkInternal = z.infer<typeof SmkOutputSchema>;
|
|
582
582
|
|
|
583
|
+
/**
|
|
584
|
+
* Conventionality evaluation output schema
|
|
585
|
+
*/
|
|
586
|
+
declare const ConventionalityOutputSchema: z.ZodObject<{
|
|
587
|
+
conventionality_features: z.ZodArray<z.ZodString, "many">;
|
|
588
|
+
grade_context: z.ZodString;
|
|
589
|
+
instructional_insights: z.ZodString;
|
|
590
|
+
complexity_score: z.ZodEnum<["Slightly complex", "Moderately complex", "Very complex", "Exceedingly complex"]>;
|
|
591
|
+
reasoning: z.ZodString;
|
|
592
|
+
}, "strip", z.ZodTypeAny, {
|
|
593
|
+
reasoning: string;
|
|
594
|
+
complexity_score: "Slightly complex" | "Moderately complex" | "Very complex" | "Exceedingly complex";
|
|
595
|
+
conventionality_features: string[];
|
|
596
|
+
grade_context: string;
|
|
597
|
+
instructional_insights: string;
|
|
598
|
+
}, {
|
|
599
|
+
reasoning: string;
|
|
600
|
+
complexity_score: "Slightly complex" | "Moderately complex" | "Very complex" | "Exceedingly complex";
|
|
601
|
+
conventionality_features: string[];
|
|
602
|
+
grade_context: string;
|
|
603
|
+
instructional_insights: string;
|
|
604
|
+
}>;
|
|
605
|
+
type ConventionalityInternal = z.infer<typeof ConventionalityOutputSchema>;
|
|
606
|
+
|
|
583
607
|
/**
|
|
584
608
|
* Evaluation status
|
|
585
609
|
*/
|
|
@@ -1114,6 +1138,69 @@ declare class SmkEvaluator extends BaseEvaluator {
|
|
|
1114
1138
|
*/
|
|
1115
1139
|
declare function evaluateSmk(text: string, grade: string, config: BaseEvaluatorConfig): Promise<EvaluationResult<TextComplexityLevel, SmkInternal>>;
|
|
1116
1140
|
|
|
1141
|
+
/**
|
|
1142
|
+
* Conventionality Evaluator
|
|
1143
|
+
*
|
|
1144
|
+
* Evaluates how explicit, literal, and straightforward a text's meaning is versus
|
|
1145
|
+
* how abstract, ironic, figurative, or archaic it is for the target grade level.
|
|
1146
|
+
*
|
|
1147
|
+
* Based on the Common Core Qualitative Text Complexity Rubric with 4 levels:
|
|
1148
|
+
* - Slightly complex
|
|
1149
|
+
* - Moderately complex
|
|
1150
|
+
* - Very complex
|
|
1151
|
+
* - Exceedingly complex
|
|
1152
|
+
*
|
|
1153
|
+
* @example
|
|
1154
|
+
* ```typescript
|
|
1155
|
+
* const evaluator = new ConventionalityEvaluator({
|
|
1156
|
+
* googleApiKey: process.env.GOOGLE_API_KEY
|
|
1157
|
+
* });
|
|
1158
|
+
*
|
|
1159
|
+
* const result = await evaluator.evaluate(text, "6");
|
|
1160
|
+
* console.log(result.score); // "Moderately complex"
|
|
1161
|
+
* console.log(result.reasoning);
|
|
1162
|
+
* ```
|
|
1163
|
+
*/
|
|
1164
|
+
declare class ConventionalityEvaluator extends BaseEvaluator {
|
|
1165
|
+
static readonly metadata: {
|
|
1166
|
+
id: string;
|
|
1167
|
+
name: string;
|
|
1168
|
+
description: string;
|
|
1169
|
+
supportedGrades: readonly ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
|
|
1170
|
+
requiresGoogleKey: boolean;
|
|
1171
|
+
requiresOpenAIKey: boolean;
|
|
1172
|
+
};
|
|
1173
|
+
private provider;
|
|
1174
|
+
constructor(config: BaseEvaluatorConfig);
|
|
1175
|
+
/**
|
|
1176
|
+
* Evaluate conventionality complexity for a given text and grade level
|
|
1177
|
+
*
|
|
1178
|
+
* @param text - The text to evaluate
|
|
1179
|
+
* @param grade - The target grade level (3-12)
|
|
1180
|
+
* @returns Evaluation result with complexity score and detailed analysis
|
|
1181
|
+
* @throws {ValidationError} If text is empty, too short/long, or grade is invalid
|
|
1182
|
+
* @throws {APIError} If LLM API calls fail (includes AuthenticationError, RateLimitError, NetworkError, TimeoutError)
|
|
1183
|
+
*/
|
|
1184
|
+
evaluate(text: string, grade: string): Promise<EvaluationResult<TextComplexityLevel, ConventionalityInternal>>;
|
|
1185
|
+
/**
|
|
1186
|
+
* Run the Conventionality evaluation LLM call
|
|
1187
|
+
*/
|
|
1188
|
+
private evaluateConventionality;
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Functional API for Conventionality evaluation
|
|
1192
|
+
*
|
|
1193
|
+
* @example
|
|
1194
|
+
* ```typescript
|
|
1195
|
+
* const result = await evaluateConventionality(
|
|
1196
|
+
* "The author uses sustained irony to critique societal norms.",
|
|
1197
|
+
* "10",
|
|
1198
|
+
* { googleApiKey: process.env.GOOGLE_API_KEY }
|
|
1199
|
+
* );
|
|
1200
|
+
* ```
|
|
1201
|
+
*/
|
|
1202
|
+
declare function evaluateConventionality(text: string, grade: string, config: BaseEvaluatorConfig): Promise<EvaluationResult<TextComplexityLevel, ConventionalityInternal>>;
|
|
1203
|
+
|
|
1117
1204
|
/**
|
|
1118
1205
|
* Result map returned by TextComplexityEvaluator.
|
|
1119
1206
|
* Each key holds the full evaluation result from its sub-evaluator, or an error if it failed.
|
|
@@ -1128,17 +1215,21 @@ interface TextComplexityResult {
|
|
|
1128
1215
|
subjectMatterKnowledge: EvaluationResult<TextComplexityLevel, SmkInternal> | {
|
|
1129
1216
|
error: Error;
|
|
1130
1217
|
};
|
|
1218
|
+
conventionality: EvaluationResult<TextComplexityLevel, ConventionalityInternal> | {
|
|
1219
|
+
error: Error;
|
|
1220
|
+
};
|
|
1131
1221
|
}
|
|
1132
1222
|
/**
|
|
1133
1223
|
* Text Complexity Evaluator
|
|
1134
1224
|
*
|
|
1135
|
-
* Composite evaluator that analyzes vocabulary, sentence structure,
|
|
1225
|
+
* Composite evaluator that analyzes vocabulary, sentence structure, subject matter knowledge, and conventionality.
|
|
1136
1226
|
* Runs all evaluations in parallel with concurrency control to avoid rate limiting.
|
|
1137
1227
|
*
|
|
1138
1228
|
* Uses:
|
|
1139
1229
|
* - VocabularyEvaluator (Google Gemini 2.5 Pro + OpenAI GPT-4o)
|
|
1140
1230
|
* - SentenceStructureEvaluator (OpenAI GPT-4o)
|
|
1141
1231
|
* - SmkEvaluator (Google Gemini 3 Flash Preview)
|
|
1232
|
+
* - ConventionalityEvaluator (Google Gemini 3 Flash Preview)
|
|
1142
1233
|
*
|
|
1143
1234
|
* @example
|
|
1144
1235
|
* ```typescript
|
|
@@ -1165,6 +1256,7 @@ declare class TextComplexityEvaluator extends BaseEvaluator {
|
|
|
1165
1256
|
private vocabularyEvaluator;
|
|
1166
1257
|
private sentenceStructureEvaluator;
|
|
1167
1258
|
private smkEvaluator;
|
|
1259
|
+
private conventionalityEvaluator;
|
|
1168
1260
|
private limit;
|
|
1169
1261
|
constructor(config: BaseEvaluatorConfig);
|
|
1170
1262
|
/**
|
|
@@ -1234,4 +1326,4 @@ declare function addEngineeredFeatures(analysis: SentenceAnalysis): SentenceFeat
|
|
|
1234
1326
|
*/
|
|
1235
1327
|
declare function featuresToJSON(features: SentenceFeatures, decimals?: number, castToInt?: boolean): string;
|
|
1236
1328
|
|
|
1237
|
-
export { APIError, AuthenticationError, type BaseEvaluatorConfig, type ComplexityClassification, ComplexityClassificationSchema, ConfigurationError, type EvaluationError, type EvaluationMetadata, type EvaluationResult, EvaluatorError, type EvaluatorMetadata, GradeBand, GradeLevelAppropriatenessEvaluator, type GradeLevelAppropriatenessInternal, GradeLevelAppropriatenessSchema, type LLMProvider, type LLMRequest, type LLMResponse, type LogContext, LogLevel, type Logger, type Message, NetworkError, type ProviderConfig, RateLimitError, type ReadabilityMetrics, type SentenceAnalysis, SentenceAnalysisSchema, type SentenceFeatures, SentenceStructureEvaluator, type SentenceStructureInternal, SmkEvaluator, type SmkInternal, type TelemetryOptions, TextComplexityEvaluator, TextComplexityLevel, type TextComplexityResult, type TextGenerationResponse, TimeoutError, ValidationError, VocabularyEvaluator, type VocabularyInternal, addEngineeredFeatures, calculateFleschKincaidGrade, calculateReadabilityMetrics, evaluateGradeLevelAppropriateness, evaluateSentenceStructure, evaluateSmk, evaluateTextComplexity, evaluateVocabulary, featuresToJSON };
|
|
1329
|
+
export { APIError, AuthenticationError, type BaseEvaluatorConfig, type ComplexityClassification, ComplexityClassificationSchema, ConfigurationError, ConventionalityEvaluator, type ConventionalityInternal, type EvaluationError, type EvaluationMetadata, type EvaluationResult, EvaluatorError, type EvaluatorMetadata, GradeBand, GradeLevelAppropriatenessEvaluator, type GradeLevelAppropriatenessInternal, GradeLevelAppropriatenessSchema, type LLMProvider, type LLMRequest, type LLMResponse, type LogContext, LogLevel, type Logger, type Message, NetworkError, type ProviderConfig, RateLimitError, type ReadabilityMetrics, type SentenceAnalysis, SentenceAnalysisSchema, type SentenceFeatures, SentenceStructureEvaluator, type SentenceStructureInternal, SmkEvaluator, type SmkInternal, type TelemetryOptions, TextComplexityEvaluator, TextComplexityLevel, type TextComplexityResult, type TextGenerationResponse, TimeoutError, ValidationError, VocabularyEvaluator, type VocabularyInternal, addEngineeredFeatures, calculateFleschKincaidGrade, calculateReadabilityMetrics, evaluateConventionality, evaluateGradeLevelAppropriateness, evaluateSentenceStructure, evaluateSmk, evaluateTextComplexity, evaluateVocabulary, featuresToJSON };
|
package/dist/index.js
CHANGED
|
@@ -1999,11 +1999,222 @@ async function evaluateSmk(text, grade, config) {
|
|
|
1999
1999
|
const evaluator = new SmkEvaluator(config);
|
|
2000
2000
|
return evaluator.evaluate(text, grade);
|
|
2001
2001
|
}
|
|
2002
|
+
var ConventionalityOutputSchema = z.object({
|
|
2003
|
+
conventionality_features: z.array(z.string()).describe("The specific language features driving the complexity (e.g., literal narrative, concrete actions, sustained irony, abstract qualities) with direct quotes from the text."),
|
|
2004
|
+
grade_context: z.string().describe("How the conventionality demands compare to general expectations for the provided target grade."),
|
|
2005
|
+
instructional_insights: z.string().describe("Actionable pedagogical suggestions for scaffolding the conventionality features in the classroom."),
|
|
2006
|
+
complexity_score: TextComplexityLevel.describe("The conventionality complexity level of the text"),
|
|
2007
|
+
reasoning: z.string().describe("A detailed explanation of the rating, citing specific features in the text and referencing the expert guardrails.")
|
|
2008
|
+
});
|
|
2009
|
+
|
|
2010
|
+
// ../../evals/prompts/conventionality/system.txt
|
|
2011
|
+
var system_default3 = `Role
|
|
2012
|
+
You are an expert reading teacher and text complexity evaluator. Your task is to evaluate the "Conventionality" of a text and assign it a complexity level based on a 4-point scale, carefully factoring in the target grade level.
|
|
2013
|
+
|
|
2014
|
+
Objective
|
|
2015
|
+
Measure how explicit, literal, and straightforward the text's meaning is, versus how abstract, ironic, figurative, or archaic it is. Focus on the hiddenness of the meaning, the use of conceptual framing, the reliance on abstract reasoning, and the familiarity of the expression for the target grade.
|
|
2016
|
+
|
|
2017
|
+
Complexity Levels
|
|
2018
|
+
- Slightly Complex: Explicit, literal, straightforward, easy to understand. Meaning is entirely on the surface. The language is concrete, and the meaning is clear and procedural, mostly referring to observable materials and actions. Contains no symbolic or ironic language, and conceptual interpretation is not required. Contains limited figurative language that is common and easy to comprehend at the target grade level.
|
|
2019
|
+
- Moderately Complex: Largely explicit and easy to understand with some occasions for more complex meaning. May contain a noticeable amount of archaic/dated phrasing, formal historical prose, vocabulary demands, background knowledge requirements, or expressions that are less familiar to the target grade level, which might make the text feel vague or slightly challenging.
|
|
2020
|
+
- Very Complex: Fairly complex; contains sustained abstract language, conceptual framing, rhetorical idealization, ironic comparisons, or central metaphors that drive the meaning of the text. Addresses concepts, beliefs, and abstract qualities rather than just concrete objects. The tone or underlying message requires interpretation, even if the surface message is clear.
|
|
2021
|
+
- Exceedingly Complex: Dense and complex; contains considerable abstract, ironic, and/or figurative language. Meaning is heavily hidden, deeply conceptual, or relies heavily on complex rhetorical devices.
|
|
2022
|
+
|
|
2023
|
+
Essential Evaluation Rules
|
|
2024
|
+
1. Concrete & Procedural Texts: Texts that are highly concrete, clear, and procedural (e.g., describing observable materials, mechanical processes, or physical actions) should typically be rated "Slightly Complex."
|
|
2025
|
+
|
|
2026
|
+
2. Grade-Level Anchoring and Vague Narratives: Always consider the target grade. A literal historical narrative that might be straightforward for older students can be "Moderately Complex" for younger students (e.g., 4th graders) if it involves less familiar expressions, older contexts (e.g., wagon loads, traveling by horseback), vocabulary demands, and background knowledge requirements that make the text feel vague or slightly demanding for that age group.
|
|
2027
|
+
|
|
2028
|
+
3. Rhetorical Idealization and Abstract Qualities: If an entire argument or narrative is built around abstract qualities (e.g., national character, bravery, liberty) and uses repeated figurative language or personification to portray a subject in a certain idealized way, rate the text as "Very Complex." Even if the figurative language is easy to interpret, the need to interpret the rhetorical tone and sustained abstract focus elevates the complexity beyond level two.
|
|
2029
|
+
|
|
2030
|
+
4. Common Idioms and Grade-Level Appropriateness: Do NOT elevate a text to "Moderately Complex" simply because it contains a few common idiomatic expressions. If these expressions are widely known and easy for the target grade to understand without making the text feel vague, the text remains "Slightly Complex."
|
|
2031
|
+
|
|
2032
|
+
5. Conversational and Hypothetical Framing: Using a second-person conversational hook (e.g., "Imagine you are...") to explain a concept is a standard, literal device for engaging readers. It does not constitute complex conceptual framing.
|
|
2033
|
+
|
|
2034
|
+
6. Sustained vs. Occasional Impact: If abstract language, figurative phrasing, irony, or conceptual framing is sustained throughout the text and central to the argument/meaning, the text is Very Complex. Reserve Moderately Complex for texts where the explicit meaning dominates but the expression, vocabulary, or archaic language provides a moderate conventionality challenge.
|
|
2035
|
+
|
|
2036
|
+
7. Central Metaphors and Conceptual Framing: When an author uses a central metaphor to explain a concept or uses figurative phrasing to explain how things "work," this abstract reasoning drives the meaning, elevating the text to Very Complex.
|
|
2037
|
+
|
|
2038
|
+
8. Irony and Abstract Comparisons: Texts that rely on sustained irony, especially through comparative arguments, are inherently Very Complex for younger students.
|
|
2039
|
+
|
|
2040
|
+
9. Isolate Conventionality from Vocabulary: Do not inflate the Conventionality score just because the text uses archaic, dated, or highly academic vocabulary.
|
|
2041
|
+
|
|
2042
|
+
Input Format
|
|
2043
|
+
You will receive:
|
|
2044
|
+
- text: The passage to evaluate.
|
|
2045
|
+
- grade_level: The target student grade level.
|
|
2046
|
+
- fk_score: The Flesch-Kincaid readability score.
|
|
2047
|
+
|
|
2048
|
+
Output Format
|
|
2049
|
+
Provide a JSON object containing ONLY the following keys:
|
|
2050
|
+
- complexity_score: (String) One of the 4 scale levels exactly as formatted: 'slightly_complex', 'moderately_complex', 'very_complex', or 'exceedingly_complex'.
|
|
2051
|
+
- reasoning: (String) A detailed explanation of the rating, citing specific features in the text and referencing the expert guardrails (e.g., noting if the text relies on abstract qualities/rhetorical idealization, if vocabulary/background knowledge demands make a literal text vague for the grade level, or if it is strictly concrete/procedural).
|
|
2052
|
+
- conventionality_features: (List of Strings) The specific language features driving the complexity (e.g., literal narrative, concrete actions, less familiar expressions, sustained irony, abstract qualities, rhetorical idealization, archaic phrasing) with direct quotes from the text.
|
|
2053
|
+
- grade_context: (String) How the conventionality demands compare to general expectations for the provided target grade.
|
|
2054
|
+
- instructional_insights: (String) Actionable pedagogical suggestions for scaffolding the conventionality features in the classroom.`;
|
|
2055
|
+
|
|
2056
|
+
// ../../evals/prompts/conventionality/user.txt
|
|
2057
|
+
var user_default3 = "Analyze:\nText: {text}\nGrade: {grade}\nFK Score: {fk_score}";
|
|
2058
|
+
|
|
2059
|
+
// src/prompts/conventionality/index.ts
|
|
2060
|
+
function getSystemPrompt4() {
|
|
2061
|
+
return system_default3;
|
|
2062
|
+
}
|
|
2063
|
+
function getUserPrompt4(text, grade, fkScore) {
|
|
2064
|
+
return user_default3.replaceAll("{text}", text).replaceAll("{grade}", grade).replaceAll("{fk_score}", fkScore.toString());
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
// src/evaluators/conventionality.ts
|
|
2068
|
+
var ConventionalityEvaluator = class _ConventionalityEvaluator extends BaseEvaluator {
|
|
2069
|
+
static metadata = {
|
|
2070
|
+
id: "conventionality",
|
|
2071
|
+
name: "Conventionality",
|
|
2072
|
+
description: "Evaluates how explicit, literal, and straightforward a text's meaning is relative to grade level",
|
|
2073
|
+
supportedGrades: ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12"],
|
|
2074
|
+
requiresGoogleKey: true,
|
|
2075
|
+
requiresOpenAIKey: false
|
|
2076
|
+
};
|
|
2077
|
+
provider;
|
|
2078
|
+
constructor(config) {
|
|
2079
|
+
super(config);
|
|
2080
|
+
this.provider = createProvider({
|
|
2081
|
+
type: "google",
|
|
2082
|
+
model: "gemini-3-flash-preview",
|
|
2083
|
+
apiKey: config.googleApiKey,
|
|
2084
|
+
maxRetries: this.config.maxRetries
|
|
2085
|
+
});
|
|
2086
|
+
}
|
|
2087
|
+
/**
|
|
2088
|
+
* Evaluate conventionality complexity for a given text and grade level
|
|
2089
|
+
*
|
|
2090
|
+
* @param text - The text to evaluate
|
|
2091
|
+
* @param grade - The target grade level (3-12)
|
|
2092
|
+
* @returns Evaluation result with complexity score and detailed analysis
|
|
2093
|
+
* @throws {ValidationError} If text is empty, too short/long, or grade is invalid
|
|
2094
|
+
* @throws {APIError} If LLM API calls fail (includes AuthenticationError, RateLimitError, NetworkError, TimeoutError)
|
|
2095
|
+
*/
|
|
2096
|
+
async evaluate(text, grade) {
|
|
2097
|
+
this.logger.info("Starting Conventionality evaluation", {
|
|
2098
|
+
evaluator: "conventionality",
|
|
2099
|
+
operation: "evaluate",
|
|
2100
|
+
grade,
|
|
2101
|
+
textLength: text.length
|
|
2102
|
+
});
|
|
2103
|
+
const startTime = Date.now();
|
|
2104
|
+
const stageDetails = [];
|
|
2105
|
+
try {
|
|
2106
|
+
this.validateText(text);
|
|
2107
|
+
this.validateGrade(grade, new Set(_ConventionalityEvaluator.metadata.supportedGrades));
|
|
2108
|
+
this.logger.debug("Evaluating conventionality complexity", {
|
|
2109
|
+
evaluator: "conventionality",
|
|
2110
|
+
operation: "conventionality_evaluation"
|
|
2111
|
+
});
|
|
2112
|
+
const fkScore = calculateFleschKincaidGrade(text);
|
|
2113
|
+
const response = await this.evaluateConventionality(text, grade, fkScore);
|
|
2114
|
+
stageDetails.push({
|
|
2115
|
+
stage: "conventionality_evaluation",
|
|
2116
|
+
provider: "google:gemini-3-flash-preview",
|
|
2117
|
+
latency_ms: response.latencyMs,
|
|
2118
|
+
token_usage: {
|
|
2119
|
+
input_tokens: response.usage.inputTokens,
|
|
2120
|
+
output_tokens: response.usage.outputTokens
|
|
2121
|
+
}
|
|
2122
|
+
});
|
|
2123
|
+
const latencyMs = Date.now() - startTime;
|
|
2124
|
+
const totalTokenUsage = {
|
|
2125
|
+
input_tokens: stageDetails.reduce((sum, s) => sum + (s.token_usage?.input_tokens || 0), 0),
|
|
2126
|
+
output_tokens: stageDetails.reduce((sum, s) => sum + (s.token_usage?.output_tokens || 0), 0)
|
|
2127
|
+
};
|
|
2128
|
+
const result = {
|
|
2129
|
+
score: response.data.complexity_score,
|
|
2130
|
+
reasoning: response.data.reasoning,
|
|
2131
|
+
metadata: {
|
|
2132
|
+
model: "google:gemini-3-flash-preview",
|
|
2133
|
+
processingTimeMs: latencyMs
|
|
2134
|
+
},
|
|
2135
|
+
_internal: response.data
|
|
2136
|
+
};
|
|
2137
|
+
this.sendTelemetry({
|
|
2138
|
+
status: "success",
|
|
2139
|
+
latencyMs,
|
|
2140
|
+
textLength: text.length,
|
|
2141
|
+
grade,
|
|
2142
|
+
provider: "google:gemini-3-flash-preview",
|
|
2143
|
+
tokenUsage: totalTokenUsage,
|
|
2144
|
+
metadata: {
|
|
2145
|
+
stage_details: stageDetails
|
|
2146
|
+
},
|
|
2147
|
+
inputText: text
|
|
2148
|
+
}).catch(() => {
|
|
2149
|
+
});
|
|
2150
|
+
this.logger.info("Conventionality evaluation completed successfully", {
|
|
2151
|
+
evaluator: "conventionality",
|
|
2152
|
+
operation: "evaluate",
|
|
2153
|
+
grade,
|
|
2154
|
+
score: result.score,
|
|
2155
|
+
processingTimeMs: latencyMs
|
|
2156
|
+
});
|
|
2157
|
+
return result;
|
|
2158
|
+
} catch (error) {
|
|
2159
|
+
const latencyMs = Date.now() - startTime;
|
|
2160
|
+
this.logger.error("Conventionality evaluation failed", {
|
|
2161
|
+
evaluator: "conventionality",
|
|
2162
|
+
operation: "evaluate",
|
|
2163
|
+
grade,
|
|
2164
|
+
error: error instanceof Error ? error : void 0,
|
|
2165
|
+
processingTimeMs: latencyMs,
|
|
2166
|
+
completedStages: stageDetails.length
|
|
2167
|
+
});
|
|
2168
|
+
const totalTokenUsage = stageDetails.length > 0 ? {
|
|
2169
|
+
input_tokens: stageDetails.reduce((sum, s) => sum + (s.token_usage?.input_tokens || 0), 0),
|
|
2170
|
+
output_tokens: stageDetails.reduce((sum, s) => sum + (s.token_usage?.output_tokens || 0), 0)
|
|
2171
|
+
} : void 0;
|
|
2172
|
+
this.sendTelemetry({
|
|
2173
|
+
status: "error",
|
|
2174
|
+
latencyMs,
|
|
2175
|
+
textLength: text.length,
|
|
2176
|
+
grade,
|
|
2177
|
+
provider: "google:gemini-3-flash-preview",
|
|
2178
|
+
tokenUsage: totalTokenUsage,
|
|
2179
|
+
errorCode: error instanceof Error ? error.name : "UnknownError",
|
|
2180
|
+
metadata: stageDetails.length > 0 ? { stage_details: stageDetails } : void 0,
|
|
2181
|
+
inputText: text
|
|
2182
|
+
}).catch(() => {
|
|
2183
|
+
});
|
|
2184
|
+
if (error instanceof ValidationError) {
|
|
2185
|
+
throw error;
|
|
2186
|
+
}
|
|
2187
|
+
throw wrapProviderError(error, "Conventionality evaluation failed");
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
/**
|
|
2191
|
+
* Run the Conventionality evaluation LLM call
|
|
2192
|
+
*/
|
|
2193
|
+
async evaluateConventionality(text, grade, fkScore) {
|
|
2194
|
+
const response = await this.provider.generateStructured({
|
|
2195
|
+
messages: [
|
|
2196
|
+
{ role: "system", content: getSystemPrompt4() },
|
|
2197
|
+
{ role: "user", content: getUserPrompt4(text, grade, fkScore) }
|
|
2198
|
+
],
|
|
2199
|
+
schema: ConventionalityOutputSchema,
|
|
2200
|
+
temperature: 0
|
|
2201
|
+
});
|
|
2202
|
+
return {
|
|
2203
|
+
data: response.data,
|
|
2204
|
+
usage: response.usage,
|
|
2205
|
+
latencyMs: response.latencyMs
|
|
2206
|
+
};
|
|
2207
|
+
}
|
|
2208
|
+
};
|
|
2209
|
+
async function evaluateConventionality(text, grade, config) {
|
|
2210
|
+
const evaluator = new ConventionalityEvaluator(config);
|
|
2211
|
+
return evaluator.evaluate(text, grade);
|
|
2212
|
+
}
|
|
2002
2213
|
var TextComplexityEvaluator = class _TextComplexityEvaluator extends BaseEvaluator {
|
|
2003
2214
|
static metadata = {
|
|
2004
2215
|
id: "text-complexity",
|
|
2005
2216
|
name: "Text Complexity",
|
|
2006
|
-
description: "Composite evaluator analyzing vocabulary, sentence structure,
|
|
2217
|
+
description: "Composite evaluator analyzing vocabulary, sentence structure, subject matter knowledge, and conventionality complexity",
|
|
2007
2218
|
supportedGrades: ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12"],
|
|
2008
2219
|
requiresGoogleKey: true,
|
|
2009
2220
|
requiresOpenAIKey: true
|
|
@@ -2011,12 +2222,14 @@ var TextComplexityEvaluator = class _TextComplexityEvaluator extends BaseEvaluat
|
|
|
2011
2222
|
vocabularyEvaluator;
|
|
2012
2223
|
sentenceStructureEvaluator;
|
|
2013
2224
|
smkEvaluator;
|
|
2225
|
+
conventionalityEvaluator;
|
|
2014
2226
|
limit;
|
|
2015
2227
|
constructor(config) {
|
|
2016
2228
|
super(config);
|
|
2017
2229
|
this.vocabularyEvaluator = new VocabularyEvaluator(config);
|
|
2018
2230
|
this.sentenceStructureEvaluator = new SentenceStructureEvaluator(config);
|
|
2019
2231
|
this.smkEvaluator = new SmkEvaluator(config);
|
|
2232
|
+
this.conventionalityEvaluator = new ConventionalityEvaluator(config);
|
|
2020
2233
|
this.limit = pLimit(3);
|
|
2021
2234
|
}
|
|
2022
2235
|
/**
|
|
@@ -2042,21 +2255,24 @@ var TextComplexityEvaluator = class _TextComplexityEvaluator extends BaseEvaluat
|
|
|
2042
2255
|
this.validateText(text);
|
|
2043
2256
|
this.validateGrade(grade, new Set(_TextComplexityEvaluator.metadata.supportedGrades));
|
|
2044
2257
|
const startTime = Date.now();
|
|
2045
|
-
const [vocabResult, sentenceResult, smkResult] = await Promise.all([
|
|
2258
|
+
const [vocabResult, sentenceResult, smkResult, conventionalityResult] = await Promise.all([
|
|
2046
2259
|
this.limit(() => this.runSubEvaluator(this.vocabularyEvaluator, text, grade)),
|
|
2047
2260
|
this.limit(() => this.runSubEvaluator(this.sentenceStructureEvaluator, text, grade)),
|
|
2048
|
-
this.limit(() => this.runSubEvaluator(this.smkEvaluator, text, grade))
|
|
2261
|
+
this.limit(() => this.runSubEvaluator(this.smkEvaluator, text, grade)),
|
|
2262
|
+
this.limit(() => this.runSubEvaluator(this.conventionalityEvaluator, text, grade))
|
|
2049
2263
|
]);
|
|
2050
2264
|
const latencyMs = Date.now() - startTime;
|
|
2051
2265
|
const vocabFailed = "error" in vocabResult;
|
|
2052
2266
|
const sentenceFailed = "error" in sentenceResult;
|
|
2053
2267
|
const smkFailed = "error" in smkResult;
|
|
2054
|
-
const
|
|
2268
|
+
const conventionalityFailed = "error" in conventionalityResult;
|
|
2269
|
+
const hasFailures = vocabFailed || sentenceFailed || smkFailed || conventionalityFailed;
|
|
2055
2270
|
if (hasFailures) {
|
|
2056
2271
|
const errors = [];
|
|
2057
2272
|
if (vocabFailed) errors.push(`Vocabulary: ${vocabResult.error.message}`);
|
|
2058
2273
|
if (sentenceFailed) errors.push(`Sentence structure: ${sentenceResult.error.message}`);
|
|
2059
2274
|
if (smkFailed) errors.push(`Subject matter knowledge: ${smkResult.error.message}`);
|
|
2275
|
+
if (conventionalityFailed) errors.push(`Conventionality: ${conventionalityResult.error.message}`);
|
|
2060
2276
|
this.logger.error("Text complexity evaluation completed with errors", {
|
|
2061
2277
|
evaluator: "text-complexity",
|
|
2062
2278
|
operation: "evaluate",
|
|
@@ -2064,7 +2280,7 @@ var TextComplexityEvaluator = class _TextComplexityEvaluator extends BaseEvaluat
|
|
|
2064
2280
|
errors,
|
|
2065
2281
|
processingTimeMs: latencyMs
|
|
2066
2282
|
});
|
|
2067
|
-
if (vocabFailed && sentenceFailed && smkFailed) {
|
|
2283
|
+
if (vocabFailed && sentenceFailed && smkFailed && conventionalityFailed) {
|
|
2068
2284
|
throw new Error(`Text complexity evaluation failed: ${errors.join("; ")}`);
|
|
2069
2285
|
}
|
|
2070
2286
|
}
|
|
@@ -2085,7 +2301,7 @@ var TextComplexityEvaluator = class _TextComplexityEvaluator extends BaseEvaluat
|
|
|
2085
2301
|
processingTimeMs: latencyMs,
|
|
2086
2302
|
hasFailures
|
|
2087
2303
|
});
|
|
2088
|
-
return { vocabulary: vocabResult, sentenceStructure: sentenceResult, subjectMatterKnowledge: smkResult };
|
|
2304
|
+
return { vocabulary: vocabResult, sentenceStructure: sentenceResult, subjectMatterKnowledge: smkResult, conventionality: conventionalityResult };
|
|
2089
2305
|
}
|
|
2090
2306
|
/**
|
|
2091
2307
|
* Run a sub-evaluator with error handling.
|
|
@@ -2104,6 +2320,6 @@ async function evaluateTextComplexity(text, grade, config) {
|
|
|
2104
2320
|
return evaluator.evaluate(text, grade);
|
|
2105
2321
|
}
|
|
2106
2322
|
|
|
2107
|
-
export { APIError, AuthenticationError, ComplexityClassificationSchema, ConfigurationError, EvaluatorError, GradeBand, GradeLevelAppropriatenessEvaluator, GradeLevelAppropriatenessSchema, LogLevel, NetworkError, RateLimitError, SentenceAnalysisSchema, SentenceStructureEvaluator, SmkEvaluator, TextComplexityEvaluator, TextComplexityLevel, TimeoutError, ValidationError, VocabularyEvaluator, addEngineeredFeatures, calculateFleschKincaidGrade, calculateReadabilityMetrics, evaluateGradeLevelAppropriateness, evaluateSentenceStructure, evaluateSmk, evaluateTextComplexity, evaluateVocabulary, featuresToJSON };
|
|
2323
|
+
export { APIError, AuthenticationError, ComplexityClassificationSchema, ConfigurationError, ConventionalityEvaluator, EvaluatorError, GradeBand, GradeLevelAppropriatenessEvaluator, GradeLevelAppropriatenessSchema, LogLevel, NetworkError, RateLimitError, SentenceAnalysisSchema, SentenceStructureEvaluator, SmkEvaluator, TextComplexityEvaluator, TextComplexityLevel, TimeoutError, ValidationError, VocabularyEvaluator, addEngineeredFeatures, calculateFleschKincaidGrade, calculateReadabilityMetrics, evaluateConventionality, evaluateGradeLevelAppropriateness, evaluateSentenceStructure, evaluateSmk, evaluateTextComplexity, evaluateVocabulary, featuresToJSON };
|
|
2108
2324
|
//# sourceMappingURL=index.js.map
|
|
2109
2325
|
//# sourceMappingURL=index.js.map
|