factored out getAcceptablePrompts
This commit is contained in:
parent
ee2415f454
commit
f7d5842010
|
@ -0,0 +1,24 @@
|
||||||
|
import logger from "./logger.mjs"
|
||||||
|
import { db } from "./db.mjs"
|
||||||
|
|
||||||
|
const blocklist = db.union([
|
||||||
|
db('bad_words').select('word'),
|
||||||
|
db('medical_dictionary').select('word'),
|
||||||
|
db('published').select('word')
|
||||||
|
])
|
||||||
|
|
||||||
|
export default async () => {
|
||||||
|
return db('dictionary')
|
||||||
|
.select('*')
|
||||||
|
.where({
|
||||||
|
derivative: 0,
|
||||||
|
scientific: 0,
|
||||||
|
})
|
||||||
|
.andWhere('count', '<', maxCount)
|
||||||
|
.andWhere('count', '>', minCount)
|
||||||
|
.andWhere('word', 'not in', blocklist)
|
||||||
|
.whereRaw('length(word) > 3')
|
||||||
|
.whereNotNull('pronunciation')
|
||||||
|
.orderByRaw('count desc')
|
||||||
|
.catch(error=>{throw error})
|
||||||
|
}
|
|
@ -1,29 +1,12 @@
|
||||||
import { db } from "./db.mjs"
|
|
||||||
import logger from "./logger.mjs"
|
import logger from "./logger.mjs"
|
||||||
|
import getAcceptablePrompts from "./getAcceptablePrompts.mjs"
|
||||||
|
|
||||||
|
|
||||||
const blocklist = db.union([
|
|
||||||
db('bad_words').select('word'),
|
|
||||||
db('medical_dictionary').select('word'),
|
|
||||||
db('published').select('word')
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
export default async function getNewPrompt({ minCount = 200000, maxCount = 30000000, rarityBias = 0.5 }) {
|
export default async function getNewPrompt({ minCount = 200000, maxCount = 30000000, rarityBias = 0.5 }) {
|
||||||
const childLogger = logger.child({minCount,maxCount,rarityBias})
|
const childLogger = logger.child({minCount,maxCount,rarityBias})
|
||||||
childLogger.trace("getNewPrompt called")
|
childLogger.trace("getNewPrompt called")
|
||||||
const prompts = await db('dictionary')
|
|
||||||
.select('*')
|
|
||||||
.where({
|
|
||||||
derivative: 0,
|
|
||||||
scientific: 0,
|
|
||||||
})
|
|
||||||
.andWhere('count', '<', maxCount)
|
|
||||||
.andWhere('count', '>', minCount)
|
|
||||||
.andWhere('word', 'not in', blocklist)
|
|
||||||
.whereRaw('length(word) > 3')
|
|
||||||
.whereNotNull('pronunciation')
|
|
||||||
.orderByRaw('count desc')
|
|
||||||
.catch(error=>{throw error})
|
|
||||||
|
|
||||||
const getBiasedRng = (min, max, bias, influence) => {
|
const getBiasedRng = (min, max, bias, influence) => {
|
||||||
const random = Math.random() * (max - min) + min
|
const random = Math.random() * (max - min) + min
|
||||||
|
@ -41,15 +24,11 @@ export default async function getNewPrompt({ minCount = 200000, maxCount = 30000
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
//await db.destroy()
|
return randomEntry(await getAcceptablePrompts())
|
||||||
return await randomEntry(prompts)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//console.dir(await getNewPrompt({}))
|
|
||||||
|
|
||||||
//console.log(await blocklist)
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue