1
+ import React from 'react'
1
2
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'
3
5
import { Box , IconButton , TextField , Typography } from '@mui/material'
4
6
import { useState , useRef } from 'react'
5
7
import useUserStatus from '../../hooks/useUserStatus'
6
8
import { useParams } from 'react-router-dom'
7
9
import { useTranslation } from 'react-i18next'
10
+ import ModelSelector from './ModelSelector'
8
11
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
+ } ) => {
10
23
const { courseId } = useParams ( )
11
24
const { userStatus, isLoading : statusLoading , refetch : refetchStatus } = useUserStatus ( courseId )
12
25
const [ message , setMessage ] = useState < string > ( '' )
@@ -20,7 +33,6 @@ export const ChatBox = ({ disabled, onSubmit }: { disabled: boolean; onSubmit: (
20
33
// This is here to prevent the form from submitting but because disabling it in the component breaks re-focusing on the text field
21
34
if ( disabled ) return
22
35
23
-
24
36
if ( message . trim ( ) ) {
25
37
onSubmit ( message )
26
38
setMessage ( '' )
@@ -53,8 +65,7 @@ export const ChatBox = ({ disabled, onSubmit }: { disabled: boolean; onSubmit: (
53
65
}
54
66
} }
55
67
>
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' } } >
58
69
< TextField
59
70
ref = { textFieldRef }
60
71
autoFocus
@@ -64,28 +75,33 @@ export const ChatBox = ({ disabled, onSubmit }: { disabled: boolean; onSubmit: (
64
75
fullWidth
65
76
multiline
66
77
maxRows = { 8 }
78
+ sx = { { padding : '0.5rem' } }
67
79
variant = "standard"
68
- sx = { { padding : '0.5rem 1rem' } }
69
80
slotProps = { {
70
81
input : {
71
82
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
- ) ,
82
83
} ,
83
84
} }
84
85
/>
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 >
85
101
</ Box >
86
102
87
103
< Box >
88
- < Typography variant = "body1" style = { { padding : '0.5rem ' , fontSize : '0.875rem' } } >
104
+ < Typography variant = "body1" style = { { padding : '1rem ' , opacity : 0.7 } } >
89
105
{ userStatus . usage } / { userStatus . limit } { t ( 'status:tokensUsed' ) }
90
106
</ Typography >
91
107
</ Box >
0 commit comments