7import * as _ from 'lodash-es' 13const memPromptsA: {model: string; content: string}[] = [] 15const isTooLong = (content: string) => { 16 const numWords = content.split(' ').length 17 const numChars = content.length 18 return numWords > 8 || numChars > 50 21export const getRandModel = async () => { 22 const configuredModels = _.values(telePromptModelsH) as string[] 24 throwIf(() => validatedModelsA.length === 0, {configuredModels}) 25 return _.sample(validatedModelsA) 28export const aiTelePrompt = async () => { 29 // Skip AI for test games to avoid API credits 30 const {existingGame} = gameActionCtx.getStore() || {} 32 return {model: 'test-placeholder', content: 'test prompt for drawing'} 36 const rows = await db.selectFrom('dbgames') 37 .where('created_at', 'is not', null) 38 .select(['game_state']) 42 const dbPromptsA = _.compact(_.flatten(_.map(statesA, ({gameActionHistA}) => { 43 return _.map(gameActionHistA, ({playerAction, pregenFncRet}) => { 44 if (playerAction == 'giveMyselfAiPrompt') return pregenFncRet 49 const model = await getRandModel() 53 content: `We are playing telestrations, in a few words write ONE original prompt that's slightly hard to draw`, 55 ..._.flatMap(_.uniq(_.compact(_.map(_.union(dbPromptsA, memPromptsA), 'content'))), (content) => [ 56 {role: 'assistant', content}, 58 if (isTooLong(content)) return 'That was too long, do not apologize. Another please' 59 if (content.length <= 3) return 'Too short, do not apologize. Another please' 60 return 'Another please' 65 const { result: respH } = await runPromptSources({ modelIds: [model!], opts: { aiMessages }, context: 'aiTelePrompt' }) 66 if (!respH) throw new Error('aiTelePrompt all sources exhausted') 67 let {content} = respH.choices[0].message 68 const {costUsd} = respH 71 memPromptsA.push({model: model!, content}) 72 if (!isTooLong(content)) { 73 return {content, model, costUsd}