Преглед на файлове

[BOOTSTRA.386 powered] logserver + better run.sh

master
The Dod преди 1 година
родител
ревизия
763712e8cf
променени са 8 файла, в които са добавени 104 реда и са изтрити 12 реда
  1. 10
    1
      README.md
  2. 6
    5
      doctor.py
  3. 16
    0
      genlogs.py
  4. 43
    0
      logs.tmpl
  5. 13
    5
      logs/index.html
  6. 3
    0
      logserver.sh
  7. 1
    0
      requirements.txt
  8. 12
    1
      run.sh

+ 10
- 1
README.md Целия файл

@@ -12,7 +12,16 @@ For best results, run on a green on black terminal, with a large and archaic mon
12 12
 
13 13
 #### Usage
14 14
 
15
-`./run.sh`
15
+`./run.sh` is an infinite loop of sessions with the doctor.
16
+Whenever you finish a non-empty session, the log is saved and
17
+the `index.html` of the `logs/` folder gets regenerated (see below).
16 18
 
19
+#### Serving session logs via web
20
+
21
+`./logserver.sh` would serve session log files on port 8000
22
+
23
+Note that you can try this as is (on a fresh repo clone, without even running `install.py`) to enjoy the 90s style gui (thanks to [BOOTSTRA.386](https://bootstra386.com/)).
24
+
25
+#### Screenshot
17 26
 
18 27
 ![Screenshot](screenshot.png)

+ 6
- 5
doctor.py Целия файл

@@ -45,14 +45,15 @@ Interactive Talk-Program loaded and started.
45 45
 Users:
46 46
 * [Doctor Kernel]
47 47
 * [JJ] <- you
48
+Hit <Enter> to exit
48 49
 =====================================================================""")
49 50
 slowprint("Doctor Kernel: {}".format(conversation.predict(input="Hello again, doctor. Please remind me what we were talking about last time.")))
50 51
 while True:
51
-    prompt = ""
52
-    while not prompt:
53
-        try:
54
-            prompt = input("> ").strip()
55
-        except EOFError:
52
+    try:
53
+        prompt = input("> ").strip()
54
+    except EOFError:
55
+        prompt = ""
56
+    if not prompt:
56 57
             slowprint("""
57 58
 =====================================================================
58 59
 End of Talk

+ 16
- 0
genlogs.py Целия файл

@@ -0,0 +1,16 @@
1
+import chevron
2
+from glob import glob
3
+import os
4
+
5
+MAX_FILES = 20
6
+
7
+
8
+def genlog():
9
+    os.chdir('logs')
10
+    filenames = list(reversed(sorted(glob("*.txt"))))[:MAX_FILES]
11
+    with open('../logs.tmpl') as fin:
12
+        with open('index.html','w') as fout:
13
+            fout.write(chevron.render(fin, {"filenames": filenames}))
14
+
15
+if __name__ == '__main__':
16
+    genlog()

+ 43
- 0
logs.tmpl Целия файл

@@ -0,0 +1,43 @@
1
+<!doctype html>
2
+<html lang="en">
3
+
4
+<head>
5
+    <meta charset="utf-8">
6
+    <meta name="viewport" content="width=device-width, initial-scale=1">
7
+    <title>Doctor Kernel's session logs &mdash; [JJ]</title>
8
+    <link href="css/bootstrap.min.css" rel="stylesheet">
9
+</head>
10
+
11
+<body>
12
+    <div class="container">
13
+        <div class="row">
14
+            <div class="col-12">
15
+                <div class="jumbotron text-center">
16
+                    <br/>
17
+                    <h1>Doctor Kernel's session logs</h1>
18
+                    <h3>Patient: JJ</h3>
19
+                </div>
20
+                <div class="alert alert-danger text-center">*** CONFIDENTIAL ***</div>
21
+            </div>
22
+        </div>
23
+        <div class="row">
24
+            <div class="col-12">
25
+                <ul class="list-group text-center">
26
+                  {{#filenames}}
27
+                    <li class="list-group-item">
28
+                        <a target="_blank" class="btn btn-success" href="{{.}}">[{{.}}]</a>
29
+                    </li>
30
+                  {{/filenames}}
31
+                </ul>
32
+             </div>
33
+        </div>
34
+        <div class="row">
35
+            <div class="col-12">
36
+                <div class="alert alert-warning text-center">*** VERTRAULICH ***</div>
37
+            </div>
38
+    </div>
39
+    <script src="js/bootstrap.min.js"></script>
40
+
41
+</body>
42
+
43
+</html>

+ 13
- 5
logs/index.html Целия файл

@@ -13,27 +13,35 @@
13 13
         <div class="row">
14 14
             <div class="col-12">
15 15
                 <div class="jumbotron text-center">
16
-                    <div class="alert alert-danger">*** CLASSIFIED ***</div>
17 16
                     <br/>
18 17
                     <h1>Doctor Kernel's session logs</h1>
19 18
                     <h3>Patient: JJ</h3>
20 19
                 </div>
21
-
20
+                <div class="alert alert-danger text-center">*** CONFIDENTIAL ***</div>
22 21
             </div>
23 22
         </div>
24 23
         <div class="row">
25 24
             <div class="col-12">
26
-
27 25
                 <ul class="list-group text-center">
28 26
                     <li class="list-group-item">
29
-                        <a target="_blank" class="btn btn-primary" href="log-20230719-100651.txt">[log-20230719-100651.txt]</a>
27
+                        <a target="_blank" class="btn btn-success" href="log-20230720-184118.txt">[log-20230720-184118.txt]</a>
30 28
                     </li>
31 29
                     <li class="list-group-item">
32
-                        <a target="_blank" class="btn btn-primary" href="log-20230718-212029.txt">[log-20230718-212029.txt]</a>
30
+                        <a target="_blank" class="btn btn-success" href="log-20230720-170422.txt">[log-20230720-170422.txt]</a>
31
+                    </li>
32
+                    <li class="list-group-item">
33
+                        <a target="_blank" class="btn btn-success" href="log-20230719-100651.txt">[log-20230719-100651.txt]</a>
34
+                    </li>
35
+                    <li class="list-group-item">
36
+                        <a target="_blank" class="btn btn-success" href="log-20230718-212029.txt">[log-20230718-212029.txt]</a>
33 37
                     </li>
34 38
                 </ul>
35 39
              </div>
36 40
         </div>
41
+        <div class="row">
42
+            <div class="col-12">
43
+                <div class="alert alert-warning text-center">*** VERTRAULICH ***</div>
44
+            </div>
37 45
     </div>
38 46
     <script src="js/bootstrap.min.js"></script>
39 47
 

+ 3
- 0
logserver.sh Целия файл

@@ -0,0 +1,3 @@
1
+#!/bin/sh
2
+cd "$(dirname "$0")/logs"
3
+python -m http.server

+ 1
- 0
requirements.txt Целия файл

@@ -1,2 +1,3 @@
1 1
 langchain
2 2
 openai
3
+chevron

+ 12
- 1
run.sh Целия файл

@@ -1,4 +1,15 @@
1 1
 #!/bin/sh
2 2
 . ./.env
3 3
 . venv/bin/activate
4
-python doctor.py|tee logs/log-$(date +%Y%m%d-%H%M%S).txt
4
+while [ 1 ] ; do
5
+    LOGFILE=log-$(date +%Y%m%d-%H%M%S).txt
6
+    python doctor.py|tee logs/$LOGFILE
7
+    # Only 3rd '>' counts. We should also skip '<Enter>' in the header ;)
8
+    if [ $(grep -c '>' logs/$LOGFILE) -lt 3 ] ; then
9
+        rm logs/$LOGFILE
10
+        dialog --title "Session aborted" --msgbox "Hit <Enter> to continue..." 5 60
11
+    else
12
+        python genlogs.py
13
+        dialog --title "Session saved" --msgbox "Session saved to file $LOGFILE" 5 60
14
+    fi
15
+done

Loading…
Отказ
Запис