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
2 changes: 2 additions & 0 deletions runner/configuration/environment-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export const environmentConfigSchema = z.object({
fullStackFramework: z.string().optional(),
/** Path to the prompt to use when rating code. */
codeRatingPrompt: z.string().optional(),
/** Path to the prompt to use when rating screenshots. */
visualRatingPrompt: z.string().optional(),
/** When enabled, the system prompts for this environment won't be included in the report. */
classifyPrompts: z.boolean().optional(),
/**
Expand Down
5 changes: 5 additions & 0 deletions runner/configuration/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export class Environment {
readonly clientSideFramework: FrameworkInfo;
/** Path from which to read the code rating prompt. */
readonly codeRatingPromptPath: string | null;
/** Path from which to read the visual rating prompt. */
readonly visualRatingPromptPath: string | null;
/** Whether the prompts should be removed from the final report. */
readonly classifyPrompts: boolean;
/** Whether this is one of the built-in environment that come with the runner. */
Expand Down Expand Up @@ -109,6 +111,9 @@ export class Environment {
this.codeRatingPromptPath = config.codeRatingPrompt
? join(rootPath, config.codeRatingPrompt)
: null;
this.visualRatingPromptPath = config.visualRatingPrompt
? join(rootPath, config.visualRatingPrompt)
: null;
this.classifyPrompts = config.classifyPrompts ?? false;
this.isBuiltIn = rootPath.includes('node_modules');
this.executor = config.executor;
Expand Down
17 changes: 16 additions & 1 deletion runner/ratings/autoraters/visuals-rater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {Environment} from '../../configuration/environment.js';
import {screenshotUrlToPngBuffer} from '../../utils/screenshots.js';
import {Usage} from '../../shared-interfaces.js';
import {AiSdkRunner} from '../../codegen/ai-sdk/ai-sdk-runner.js';
import {readFileSync} from 'fs';

/** Cache for visual rating prompts that have been read from disk. */
const CACHED_VISUAL_RATING_PROMPTS: Record<string, string> = {};

/**
* Automatically rate the appearance of a screenshot using an LLM.
Expand All @@ -32,7 +36,18 @@ export async function autoRateAppearance(
screenshotPngUrl: string,
label: string,
): Promise<AutoRateResult> {
const prompt = environment.renderPrompt(defaultVisualRaterPrompt, null, {
let promptText: string;
if (environment.visualRatingPromptPath) {
CACHED_VISUAL_RATING_PROMPTS[environment.visualRatingPromptPath] ??= readFileSync(
environment.visualRatingPromptPath,
'utf8',
);
promptText = CACHED_VISUAL_RATING_PROMPTS[environment.visualRatingPromptPath];
} else {
promptText = defaultVisualRaterPrompt;
}

const prompt = environment.renderPrompt(promptText, environment.visualRatingPromptPath, {
APP_PROMPT: appPrompt,
}).result;

Expand Down
Loading