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

Method initialize

src/providers/pythonCompletion.ts:210–258  ·  view source on GitHub ↗

* Process any file:// references in the configuration and initialize worker pool * This should be called after initialization * @returns A promise that resolves when all file references have been processed

()

Source from the content-addressed store, hash-verified

208 * @returns A promise that resolves when all file references have been processed
209 */
210 public async initialize(): Promise<void> {
211 // If already initialized, return immediately
212 if (this.isInitialized) {
213 return;
214 }
215
216 // If initialization is in progress, return the existing promise
217 if (this.initializationPromise != null) {
218 return this.initializationPromise;
219 }
220
221 // Start initialization and store the promise
222 this.initializationPromise = (async () => {
223 try {
224 this.config = await processConfigFileReferences(
225 this.config,
226 this.options?.config.basePath || '',
227 );
228
229 // Initialize worker pool
230 const workerCount = this.getWorkerCount();
231 const absPath = path.resolve(
232 path.join(this.options?.config.basePath || '', this.scriptPath),
233 );
234
235 this.pool = new PythonWorkerPool(
236 absPath,
237 this.functionName || 'call_api',
238 workerCount,
239 getConfiguredPythonPath(this.config.pythonExecutable),
240 this.config.timeout,
241 );
242
243 await this.pool.initialize();
244
245 // Register for cleanup
246 providerRegistry.register(this);
247
248 this.isInitialized = true;
249 logger.debug(`Initialized Python provider ${this.id()} with ${workerCount} workers`);
250 } catch (error) {
251 // Reset the initialization promise so future calls can retry
252 this.initializationPromise = null;
253 throw error;
254 }
255 })();
256
257 return this.initializationPromise;
258 }
259
260 /**
261 * Determine worker count based on config and environment

Callers 4

executePythonScriptMethod · 0.95
callApiMethod · 0.95
callEmbeddingApiMethod · 0.95
callClassificationApiMethod · 0.95

Calls 6

getWorkerCountMethod · 0.95
idMethod · 0.95
getConfiguredPythonPathFunction · 0.90
resolveMethod · 0.80
registerMethod · 0.65

Tested by

no test coverage detected