@@ -10,15 +10,16 @@ import {
10
10
Tooltip ,
11
11
IconButton ,
12
12
selectClasses ,
13
- Button
13
+ Button ,
14
14
} from "@mui/joy" ;
15
15
import { useEffect , useState , useMemo } from "react" ;
16
16
import { setOpenAiParams } from "../lib/OpenAi.jsx" ;
17
17
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined' ;
18
18
import KeyboardArrowDown from '@mui/icons-material/KeyboardArrowDown'
19
19
import { SnackBar } from "./SnackBar.jsx" ;
20
+ import CloseIcon from '@mui/icons-material/Close' ;
20
21
21
- const Sidebar = ( { openSettings } ) => {
22
+ const Sidebar = ( { openSettings, setOpenSettings } ) => {
22
23
const [ model , setModel ] = useState ( localStorage . getItem ( 'model' ) || 'gpt-3.5-turbo' )
23
24
const [ temperature , setTemperature ] = useState ( parseFloat ( localStorage . getItem ( 'temperature' ) ) || 0.7 )
24
25
const [ frequencyPenalty , setFrequencyPenalty ] = useState ( parseFloat ( localStorage . getItem ( 'frequencyPenalty' ) ) || 0 )
@@ -48,7 +49,7 @@ const Sidebar = ({ openSettings }) => {
48
49
top_p : topP ,
49
50
} ) , [ model , temperature , maxTokens , frequencyPenalty , topP ] ) ;
50
51
51
- useEffect ( ( ) => {
52
+ useEffect ( ( ) => {
52
53
if ( initialLoad ) {
53
54
const timeout = setTimeout ( ( ) => {
54
55
setOpenAiParams ( params ) ;
@@ -70,30 +71,70 @@ const Sidebar = ({ openSettings }) => {
70
71
setInitialLoad ( false ) ;
71
72
}
72
73
73
- useEffect ( ( ) => {
74
- console . log ( openSettings )
75
- } , [ openSettings ] )
74
+ const handleCloseSettings = ( ) => {
75
+ setOpenSettings ( false )
76
+ }
76
77
77
- return < Sheet sx = { { display : { xs : "none" , md : "flow" } , borderRight : '1px solid' , borderColor : 'divider' , overflowY : 'scroll' , width : "25rem" , p : 3 } } >
78
- < Divider sx = { { mb : 2 } } > < Chip variant = "outlined" > Settings</ Chip > </ Divider >
79
- < Box sx = { { my : 2 , mb : 3 } } >
78
+ return < Sheet sx = { {
79
+ ...( openSettings ? {
80
+ display : { xs : "flow" , md : "none" } ,
81
+ position : "fixed" ,
82
+ width : "100dvw" ,
83
+ zIndex : 3
84
+ } : { display : { xs : "none" , md : "flow" } , position : "initial" , width : "25rem" } ) ,
85
+ height : "calc(100dvh - var(--Header-height))" ,
86
+ borderRight : '1px solid' ,
87
+ borderColor : 'divider' ,
88
+ overflowY : 'scroll' ,
89
+ p : 3
90
+ } } >
91
+ < Box sx = { { mb : 1 , display : { xs : "auto" , md : "none" } } } >
92
+ < Box display = "flex" flexDirection = "row" justifyContent = "space-between" alignItems = "center" sx = { { mb : 2 } } >
93
+ < Typography fontWeight = "xl" fontSize = "lg" > Settings</ Typography >
94
+ < Button variant = "outlined" onClick = { handleCloseSettings }
95
+ sx = { {
96
+ display : 'flex' ,
97
+ alignItems : 'center' ,
98
+ gap : 0.5 ,
99
+ ml : 'auto' ,
100
+ } }
101
+ >
102
+ < Typography
103
+ component = "label"
104
+ htmlFor = "close-icon"
105
+ fontSize = "sm"
106
+ fontWeight = "lg"
107
+ sx = { { cursor : 'pointer' , pb : 0.3 } }
108
+ >
109
+ Close
110
+ </ Typography >
111
+ < CloseIcon id = "close-icon" sx = { { position : 'initial' } } />
112
+ </ Button >
113
+ </ Box >
114
+ < Divider />
115
+ </ Box >
116
+ < Divider sx = { { mb : 2 , display : { xs : "none" , md : "flex" } } } > < Chip variant = "outlined" > Settings</ Chip > </ Divider >
117
+ < Box sx = { { mb : 3 } } >
80
118
< Box sx = { { mb : 1 } } display = "flex" justifyContent = "space-between" alignItems = "center" >
81
- < Typography component = "div" level = "title-sm" > Model:</ Typography >
82
- < Tooltip title = { < div > Choose the AI language model for your chat. < br /> Different models have varying capabilities and performance.</ div > }
83
- size = "sm" placement = "top" sx = { { whiteSpace : 'pre-line' , textAlign : "center" , p : 1 } } >
119
+ < Typography component = "div" level = "title-sm" > Model:</ Typography >
120
+ < Tooltip title = { < div > Choose the AI language model for your chat. < br /> Different models have varying
121
+ capabilities and performance.</ div > }
122
+ size = "sm" placement = "top" sx = { { whiteSpace : 'pre-line' , textAlign : "center" , p : 1 } } >
84
123
< IconButton size = "sm" sx = { { borderRadius : 40 } } >
85
124
< InfoOutlinedIcon />
86
125
</ IconButton >
87
126
</ Tooltip >
88
127
</ Box >
89
- < Select value = { model } defaultValue = { model } size = "sm" onChange = { ( event , value ) => setModel ( value ) } indicator = { < KeyboardArrowDown /> }
128
+ < Select value = { model } defaultValue = { model } size = "sm" onChange = { ( event , value ) => setModel ( value ) }
129
+ indicator = { < KeyboardArrowDown /> }
90
130
sx = { {
91
- [ `& .${ selectClasses . indicator } ` ] : {
92
- transition : '0.2s' ,
93
- [ `&.${ selectClasses . expanded } ` ] : {
94
- transform : 'rotate(-180deg)' ,
95
- } ,
96
- } } } >
131
+ [ `& .${ selectClasses . indicator } ` ] : {
132
+ transition : '0.2s' ,
133
+ [ `&.${ selectClasses . expanded } ` ] : {
134
+ transform : 'rotate(-180deg)' ,
135
+ } ,
136
+ }
137
+ } } >
97
138
< Option value = "gpt-3.5-turbo" > gpt-3.5-turbo</ Option >
98
139
< Option value = "gpt-3.5-turbo-0301" > gpt-3.5-turbo-0301</ Option >
99
140
< Option value = "gpt-3.5-turbo-0613" > gpt-3.5-turbo-0613</ Option >
@@ -110,11 +151,12 @@ const Sidebar = ({ openSettings }) => {
110
151
111
152
< Box sx = { { my : 2 } } >
112
153
< Box display = "flex" justifyContent = "space-between" alignItems = "center" >
113
- < Typography component = "div" level = "title-sm" > Temperature: < Chip variant = "soft" > { temperature } </ Chip > </ Typography >
154
+ < Typography component = "div" level = "title-sm" > Temperature: < Chip
155
+ variant = "soft" > { temperature } </ Chip > </ Typography >
114
156
< Tooltip title = { < div > Control the randomness of AI responses. Higher values (e.g., 0.8) make output
115
157
more< br /> diverse, while lower values (e.g., 0.2) yield focused and deterministic replies.< br />
116
158
Adjust alongside top-p, but not both. (Default: 1)</ div > }
117
- size = "sm" placement = "top" sx = { { whiteSpace : 'pre-line' , textAlign : "center" , p : 1 } } >
159
+ size = "sm" placement = "top" sx = { { whiteSpace : 'pre-line' , textAlign : "center" , p : 1 } } >
118
160
< IconButton size = "sm" sx = { { borderRadius : 40 } } >
119
161
< InfoOutlinedIcon />
120
162
</ IconButton >
@@ -139,11 +181,12 @@ const Sidebar = ({ openSettings }) => {
139
181
140
182
< Box sx = { { my : 2 } } >
141
183
< Box display = "flex" justifyContent = "space-between" alignItems = "center" >
142
- < Typography component = "div" level = "title-sm" > Frequency Penalty: < Chip variant = "soft" > { frequencyPenalty } </ Chip > </ Typography >
184
+ < Typography component = "div" level = "title-sm" > Frequency Penalty: < Chip
185
+ variant = "soft" > { frequencyPenalty } </ Chip > </ Typography >
143
186
< Tooltip title = { < div > Influence tendency to introduce new topics.< br /> Positive values (0 to 2.0)
144
187
penalize new tokens based on their presence in the text,< br /> encouraging the AI to explore and
145
188
discuss fresh ideas. (Default: 0)</ div > }
146
- size = "sm" placement = "top" sx = { { whiteSpace : 'pre-line' , textAlign : "center" , p : 1 } } >
189
+ size = "sm" placement = "top" sx = { { whiteSpace : 'pre-line' , textAlign : "center" , p : 1 } } >
147
190
< IconButton size = "sm" sx = { { borderRadius : 40 } } >
148
191
< InfoOutlinedIcon />
149
192
</ IconButton >
@@ -168,11 +211,12 @@ const Sidebar = ({ openSettings }) => {
168
211
169
212
< Box sx = { { my : 2 } } >
170
213
< Box display = "flex" justifyContent = "space-between" alignItems = "center" >
171
- < Typography component = "div" level = "title-sm" > Max tokens: < Chip variant = "soft" > { maxTokens } </ Chip > </ Typography >
214
+ < Typography component = "div" level = "title-sm" > Max tokens: < Chip
215
+ variant = "soft" > { maxTokens } </ Chip > </ Typography >
172
216
< Tooltip title = { < div > Limit the total tokens generated in chat completion.< br /> The sum of input and
173
217
output tokens is restricted by the context length.< br /> Adjust this to manage the length of
174
218
your AI-generated responses.</ div > }
175
- size = "sm" placement = "top" sx = { { whiteSpace : 'pre-line' , textAlign : "center" , p : 1 } } >
219
+ size = "sm" placement = "top" sx = { { whiteSpace : 'pre-line' , textAlign : "center" , p : 1 } } >
176
220
< IconButton size = "sm" sx = { { borderRadius : 40 } } >
177
221
< InfoOutlinedIcon />
178
222
</ IconButton >
@@ -226,7 +270,9 @@ const Sidebar = ({ openSettings }) => {
226
270
</ Box >
227
271
228
272
< Box sx = { { my : 2 } } >
229
- < Button onClick = { ( ) => { handleReset ( ) } } color = "primary" variant = "soft" sx = { { width : "100%" } } > Reset settings </ Button >
273
+ < Button onClick = { ( ) => {
274
+ handleReset ( )
275
+ } } color = "primary" variant = "soft" sx = { { width : "100%" } } > Reset settings </ Button >
230
276
</ Box >
231
277
< SnackBar message = { messageSnackbar } closeSnackBar = { setMessageSnackbar } />
232
278
</ Sheet >
0 commit comments