summaryrefslogtreecommitdiff
path: root/scripts/toy.groovy
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2026-06-20 18:38:59 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2026-06-20 18:38:59 +0100
commite42487bbe44eaebfd68114e28f74f17f62d4603d (patch)
tree8cc9fb8d64b9661b45ee24973ff37de05cf2e131 /scripts/toy.groovy
parentRemove more of the tag based image selection (diff)
downloadtoy-e42487bbe44eaebfd68114e28f74f17f62d4603d.zip
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.
Diffstat (limited to 'scripts/toy.groovy')
-rw-r--r--scripts/toy.groovy20
1 files changed, 20 insertions, 0 deletions
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: """