Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions js/src/framework.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,63 @@ describe("framework2 metadata support", () => {
expect(scorers).toHaveLength(1);
expect(scorers[0].tags).toBeUndefined();
});

test("LLM scorer (chat) stores templateFormat in promptData", () => {
const project = projects.create({ name: "test-project" });

project.scorers.create({
name: "nunjucks-scorer",
messages: [{ role: "user", content: "Grade: {{ output }}" }],
model: "gpt-4o",
useCot: true,
choiceScores: { pass: 1, fail: 0 },
templateFormat: "nunjucks",
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const prompts = (project as any)._publishablePrompts;
expect(prompts).toHaveLength(1);
// template_format must be present on the stored PromptData, which is
// spread directly into the API payload by toFunctionDefinition().
expect(prompts[0].prompt.template_format).toBe("nunjucks");
});

test("LLM scorer (completion) stores templateFormat in promptData", () => {
const project = projects.create({ name: "test-project" });

project.scorers.create({
name: "none-format-scorer",
prompt: "Grade the output.",
model: "gpt-4o",
useCot: false,
choiceScores: { pass: 1, fail: 0 },
templateFormat: "none",
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const prompts = (project as any)._publishablePrompts;
expect(prompts).toHaveLength(1);
expect(prompts[0].prompt.template_format).toBe("none");
});

test("LLM scorer without templateFormat leaves template_format absent", () => {
const project = projects.create({ name: "test-project" });

project.scorers.create({
name: "default-format-scorer",
prompt: "Is this correct?",
model: "gpt-4o",
useCot: false,
choiceScores: { yes: 1, no: 0 },
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const prompts = (project as any)._publishablePrompts;
expect(prompts).toHaveLength(1);
// No templateFormat passed → field must be absent so the API applies its
// own default rather than receiving an explicit undefined.
expect(prompts[0].prompt.template_format).toBeUndefined();
});
});

describe("Project with messages", () => {
Expand Down
3 changes: 3 additions & 0 deletions js/src/framework2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ export class ScorerBuilder {
use_cot: opts.useCot,
choice_scores: opts.choiceScores,
},
...(opts.templateFormat
? { template_format: opts.templateFormat }
: {}),
};
const codePrompt = new CodePrompt(
this.project,
Expand Down
Loading