#+title: kagi.el README #+author: Bram Schoenmakers #+macro: issue [[https://codeberg.org/bram85/kagi.el/issues/$1][issue #$1]] #+macro: pr [[https://codeberg.org/bram85/kagi.el/pulls/$1][PR #$1]] #+export_file_name: kagi #+property: header-args:elisp :results none :exports code #+begin_export html MELPA MELPA Stable #+end_export * Introduction This Emacs package provides the following functionalities from the [[https://www.kagi.com][Kagi search engine]]: - FastGPT :: Kagi's LLM offering, as a shell inspired by [[https://github.com/xenodium/chatgpt-shell][xenodium's chatgpt-shell]]. - Universal Summarizer :: Summarizes texts, webpages, videos, and more. Both functions are accessed through Kagi's [[https://help.kagi.com/kagi/api/overview.html][APIs]]. Before a call can be made, some setup should be done on the Kagi website (see below). [[file:img/fastgpt.png]] * Commands and functions ** FastGPT - =kagi-fastgpt-shell= :: Opens a shell buffer in a new window where prompts can be typed. This Kagi FastGPT typically returns output based on actual search results. When point is on one of the listed URLs, press =C-c RET= to open it. - =kagi-fastgpt-prompt= :: Enter a prompt in the minibuffer and show the result in a separate buffer. With a universal prefix (=C-u=), the result is inserted at point. This function can also be used from Lisp code. kagi.el has some functions that use FastGPT to perform certain operations on text: - =kagi-translate= :: Translates strings or complete buffers to another language (including programming languages). - =kagi-proofread= :: Proofreads a string or buffer. - =kagi-fastgpt-prompt-definition= :: Returns the definition of a word. ** Universal Summarizer - =kagi-summarize-buffer= :: Summarizes the content of a buffer. - =kagi-summarize-region= :: Similarly, the text inside the region is summarized. - =kagi-summarize-url= :: Prompts for a URL of which a summary is composed and displayed. - =kagi-summarize= :: Function to retrieve a summary from a text or URL, to be used from Lisp code. The summarize commands accept a single universal prefix, which allows you to: - insert the summary at point; - choose a (different) target language; - choose which summary engine to use; - choose which summary format to use (prose or bullet list); - opt-out from caching at Kagi for confidential content. Note that texts submitted to Kagi are subject to their [[https://kagi.com/privacy#Summarizer][Privacy Policy]]. * Installation and configuration kagi.el is available on [[https://melpa.org/#/kagi][MELPA]] and [[https://stable.melpa.org/#/kagi][MELPA Stable]]. To install from Git, clone with: : git clone https://codeberg.org/bram85/kagi.el.git /path/to/kagi.el Note that kagi.el has a dependency on the [[https://melpa.org/#/shell-maker][shell-maker package]], which is available on MELPA. You may want to load and configure the package with ~use-package~, for example put the following in your Emacs init file: #+begin_src elisp (use-package kagi :ensure t :custom (kagi-api-token "ABCDEF") ;; or use a function, e.g. with the password-store package: (kagi-api-token (lambda () (password-store-get "Kagi/API"))) ;; Universal Summarizer settings (kagi-summarizer-engine "cecil") (kagi-summarizer-default-language "EN") (kagi-summarizer-cache t) :custom-face ;; kagi-code defaults to fixed-pitch, but can be overridden as ;; follows: (kagi-code ((t (:inherit org-verbatim)))) ;; likewise for kagi-bold: (kagi-bold ((t (:inherit modus-themes-bold))))) #+end_src The token can be supplied directly as a string, but you could write a lambda to retrieve the token from a more secure location (e.g. with the combination of [[https://passwordstore.org/][pass(1)]] and the /password-store/ package that comes with it). ** Kagi API setup 1. Create a Kagi account if you haven't done so already. An account is free, and comes with 100 trial searches. 2. In [[https://kagi.com/settings?p=billing_api][your account settings]], put a balance for the API part (note that this is a separate balance than the subscription). The recommendation is to start with a one-time charge of $5. Check the pricing for the [[https://help.kagi.com/kagi/api/fastgpt.html#pricing][FastGPT API]] and the [[https://help.kagi.com/kagi/api/summarizer.html#pricing][Summarizer API]] for the actual costs. 3. In [[https://kagi.com/settings?p=api][the API portal]], create an API token. Put the result in ~kagi-api-token~ (or write a function to access it securely). ** Configuration settings #+begin_src emacs-lisp :exports results :results table :colnames '("Custom variable" "Description") (let ((rows)) (mapatoms (lambda (symbol) (when (and (string-match "\\_