MCPcopy Index your code
hub / github.com/promptfoo/promptfoo / getFileTransformFunction

Function getFileTransformFunction

src/util/transform.ts:115–128  ·  view source on GitHub ↗

* Retrieves a transform function from a file, supporting both JavaScript and Python. * @param filePath - The path to the file, including the 'file://' prefix. * @returns A Promise resolving to the requested function. * @throws Error if the file format is unsupported.

(filePath: string)

Source from the content-addressed store, hash-verified

113 * @throws Error if the file format is unsupported.
114 */
115async function getFileTransformFunction(filePath: string): Promise<Function> {
116 const [actualFilePath, functionName] = parseFilePathAndFunctionName(
117 filePath.slice('file://'.length),
118 );
119
120 const fullPath = safeJoin(cliState.basePath || '', actualFilePath);
121
122 if (isJavascriptFile(fullPath)) {
123 return getJavascriptTransformFunction(fullPath, functionName);
124 } else if (fullPath.endsWith('.py')) {
125 return getPythonTransformFunction(fullPath, functionName);
126 }
127 throw new Error(`Unsupported transform file format: file://${actualFilePath}`);
128}
129
130/**
131 * Creates a function from inline JavaScript code.

Callers 1

getTransformFunctionFunction · 0.85

Calls 5

safeJoinFunction · 0.90
isJavascriptFileFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…