Skip to content

Commit 632605b

Browse files
committed
lint fix
1 parent 0dbc5e5 commit 632605b

File tree

5 files changed

+56
-11
lines changed

5 files changed

+56
-11
lines changed

src/client/components/Chat/SendMessage.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import React from 'react'
2-
import { Box, TextField, Button, Typography } from '@mui/material'
2+
import {
3+
Box,
4+
TextField,
5+
Button,
6+
Typography,
7+
Switch,
8+
FormControlLabel,
9+
} from '@mui/material'
310
import UploadFileIcon from '@mui/icons-material/UploadFile'
411
import { useTranslation } from 'react-i18next'
512
import AttachmentButton from './AttachmentButton'
@@ -18,10 +25,13 @@ const SendMessage = ({
1825
setFileName,
1926
setDisallowedFileType,
2027
setAlertOpen,
28+
saveChat,
29+
saveConsent,
30+
setSaveConsent,
2131
}: {
2232
message: string
2333
setMessage: SetState<string>
24-
handleSend: (userConsent: boolean) => void
34+
handleSend: (userConsent: boolean, saveConsent: boolean) => void
2535
handleReset: () => void
2636
disabled: boolean
2737
resetDisabled: boolean
@@ -30,6 +40,9 @@ const SendMessage = ({
3040
setFileName: (name: string) => void
3141
setDisallowedFileType: React.Dispatch<string>
3242
setAlertOpen: React.Dispatch<boolean>
43+
saveConsent: boolean
44+
setSaveConsent: React.Dispatch<boolean>
45+
saveChat: boolean
3346
}) => {
3447
const { t } = useTranslation()
3548

@@ -59,7 +72,7 @@ const SendMessage = ({
5972
}
6073
}
6174
const handleOnClick = () => {
62-
handleSend(false)
75+
handleSend(false, saveConsent)
6376
}
6477
return (
6578
<Box mb={2}>
@@ -108,6 +121,17 @@ const SendMessage = ({
108121
<Button onClick={() => handleReset()} disabled={resetDisabled}>
109122
{t('reset')}
110123
</Button>
124+
{saveChat && (
125+
<FormControlLabel
126+
control={
127+
<Switch
128+
onChange={() => setSaveConsent(!saveConsent)}
129+
checked={saveConsent}
130+
/>
131+
}
132+
label="keskustelun saa tallentaa"
133+
/>
134+
)}
111135
</Box>
112136
</Box>
113137
)

src/client/components/Chat/index.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ const CourseInfo = ({ course }: { course: Course }) => {
8080
</div>
8181

8282
<div style={{ marginTop: 10 }}>{formatDate(course.activityPeriod)}</div>
83+
84+
{course.saveDiscussions && (
85+
<Alert severity="warning" style={{ marginTop: 20 }}>
86+
<Typography variant="h6">
87+
Kurssin keskustelut talletetaan anonyymisti jos annat tallennusluvan
88+
</Typography>
89+
</Alert>
90+
)}
8391
</Box>
8492
)
8593
}
@@ -114,6 +122,7 @@ const Chat = () => {
114122
const [tokenWarningVisible, setTokenWarningVisible] = useState(false)
115123
const [modelTemperature, setModelTemperature] = useState(0.5)
116124
const [setRetryTimeout, clearRetryTimeout] = useRetryTimeout()
125+
const [saveConsent, setSaveConsent] = useState(true)
117126

118127
const { t, i18n } = useTranslation()
119128
const { language } = i18n
@@ -281,7 +290,7 @@ const Chat = () => {
281290
}
282291
}
283292

284-
const handleSend = async (userConsent: boolean) => {
293+
const handleSend = async (userConsent: boolean, saveConsent: boolean) => {
285294
const formData = new FormData()
286295
let file = inputFileRef.current.files[0] as File
287296
if (file) {
@@ -326,7 +335,11 @@ const Chat = () => {
326335
modelTemperature,
327336
courseId,
328337
abortController,
338+
saveConsent,
329339
}
340+
341+
console.log('getCompletionsArgs', getCompletionsArgs)
342+
330343
// Retry the request if the server is stuck for WAIT_FOR_STREAM_TIMEOUT seconds
331344
setRetryTimeout(
332345
() => handleRetry(getCompletionsArgs, abortController),
@@ -351,7 +364,7 @@ const Chat = () => {
351364
}
352365

353366
const handleContinue = () => {
354-
handleSend(true)
367+
handleSend(true, saveConsent)
355368
setTokenWarningVisible(false)
356369
}
357370

@@ -419,6 +432,9 @@ const Chat = () => {
419432
setFileName={setFileName}
420433
setDisallowedFileType={setDisallowedFileType}
421434
setAlertOpen={setAlertOpen}
435+
saveConsent={saveConsent}
436+
setSaveConsent={setSaveConsent}
437+
saveChat={course && course.saveDiscussions}
422438
/>
423439
<Email
424440
system={system}

src/client/components/Chat/util.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface GetCompletoinStreamProps {
1010
modelTemperature: number
1111
courseId?: string
1212
abortController?: AbortController
13+
saveConsent: boolean
1314
}
1415
export const getCompletionStream = async ({
1516
system,
@@ -20,6 +21,7 @@ export const getCompletionStream = async ({
2021
modelTemperature,
2122
courseId,
2223
abortController,
24+
saveConsent,
2325
}: GetCompletoinStreamProps) => {
2426
const data = {
2527
courseId,
@@ -34,6 +36,7 @@ export const getCompletionStream = async ({
3436
model,
3537
userConsent,
3638
modelTemperature,
39+
saveConsent,
3740
},
3841
}
3942

src/client/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export interface Course extends ChatInstance {
120120
enrolments: Enrolment[]
121121
responsibilities: Responsebility[]
122122
courseUnits: CourseUnit[]
123+
saveDiscussions: boolean
123124
}
124125

125126
export type ChatInstanceUsage = {

src/server/routes/openai.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,15 @@ openaiRouter.post('/stream', upload.single('file'), async (r, res) => {
166166
where: { courseId },
167167
})
168168

169-
console.log('-->', course.saveDiscussions)
170-
171-
const consentToSave =
172-
course.saveDiscussions &&
173-
['testUser', 'mluukkai', 'admini2'].includes(user.username)
169+
const consentToSave = course.saveDiscussions && options.saveConsent
174170

175171
// eslint-disable-next-line no-console
176-
console.log('consentToSave', consentToSave, user.username)
172+
console.log(
173+
'consentToSave',
174+
consentToSave,
175+
options.saveConsent,
176+
user.username
177+
)
177178

178179
if (consentToSave) {
179180
const discussion = {

0 commit comments

Comments
 (0)