Skip to content

Commit fdb65e6

Browse files
committed
lint and fix
1 parent bd61828 commit fdb65e6

File tree

5 files changed

+64
-49
lines changed

5 files changed

+64
-49
lines changed

apps/hash-ai-agent/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"scripts": {
1010
"build": "mastra build",
1111
"dev": "mastra dev",
12-
"generate-schemas": "tsx src/mastra/fixtures/generate-schemas.ts",
1312
"fix": "npm-run-all --continue-on-error \"fix:*\"",
1413
"fix:eslint": "eslint --fix .",
1514
"fix:format": "biome format --write",
15+
"generate-schemas": "tsx src/mastra/fixtures/generate-schemas.ts",
1616
"lint": "npm-run-all --continue-on-error \"lint:*\"",
1717
"lint:eslint": "eslint --report-unused-disable-directives .",
1818
"lint:tsc": "tsc --noEmit",
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { Agent } from '@mastra/core/agent';
1+
import { Agent } from "@mastra/core/agent";
22

3-
import { DEFAULT_MODEL } from '../constants';
3+
import { DEFAULT_MODEL } from "../constants";
44

55
export const genericAgent = new Agent({
6-
id: 'generic-agent',
7-
name: 'Generic Agent',
8-
instructions: ['You are a generic AI agent, designed to handle a variety of tasks.'],
6+
id: "generic-agent",
7+
name: "Generic Agent",
8+
instructions: [
9+
"You are a generic AI agent, designed to handle a variety of tasks.",
10+
],
911
model: DEFAULT_MODEL,
1012
});

apps/hash-ai-agent/src/mastra/scorers/ner-people-scorer.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { createScorer } from '@mastra/core/evals';
2-
import { z } from 'zod';
1+
import { createScorer } from "@mastra/core/evals";
2+
import { z } from "zod";
33

4-
import { DEFAULT_MODEL, NAME_PROPERTY } from '../constants';
4+
import { DEFAULT_MODEL, NAME_PROPERTY } from "../constants";
55

66
/** Schema for extracted person entity */
77
const zPersonEntity = z
@@ -41,8 +41,8 @@ const zAnalysisResult = z.object({
4141
* (e.g., "Bill Gates" matches "William Gates").
4242
*/
4343
export const nerPeopleScorer = createScorer({
44-
id: 'ner-people',
45-
description: 'Evaluates NER people extraction against expected persons list',
44+
id: "ner-people",
45+
description: "Evaluates NER people extraction against expected persons list",
4646
judge: {
4747
model: DEFAULT_MODEL,
4848
instructions: `You are an expert at comparing person names for semantic equivalence.
@@ -59,31 +59,38 @@ Be precise: only match names that clearly refer to the same real-world person.`,
5959

6060
if (!Array.isArray(output)) {
6161
// eslint-disable-next-line no-console
62-
console.warn('[nerPeopleScorer] Expected run.output to be an array, got:', typeof output);
62+
console.warn(
63+
"[nerPeopleScorer] Expected run.output to be an array, got:",
64+
typeof output,
65+
);
6366
} else {
6467
for (const person of output) {
6568
const personObj = person as Record<string, unknown>;
6669
const name = personObj[NAME_PROPERTY];
67-
if (typeof name === 'string') {
70+
if (typeof name === "string") {
6871
extractedNames.push(name);
6972
}
7073
}
7174
}
7275

7376
// Parse ground truth
7477
const groundTruth = zGroundTruth.parse(run.groundTruth);
75-
const expectedNames = groundTruth.expectedPersons.map((person) => person[NAME_PROPERTY]);
78+
const expectedNames = groundTruth.expectedPersons.map(
79+
(person) => person[NAME_PROPERTY],
80+
);
7681

7782
return { extractedNames, expectedNames };
7883
})
7984
.analyze({
80-
description: 'Match extracted person names against expected persons using fuzzy matching',
85+
description:
86+
"Match extracted person names against expected persons using fuzzy matching",
8187
outputSchema: zAnalysisResult,
8288
createPrompt: ({ results }) => {
83-
const { extractedNames, expectedNames } = results.preprocessStepResult as {
84-
extractedNames: string[];
85-
expectedNames: string[];
86-
};
89+
const { extractedNames, expectedNames } =
90+
results.preprocessStepResult as {
91+
extractedNames: string[];
92+
expectedNames: string[];
93+
};
8794
return `Compare extracted person names against expected names.
8895
8996
EXTRACTED PERSONS (from NER step):
@@ -113,18 +120,24 @@ Return JSON with:
113120
// - Recall (finding expected persons): 70% weight
114121
// - Precision (not having false positives): 30% weight
115122
const recall = matchedPersons.length / totalExpected;
116-
const precision = totalExtracted > 0 ? matchedPersons.length / totalExtracted : 1;
123+
const precision =
124+
totalExtracted > 0 ? matchedPersons.length / totalExtracted : 1;
117125

118126
return 0.7 * recall + 0.3 * precision;
119127
})
120128
.generateReason(({ results, score }) => {
121-
const { matchedPersons, missingPersons, extraPersons, totalExtracted, totalExpected } =
122-
results.analyzeStepResult;
129+
const {
130+
matchedPersons,
131+
missingPersons,
132+
extraPersons,
133+
totalExtracted,
134+
totalExpected,
135+
} = results.analyzeStepResult;
123136

124137
return (
125138
`Score: ${score.toFixed(2)}. Found ${matchedPersons.length}/${totalExpected} expected persons. ` +
126-
`${missingPersons.length > 0 ? `Missing: ${missingPersons.join(', ')}. ` : ''}` +
127-
`${extraPersons.length > 0 ? `Extra: ${extraPersons.join(', ')}. ` : ''}` +
139+
`${missingPersons.length > 0 ? `Missing: ${missingPersons.join(", ")}. ` : ""}` +
140+
`${extraPersons.length > 0 ? `Extra: ${extraPersons.join(", ")}. ` : ""}` +
128141
`Total extracted: ${totalExtracted}.`
129142
);
130143
});

apps/hash-ai-agent/src/mastra/workflows/ner-people-workflow.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { createStep, createWorkflow } from '@mastra/core/workflows';
2-
import { type TSchema, Type } from '@sinclair/typebox';
3-
import dedent from 'dedent';
4-
import { z } from 'zod';
1+
import { createStep, createWorkflow } from "@mastra/core/workflows";
2+
import { type TSchema, Type } from "@sinclair/typebox";
3+
import dedent from "dedent";
4+
import { z } from "zod";
55

6-
import { nerAgent } from '../agents/ner-agent';
7-
import personSchemaDereferenced from '../fixtures/entity-schemas/person.dereferenced.json';
8-
import { schemaToPromptSummary } from '../utils/schema-to-prompt-summary';
6+
import { nerAgent } from "../agents/ner-agent";
7+
import personSchemaDereferenced from "../fixtures/entity-schemas/person.dereferenced.json";
8+
import { schemaToPromptSummary } from "../utils/schema-to-prompt-summary";
99

1010
const nerPeopleInputSchema = z.object({
1111
sourceText: z.string(),
@@ -16,7 +16,7 @@ const nerPeopleInputSchema = z.object({
1616
const nerPeopleOutputSchema = z.array(z.any());
1717

1818
export const nerPeopleStep = createStep({
19-
id: 'ner-people-step',
19+
id: "ner-people-step",
2020

2121
inputSchema: nerPeopleInputSchema,
2222
outputSchema: nerPeopleOutputSchema,
@@ -47,20 +47,20 @@ ${sourceText}
4747
{
4848
structuredOutput: {
4949
schema: Type.Array(personSchemaDereferenced as unknown as TSchema, {
50-
$id: 'https://my-internal/wrapper-array',
51-
title: 'EntityArray',
50+
$id: "https://my-internal/wrapper-array",
51+
title: "EntityArray",
5252
}),
5353
},
54-
}
54+
},
5555
);
5656
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
5757
return response.object;
5858
},
5959
});
6060

6161
export const nerPeopleWorkflow = createWorkflow({
62-
id: 'ner-people-workflow',
63-
description: 'Workflow to extract people entities from text using NER.',
62+
id: "ner-people-workflow",
63+
description: "Workflow to extract people entities from text using NER.",
6464
inputSchema: nerPeopleInputSchema,
6565
outputSchema: nerPeopleOutputSchema,
6666
})

yarn.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,6 @@ __metadata:
258258
languageName: node
259259
linkType: hard
260260

261-
"@apidevtools/json-schema-ref-parser@npm:11.9.3, @apidevtools/json-schema-ref-parser@npm:^11.5.5":
262-
version: 11.9.3
263-
resolution: "@apidevtools/json-schema-ref-parser@npm:11.9.3"
264-
dependencies:
265-
"@jsdevtools/ono": "npm:^7.1.3"
266-
"@types/json-schema": "npm:^7.0.15"
267-
js-yaml: "npm:^4.1.0"
268-
checksum: 10c0/5745813b3d964279f387677b7a903ba6634cdeaf879ff3a331a694392cbc923763f398506df190be114f2574b8b570baab3e367c2194bb35f50147ff6cf27d7a
269-
languageName: node
270-
linkType: hard
271-
272261
"@apidevtools/json-schema-ref-parser@npm:15.1.3":
273262
version: 15.1.3
274263
resolution: "@apidevtools/json-schema-ref-parser@npm:15.1.3"
@@ -280,6 +269,17 @@ __metadata:
280269
languageName: node
281270
linkType: hard
282271

272+
"@apidevtools/json-schema-ref-parser@npm:^11.5.5":
273+
version: 11.9.3
274+
resolution: "@apidevtools/json-schema-ref-parser@npm:11.9.3"
275+
dependencies:
276+
"@jsdevtools/ono": "npm:^7.1.3"
277+
"@types/json-schema": "npm:^7.0.15"
278+
js-yaml: "npm:^4.1.0"
279+
checksum: 10c0/5745813b3d964279f387677b7a903ba6634cdeaf879ff3a331a694392cbc923763f398506df190be114f2574b8b570baab3e367c2194bb35f50147ff6cf27d7a
280+
languageName: node
281+
linkType: hard
282+
283283
"@apidevtools/json-schema-ref-parser@npm:^14.2.1":
284284
version: 14.2.1
285285
resolution: "@apidevtools/json-schema-ref-parser@npm:14.2.1"
@@ -5606,7 +5606,7 @@ __metadata:
56065606
version: 0.0.0-use.local
56075607
resolution: "@blockprotocol/graph@workspace:libs/@blockprotocol/graph"
56085608
dependencies:
5609-
"@apidevtools/json-schema-ref-parser": "npm:11.9.3"
5609+
"@apidevtools/json-schema-ref-parser": "npm:15.1.3"
56105610
"@blockprotocol/core": "npm:0.1.4"
56115611
"@blockprotocol/type-system": "npm:0.1.2-canary.1"
56125612
"@local/eslint": "npm:0.0.0-private"

0 commit comments

Comments
 (0)