Skip to content

Commit 0dbc5e5

Browse files
committed
save course chat save status to db
1 parent a2d1cc8 commit 0dbc5e5

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { DataTypes } from 'sequelize'
2+
3+
import { Migration } from '../connection'
4+
5+
export const up: Migration = async ({ context: queryInterface }) => {
6+
await queryInterface.addColumn('chat_instances', 'save_discussions', {
7+
type: DataTypes.BOOLEAN,
8+
})
9+
}
10+
11+
export const down: Migration = async ({ context: queryInterface }) => {
12+
await queryInterface.removeColumn('chat_instances', 'save_discussions')
13+
}

src/server/db/models/chatInstance.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class ChatInstance extends Model<
3434
declare courseUnitRealisationTypeUrn: string | null
3535

3636
declare courseUnits: CreationOptional<CourseUnit[]>
37+
38+
declare saveDiscussions: boolean
3739
}
3840

3941
ChatInstance.init(
@@ -93,6 +95,9 @@ ChatInstance.init(
9395
allowNull: true,
9496
defaultValue: [],
9597
},
98+
saveDiscussions: {
99+
type: DataTypes.BOOLEAN,
100+
},
96101
},
97102
{
98103
underscored: true,

src/server/routes/openai.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import getEncoding from '../util/tiktoken'
2121
import logger from '../util/logger'
2222
import { inProduction, DEFAULT_TOKEN_LIMIT, FREE_MODEL } from '../../config'
2323
import { pdfToText } from '../util/pdfToText'
24-
import { Discussion } from '../db/models'
24+
import { Discussion, ChatInstance } from '../db/models'
2525

2626
const openaiRouter = express.Router()
2727

@@ -162,9 +162,15 @@ openaiRouter.post('/stream', upload.single('file'), async (r, res) => {
162162
courseId,
163163
})
164164

165+
const course = await ChatInstance.findOne({
166+
where: { courseId },
167+
})
168+
169+
console.log('-->', course.saveDiscussions)
170+
165171
const consentToSave =
166-
['testUser', 'mluukkai', 'admini2'].includes(user.username) &&
167-
courseId === 'sandbox'
172+
course.saveDiscussions &&
173+
['testUser', 'mluukkai', 'admini2'].includes(user.username)
168174

169175
// eslint-disable-next-line no-console
170176
console.log('consentToSave', consentToSave, user.username)

0 commit comments

Comments
 (0)