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

updates.ts 1.3 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
  1. import chalk from 'chalk';
  2. import semverGt from 'semver/functions/gt';
  3. import logger from './logger';
  4. import { fetchWithTimeout } from './fetch';
  5. import packageJson from '../package.json';
  6. const VERSION = packageJson.version;
  7. export async function getLatestVersion() {
  8. const response = await fetchWithTimeout(`https://api.promptfoo.dev/api/latestVersion`, {}, 1000);
  9. if (!response.ok) {
  10. throw new Error(`Failed to fetch package information for promptfoo`);
  11. }
  12. const data = (await response.json()) as { latestVersion: string };
  13. return data.latestVersion;
  14. }
  15. export async function checkForUpdates(): Promise<boolean> {
  16. if (process.env.PROMPTFOO_DISABLE_UPDATE) {
  17. return false;
  18. }
  19. let latestVersion: string;
  20. try {
  21. latestVersion = await getLatestVersion();
  22. } catch {
  23. return false;
  24. }
  25. if (semverGt(latestVersion, VERSION)) {
  26. const border = '='.repeat(process.stdout.columns - 10);
  27. logger.info(
  28. `\n${border}
  29. ${chalk.yellow('⚠️')} The current version of promptfoo ${chalk.yellow(
  30. VERSION,
  31. )} is lower than the latest available version ${chalk.green(latestVersion)}.
  32. Please run ${chalk.green('npx promptfoo@latest')} or ${chalk.green(
  33. 'npm install -g promptfoo@latest',
  34. )} to update.
  35. ${border}\n`,
  36. );
  37. return true;
  38. }
  39. return false;
  40. }
Tip!

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

Comments

Loading...