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

Function buildPythonScript

src/assertions/python.ts:7–30  ·  view source on GitHub ↗
(renderedValue: string)

Source from the content-addressed store, hash-verified

5import type { AssertionParams, GradingResult } from '../types/index';
6
7function buildPythonScript(renderedValue: string): string {
8 const isMultiline = renderedValue.includes('\n');
9 let indentStyle = ' ';
10 if (isMultiline) {
11 // Detect the indentation style of the first indented line.
12 const match = renderedValue.match(/^(?!\s*$)\s+/m);
13 if (match) {
14 indentStyle = match[0];
15 }
16 }
17
18 return `import json
19
20def main(output, context):
21${
22 isMultiline
23 ? renderedValue
24 .split('\n')
25 .map((line) => `${indentStyle}${line}`)
26 .join('\n')
27 : ` return ${renderedValue}`
28}
29`;
30}
31
32export const handlePython = async ({
33 assertion,

Callers 1

handlePythonFunction · 0.85

Calls 1

splitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…