Skip to content

Commit 99bb633

Browse files
committed
added: useMemo to params in Sidebar
1 parent 45f4fd3 commit 99bb633

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/components/Sidebar.jsx

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Divider, Select, Sheet, Slider, Typography, Option, Box, Chip, Tooltip, IconButton, selectClasses} from "@mui/joy";
2-
import {useEffect, useState} from "react";
2+
import {useEffect, useState, useMemo} from "react";
33
import {setOpenAiParams} from "../lib/OpenAi.jsx";
44
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
55
import KeyboardArrowDown from '@mui/icons-material/KeyboardArrowDown'
@@ -11,18 +11,20 @@ const Sidebar = () => {
1111
const [frequencyPenalty, setFrequencyPenalty] = useState(0);
1212
const [topP, setTopP] = useState(1);
1313

14+
const params = useMemo(() => ({
15+
model: model,
16+
temperature: temperature,
17+
max_tokens: maxTokens,
18+
frequency_penalty: frequencyPenalty,
19+
top_p: topP,
20+
}), [model, temperature, maxTokens, frequencyPenalty, topP]);
21+
1422
useEffect(() => {
1523
const timeout = setTimeout(() => {
16-
setOpenAiParams({
17-
model: model,
18-
temperature: temperature,
19-
max_tokens: maxTokens,
20-
frequency_penalty: frequencyPenalty,
21-
top_p: topP,
22-
});
24+
setOpenAiParams(params);
2325
}, 400);
2426
return () => clearTimeout(timeout);
25-
}, [model, temperature, maxTokens, frequencyPenalty, topP])
27+
}, [params])
2628

2729
return <Sheet sx={{display: {xs: "none", md: "flow"}, borderRight: '1px solid', borderColor: 'divider', overflowY: 'scroll', width: "25rem", p: 3}}>
2830
<Divider sx={{mb: 2}}><Chip variant="outlined">Settings</Chip></Divider>

src/lib/OpenAi.jsx

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ let openAiParams = {
1515

1616
export function setOpenAiParams(newParams) {
1717
openAiParams = {...openAiParams, ...newParams};
18+
console.log(openAiParams)
1819
}
1920

2021
export async function sendMessage(message) {
@@ -28,6 +29,15 @@ export async function sendMessage(message) {
2829
})
2930
return chatCompletion.choices[0].message.content;
3031
} catch (error) {
32+
if (error.status === 429) {
33+
console.error("Error: " + "Rate limit reached for requests")
34+
} else if (error.status === 500) {
35+
console.error("Error: " + "The server had an error while processing your request")
36+
} else if (error.status === 503) {
37+
console.error("Error: " + "The engine is currently overloaded, please try again later")
38+
} else if (error.status === 401) {
39+
console.error("Error: " + "Invalid Authentication")
40+
}
3141
throw error
3242
}
3343
}

0 commit comments

Comments
 (0)