Skip to content

Commit f29d165

Browse files
christsoCopilot
andcommitted
fix(cli): update assertion scaffold to use Message arrays instead of removed outputText
The outputText field was removed from CodeGraderInput. Update the agentv create assertion template to extract text from output Message arrays using a getMessageText() helper. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 65299ed commit f29d165

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

apps/cli/src/commands/create/commands.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,23 @@ const ASSERTION_TEMPLATES: Record<string, string> = {
66
default: `#!/usr/bin/env bun
77
import { defineAssertion } from '@agentv/eval';
88
9-
export default defineAssertion(({ outputText }) => {
9+
/** Extract text from the last message with the given role. */
10+
function getMessageText(messages: Array<{ role: string; content?: unknown }>, role = 'assistant'): string {
11+
for (let i = messages.length - 1; i >= 0; i--) {
12+
const msg = messages[i];
13+
if (msg.role !== role) continue;
14+
if (typeof msg.content === 'string') return msg.content;
15+
if (Array.isArray(msg.content)) {
16+
return msg.content.filter((b: any) => b.type === 'text').map((b: any) => b.text).join('\\n');
17+
}
18+
}
19+
return '';
20+
}
21+
22+
export default defineAssertion(({ output }) => {
1023
// TODO: Implement your assertion logic
11-
const pass = outputText.length > 0;
24+
const text = getMessageText(output ?? []);
25+
const pass = text.length > 0;
1226
return {
1327
pass,
1428
reasoning: pass ? 'Output has content' : 'Output is empty',
@@ -18,9 +32,23 @@ export default defineAssertion(({ outputText }) => {
1832
score: `#!/usr/bin/env bun
1933
import { defineAssertion } from '@agentv/eval';
2034
21-
export default defineAssertion(({ outputText }) => {
35+
/** Extract text from the last message with the given role. */
36+
function getMessageText(messages: Array<{ role: string; content?: unknown }>, role = 'assistant'): string {
37+
for (let i = messages.length - 1; i >= 0; i--) {
38+
const msg = messages[i];
39+
if (msg.role !== role) continue;
40+
if (typeof msg.content === 'string') return msg.content;
41+
if (Array.isArray(msg.content)) {
42+
return msg.content.filter((b: any) => b.type === 'text').map((b: any) => b.text).join('\\n');
43+
}
44+
}
45+
return '';
46+
}
47+
48+
export default defineAssertion(({ output }) => {
2249
// TODO: Implement your scoring logic (0.0 to 1.0)
23-
const score = outputText.length > 0 ? 1.0 : 0.0;
50+
const text = getMessageText(output ?? []);
51+
const score = text.length > 0 ? 1.0 : 0.0;
2452
return {
2553
pass: score >= 0.5,
2654
score,

0 commit comments

Comments
 (0)