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

feedback.ts 1.2 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
  1. import readline from 'readline';
  2. import logger from './logger';
  3. import { fetchWithProxy } from './fetch';
  4. import { REMOTE_API_BASE_URL } from './constants';
  5. export function gatherFeedback(message?: string) {
  6. if (message) {
  7. sendFeedback(message);
  8. } else {
  9. const reader = readline.createInterface({
  10. input: process.stdin,
  11. output: process.stdout,
  12. });
  13. reader.on('keypress', (str, key) => {
  14. if (key.name === 'enter' && key.shift) {
  15. reader.write('\n');
  16. }
  17. });
  18. reader.question(
  19. '\n\nPlease enter your feedback. Leave your email address if you want to hear back:\n\n> ',
  20. (input: string) => {
  21. reader.close();
  22. sendFeedback(input);
  23. },
  24. );
  25. }
  26. }
  27. export async function sendFeedback(feedback: string) {
  28. const resp = await fetchWithProxy(`${REMOTE_API_BASE_URL}/api/feedback`, {
  29. method: 'POST',
  30. headers: {
  31. 'Content-Type': 'application/json',
  32. },
  33. body: JSON.stringify({
  34. message: feedback,
  35. }),
  36. });
  37. if (resp.ok) {
  38. logger.info('Feedback sent. Thank you!');
  39. } else {
  40. logger.info(
  41. 'Sorry, feedback failed to send for some reason. You can also open an issue at https://github.com/promptfoo/promptfoo/issues/new',
  42. );
  43. }
  44. }
Tip!

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

Comments

Loading...