Skip to content

Commit

Permalink
Add skip ChatGPT functionality to Form component
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhmeetbawa committed Dec 17, 2023
1 parent 1c606fb commit ff8012f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
7 changes: 7 additions & 0 deletions frontend/src/pages/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Form = () => {

const steps = [
"Basic Details",
"Getting Data",
"Criteria Details",
"Alternative Details",
"Result",
Expand All @@ -39,6 +40,9 @@ const Form = () => {
//Consistency Check
const [consistencyCheck, setConsistencyCheck] = useState(false);

//ChatGPT
const [chatGPT, setChatGPT] = useState(false);

//Functions
const nextStep: () => void = () => {
setStep(step + 1);
Expand Down Expand Up @@ -83,6 +87,8 @@ const Form = () => {
setUsecase={setUsecase}
consistency={consistencyCheck}
setConsistency={setConsistencyCheck}
chatgpt={chatGPT}
setChatGPT={setChatGPT}
/>
)}
{step == 2 && (
Expand All @@ -93,6 +99,7 @@ const Form = () => {
setCriteriaMatrix={setCriteriaMatrix}
setAlternativeMatrices={setAlternativeMatrices}
nextStep={nextStep}
chatgpt={chatGPT}
/>
)}

Expand Down
20 changes: 20 additions & 0 deletions frontend/src/pages/Form/BasicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface BasicFormProps {
usecase: string;
consistency: boolean;
setConsistency: (consistency: boolean) => void;
chatgpt: boolean;
setChatGPT: (chatgpt: boolean) => void;
}
const BasicForm: React.FC<BasicFormProps> = ({
nextStep,
Expand All @@ -28,6 +30,8 @@ const BasicForm: React.FC<BasicFormProps> = ({
usecase,
consistency,
setConsistency,
chatgpt,
setChatGPT,
}) => {
const handleCriteriaChange = (
event: React.ChangeEvent<HTMLInputElement>,
Expand Down Expand Up @@ -78,6 +82,12 @@ const BasicForm: React.FC<BasicFormProps> = ({
setConsistency(event.target.checked);
};

const handleChatGPTChange = (
event: React.ChangeEvent<HTMLInputElement>,
) => {
setChatGPT(event.target.checked);
};

return (
<Grid
container
Expand Down Expand Up @@ -146,6 +156,16 @@ const BasicForm: React.FC<BasicFormProps> = ({
}
label="Use Consistency Check for AHP Calculation"
/>{" "}
<FormControlLabel
control={
<Checkbox
checked={chatgpt}
onChange={handleChatGPTChange}
color="primary"
/>
}
label="Use ChatGPT for generating values"
/>{" "}
</Grid>
<Grid item xs />
</Grid>
Expand Down
22 changes: 20 additions & 2 deletions frontend/src/pages/Form/Response.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface ResponseProps {
setCriteriaMatrix: (criteriaMatrix: number[][]) => void;
setAlternativeMatrices: (alternativeMatrices: number[][][]) => void;
nextStep: () => void;
chatgpt: boolean;
}

const Response: React.FC<ResponseProps> = ({
Expand All @@ -21,6 +22,7 @@ const Response: React.FC<ResponseProps> = ({
setCriteriaMatrix,
setAlternativeMatrices,
nextStep,
chatgpt,
}) => {
const navigate = useNavigate();
const apiKey = useCookies(["api_key"]);
Expand All @@ -29,6 +31,24 @@ const Response: React.FC<ResponseProps> = ({
const [randomFact, setRandomFact] = useState<string>("");

const getMatrices = async () => {
if (!chatgpt) {
// Initialize criteria matrix with 1s
const criteriaMatrix = Array(criteria.length).fill(
Array(criteria.length).fill(1),
);
setCriteriaMatrix(criteriaMatrix);

// Initialize alternative matrices with 1s
const alternativeMatrices = Array(criteria.length).fill(
Array(alternatives.length).fill(
Array(alternatives.length).fill(1),
),
);
setAlternativeMatrices(alternativeMatrices);

nextStep();
return;
}
if (!apiKey[0].api_key) {
alert("API Key not found");
navigate("/preferences");
Expand Down Expand Up @@ -65,8 +85,6 @@ const Response: React.FC<ResponseProps> = ({
console.log("Matrices recieved from API");

nextStep();
// setTimeout(() => {
// }, 10000);
} catch (error) {
console.log(error);
alert("Invalid API Key");
Expand Down

0 comments on commit ff8012f

Please sign in to comment.