mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 05:40:17 +00:00
Load Khoj Chat buffer before asking for query to provide context
This commit is contained in:
@@ -335,9 +335,12 @@ Render results in BUFFER-NAME using QUERY, CONTENT-TYPE."
|
|||||||
|
|
||||||
(defun khoj--chat ()
|
(defun khoj--chat ()
|
||||||
"Chat with Khoj."
|
"Chat with Khoj."
|
||||||
|
(when (not (get-buffer khoj--chat-buffer-name))
|
||||||
|
(khoj--load-chat-history khoj--chat-buffer-name))
|
||||||
|
(switch-to-buffer khoj--chat-buffer-name)
|
||||||
(let ((query (read-string "Query: ")))
|
(let ((query (read-string "Query: ")))
|
||||||
(khoj--query-chat-api-and-render-messages query khoj--chat-buffer-name)
|
(when (not (string-empty-p query))
|
||||||
(switch-to-buffer khoj--chat-buffer-name)))
|
(khoj--query-chat-api-and-render-messages query khoj--chat-buffer-name))))
|
||||||
|
|
||||||
(defun khoj--load-chat-history (buffer-name)
|
(defun khoj--load-chat-history (buffer-name)
|
||||||
(let ((json-response (cdr (assoc 'response (khoj--query-chat-api "")))))
|
(let ((json-response (cdr (assoc 'response (khoj--query-chat-api "")))))
|
||||||
@@ -357,8 +360,6 @@ Render results in BUFFER-NAME using QUERY, CONTENT-TYPE."
|
|||||||
(defun khoj--query-chat-api-and-render-messages (query buffer-name)
|
(defun khoj--query-chat-api-and-render-messages (query buffer-name)
|
||||||
"Send QUERY to Khoj Chat. Render the chat messages from exchange in BUFFER-NAME."
|
"Send QUERY to Khoj Chat. Render the chat messages from exchange in BUFFER-NAME."
|
||||||
;; render json response into formatted chat messages
|
;; render json response into formatted chat messages
|
||||||
(if (not (get-buffer buffer-name))
|
|
||||||
(khoj--load-chat-history buffer-name)
|
|
||||||
(with-current-buffer (get-buffer buffer-name)
|
(with-current-buffer (get-buffer buffer-name)
|
||||||
(let ((inhibit-read-only t)
|
(let ((inhibit-read-only t)
|
||||||
(json-response (khoj--query-chat-api query)))
|
(json-response (khoj--query-chat-api query)))
|
||||||
@@ -368,7 +369,7 @@ Render results in BUFFER-NAME using QUERY, CONTENT-TYPE."
|
|||||||
(khoj--render-chat-response json-response)))
|
(khoj--render-chat-response json-response)))
|
||||||
(progn (org-mode)
|
(progn (org-mode)
|
||||||
(visual-line-mode))
|
(visual-line-mode))
|
||||||
(read-only-mode t))))
|
(read-only-mode t)))
|
||||||
|
|
||||||
(defun khoj--query-chat-api (query)
|
(defun khoj--query-chat-api (query)
|
||||||
"Send QUERY to Khoj Chat API."
|
"Send QUERY to Khoj Chat API."
|
||||||
|
|||||||
Reference in New Issue
Block a user