23 lines
626 B
TypeScript
23 lines
626 B
TypeScript
import type { ChatModel } from "./modelRegistry.js";
|
|
|
|
export type TemplateContext = {
|
|
draw: number;
|
|
model: ChatModel;
|
|
startedAt: Date;
|
|
};
|
|
|
|
export const renderPrompt = (template: string, context: TemplateContext) => {
|
|
const values: Record<string, string> = {
|
|
draw: String(context.draw),
|
|
model: context.model.label,
|
|
provider: context.model.providerName,
|
|
now: context.startedAt.toLocaleString("zh-CN", { hour12: false }),
|
|
timestamp: context.startedAt.toISOString()
|
|
};
|
|
|
|
return template.replace(/\{\{\s*([a-zA-Z0-9_-]+)\s*\}\}/g, (match, key: string) => {
|
|
return values[key] ?? match;
|
|
});
|
|
};
|
|
|