MCPcopy
hub / github.com/promptfoo/promptfoo / parseConfigSystemInstruction

Function parseConfigSystemInstruction

src/providers/google/util.ts:1046–1082  ·  view source on GitHub ↗
(
  configSystemInstruction: Content | string | undefined,
  contextVars?: Record<string, VarValue>,
)

Source from the content-addressed store, hash-verified

1044 * @returns Processed Content object or undefined
1045 */
1046export function parseConfigSystemInstruction(
1047 configSystemInstruction: Content | string | undefined,
1048 contextVars?: Record<string, VarValue>,
1049): Content | undefined {
1050 if (!configSystemInstruction) {
1051 return undefined;
1052 }
1053
1054 // Make a copy to avoid mutating the original
1055 let configInstruction = clone(configSystemInstruction);
1056
1057 // Load systemInstruction from file if it's a file path
1058 if (typeof configSystemInstruction === 'string') {
1059 configInstruction = loadFile(configSystemInstruction, contextVars);
1060 }
1061
1062 // Convert string to Content structure
1063 if (typeof configInstruction === 'string') {
1064 configInstruction = { parts: [{ text: configInstruction }] };
1065 }
1066
1067 // Render Nunjucks templates in all text parts
1068 if (contextVars && configInstruction) {
1069 const nunjucks = getNunjucksEngine();
1070 for (const part of configInstruction.parts) {
1071 if (part.text) {
1072 try {
1073 part.text = nunjucks.renderString(part.text, contextVars);
1074 } catch (err) {
1075 throw new Error(`Unable to render nunjucks in systemInstruction: ${err}`);
1076 }
1077 }
1078 }
1079 }
1080
1081 return configInstruction;
1082}
1083
1084export function geminiFormatAndSystemInstructions(
1085 prompt: string,

Callers 2

callClaudeApiMethod · 0.90

Calls 3

getNunjucksEngineFunction · 0.90
cloneFunction · 0.85
loadFileFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…