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
19 changes: 7 additions & 12 deletions runner/configuration/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import {
RootPromptDefinition,
} from '../shared-interfaces.js';
import { Rating } from '../ratings/rating-types.js';
import {
extractPromptContextFilePatterns,
renderHandlebarsTemplate,
} from './prompt-templating.js';
import { renderHandlebarsTemplate } from './prompt-templating.js';
import { McpServerOptions } from '../codegen/llm-runner.js';
import { lazy } from '../utils/lazy-creation.js';
import { EnvironmentConfig } from './environment-config.js';
Expand Down Expand Up @@ -120,21 +117,21 @@ export class Environment {
}

systemPromptGeneration = lazy(() => {
return this.renderRelativePrompt(this.config.generationSystemPrompt);
return this.renderRelativePrompt(this.config.generationSystemPrompt).result;
});

systemPromptRepair = lazy(() => {
if (!this.config.repairSystemPrompt) {
return 'Please fix the given errors and return the corrected code.';
}
return this.renderRelativePrompt(this.config.repairSystemPrompt);
return this.renderRelativePrompt(this.config.repairSystemPrompt).result;
});

systemPromptEditing = lazy(() => {
if (!this.config.editingSystemPrompt) {
return this.systemPromptGeneration();
}
return this.renderRelativePrompt(this.config.editingSystemPrompt);
return this.renderRelativePrompt(this.config.editingSystemPrompt).result;
});

/**
Expand Down Expand Up @@ -275,14 +272,12 @@ export class Environment {
ratings: Rating[],
isEditing: boolean
): PromptDefinition {
const { promptText, contextFiles } = extractPromptContextFilePatterns(
this.renderRelativePrompt(relativePath)
);
const { result, contextFiles } = this.renderRelativePrompt(relativePath);

return {
name: name,
kind: 'single',
prompt: promptText,
prompt: result,
ratings,
systemPromptType: isEditing ? 'editing' : 'generation',
contextFilePatterns: contextFiles,
Expand Down Expand Up @@ -387,7 +382,7 @@ export class Environment {
}

/** Renders a prompt from a path relative to the environment config. */
private renderRelativePrompt(relativePath: string): string {
private renderRelativePrompt(relativePath: string) {
const path = resolve(this.rootPath, relativePath);
return this.renderPrompt(readFileSync(path, 'utf8'), path);
}
Expand Down
17 changes: 3 additions & 14 deletions runner/configuration/prompt-templating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,10 @@ initializeHandlebars();
export function renderHandlebarsTemplate<T extends { rootDir: string | null }>(
content: string,
ctx: T
): string {
) {
const template = Handlebars.compile(content, { strict: true });
return template(ctx);
}

/**
* Extracts the context file patterns from a prompt's text. Returns the prompt's text without
* any special context file syntax and the context file patterns.
* @param initialPromptText Initial text of the prompt.
*/
export function extractPromptContextFilePatterns(initialPromptText: string) {
const contextFiles: string[] = [];
const promptText = Handlebars.compile(initialPromptText, {
strict: true,
})(null, {
const result = template(ctx, {
partials: {
contextFiles: (ctx) => {
if (typeof ctx !== 'string') {
Expand Down Expand Up @@ -84,7 +73,7 @@ export function extractPromptContextFilePatterns(initialPromptText: string) {
});

return {
promptText,
result,
contextFiles,
};
}
2 changes: 1 addition & 1 deletion runner/ratings/autoraters/code-rater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function autoRateCode(
const prompt = environment.renderPrompt(promptText, null, {
APP_PROMPT: appPrompt,
FRAMEWORK_SPECIFIC_HINTS: FW_HINTS[environment.fullStackFramework.id] ?? '',
});
}).result;

const result = await llm.generateConstrained({
abortSignal,
Expand Down
2 changes: 1 addition & 1 deletion runner/ratings/autoraters/visuals-rater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function autoRateAppearance(
): Promise<AutoRateResult> {
const prompt = environment.renderPrompt(defaultVisualRaterPrompt, null, {
APP_PROMPT: appPrompt,
});
}).result;

const messages: PromptDataMessage[] = [
{
Expand Down
Loading