Merge branch 'main' into test
This commit is contained in:
commit
019391a618
2 changed files with 19 additions and 7 deletions
|
@ -24,8 +24,7 @@ Both functions are accessed through Kagi's [[https://help.kagi.com/kagi/api/over
|
||||||
** FastGPT
|
** 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-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-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-fastgpt= :: Function to retrieve a FastGPT response, to be used from Lisp code.
|
|
||||||
|
|
||||||
kagi.el has some functions that use FastGPT to perform certain operations on text:
|
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
|
** 0.4pre
|
||||||
|
|
||||||
|
*** Breaking changes
|
||||||
|
|
||||||
|
- Obsoleted function =kagi-fastgpt= in favor of =kagi-fastgpt-prompt=. To be removed in a next release.
|
||||||
|
|
||||||
*** New
|
*** New
|
||||||
|
|
||||||
- Introduce variable =kagi-summarizer-default-summary-format=, to produce a paragraph summary (default) or a take-away in bullet-list format.
|
- Introduce variable =kagi-summarizer-default-summary-format=, to produce a paragraph summary (default) or a take-away in bullet-list format.
|
||||||
|
|
19
kagi.el
19
kagi.el
|
@ -332,13 +332,22 @@ list of conses."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(insert (substring-no-properties summary))))
|
(insert (substring-no-properties summary))))
|
||||||
|
|
||||||
(defun kagi-fastgpt (prompt)
|
(defun kagi--fastgpt (prompt)
|
||||||
"Submit a PROMPT to FastGPT and return a formatted response string."
|
"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))
|
(let* ((response (kagi--call-fastgpt prompt))
|
||||||
(parsed-response (json-parse-string response))
|
(parsed-response (json-parse-string response))
|
||||||
(output (kagi--gethash parsed-response "data" "output"))
|
(output (kagi--gethash parsed-response "data" "output"))
|
||||||
(references (kagi--gethash parsed-response "data" "references")))
|
(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)
|
(defun kagi--fastgpt-display-result (result)
|
||||||
"Display the RESULT of a FastGPT prompt in a new buffer."
|
"Display the RESULT of a FastGPT prompt in a new buffer."
|
||||||
|
@ -356,7 +365,7 @@ list of conses."
|
||||||
:execute-command
|
:execute-command
|
||||||
(lambda (command _history callback error-callback)
|
(lambda (command _history callback error-callback)
|
||||||
(condition-case err
|
(condition-case err
|
||||||
(funcall callback (kagi-fastgpt command) nil)
|
(funcall callback (kagi--fastgpt command) nil)
|
||||||
(json-parse-error (funcall error-callback
|
(json-parse-error (funcall error-callback
|
||||||
(format "Could not parse the server response %s" (cdr err))))
|
(format "Could not parse the server response %s" (cdr err))))
|
||||||
(error (funcall error-callback (format "An error occurred during the request %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> ")
|
(interactive (list (read-string "fastgpt> ")
|
||||||
current-prefix-arg
|
current-prefix-arg
|
||||||
t))
|
t))
|
||||||
(let* ((result (string-trim (kagi-fastgpt prompt)))
|
(let* ((result (kagi--fastgpt prompt))
|
||||||
(result-lines (length (string-lines result))))
|
(result-lines (length (string-lines result))))
|
||||||
(cond ((and insert (not buffer-read-only))
|
(cond ((and insert (not buffer-read-only))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
|
|
Loading…
Reference in a new issue