Skip to content

Commit c64d8da

Browse files
committed
make genearal evaluator 2nd arg optional
update tests and some example usages that were passing an empty arg in those cases
1 parent 1dde10f commit c64d8da

4 files changed

Lines changed: 8 additions & 7 deletions

File tree

packages/langium-ai-mcp/src/mcp-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ server.registerTool(
3434
export const langiumEvaluator = new LangiumEvaluator(createLangiumGrammarServices(NodeFileSystem).grammar);
3535

3636
export async function validateLangiumCode(code: string): Promise<string | undefined> {
37-
const evalResult = await langiumEvaluator.evaluate(code, '');
37+
const evalResult = await langiumEvaluator.evaluate(code);
3838
if (evalResult.data) {
3939
const langiumData = evalResult.data;
4040
if (langiumData.diagnostics.length > 0) {

packages/langium-ai-tools/src/evaluator/document-evaluator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ export abstract class AbstractDocumentEvaluator<
3030
* Validate an agent response as if it's a langium program. If we can parse it, we attempt to validate it.
3131
*
3232
* @param input The input to compare
33-
* @param expected_response Th expected response to compare against (unused in this evaluator)
34-
* @param fileExtension The extension of the language to apply explicitly,
33+
* @param expected_response Optional expected response to compare against (unused in this evaluator)
34+
* @param fileExtension Optional extension of the language to apply explicitly,
3535
* otherwise the first one that's registered will be applied from the services
3636
*/
37-
async evaluate(input: string, _expected_response: string, fileExtension?: string): Promise<EvaluatorResult<RD>> {
37+
async evaluate(input: string, _expected_response?: string, fileExtension?: string): Promise<EvaluatorResult<RD>> {
3838
if (input.includes('```')) {
3939
// take the first code block instead, if present (assuming it's a langium grammar)
4040
const codeBlock = input.split(/```[a-z-]*/)[1];

packages/langium-ai-tools/src/evaluator/evaluator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ export function loadLastResults(dir: string, take?: number): EvaluatorResult[] {
219219
*/
220220
export abstract class Evaluator {
221221
/**
222-
* Run an evaluation over some response and compare with an expected one.
222+
* Run an evaluation over some response, possibly compares with an expected one if provided
223223
* Produces a complete evaluator result (name, metadata & data).
224224
*/
225-
abstract evaluate(response: string, expected_response: string): Promise<EvaluatorResult>;
225+
abstract evaluate(response: string, expected_response?: string): Promise<EvaluatorResult>;
226226
}
227227

228228
export function mergeEvaluators(...evaluators: Evaluator[]): Evaluator {

packages/langium-ai-tools/tests/evaluator.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
mergeEvaluators,
1313
} from '../src/evaluator/evaluator.js';
1414
import { LangiumEvaluator } from '../src/evaluator/langium-evaluator.js';
15+
import { LangiumServices } from 'langium/lsp';
1516

1617
// create test services using the same domain model grammar as document-analyzer tests
1718
const domainModelServices = await createServicesForGrammar({
@@ -338,7 +339,7 @@ describe('Evaluator Utility Functions', () => {
338339
});
339340

340341
describe('LangiumEvaluator', () => {
341-
let evaluator: LangiumEvaluator;
342+
let evaluator: LangiumEvaluator<LangiumServices>;
342343

343344
beforeEach(() => {
344345
// create a fresh evaluator instance before each test to ensure clean state

0 commit comments

Comments
 (0)