From e42487bbe44eaebfd68114e28f74f17f62d4603d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Jun 2026 18:38:59 +0100 Subject: Replace the remaining legacy image stuff Generalises the textMatcher for any purpose, including its original use of selecting an image for some text. Then replaces the legacy outfit selector with an LLM based one using it. --- scripts/toy.groovy | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'scripts/toy.groovy') diff --git a/scripts/toy.groovy b/scripts/toy.groovy index a19b024..b89f6b0 100644 --- a/scripts/toy.groovy +++ b/scripts/toy.groovy @@ -402,6 +402,26 @@ ${jspec.collect{ k, v -> "\"${k}\": ${v}" }.join(",\n ")} } } + final textMatcher = { text, dommePrompt, assetDetail, assetType, requestPrompt, assets -> + final assetList = assets.collect{ id, value -> "* ${id} : ${value}" }.join("\n"); + final idList = assets.keySet().collect{ id -> "\"${id}\"" }.join(" | "); + final request = [ + model: loadString("toy.chatModel"), + grammar: "root ::= ( ${idList} )", + messages: [ + [role: "system", content: """ +You are ${DOMME.title} ${DOMME.fullName}. +${dommePrompt} +Given a list of ${assetDetail}, you select the ${assetType} which best ${requestPrompt}. +The available ${assetType}s are: +${assetList}""" + ], + [role: "user", content: "Write only an ${assetType} Id from the list as an unformatted string, select an ${assetType} for the text: ${text}"] + ] + ]; + return callAPI("chat/completions", request)?.choices?[0]?.message?.content; + } + final chatInitialMessages = { String ... extra -> def messages = [ [role: "system", content: """ -- cgit v1.3