escape {} in prompt

This commit is contained in:
an-lee
2024-10-13 12:01:15 +08:00
parent 5fbe381038
commit 9deed980ba
2 changed files with 6 additions and 2 deletions

View File

@@ -30,13 +30,15 @@ export const chatSuggestionCommand = async (
),
});
const formattedContext = context.replace(/\{/g, "{{").replace(/\}/g, "}}");
const prompt = await ChatPromptTemplate.fromMessages([
["system", SYSTEM_PROMPT],
["human", PROMPT],
]).format({
native_language: nativeLanguage,
learning_language: learningLanguage,
context,
context: formattedContext,
});
return jsonCommand(prompt, { ...options, schema });

View File

@@ -19,13 +19,15 @@ export const refineCommand = async (
if (!text) throw new Error("Text is required");
const { learningLanguage, nativeLanguage, context = "None" } = params;
const formattedContext = context.replace(/\{/g, "{{").replace(/\}/g, "}}");
const prompt = await ChatPromptTemplate.fromMessages([
["system", SYSTEM_PROMPT],
["human", text],
]).format({
learning_language: LANGUAGES.find((l) => l.code === learningLanguage).name,
native_language: LANGUAGES.find((l) => l.code === nativeLanguage).name,
context,
context: formattedContext,
});
return textCommand(prompt, options);