Skip to content

Commit e1b3469

Browse files
committed
remove model from chat_instances
1 parent 858794d commit e1b3469

File tree

9 files changed

+21
-64
lines changed

9 files changed

+21
-64
lines changed

src/client/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,8 @@ export type ChatInstanceUsage = {
133133
}
134134

135135
export type UserStatus = {
136-
model: ValidModelName
137-
models: ValidModelName[]
138136
usage: number
139137
limit: number
140-
isTike: boolean
141138
}
142139

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

src/server/db/models/chatInstance.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ class ChatInstance extends Model<InferAttributes<ChatInstance>, InferCreationAtt
1515

1616
declare description: CreationOptional<string>
1717

18-
declare model: CreationOptional<string>
19-
2018
declare usageLimit: CreationOptional<number>
2119

2220
declare resetCron: CreationOptional<string | null>
@@ -66,11 +64,6 @@ ChatInstance.init(
6664
allowNull: false,
6765
defaultValue: 'No description',
6866
},
69-
model: {
70-
type: DataTypes.STRING,
71-
allowNull: false,
72-
defaultValue: 'gpt-4o',
73-
},
7467
usageLimit: {
7568
type: DataTypes.INTEGER,
7669
allowNull: false,

src/server/routes/admin.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import { run as runUpdater } from '../updater'
1010
import InfoText from '../db/models/infotext'
1111
import { statsViewerIams } from '../util/config'
1212
import { generateTerms } from '../util/util'
13-
import { Where } from 'sequelize/types/utils'
1413
import { ApplicationError } from '../util/ApplicationError'
15-
import { ValidModelName } from '../../config'
1614

1715
const adminRouter = express.Router()
1816

@@ -31,14 +29,13 @@ adminRouter.use((req, _, next) => {
3129
interface NewChatInstanceData {
3230
name: string
3331
description: string
34-
model: ValidModelName
3532
usageLimit: number
3633
courseId: string
3734
}
3835

3936
adminRouter.post('/chatinstances', async (req, res) => {
4037
const data = req.body as NewChatInstanceData
41-
const { name, description, model, usageLimit, courseId } = data
38+
const { name, description, usageLimit, courseId } = data
4239

4340
const course = await getCourse(courseId)
4441
if (!course) {
@@ -48,7 +45,6 @@ adminRouter.post('/chatinstances', async (req, res) => {
4845
const newChatInstance = await ChatInstance.create({
4946
name: { en: name, fi: name, sv: name },
5047
description,
51-
model,
5248
usageLimit,
5349
courseId,
5450
activityPeriod: course.activityPeriod,
@@ -162,15 +158,14 @@ adminRouter.get('/statistics', async (req, res) => {
162158
interface UpdatedChatInstanceData {
163159
name: string
164160
description: string
165-
model: ValidModelName
166161
usageLimit: number
167162
courseId: string
168163
}
169164

170165
adminRouter.put('/chatinstances/:id', async (req, res) => {
171166
const { id } = req.params
172167
const data = req.body as UpdatedChatInstanceData
173-
const { description, model, usageLimit, courseId, name } = data
168+
const { description, usageLimit, courseId, name } = data
174169

175170
const chatInstance = await ChatInstance.findByPk(id)
176171

@@ -180,7 +175,6 @@ adminRouter.put('/chatinstances/:id', async (req, res) => {
180175

181176
chatInstance.name = { en: name, fi: name, sv: name }
182177
chatInstance.description = description
183-
chatInstance.model = model
184178
chatInstance.usageLimit = usageLimit
185179
chatInstance.courseId = courseId
186180

src/server/routes/ai/v3.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,6 @@ router.post('/stream', upload.single('file'), async (r, res) => {
5252
throw ApplicationError.Forbidden('Usage limit reached')
5353
}
5454

55-
// Check if the model is allowed for the course
56-
if (course) {
57-
const courseModel = course.model
58-
59-
if (generationInfo.model) {
60-
const allowedModels = getAllowedModels(courseModel)
61-
if (!allowedModels.includes(generationInfo.model)) {
62-
throw ApplicationError.Forbidden('Model not allowed')
63-
}
64-
} else {
65-
generationInfo.model = courseModel as (typeof validModels)[number]['name']
66-
}
67-
}
68-
6955
// Check file
7056
let optionsMessagesWithFile: ChatMessage[] | undefined
7157

@@ -140,7 +126,7 @@ router.post('/stream', upload.single('file'), async (r, res) => {
140126
user,
141127
chatMessages: options.chatMessages,
142128
systemMessage,
143-
model: generationInfo.model,
129+
model: prompt?.model ?? generationInfo.model,
144130
temperature: options.modelTemperature,
145131
tools,
146132
writeEvent: async (event: ChatEvent) => {

src/server/routes/chatInstance.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Op } from 'sequelize'
33
import { addMonths } from 'date-fns'
44

55
import { ChatInstance, User, UserChatInstanceUsage } from '../db/models'
6-
import { DEFAULT_MODEL_ON_ENABLE, DEFAULT_TOKEN_LIMIT } from '../../config'
6+
import { DEFAULT_TOKEN_LIMIT } from '../../config'
77
import { sequelize } from '../db/connection'
88
import { ApplicationError } from '../util/ApplicationError'
99

@@ -102,7 +102,6 @@ chatInstanceRouter.post('/:id/enable', async (req, res) => {
102102

103103
chatInstance.usageLimit = DEFAULT_TOKEN_LIMIT
104104
chatInstance.activityPeriod = defaultActivityPeriod
105-
chatInstance.model = DEFAULT_MODEL_ON_ENABLE
106105

107106
await chatInstance.save()
108107

src/server/routes/course.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { ChatInstance, Enrolment, UserChatInstanceUsage, Prompt, User, Responsib
66
import { getOwnCourses } from '../services/chatInstances/access'
77
import { encrypt, decrypt } from '../util/util'
88
import { ApplicationError } from '../util/ApplicationError'
9-
import { ValidModelName } from '../../config'
109

1110
const courseRouter = express.Router()
1211

@@ -258,9 +257,8 @@ courseRouter.get('/:id/discussers', checkDiscussionAccess, async (req, res) => {
258257

259258
courseRouter.put('/:id', async (req, res) => {
260259
const { id } = req.params
261-
const { activityPeriod, model, usageLimit, saveDiscussions, notOptoutSaving } = req.body as {
260+
const { activityPeriod, usageLimit, saveDiscussions, notOptoutSaving } = req.body as {
262261
activityPeriod: ActivityPeriod
263-
model: ValidModelName
264262
usageLimit: number
265263
saveDiscussions: boolean
266264
notOptoutSaving: boolean
@@ -273,7 +271,6 @@ courseRouter.put('/:id', async (req, res) => {
273271
if (!chatInstance) throw ApplicationError.NotFound('ChatInstance not found')
274272

275273
chatInstance.activityPeriod = activityPeriod
276-
chatInstance.model = model
277274
chatInstance.usageLimit = usageLimit
278275
if (saveDiscussions !== undefined) {
279276
chatInstance.saveDiscussions = saveDiscussions
@@ -295,15 +292,6 @@ const userAssignedAsResponsible = (userId, chatInstance) => {
295292
return isResponsible
296293
}
297294

298-
const getUser = async (id: string): Promise<User | null> => {
299-
const user = await User.findByPk(id)
300-
if (!user) {
301-
throw ApplicationError.NotFound('User not found')
302-
return null
303-
}
304-
return user
305-
}
306-
307295
const getUserByUsername = async (username: string): Promise<User | null> => {
308296
const user = await User.findOne({
309297
where: {

src/server/routes/user.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ userRouter.get('/login', async (req, res) => {
4444
// When acual user logs in, update the users info.
4545
if (!request.hijackedBy) {
4646
user.lastLoggedInAt = new Date()
47-
;[dbUser] = await User.upsert(user)
47+
;[dbUser] = await User.upsert(user)
4848
} else {
4949
dbUser = await User.findByPk(id)
5050

@@ -97,13 +97,11 @@ userRouter.get('/status/:courseId', async (req, res) => {
9797
const request = req as any as RequestWithUser
9898
const { user } = request
9999

100-
const { usage, limit, model, models } = await getUserStatus(user, courseId)
100+
const { usage, limit } = await getUserStatus(user, courseId)
101101

102102
res.send({
103103
usage,
104104
limit,
105-
model,
106-
models,
107105
})
108106
return
109107
})

src/server/services/chatInstances/usage.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ export const incrementCourseUsage = async (chatInstance: ChatInstance, tokenCoun
7575
}
7676

7777
export const getUserStatus = async (user: UserType, courseId: string) => {
78-
const isTike = user.iamGroups.some((iam) => iam.includes(tikeIam))
79-
8078
const chatInstance = await ChatInstance.findOne({
8179
where: {
8280
courseId,
@@ -109,9 +107,6 @@ export const getUserStatus = async (user: UserType, courseId: string) => {
109107
return {
110108
usage: 0,
111109
limit: 0,
112-
model: '',
113-
models: [],
114-
isTike,
115110
}
116111
}
117112

@@ -127,15 +122,8 @@ export const getUserStatus = async (user: UserType, courseId: string) => {
127122
attributes: ['usageCount'],
128123
})
129124

130-
const model = chatInstance.model ?? ''
131-
132-
const models = getAllowedModels(model)
133-
134125
return {
135126
usage: chatInstanceUsage?.usageCount ?? 0,
136127
limit: chatInstance?.usageLimit ?? 0,
137-
model,
138-
models,
139-
isTike,
140128
}
141129
}

0 commit comments

Comments
 (0)