main: 初始化 Face to API 项目
- 添加前端抽卡台与模型配置界面 - 添加 Express API 服务与多厂商模型调用适配 - 配置本地环境示例、构建脚本和忽略规则
This commit is contained in:
22
server/template.ts
Normal file
22
server/template.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
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;
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user