Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

envars.ts 14 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
  1. import 'dotenv/config';
  2. import cliState from './cliState';
  3. import type { EnvOverrides } from './types/env';
  4. // Define the supported environment variables and their types
  5. export type EnvVars = {
  6. //=========================================================================
  7. // Core promptfoo configuration
  8. //=========================================================================
  9. LOG_LEVEL?: 'error' | 'warn' | 'info' | 'debug';
  10. NODE_ENV?: string;
  11. npm_execpath?: string;
  12. npm_lifecycle_script?: string;
  13. //=========================================================================
  14. // promptfoo feature flags
  15. //=========================================================================
  16. PROMPTFOO_CACHE_ENABLED?: boolean;
  17. PROMPTFOO_DISABLE_AJV_STRICT_MODE?: boolean;
  18. PROMPTFOO_DISABLE_CONVERSATION_VAR?: boolean;
  19. PROMPTFOO_DISABLE_ERROR_LOG?: boolean;
  20. PROMPTFOO_DISABLE_JSON_AUTOESCAPE?: boolean;
  21. PROMPTFOO_DISABLE_MULTIMEDIA_AS_BASE64?: boolean;
  22. PROMPTFOO_DISABLE_OBJECT_STRINGIFY?: boolean;
  23. PROMPTFOO_DISABLE_PDF_AS_TEXT?: boolean;
  24. PROMPTFOO_DISABLE_REDTEAM_MODERATION?: boolean;
  25. PROMPTFOO_DISABLE_REDTEAM_REMOTE_GENERATION?: boolean;
  26. PROMPTFOO_DISABLE_REF_PARSER?: boolean;
  27. PROMPTFOO_DISABLE_SHARE_EMAIL_REQUEST?: boolean;
  28. PROMPTFOO_DISABLE_SHARE_WARNING?: boolean;
  29. PROMPTFOO_DISABLE_SHARING?: boolean;
  30. PROMPTFOO_DISABLE_TELEMETRY?: boolean;
  31. PROMPTFOO_DISABLE_TEMPLATE_ENV_VARS?: boolean;
  32. PROMPTFOO_DISABLE_TEMPLATING?: boolean;
  33. PROMPTFOO_DISABLE_UPDATE?: boolean;
  34. PROMPTFOO_DISABLE_VAR_EXPANSION?: boolean;
  35. PROMPTFOO_DISABLE_WAL_MODE?: boolean;
  36. PROMPTFOO_ENABLE_DATABASE_LOGS?: boolean;
  37. PROMPTFOO_EVAL_TIMEOUT_MS?: number;
  38. PROMPTFOO_EXPERIMENTAL?: boolean;
  39. PROMPTFOO_MAX_EVAL_TIME_MS?: number;
  40. PROMPTFOO_NO_TESTCASE_ASSERT_WARNING?: boolean;
  41. PROMPTFOO_PYTHON_DEBUG_ENABLED?: boolean;
  42. PROMPTFOO_RETRY_5XX?: boolean;
  43. PROMPTFOO_SELF_HOSTED?: boolean;
  44. PROMPTFOO_SHORT_CIRCUIT_TEST_FAILURES?: boolean;
  45. PROMPTFOO_STRICT_FILES?: boolean;
  46. PROMPTFOO_STRIP_GRADING_RESULT?: boolean;
  47. PROMPTFOO_STRIP_METADATA?: boolean;
  48. PROMPTFOO_STRIP_PROMPT_TEXT?: boolean;
  49. PROMPTFOO_STRIP_RESPONSE_OUTPUT?: boolean;
  50. PROMPTFOO_STRIP_TEST_VARS?: boolean;
  51. PROMPTFOO_TELEMETRY_DEBUG?: boolean;
  52. //=========================================================================
  53. // promptfoo configuration options
  54. //=========================================================================
  55. PROMPTFOO_ASSERTIONS_MAX_CONCURRENCY?: number;
  56. PROMPTFOO_AUTHOR?: string;
  57. PROMPTFOO_CACHE_MAX_FILE_COUNT?: number;
  58. PROMPTFOO_CACHE_MAX_SIZE?: number;
  59. PROMPTFOO_CACHE_PATH?: string;
  60. PROMPTFOO_CACHE_TTL?: number;
  61. PROMPTFOO_CACHE_TYPE?: 'memory' | 'disk';
  62. PROMPTFOO_CLOUD_API_URL?: string;
  63. PROMPTFOO_CONFIG_DIR?: string;
  64. PROMPTFOO_CSV_DELIMITER?: string;
  65. PROMPTFOO_CSV_STRICT?: boolean;
  66. PROMPTFOO_DELAY_MS?: number;
  67. PROMPTFOO_FAILED_TEST_EXIT_CODE?: number;
  68. PROMPTFOO_INSECURE_SSL?: boolean | string;
  69. PROMPTFOO_JAILBREAK_TEMPERATURE?: string;
  70. PROMPTFOO_LOG_DIR?: string;
  71. PROMPTFOO_MAX_HARMFUL_TESTS_PER_REQUEST?: number;
  72. PROMPTFOO_NUM_JAILBREAK_ITERATIONS?: string;
  73. PROMPTFOO_PASS_RATE_THRESHOLD?: number;
  74. PROMPTFOO_PROMPT_SEPARATOR?: string;
  75. PROMPTFOO_PYTHON?: string;
  76. PROMPTFOO_REMOTE_API_BASE_URL?: string;
  77. PROMPTFOO_REMOTE_APP_BASE_URL?: string;
  78. PROMPTFOO_REMOTE_GENERATION_URL?: string;
  79. PROMPTFOO_REQUEST_BACKOFF_MS?: number;
  80. PROMPTFOO_REQUIRE_JSON_PROMPTS?: boolean;
  81. PROMPTFOO_SHARING_APP_BASE_URL?: string;
  82. PROMPTFOO_SHARE_CHUNK_SIZE?: number;
  83. PROMPTFOO_UNALIGNED_INFERENCE_ENDPOINT?: string;
  84. PROMPTFOO_CA_CERT_PATH?: string;
  85. //=========================================================================
  86. // HTTP proxy settings
  87. //=========================================================================
  88. ALL_PROXY?: string;
  89. all_proxy?: string;
  90. HTTP_PROXY?: string;
  91. http_proxy?: string;
  92. HTTPS_PROXY?: string;
  93. https_proxy?: string;
  94. NO_PROXY?: string;
  95. no_proxy?: string;
  96. //=========================================================================
  97. // System and network settings
  98. //=========================================================================
  99. API_HOST?: string;
  100. API_PORT?: string | number;
  101. DISPLAY?: string;
  102. IS_TESTING?: string | boolean;
  103. JEST_WORKER_ID?: string;
  104. NODE_EXTRA_CA_CERTS?: string;
  105. NODE_TLS_REJECT_UNAUTHORIZED?: string;
  106. REQUEST_TIMEOUT_MS?: number;
  107. RESULT_HISTORY_LENGTH?: number;
  108. WEBHOOK_TIMEOUT?: number;
  109. // Posthog
  110. PROMPTFOO_POSTHOG_KEY?: string;
  111. PROMPTFOO_POSTHOG_HOST?: string;
  112. //=========================================================================
  113. // UI configuration
  114. //=========================================================================
  115. /**
  116. * @deprecated Use PROMPTFOO_REMOTE_APP_BASE_URL instead
  117. */
  118. NEXT_PUBLIC_PROMPTFOO_BASE_URL?: string;
  119. /**
  120. * @deprecated Use PROMPTFOO_REMOTE_API_BASE_URL instead
  121. */
  122. NEXT_PUBLIC_PROMPTFOO_REMOTE_API_BASE_URL?: string;
  123. VITE_PUBLIC_BASENAME?: string;
  124. VITE_PUBLIC_PROMPTFOO_APP_SHARE_URL?: string;
  125. VITE_PUBLIC_PROMPTFOO_REMOTE_API_BASE_URL?: string;
  126. VITE_PUBLIC_PROMPTFOO_SHARE_API_URL?: string;
  127. //=========================================================================
  128. // Continuous Integration
  129. //=========================================================================
  130. APPVEYOR?: boolean;
  131. BITBUCKET_COMMIT?: boolean;
  132. BUDDY?: boolean;
  133. BUILDKITE?: boolean;
  134. CI?: boolean;
  135. CIRCLECI?: boolean;
  136. CODEBUILD_BUILD_ID?: boolean;
  137. GITHUB_ACTIONS?: boolean;
  138. GITLAB_CI?: boolean;
  139. JENKINS?: boolean;
  140. TEAMCITY_VERSION?: boolean;
  141. TF_BUILD?: boolean;
  142. TRAVIS?: boolean;
  143. //=========================================================================
  144. // Provider-specific settings
  145. //=========================================================================
  146. // AI21
  147. AI21_API_BASE_URL?: string;
  148. AI21_API_KEY?: string;
  149. // AIML API
  150. AIML_API_KEY?: string;
  151. // Anthropic
  152. ANTHROPIC_API_KEY?: string;
  153. ANTHROPIC_MAX_TOKENS?: number;
  154. ANTHROPIC_STOP?: string;
  155. ANTHROPIC_TEMPERATURE?: number;
  156. // AWS Bedrock
  157. AWS_BEDROCK_FREQUENCY_PENALTY?: string;
  158. AWS_BEDROCK_MAX_GEN_LEN?: number;
  159. AWS_BEDROCK_MAX_NEW_TOKENS?: number;
  160. AWS_BEDROCK_MAX_RETRIES?: string;
  161. AWS_BEDROCK_MAX_TOKENS?: string;
  162. AWS_BEDROCK_PRESENCE_PENALTY?: string;
  163. AWS_BEDROCK_REGION?: string;
  164. AWS_BEDROCK_STOP?: string;
  165. AWS_BEDROCK_TEMPERATURE?: number;
  166. AWS_BEDROCK_TOP_P?: string;
  167. CEREBRAS_API_KEY?: string;
  168. // Azure OpenAI auth params
  169. AZURE_AUTHORITY_HOST?: string;
  170. AZURE_CLIENT_ID?: string;
  171. AZURE_CLIENT_SECRET?: string;
  172. AZURE_DEPLOYMENT_NAME?: string;
  173. AZURE_EMBEDDING_DEPLOYMENT_NAME?: string;
  174. AZURE_OPENAI_DEPLOYMENT_NAME?: string;
  175. AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME?: string;
  176. AZURE_TENANT_ID?: string;
  177. AZURE_TOKEN_SCOPE?: string;
  178. // Azure Content Safety params
  179. AZURE_CONTENT_SAFETY_API_KEY?: string;
  180. AZURE_CONTENT_SAFETY_API_VERSION?: string;
  181. AZURE_CONTENT_SAFETY_ENDPOINT?: string;
  182. // Cohere
  183. COHERE_CLIENT_NAME?: string;
  184. COHERE_K?: string;
  185. COHERE_MAX_TOKENS?: string;
  186. COHERE_P?: string;
  187. COHERE_TEMPERATURE?: string;
  188. // Cloudflare
  189. CLOUDFLARE_ACCOUNT_ID?: string;
  190. CLOUDFLARE_API_KEY?: string;
  191. // CDP
  192. CDP_DOMAIN?: string;
  193. // FAL
  194. FAL_KEY?: string;
  195. // Groq
  196. GROQ_API_KEY?: string;
  197. // Helicone
  198. HELICONE_API_KEY?: string;
  199. // Hugging Face
  200. /** @deprecated Use HF_TOKEN instead */
  201. HF_API_TOKEN?: string;
  202. HF_TOKEN?: string;
  203. // Hyperbolic
  204. HYPERBOLIC_API_KEY?: string;
  205. // Langfuse
  206. LANGFUSE_HOST?: string;
  207. LANGFUSE_PUBLIC_KEY?: string;
  208. LANGFUSE_SECRET_KEY?: string;
  209. // LLaMa
  210. LLAMA_BASE_URL?: string;
  211. // Local AI
  212. LOCALAI_BASE_URL?: string;
  213. LOCALAI_TEMPERATURE?: number;
  214. // Mistral
  215. MISTRAL_MAX_TOKENS?: string;
  216. MISTRAL_TEMPERATURE?: string;
  217. MISTRAL_TOP_K?: string;
  218. MISTRAL_TOP_P?: string;
  219. // Ollama
  220. OLLAMA_API_KEY?: string;
  221. OLLAMA_BASE_URL?: string;
  222. // OpenAI
  223. OPENAI_API_KEY?: string;
  224. OPENAI_BEST_OF?: number;
  225. OPENAI_FREQUENCY_PENALTY?: number;
  226. OPENAI_MAX_COMPLETION_TOKENS?: number;
  227. OPENAI_MAX_TOKENS?: number;
  228. OPENAI_PRESENCE_PENALTY?: number;
  229. OPENAI_STOP?: string;
  230. OPENAI_TEMPERATURE?: number;
  231. OPENAI_TOP_P?: number;
  232. // OpenRouter
  233. OPENROUTER_API_KEY?: string;
  234. // Portkey
  235. PORTKEY_API_BASE_URL?: string;
  236. PORTKEY_API_KEY?: string;
  237. // Replicate
  238. REPLICATE_MAX_LENGTH?: number;
  239. REPLICATE_MAX_NEW_TOKENS?: number;
  240. REPLICATE_REPETITION_PENALTY?: number;
  241. REPLICATE_SEED?: number;
  242. REPLICATE_STOP_SEQUENCES?: string;
  243. REPLICATE_SYSTEM_PROMPT?: string;
  244. REPLICATE_TEMPERATURE?: number;
  245. REPLICATE_TOP_K?: number;
  246. REPLICATE_TOP_P?: number;
  247. // Together AI
  248. TOGETHER_API_KEY?: string;
  249. // Vertex AI
  250. VERTEX_API_VERSION?: string;
  251. // Voyage AI
  252. VOYAGE_API_BASE_URL?: string;
  253. VOYAGE_API_KEY?: string;
  254. // Watson X
  255. WATSONX_AI_APIKEY?: string;
  256. WATSONX_AI_AUTH_TYPE?: string;
  257. WATSONX_AI_BEARER_TOKEN?: string;
  258. WATSONX_AI_PROJECT_ID?: string;
  259. // Pi Labs
  260. WITHPI_API_KEY?: string;
  261. // xAI
  262. XAI_API_KEY?: string;
  263. } & EnvOverrides;
  264. // Allow string access to any key for environment variables not explicitly listed
  265. export type EnvVarKey = keyof EnvVars;
  266. /**
  267. * Get an environment variable.
  268. * @param key The name of the environment variable.
  269. * @param defaultValue Optional default value if the environment variable is not set.
  270. * @returns The value of the environment variable, or the default value if provided.
  271. */
  272. export function getEnvString(key: EnvVarKey): string | undefined;
  273. export function getEnvString(key: EnvVarKey, defaultValue: string): string;
  274. export function getEnvString(key: EnvVarKey, defaultValue?: string): string | undefined {
  275. // First check if the key exists in CLI state env config
  276. if (cliState.config?.env && typeof cliState.config.env === 'object') {
  277. // Handle both ProviderEnvOverridesSchema and Record<string, string|number|boolean> type
  278. const envValue = cliState.config.env[key as keyof typeof cliState.config.env];
  279. if (envValue !== undefined) {
  280. return String(envValue);
  281. }
  282. }
  283. // Fallback to process.env
  284. const value = process.env[key as string];
  285. if (value === undefined) {
  286. return defaultValue;
  287. }
  288. return value;
  289. }
  290. /**
  291. * Get a boolean environment variable.
  292. * @param key The name of the environment variable.
  293. * @param defaultValue Optional default value if the environment variable is not set.
  294. * @returns The boolean value of the environment variable, or the default value if provided.
  295. */
  296. export function getEnvBool(key: EnvVarKey, defaultValue?: boolean): boolean {
  297. const value = getEnvString(key) || defaultValue;
  298. if (typeof value === 'boolean') {
  299. return value;
  300. }
  301. if (typeof value === 'string') {
  302. return ['1', 'true', 'yes', 'yup', 'yeppers'].includes(value.toLowerCase());
  303. }
  304. return Boolean(defaultValue);
  305. }
  306. /**
  307. * Get an integer environment variable.
  308. * @param key The name of the environment variable.
  309. * @param defaultValue Optional default value if the environment variable is not set.
  310. * @returns The integer value of the environment variable, or the default value if provided.
  311. */
  312. export function getEnvInt(key: EnvVarKey): number | undefined;
  313. export function getEnvInt(key: EnvVarKey, defaultValue: number): number;
  314. export function getEnvInt(key: EnvVarKey, defaultValue?: number): number | undefined {
  315. const value = getEnvString(key) || defaultValue;
  316. if (typeof value === 'number') {
  317. return Math.floor(value);
  318. }
  319. if (typeof value === 'string') {
  320. const parsedValue = Number.parseInt(value, 10);
  321. if (!Number.isNaN(parsedValue)) {
  322. return parsedValue;
  323. }
  324. }
  325. return defaultValue;
  326. }
  327. /**
  328. * Get a float environment variable.
  329. * @param key The name of the environment variable.
  330. * @param defaultValue Optional default value if the environment variable is not set.
  331. * @returns The float value of the environment variable, or the default value if provided.
  332. */
  333. export function getEnvFloat(key: EnvVarKey): number | undefined;
  334. export function getEnvFloat(key: EnvVarKey, defaultValue: number): number;
  335. export function getEnvFloat(key: EnvVarKey, defaultValue?: number): number | undefined {
  336. const value = getEnvString(key) || defaultValue;
  337. if (typeof value === 'number') {
  338. return value;
  339. }
  340. if (typeof value === 'string') {
  341. const parsedValue = Number.parseFloat(value);
  342. if (!Number.isNaN(parsedValue)) {
  343. return parsedValue;
  344. }
  345. }
  346. return defaultValue;
  347. }
  348. /**
  349. * Get the evaluation timeout in milliseconds.
  350. * @param defaultValue Optional default value if the environment variable is not set. Defaults to 0 (no timeout).
  351. * @returns The timeout value in milliseconds, or the default value if not set.
  352. */
  353. export function getEvalTimeoutMs(defaultValue: number = 0): number {
  354. return getEnvInt('PROMPTFOO_EVAL_TIMEOUT_MS', defaultValue);
  355. }
  356. /**
  357. * Get the maximum duration for an evaluation in milliseconds.
  358. * @param defaultValue Optional default value if the environment variable is not set. Defaults to 0 (no limit).
  359. * @returns The max duration in milliseconds, or the default value if not set.
  360. */
  361. export function getMaxEvalTimeMs(defaultValue: number = 0): number {
  362. return getEnvInt('PROMPTFOO_MAX_EVAL_TIME_MS', defaultValue);
  363. }
  364. /**
  365. * Check if the application is running in a CI environment.
  366. * @returns True if running in a CI environment, false otherwise.
  367. */
  368. export function isCI() {
  369. return (
  370. getEnvBool('CI') ||
  371. getEnvBool('GITHUB_ACTIONS') ||
  372. getEnvBool('TRAVIS') ||
  373. getEnvBool('CIRCLECI') ||
  374. getEnvBool('JENKINS') ||
  375. getEnvBool('GITLAB_CI') ||
  376. getEnvBool('APPVEYOR') ||
  377. getEnvBool('CODEBUILD_BUILD_ID') ||
  378. getEnvBool('TF_BUILD') ||
  379. getEnvBool('BITBUCKET_COMMIT') ||
  380. getEnvBool('BUDDY') ||
  381. getEnvBool('BUILDKITE') ||
  382. getEnvBool('TEAMCITY_VERSION')
  383. );
  384. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...