|
| 1 | +import { useEffect, useState } from "react"; |
1 | 2 | import { Example } from "./Example";
|
2 |
| - |
| 3 | +import { DEFAULT_EXAMPLES, GPT4V_EXAMPLES } from "../../i18n/examples.js"; |
3 | 4 | import styles from "./Example.module.css";
|
4 | 5 |
|
5 |
| -const DEFAULT_EXAMPLES: string[] = [ |
6 |
| - "What is Sanlam's IT Strategy?", |
7 |
| - "How was Retail Affluent's performance in 2023?", |
8 |
| - "What savings products does Sanlam sell?" |
9 |
| -]; |
| 6 | +// const DEFAULT_EXAMPLES: string[] = [ |
| 7 | +// "What is Sanlam's IT Strategy?", |
| 8 | +// "How was Retail Affluent's performance in 2023?", |
| 9 | +// "What savings products does Sanlam sell?" |
| 10 | +// ]; |
| 11 | + |
| 12 | +// const GPT4V_EXAMPLES: string[] = [ |
| 13 | +// "Compare the impact of interest rates and GDP in financial markets.", |
| 14 | +// "What is the expected trend for the S&P 500 index over the next five years? Compare it to the past S&P 500 performance", |
| 15 | +// "Can you identify any correlation between oil prices and stock market trends?" |
| 16 | +// ]; |
10 | 17 |
|
11 |
| -const GPT4V_EXAMPLES: string[] = [ |
12 |
| - "Compare the impact of interest rates and GDP in financial markets.", |
13 |
| - "What is the expected trend for the S&P 500 index over the next five years? Compare it to the past S&P 500 performance", |
14 |
| - "Can you identify any correlation between oil prices and stock market trends?" |
15 |
| -]; |
| 18 | +const shuffleArray = (array: string[]) => { |
| 19 | + for (let i = array.length - 1; i > 0; i--) { |
| 20 | + const j = Math.floor(Math.random() * (i + 1)); |
| 21 | + [array[i], array[j]] = [array[j], array[i]]; |
| 22 | + } |
| 23 | + return array; |
| 24 | +}; |
16 | 25 |
|
17 | 26 | interface Props {
|
18 | 27 | onExampleClicked: (value: string) => void;
|
19 | 28 | useGPT4V?: boolean;
|
20 | 29 | }
|
21 | 30 |
|
22 | 31 | export const ExampleList = ({ onExampleClicked, useGPT4V }: Props) => {
|
| 32 | + const [currentExamples, setCurrentExamples] = useState<string[]>([]); |
| 33 | + |
| 34 | + useEffect(() => { |
| 35 | + const loadExamples = () => { |
| 36 | + const examples = useGPT4V ? GPT4V_EXAMPLES : DEFAULT_EXAMPLES; |
| 37 | + setCurrentExamples(shuffleArray(examples).slice(0, 3)); |
| 38 | + }; |
| 39 | + |
| 40 | + loadExamples(); |
| 41 | + const intervalId = setInterval(loadExamples, 7000); // Replaced workerSetInterval |
| 42 | + |
| 43 | + return () => clearInterval(intervalId); // Replaced workerClearInterval |
| 44 | + }, [useGPT4V]); |
| 45 | + |
23 | 46 | return (
|
24 | 47 | <ul className={styles.examplesNavList}>
|
25 |
| - {(useGPT4V ? GPT4V_EXAMPLES : DEFAULT_EXAMPLES).map((question, i) => ( |
| 48 | + {currentExamples.map((question, i) => ( |
26 | 49 | <li key={i}>
|
27 | 50 | <Example text={question} value={question} onClick={onExampleClicked} />
|
28 | 51 | </li>
|
|
0 commit comments