Skip to content

Commit

Permalink
docs: Fix preset loading error
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Nov 11, 2024
1 parent 2ecc16f commit f01d578
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"name": "@tolgee/ai-migrator",
"version": "1.0.0-alpha.4",
"version": "1.0.0-alpha.7",
"description": "AI migration tool to migrate your project from raw string to Tolgee SDKs",
"bin": {
"tolgee-migrator": "./dist/src/cli.js"
},
"type": "commonjs",
"repository": {
"type": "git",
"url": "git+https://github.com/tolgee/ai-migrator.git"
}, "type": "commonjs",
"scripts": {
"build": "tsc && tsx scripts/copyResources.ts",
"test:unit": "jest tests/**",
Expand Down
18 changes: 14 additions & 4 deletions src/presets/buildNativePreset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,31 @@ import fs from 'node:fs';
import path from 'node:path';
import Handlebars from 'handlebars';
import { PresetType } from './PresetType';
import { ExpectedError } from '../common/ExpectedError';

export function buildNativePreset(name: string): PresetType {
function getPromptContents(fileName: string) {
return fs.readFileSync(path.resolve(__dirname, name, fileName), 'utf8');
const presetPath = path.resolve(__dirname, name, fileName);
try {
return fs.readFileSync(presetPath, 'utf8');
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (_) {
throw new ExpectedError(
`Failed to open preset file on ${presetPath}.\nDoes the ${name} preset exist?`
);
}
}

const systemTemplateRaw = getPromptContents('system.handlebars');
const userTemplateRaw = getPromptContents('user.handlebars');

function getSystemPrompt() {
const systemTemplateRaw = getPromptContents('system.handlebars');
const systemTemplate = Handlebars.compile(systemTemplateRaw);
return systemTemplate({});
}

function getUserPrompt(props: { fileContent: string }) {
const systemTemplateRaw = getPromptContents('user.handlebars');
const systemTemplate = Handlebars.compile(systemTemplateRaw);
const systemTemplate = Handlebars.compile(userTemplateRaw);
return systemTemplate(props);
}

Expand Down

0 comments on commit f01d578

Please sign in to comment.