Skip to content

Instantly share code, notes, and snippets.

@ahyatt
Created November 15, 2025 19:38
Show Gist options
  • Select an option

  • Save ahyatt/cf27b7c6ed360aade41c4965e3998be6 to your computer and use it in GitHub Desktop.

Select an option

Save ahyatt/cf27b7c6ed360aade41c4965e3998be6 to your computer and use it in GitHub Desktop.
LLMs in your Emacs yes-or-no prompts
;;; llm-yes-or-no.el --- Don't configure yourself to yes or no! -*- lexical-binding: t -*-
(require 'llm)
(defconst yes-or-no-p-llm my-small-llm-model)
(defun llm-yes-or-no-p (prompt)
(let ((response nil))
(llm-chat yes-or-no-p-llm (llm-make-chat-prompt
(format "The user has been asked a yes or no question (%s) and has answered '%s'. Report whether they have answered yes or no by calling the appropriate function. Always call one of the two functions."
prompt
(read-string (format "%s (yes/no): " prompt)))
:tools (list
(llm-make-tool
:name "yes"
:description "Indicates that the user has answered yes to the question."
:function (lambda (&rest _) (setq response t))
:args '())
(llm-make-tool
:name "no"
:description "Indicates that the user has answered no to the question."
:function (lambda (&rest _) (setq response nil))
:args '()))))
response))
(defalias 'y-or-n-p #'llm-yes-or-no-p)
@yibie
Copy link

yibie commented Nov 16, 2025

Cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment