Skip to content

Commit 87f7de7

Browse files
Merge branch 'main' of github.com:UniversityOfHelsinkiCS/gptwrapper
2 parents 4dec432 + 5c4c71e commit 87f7de7

File tree

6 files changed

+276
-74
lines changed

6 files changed

+276
-74
lines changed

scripts/k6_load_test.js

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
2-
* This script requires the use of k6 docker image version
2+
* This script requires the use of k6 docker image and it needs to be run inside the docker container. Check the command below
3+
* The k6 modules are imported from within the docker container. So it is not a dependency in Currechat
34
*
4-
* run using: docker run --rm -i grafana/k6 run - <script.js
5+
* run using: docker run --rm -i grafana/k6 run - <scripts/k6_load_test.js
56
*/
67

78
import http from 'k6/http'
@@ -10,39 +11,29 @@ import { sleep, check } from 'k6'
1011
const staging = 'http://gptwrapper.toska.svc.cluster.local:8000/api/ai/stream'
1112
const local = 'http://172.17.0.1:3000/api//ai/stream'
1213

14+
// k6 will pickup the options object internally.
1315
const vusit = 50
14-
1516
export const options = {
1617
vus: vusit,
1718
iterations: vusit,
18-
// duration: "1s",
1919
}
2020

21-
const messages = [
22-
'listaa viisi numeroa',
23-
'listaa viisi väriä',
24-
'listaa viisi esinettä',
25-
'listaa viisi makua',
26-
'listaa viisi huonekalua',
27-
'listaa viisi presidenttiä',
28-
'listaa viisi maata',
29-
'listaa viisi ohjelmointikieltä',
30-
'listaa viisi kaupunkia',
31-
'listaa viisi vaatemerkkiä',
32-
'listaa viisi urheilulajia',
33-
]
21+
const headers = {
22+
headers: {
23+
'Content-Type': 'application/json',
24+
uid: 'testUser',
25+
26+
preferredlanguage: 'fi',
27+
hypersonsisuid: 'hy-hlo-123',
28+
hygroupcn: 'grp-toska;hy-employees;grp-currechat-demostudents;grp-currechat-demoteachers',
29+
},
30+
}
3431

3532
const data = {
3633
options: {
37-
messages: [
38-
{ role: 'system', content: 'Olet avulias avustaja' },
39-
{
40-
role: 'user',
41-
content: undefined, // will be substituted from messages list
42-
},
43-
],
34+
messages: [],
4435
assistantInstructions: 'Olet avulias avustaja',
45-
model: 'mock',
36+
model: 'gpt-4o-mini',
4637
modelTemperature: 0.5,
4738
saveConsent: false,
4839
prevResponseId: '',
@@ -51,50 +42,52 @@ const data = {
5142
courseId: 'sandbox',
5243
}
5344

54-
function tokensToText(tokenizedStr) {
55-
return tokenizedStr
45+
const messages = ['listaa viisi esinettä', 'kerro niistä jotain', 'anna esimerkki jokaisesta esineestä', 'kerro yksityiskohtaisemmin', 'tiivistä kertomasi']
46+
47+
function handleTokens(tokenizedStr) {
48+
let texts = []
49+
let responseId = ''
50+
51+
tokenizedStr
5652
.split('\n')
5753
.filter(Boolean)
58-
.map((line) => {
54+
.forEach((line) => {
5955
try {
60-
return JSON.parse(line).text
56+
const parsedLine = JSON.parse(line)
57+
if (parsedLine.text) texts.push(parsedLine.text)
58+
if (parsedLine.prevResponseId) responseId = parsedLine.prevResponseId
6159
} catch {
62-
return ''
60+
console.log('📌 error parsing line')
6361
}
6462
})
63+
64+
const response = texts
6565
.join('')
66+
.replace(/\n+/g, ' ')
67+
.replace(/\s{2,}/g, ' ')
68+
.trim()
69+
70+
return { response, responseId }
6671
}
6772

6873
export default function () {
6974
const url = `${staging}/v2`
75+
let prevResponseId = ''
7076

7177
for (const message of messages) {
72-
const dataCopy = { ...data }
73-
dataCopy.options.messages = [
74-
{ role: 'system', content: 'Olet load testissä' },
75-
{
76-
role: 'user',
77-
content: message,
78-
},
79-
]
80-
const updatedData = dataCopy
78+
const newData = { ...data }
79+
newData.options.messages = [{ role: 'user', content: message }]
80+
newData.options.prevResponseId = prevResponseId
8181

8282
const payload = JSON.stringify({
83-
data: JSON.stringify(updatedData),
83+
data: JSON.stringify(newData),
8484
})
85-
const params = {
86-
headers: {
87-
'Content-Type': 'application/json',
88-
uid: 'testUser',
89-
90-
preferredlanguage: 'fi',
91-
hypersonsisuid: 'hy-hlo-123',
92-
hygroupcn: 'grp-toska;hy-employees;grp-currechat-demostudents;grp-currechat-demoteachers',
93-
},
94-
}
9585

96-
let res = http.post(url, payload, params)
97-
console.log('📌', tokensToText(res.body))
86+
let res = http.post(url, payload, headers)
87+
const { response, responseId } = handleTokens(res.body)
88+
prevResponseId = responseId
89+
90+
console.log('📌 response:', response)
9891
check(res, { 'status is 200': (res) => res.status === 200 })
9992
sleep(5)
10093
}

src/client/components/ChatV2/ChatV2.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import RestartAltIcon from '@mui/icons-material/RestartAlt'
2-
import EmailIcon from '@mui/icons-material/Email'
32
import HelpIcon from '@mui/icons-material/Help'
43
import SettingsIcon from '@mui/icons-material/Settings'
54
import { Alert, Box, Button, Drawer, Tooltip, Typography } from '@mui/material'
@@ -32,6 +31,7 @@ import Annotations from './Annotations'
3231
import { useIsEmbedded } from '../../contexts/EmbeddedContext'
3332
import { enqueueSnackbar } from 'notistack'
3433
import { useAnalyticsDispatch } from '../../stores/analytics'
34+
import EmailButton from './EmailButton'
3535

3636
function useLocalStorageStateWithURLDefault(key: string, defaultValue: string, urlKey: string) {
3737
const [value, setValue] = useLocalStorageState(key, defaultValue)
@@ -397,6 +397,7 @@ export const ChatV2 = () => {
397397
ragIndex={ragIndex}
398398
setRagIndexId={setRagIndexId}
399399
ragIndices={ragIndices}
400+
messages={messages}
400401
/>
401402
</Drawer>
402403
<LeftMenu
@@ -411,6 +412,7 @@ export const ChatV2 = () => {
411412
ragIndex={ragIndex}
412413
setRagIndexId={setRagIndexId}
413414
ragIndices={ragIndices}
415+
messages={messages}
414416
/>
415417
</>
416418
)}
@@ -535,7 +537,20 @@ export const ChatV2 = () => {
535537
)
536538
}
537539

538-
const LeftMenu = ({ sx, course, handleReset, user, t, setSettingsModalOpen, setDisclaimerStatus, showRagSelector, ragIndex, setRagIndexId, ragIndices }) => {
540+
const LeftMenu = ({
541+
sx,
542+
course,
543+
handleReset,
544+
user,
545+
t,
546+
setSettingsModalOpen,
547+
setDisclaimerStatus,
548+
showRagSelector,
549+
ragIndex,
550+
setRagIndexId,
551+
ragIndices,
552+
messages,
553+
}) => {
539554
return (
540555
<Box sx={sx}>
541556
<Box
@@ -553,19 +568,8 @@ const LeftMenu = ({ sx, course, handleReset, user, t, setSettingsModalOpen, setD
553568
<OutlineButtonBlack startIcon={<RestartAltIcon />} onClick={handleReset} id="empty-conversation-button">
554569
{t('chat:emptyConversation')}
555570
</OutlineButtonBlack>
556-
<Tooltip
557-
title={
558-
<Typography variant="body2" sx={{ p: 0.5 }}>
559-
{t('info:email', { email: user?.email })}
560-
</Typography>
561-
}
562-
arrow
563-
placement="right"
564-
>
565-
<OutlineButtonBlack startIcon={<EmailIcon />} onClick={() => alert('Not yet supported')}>
566-
{t('email:save')}
567-
</OutlineButtonBlack>
568-
</Tooltip>
571+
572+
<EmailButton messages={messages} disabled={!messages?.length} />
569573
<OutlineButtonBlack startIcon={<SettingsIcon />} onClick={() => setSettingsModalOpen(true)} id="settings-button">
570574
{t('chat:settings')}
571575
</OutlineButtonBlack>

0 commit comments

Comments
 (0)