(
filePath: string,
context: {
vars: Record<string, VarValue>;
provider?: ApiProvider;
config?: Record<string, unknown>;
},
)
| 47 | * @returns The prompts |
| 48 | */ |
| 49 | export 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. |
no test coverage detected
searching dependent graphs…