Skip to content

Instantly share code, notes, and snippets.

@ahyatt
Last active February 11, 2025 05:30
Show Gist options
  • Save ahyatt/9b1a8d8fff4580259fce489b706c80af to your computer and use it in GitHub Desktop.
Save ahyatt/9b1a8d8fff4580259fce489b706c80af to your computer and use it in GitHub Desktop.
5e-llm.el
;;; 5e-llm.el --- LLM functions for D&D 5e -*- lexical-binding: t -*-
(require 'llm)
(defvar 5e-llm-provider nil
"The LLM provider to use for 5e-llm.")
(defvar 5e-llm-small-provider nil
"The LLM provider to use for small models.")
(defun 5e-llm-insert-name (description)
"Generate and insert a name for a character based on DESCRIPTION."
(interactive "sDescription: ")
(llm-chat 5e-llm-small-provider
(llm-make-chat-prompt
description
:context "Generate a name for a character in D&D 5e based on a given description."
:temperature 0.7
:functions (list
(llm-make-tool
:function (lambda (name) (insert name))
:name "insert_name"
:description "Insert the specified name into the current document."
:args '((:name "name"
:description "The name to insert."
:type 'string
:required t)))))))
(provide '5e-llm)
@danielkrizian
Copy link

danielkrizian commented Feb 10, 2025

following the API-breaking changes discussed here, this works:

(defun 5e-llm-insert-name (description)
  "Generate and insert a name for a character based on DESCRIPTION."
  (interactive "sDescription: ")
  (llm-chat provider
            (llm-make-chat-prompt
             description
             :context "Generate a name for a character in D&D 5e based on a given description."
             :temperature 0.7
             :tools (list
                     (make-llm-tool
                      :function (lambda (name) (insert name))
                      :name "insert_name"
                      :description "Insert the specified name into the current document."
                      :args (list '(:name "name"
                                    :type string
                                    :description "The name to insert.")))))))

@ahyatt
Copy link
Author

ahyatt commented Feb 11, 2025

Thanks for pointing this out, I'll make a new revision.

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