Action
Ask Model
Posted by agiletortoise,
Last update
1 day ago
Prompts for, well, a prompt to submit to the ModelSession, and displays its respond. Useful and a test/debugging tool for trying out prompts.
Prompt also includes options to select the model to use, and how to output the response (as alert, new draft, or to clipboard).
This also includes the draft tools in the model query, to support making basic. queries about your drafts library, like “Do I have any drafts that contain the text ‘hello’?” or “Create a draft with the text Hello World”
This action is meant as an example action to demonstrate the use of ModelSession scripting. (docs)
(requires iOS/macOS 27 + Apple Intelligence)
Steps
-
script
let f = () => { const modes = ModelSession.availableModes() if (modes.length == 0) { alert("No models available on this device.") return false } let initialMode = "onDevice" if (modes.includes("pcc")) { initialMode = "pcc" } // PROMPT USER FOR, WELL, PROMPT let p = new Prompt() p.title = "Ask Model" p.message = "Type a prompt below, and get a response from the model" p.addTextView("prompt", "Prompt") p.addSelect("mode", "Use model", modes, [initialMode], false) p.addSelect("output", "Output to...", ["Show Alert", "New Draft", "Clipboard"], ["Show Alert"], false) p.addButton("Submit") if(!p.show()) { return false } // GET PROMPT AND SUBMIT TO MODEL let prompt = p.fieldValues["prompt"] let lm = new ModelSession() lm.mode = p.fieldValues["mode"][0] let response = lm.respond(prompt) // DISPLAY RESPONSE OR ERROR if (!response) { alert(lm.lastError) return false } else { switch(p.fieldValues["output"][0]) { case "New Draft": let d = new Draft() d.content = `# Ask Model **Prompt**: ${prompt} **Response**: ${response} ` d.update() editor.load(d) break case "Clipboard": app.setClipboard(response) break default: alert(`${response}`) break } } return true } if (!f()) { context.fail() }
Options
-
After Success Default Notification Error Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.