1
0
Fork 0

Merge branch 'main' into test

This commit is contained in:
Bram Schoenmakers 2024-02-14 08:49:57 +01:00
commit 019391a618
Signed by: bram
GPG key ID: 0CCD19DFDC63258F
2 changed files with 19 additions and 7 deletions

View file

@ -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.

19
kagi.el
View file

@ -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