From b2fd821a80b13a0fcd3f8e71b5d18e4b48a51b31 Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Sun, 21 Jul 2024 21:59:18 +0200 Subject: [PATCH 1/2] Let the FastGPT shell use kagi-fastgpt-prompt function directly Also remove the function kagi--call-fastgpt that was only called by kagi--fastgpt, embed its content in kagi--fastgpt instead. This reduces the call stack by 1 towards the Kagi API call. --- kagi.el | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/kagi.el b/kagi.el index e030fce..7b67180 100644 --- a/kagi.el +++ b/kagi.el @@ -301,14 +301,6 @@ The OBJECT will be JSON encoded and sent as HTTP POST data." (buffer-string) (error "Call to Kagi API returned with status %s" return))))) -(defun kagi--call-fastgpt (prompt) - "Submit the given PROMPT to the FastGPT API. - -Returns the JSON response as a string. See -https://help.kagi.com/kagi/api/fastgpt.html for the -interpretation." - (kagi--call-api (list (cons 'query prompt)) kagi-fastgpt-api-url)) - (defun kagi--call-summarizer (obj) "Submit a request to the Summarizer API. @@ -374,10 +366,10 @@ list of conses." (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)) +This is used by `kagi-fastgpt-prompt' to obtain a result from +FastGPT. Use that function instead for retrieving a result from +Lisp code." + (let* ((response (kagi--call-api (list (cons 'query prompt)) kagi-fastgpt-api-url)) (parsed-response (json-parse-string response)) (output (kagi--gethash parsed-response "data" "output")) (references (kagi--gethash parsed-response "data" "references"))) @@ -427,7 +419,7 @@ object (created with `make-shell-maker-config')." :execute-command (lambda (command _history callback error-callback) (condition-case err - (funcall callback (kagi--fastgpt command) nil) + (funcall callback (kagi-fastgpt-prompt 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))))))) From 1142c2c68c6482ead304a92433906568dcedfe8f Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Sun, 21 Jul 2024 22:32:59 +0200 Subject: [PATCH 2/2] Update changelog --- README.org | 4 ++++ kagi.info | Bin 17192 -> 17382 bytes 2 files changed, 4 insertions(+) diff --git a/README.org b/README.org index 0098ec5..07c8915 100644 --- a/README.org +++ b/README.org @@ -268,6 +268,10 @@ The full changelog can be found in README.org. - Show a welcome message when starting the FastGPT shell (=kagi-fastgpt-shell=). This can be customized with =kagi-fastgpt-welcome-function=, a variable with a function that returns a welcome string. +*** Misc + +- Minor refactoring in the code calling the FastGPT API. + ** 0.5 *** Breaking changes diff --git a/kagi.info b/kagi.info index ac23c00c031e1fe40e9f327464c6b0b1e36c438d..7f9725f13b4e29f54ad1038ee828d25239675933 100644 GIT binary patch delta 495 zcmX|-%}T>S6oqM|MF!kT(TZ1ep`u|X$>a~jwn|;K6w!rlB*f_tYEsfryBinMKES+z zE0;pIBEE|XxQ2QFZ95HWnXXqy70q2mrnwo+J;# z2qM<;{5XvIK^OV~#61Rnc+JGm0i8YCmx~I);lIA)yfORLZVr&l(?x8jKoG|y~r)%VDVmCRSYUVYHJIcj>Mq~oD*Ve zb~fXfjo58CxMM-giH>!e@uQv>bY-V2sZE`Xrq^;}U}|PWCLwEL=5-R21jhUbOl4`3 z+_xSv=G`O_`00e9>{>?dFWq39>`3MqMmC|*A2X?2 zVa5TKDQFmK0_Duj4WU}yGAmMxfqpSFf_g?FC^ap$C^at`ENo#8Gt)UguOuFZsq