🌳
pt0/gamesapp/serverF/telgame/aiDescribeF.mjs
11export const aiDescribeDraw = async () => {
12 const {existingGame, finishedTrails, assignedStackName} = getReqGameActionCtx()
13 if (!getIsAssignedStack().isCorrectStack) return
15 // Skip AI for test games - let agents describe drawings manually
16 if (isTestGame({existingGame})) return
18 if (existingGame.settings && !existingGame.settings.aiDescriptEnabled) return
20 const {paperStacks} = getGamePlayerStatesPaperStacks({existingGame})
22 const stack = paperStacks[assignedStackName]
24 const {length: noResp} = stack.responses
25 if (!(noResp >= 2 && noResp <= 3)) return
27 // console.log('WOULDRUNAIDESCRIBE-------------')
28 // return
30 const imageUrlStr = finishedTrailsToImgUrl({finishedTrails})
32 const model = 'openai/gpt-4.1'
33 // const model = 'meta-llama/llama-3.2-11b-vision-instruct'
35 const aiMessages = [
36 {role: 'user', content: `We are playing telestrations. In <10 words please describe the following drawing:`},
37 userMsgImg({imageUrlStr}),
38 ]
40 let resp
41 try {
42 const r = await runPromptSources({ modelIds: [model], opts: { max_tokens: 100, aiMessages }, context: 'aiDescribeDraw' })
43 resp = r.result
44 } catch (err) { // openRouterErr shouldn't break game
45 await maybeNotifError({err})
46 return false
47 }
49 if (!resp) return false
50 let {content} = resp.choices[0].message
51 content = sanitizeAiContent(content)
52 const {costUsd} = resp
54 return {model, content, costUsd}