MCPcopy Create free account
hub / github.com/promptfoo/promptfoo / pythonPromptFunctionLegacy

Function pythonPromptFunctionLegacy

src/prompts/processors/python.ts:49–76  ·  view source on GitHub ↗
(
  filePath: string,
  context: {
    vars: Record<string, VarValue>;
    provider?: ApiProvider;
    config?: Record<string, unknown>;
  },
)

Source from the content-addressed store, hash-verified

47 * @returns The prompts
48 */
49export const pythonPromptFunctionLegacy = async (
50 filePath: string,
51 context: {
52 vars: Record<string, VarValue>;
53 provider?: ApiProvider;
54 config?: Record<string, unknown>;
55 },
56): Promise<string> => {
57 invariant(context?.provider?.id, 'provider.id is required');
58 const transformedContext: PromptFunctionContext = {
59 vars: context.vars,
60 provider: {
61 id:
62 typeof context.provider?.id === 'function' ? context.provider?.id() : context.provider?.id,
63 label: context.provider?.label,
64 },
65 config: context.config ?? {},
66 };
67 const options: PythonShellOptions = {
68 mode: 'text',
69 pythonPath: getEnvString('PROMPTFOO_PYTHON', 'python'),
70 args: [safeJsonStringify(transformedContext) as string],
71 };
72 logger.debug(`Executing python prompt script ${filePath}`);
73 const results = (await PythonShell.run(filePath, options)).join('\n');
74 logger.debug(`Python prompt script ${filePath} returned: ${results}`);
75 return results;
76};
77
78/**
79 * Processes a Python file to extract or execute a function as a prompt.

Callers 2

processPythonFileFunction · 0.85

Calls 5

getEnvStringFunction · 0.90
safeJsonStringifyFunction · 0.90
invariantFunction · 0.85
idMethod · 0.65
runMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…