Browse Source

Do not show JJ's prompt twice in GUI

master
The Dod 1 year ago
parent
commit
8e225f97ea
2 changed files with 21 additions and 7 deletions
  1. 20
    6
      doctor.py
  2. 1
    1
      run.sh

+ 20
- 6
doctor.py View File

8
 import sys
8
 import sys
9
 import os
9
 import os
10
 
10
 
11
-def slowprint(s):
11
+logfile = None
12
+
13
+
14
+def slowprint(s, logfile=None):
12
     for c in s+'\n':
15
     for c in s+'\n':
13
         sys.stdout.write(c)
16
         sys.stdout.write(c)
14
         sys.stdout.flush()
17
         sys.stdout.flush()
15
         sleep(0.01)
18
         sleep(0.01)
19
+    if logfile:
20
+        logfile.write(s+'\n')
16
 
21
 
17
 MODEL_NAME = "gpt-3.5-turbo-16k-0613"
22
 MODEL_NAME = "gpt-3.5-turbo-16k-0613"
18
 
23
 
40
 
45
 
41
 sys.stderr.write("{esc}[2J{esc}[H".format(esc=chr(27))) # Clear screen ;)
46
 sys.stderr.write("{esc}[2J{esc}[H".format(esc=chr(27))) # Clear screen ;)
42
 sys.stderr.flush()
47
 sys.stderr.flush()
48
+
49
+if len(sys.argv)>1:
50
+    try:
51
+        logfile = open(sys.argv[1], "w")
52
+    except:
53
+        slowprint("Couldn't open log file '{}'!!!\n".format(sys.argv[1]))
54
+
43
 slowprint("""=====================================================================
55
 slowprint("""=====================================================================
44
 Interactive Talk-Program loaded and started.
56
 Interactive Talk-Program loaded and started.
45
 Users:
57
 Users:
46
 * [Doctor Kernel]
58
 * [Doctor Kernel]
47
 * [JJ] <- you
59
 * [JJ] <- you
48
 Hit <Enter> to exit
60
 Hit <Enter> to exit
49
-=====================================================================""")
50
-slowprint("Doctor Kernel: {}".format(conversation.predict(input="Hello again, doctor. Please remind me what we were talking about last time.")))
61
+=====================================================================""", logfile)
62
+slowprint("Doctor Kernel: {}\n".format(
63
+    conversation.predict(input="Hello again, doctor. Please remind me what we were talking about last time."), logfile))
51
 while True:
64
 while True:
52
     try:
65
     try:
53
-        prompt = input("> ").strip()
66
+        prompt = input("JJ: > ").strip()
54
     except EOFError:
67
     except EOFError:
55
         prompt = ""
68
         prompt = ""
56
     if not prompt:
69
     if not prompt:
59
 End of Talk
72
 End of Talk
60
 =====================================================================""")
73
 =====================================================================""")
61
             sys.exit(0)
74
             sys.exit(0)
62
-    slowprint("\nJJ: {}".format(prompt))
63
-    slowprint("Doctor Kernel: {}".format(conversation.predict(input=prompt)))
75
+    if logfile:
76
+        logfile.write("JJ: {}\n".format(prompt))
77
+    slowprint("Doctor Kernel: {}".format(conversation.predict(input=prompt)), logfile)

+ 1
- 1
run.sh View File

5
 trap 'echo "Caught Ctrl-C"' INT
5
 trap 'echo "Caught Ctrl-C"' INT
6
 while [ 1 ] ; do
6
 while [ 1 ] ; do
7
     LOGFILE=log-$(date +%Y%m%d-%H%M%S).txt
7
     LOGFILE=log-$(date +%Y%m%d-%H%M%S).txt
8
-    python doctor.py|tee logs/$LOGFILE
8
+    python doctor.py logs/$LOGFILE
9
     # We expect at least
9
     # We expect at least
10
     # * '<Enter>' in the header
10
     # * '<Enter>' in the header
11
     # * first '>' prompt
11
     # * first '>' prompt

Loading…
Cancel
Save