diff --git a/README.org b/README.org index f129f55..f931841 100644 --- a/README.org +++ b/README.org @@ -24,8 +24,7 @@ Both functions are accessed through Kagi's [[https://help.kagi.com/kagi/api/over ** 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. -- =kagi-fastgpt= :: Function to retrieve a FastGPT response, to be used from Lisp code. +- =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: @@ -205,6 +204,10 @@ Because the =fastgpt-shell-mode-map= only becomes available when =kagi-fastgpt-s ** 0.4pre +*** Breaking changes + +- Obsoleted function =kagi-fastgpt= in favor of =kagi-fastgpt-prompt=. To be removed in a next release. + *** New - Introduce variable =kagi-summarizer-default-summary-format=, to produce a paragraph summary (default) or a take-away in bullet-list format. diff --git a/kagi.el b/kagi.el index e5d4f80..457acb2 100644 --- a/kagi.el +++ b/kagi.el @@ -332,13 +332,22 @@ list of conses." (save-excursion (insert (substring-no-properties summary)))) -(defun kagi-fastgpt (prompt) - "Submit a PROMPT to FastGPT and return a formatted response string." +(defun kagi--fastgpt (prompt) + "Submit a PROMPT to FastGPT and return a formatted response string. + +This is used by `kagi-fastgpt-shell' and `kagi-fastgpt-prompt' to +obtain a result from FastGPT. Use the latter function for +retrieving a result from Lisp code." (let* ((response (kagi--call-fastgpt prompt)) (parsed-response (json-parse-string response)) (output (kagi--gethash parsed-response "data" "output")) (references (kagi--gethash parsed-response "data" "references"))) - (format "%s\n\n%s" (kagi--format-output output) (kagi--format-references references)))) + (string-trim + (format "%s\n\n%s" + (kagi--format-output output) + (kagi--format-references references))))) + +(define-obsolete-function-alias 'kagi-fastgpt 'kagi-fastgpt-prompt "0.4") (defun kagi--fastgpt-display-result (result) "Display the RESULT of a FastGPT prompt in a new buffer." @@ -356,7 +365,7 @@ list of conses." :execute-command (lambda (command _history callback error-callback) (condition-case err - (funcall callback (kagi-fastgpt command) nil) + (funcall callback (kagi--fastgpt command) nil) (json-parse-error (funcall error-callback (format "Could not parse the server response %s" (cdr err)))) (error (funcall error-callback (format "An error occurred during the request %s" (cdr err))))))) @@ -386,7 +395,7 @@ string (suitable for invocations from Emacs Lisp)." (interactive (list (read-string "fastgpt> ") current-prefix-arg t)) - (let* ((result (string-trim (kagi-fastgpt prompt))) + (let* ((result (kagi--fastgpt prompt)) (result-lines (length (string-lines result)))) (cond ((and insert (not buffer-read-only)) (save-excursion