Spaces:
				
			
			
	
			
			
		Paused
		
	
	
	
			
			
	
	
	
	
		
		
		Paused
		
	File size: 828 Bytes
			
			| 54c5dd9 a8a9533 54c5dd9 a8a9533 54c5dd9 a8a9533 54c5dd9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import type { Migration } from ".";
import { collections } from "$lib/server/database";
import { ObjectId } from "mongodb";
const updateAssistantsModels: Migration = {
	_id: new ObjectId("5f9f3f3f3f3f3f3f3f3f3f3f"),
	name: "Update deprecated models in assistants with the default model",
	up: async () => {
		const models = (await import("$lib/server/models")).models;
		const { assistants } = collections;
		const modelIds = models.map((el) => el.id); // string[]
		const defaultModelId = models[0].id;
		// Find all assistants whose modelId is not in modelIds, and update it to use defaultModelId
		await assistants.updateMany(
			{ modelId: { $nin: modelIds } },
			{ $set: { modelId: defaultModelId } }
		);
		return true;
	},
	runEveryTime: true,
	runForHuggingChat: "only",
};
export default updateAssistantsModels;
 | 
 
			
