-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheva.el
64 lines (47 loc) · 1.82 KB
/
eva.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
;;; eva.el --- Emacs virtual assistant -*- lexical-binding: t; -*-
;; Author: Finn Luca Frotscher <[email protected]>
;; Version: 0.0.1
;; Package-Requires: ((emacs "24.5"))
;; Keywords: convenience
;; URL: https://github.com/LazerJesus/EVA
;; This file is not part of GNU Emacs.
;; Commentary:
;; Brief introduction to what your package does and/or why it exists.
;; Code:
;;; eva-package.el --- Evaluate user input from an external API -*- lexical-binding: t; -*-
;; Author: Your Name <[email protected]>
;; Version: 0.0.1
;; Package-Requires: ((emacs "25.1") (request "0.3.0") (json "1.4"))
;; Keywords: lisp eval api
;; URL: https://github.com/your-github-username/eva-package
;; This file is not part of GNU Emacs.
;;; Commentary:
;; Use an API to evaluate user input as Emacs Lisp code.
;;; Code:
(require 'request)
(require 'json)
(defvar eva-api-url "https://default-api-url.com/endpoint"
"API URL used by the eva function. Set this to the desired endpoint.")
(defun eva (prompt)
"Fetch evaluation for PROMPT from the API and evaluate it in Emacs."
(interactive "sEnter your prompt: ")
(message "prompt: %s" prompt)
;; Call the API
(request
eva-api-url
:type "POST"
:headers '(("Content-Type" . "application/json"))
:data (json-encode `(("prompt" . ,prompt)))
:parser 'json-read
:success (cl-function
(lambda (&key data &allow-other-keys)
;; Extract the completion value and evaluate it
(when data
(let ((completion (alist-get 'completion data)))
(when completion
(eval (read completion)))))))
:error (cl-function
(lambda (&rest args &key error-thrown &allow-other-keys)
(message "Got error: %S" error-thrown)))))
(provide 'eva-package)
;;; eva-package.el ends here