-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structured-output.el
58 lines (50 loc) · 1.43 KB
/
structured-output.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
(defun science-bot-structured (question)
(let ((input (format
"I am a science bot. I give scientific answers.
I am a lisp machine and I will answer with machine readable structured data.
Q: The major taxa of insects are
Output:
((topics . (zoology entomology taxonomy))
(taxa .
((Coleoptera beetles)
(Diptera flies)
(Hymenoptera ants bees wasps)
(Lepidoptera butterflies moths)
(Hemiptera true-bugs)
(Orthoptera grasshoppers crickets katydids)
(Isoptera termites))))
Q: %s"
question)))
(with-current-buffer-window
"*science-bot*"
nil
nil
(insert question "\n")
(cl-loop
for
answer
(openai-api-sync
(list
`((model . "text-davinci-003")
(prompt . ,input)
(top_p . 1)
(max_tokens . 512)
(temperature . 0.5)
(presence_penalty . 0))))
do
(insert answer))
(buffer-string))))
(science-bot-structured "The major topics of psychology")
;; The major topics of psychology
;; Output:
(defvar my-response
'((topics . (psychology))
(subtopics .
((cognitive psychology)
(developmental psychology)
(personality psychology)
(social psychology)
(abnormal psychology)
(clinical psychology)))))
(length (assoc 'subtopics my-response))
7