-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflash_gen.sh
executable file
·83 lines (70 loc) · 2.2 KB
/
flash_gen.sh
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# [reference files ...]
# Generate AI flashcards for a given audience
flash_gen() {
local m= # LLM model
local n=10 # number of flashcards to generate
local aud="programmers" # audience
local topic="deep learning" # topic
local adj="illuminating" # adjective for the notes
local types="concepts, terms, and other topics" # types of terms to cover
local extra="" # extra guidance
. opts
# strict mode
local old_opts=$(set +o)
set -e -u -o pipefail
if [ -n "$n" ]; then
n=" $n"
fi
if [ -n "$adj" ]; then
adj=" $adj"
fi
if [ -n "$topic" ]; then
topic=", about $topic"
fi
if [ -n "$aud" ]; then
aud=", for $aud"
fi
if [ -n "$types" ]; then
types=" Please cover the main $types, with definitions suitable for flashcard study."
fi
if [ -n "$extra" ]; then
extra=" $extra"
fi
local refs=("$@")
local refs_prompt=""
if [ "${#refs[@]}" -gt 0 ]; then
refs_prompt="Reference material: "
fi
local prompt2=$(cat <<END
Generate$n$adj flashcard notes$aud$topic.$types Use markdown format with
TeX for math and \`\`\`code snippets\`\`\`, command samples, tables, links and markdown
images where appropriate. Embedded HTML fragments are okay if useful. You can
use mermaid graphviz or SVG for diagrams in some cards where appropriate.
Please highlight the main terms in bold. Each note should be numbered, and have
like '# 1. Front', '# 1. Back', and '# 1. Extra' sections. Front and Back
should be reversible. Front is generally a term, and Back is its
definition (without using the text of the Term). Don't do it the other way around,
we will use the cards both ways but normally it's term -> definition.
Extra should contain additional details to display on the answer side. Double
newline between notes. Please produce rich and detailed flashcards, with plenty
of extra info.
$extra
END
)
# clean up whitespace in the prompt
prompt2=$(echo "$prompt2" | tr -s ' \n\t' ' ')
local prompt1="$prompt2. $refs_prompt"
local input=""
if [ ${#refs[@]} -gt 0 ]; then
input=$(cat-named -p -b "${refs[@]}")
fi
if [ -z "$input" ]; then
input=":)"
fi
printf "%s\n" "$input" | llm process -m "$m" -P "$prompt2" "$prompt1"
}
if [ "$BASH_SOURCE" = "$0" ]; then
log "$0" "$@"
flash_gen "$@"
fi