Skip to content

Commit d351fd1

Browse files
committed
add model selection
1 parent b94572a commit d351fd1

File tree

3 files changed

+64
-40
lines changed

3 files changed

+64
-40
lines changed

src/client/components/ChatV2/ChatBox.tsx

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1+
import React from 'react'
12
import { Send } from '@mui/icons-material'
2-
import StopIcon from '@mui/icons-material/Stop';
3+
import StopIcon from '@mui/icons-material/Stop'
4+
import { validModels } from '../../../config'
35
import { Box, IconButton, TextField, Typography } from '@mui/material'
46
import { useState, useRef } from 'react'
57
import useUserStatus from '../../hooks/useUserStatus'
68
import { useParams } from 'react-router-dom'
79
import { useTranslation } from 'react-i18next'
10+
import ModelSelector from './ModelSelector'
811

9-
export const ChatBox = ({ disabled, onSubmit }: { disabled: boolean; onSubmit: (message: string) => void }) => {
12+
export const ChatBox = ({
13+
disabled,
14+
currentModel,
15+
setModel,
16+
onSubmit,
17+
}: {
18+
disabled: boolean
19+
currentModel: string
20+
setModel: (model: string) => void
21+
onSubmit: (message: string) => void
22+
}) => {
1023
const { courseId } = useParams()
1124
const { userStatus, isLoading: statusLoading, refetch: refetchStatus } = useUserStatus(courseId)
1225
const [message, setMessage] = useState<string>('')
@@ -20,7 +33,6 @@ export const ChatBox = ({ disabled, onSubmit }: { disabled: boolean; onSubmit: (
2033
// This is here to prevent the form from submitting but because disabling it in the component breaks re-focusing on the text field
2134
if (disabled) return
2235

23-
2436
if (message.trim()) {
2537
onSubmit(message)
2638
setMessage('')
@@ -53,8 +65,7 @@ export const ChatBox = ({ disabled, onSubmit }: { disabled: boolean; onSubmit: (
5365
}
5466
}}
5567
>
56-
<Box sx={{ border: '1px solid rgba(0,0,0,0.4)', borderRadius: '0.2rem' }}>
57-
68+
<Box sx={{ border: '1px solid rgba(0,0,0,0.3)', borderRadius: '0.3rem', padding: '0.5rem 1rem' }}>
5869
<TextField
5970
ref={textFieldRef}
6071
autoFocus
@@ -64,28 +75,33 @@ export const ChatBox = ({ disabled, onSubmit }: { disabled: boolean; onSubmit: (
6475
fullWidth
6576
multiline
6677
maxRows={8}
78+
sx={{ padding: '0.5rem' }}
6779
variant="standard"
68-
sx={{ padding: '0.5rem 1rem' }}
6980
slotProps={{
7081
input: {
7182
disableUnderline: true,
72-
endAdornment: disabled ? (
73-
// TODO: finish the stop signal API
74-
<IconButton disabled={!disabled}>
75-
<StopIcon />
76-
</IconButton>
77-
) : (
78-
<IconButton disabled={disabled} type="submit">
79-
<Send />
80-
</IconButton>
81-
),
8283
},
8384
}}
8485
/>
86+
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mt: '0.5rem' }}>
87+
<ModelSelector currentModel={currentModel} setModel={setModel} models={validModels.map((m) => m.name)} />
88+
89+
{/* Submit/Stop button */}
90+
{disabled ? (
91+
// TODO: finish the stop signal API
92+
<IconButton disabled={!disabled}>
93+
<StopIcon />
94+
</IconButton>
95+
) : (
96+
<IconButton disabled={disabled} type="submit">
97+
<Send />
98+
</IconButton>
99+
)}
100+
</Box>
85101
</Box>
86102

87103
<Box>
88-
<Typography variant="body1" style={{ padding: '0.5rem', fontSize: '0.875rem' }}>
104+
<Typography variant="body1" style={{ padding: '1rem', opacity: 0.7 }}>
89105
{userStatus.usage} / {userStatus.limit} {t('status:tokensUsed')}
90106
</Typography>
91107
</Box>

src/client/components/ChatV2/ChatV2.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ export const ChatV2 = () => {
302302
}}
303303
>
304304
{course && (
305-
<Typography variant="h4" sx={{ textAlign: 'center', fontWeight: 'bold', mb: '1.5rem' }}>
306-
{course.id}
305+
<Typography variant="h5" sx={{ textAlign: 'center', fontWeight: 'bold', mb: '1.5rem' }}>
306+
{course.id === 'sandbox' ? 'OHTE Sandbox' : course.id}
307307
</Typography>
308308
)}
309309

@@ -346,6 +346,8 @@ export const ChatV2 = () => {
346346
<Box ref={inputFieldRef} sx={{ position: 'sticky', bottom: 0, backgroundColor: 'white', paddingBottom: '1.5rem' }}>
347347
<ChatBox
348348
disabled={!isCompletionDone}
349+
currentModel={model.name}
350+
setModel={(name) => setModel({ name })}
349351
onSubmit={(message) => {
350352
if (message.trim()) {
351353
handleSubmit(message)

src/client/components/ChatV2/ModelSelector.tsx

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,35 @@ import { FREE_MODEL } from '../../../config'
55
const ModelSelector = ({ currentModel, setModel, models }: { currentModel: string; setModel: (model: string) => void; models: string[] }) => {
66
const { t } = useTranslation()
77

8-
if (models.length === 1) {
9-
return (
10-
<Box style={{ marginBottom: 5 }}>
11-
<Typography variant="body1">
12-
{t('status:modelInUse')} <code>{models[0]}</code>
13-
</Typography>
14-
</Box>
15-
)
16-
}
8+
// if (models.length === 1) {
9+
// return (
10+
// <Box style={{ marginBottom: 5 }}>
11+
// <Typography variant="body1">
12+
// {t('status:modelInUse')} <code>{models[0]}</code>
13+
// </Typography>
14+
// </Box>
15+
// )
16+
// }
1717

1818
return (
19-
<Box mb={2}>
20-
<FormControl sx={{ width: '200px' }}>
21-
<InputLabel>{t('status:modelInUse')}</InputLabel>
22-
<Select label={t('status:modelInUse')} value={currentModel} onChange={(event: SelectChangeEvent) => setModel(event.target.value)}>
23-
{models.map((model) => (
24-
<MenuItem key={model} value={model}>
25-
{model}
26-
</MenuItem>
27-
))}
28-
</Select>
29-
</FormControl>
30-
</Box>
19+
<FormControl sx={{ minWidth: 100, opacity: 0.7 }} size="small">
20+
{/* <InputLabel>{t('status:modelInUse')}</InputLabel> */}
21+
<Select
22+
sx={{
23+
'& .MuiOutlinedInput-notchedOutline': {
24+
border: 'none',
25+
},
26+
}}
27+
value={currentModel}
28+
onChange={(event: SelectChangeEvent) => setModel(event.target.value)}
29+
>
30+
{models.map((model) => (
31+
<MenuItem key={model} value={model}>
32+
{model}
33+
</MenuItem>
34+
))}
35+
</Select>
36+
</FormControl>
3137
)
3238
}
3339

0 commit comments

Comments
 (0)