Ver código fonte

Do not show JJ's prompt twice in GUI

master
The Dod 1 ano atrás
pai
commit
8e225f97ea
2 arquivos alterados com 21 adições e 7 exclusões
  1. 20
    6
      doctor.py
  2. 1
    1
      run.sh

+ 20
- 6
doctor.py Ver arquivo

@@ -8,11 +8,16 @@ from time import sleep
8 8
 import sys
9 9
 import os
10 10
 
11
-def slowprint(s):
11
+logfile = None
12
+
13
+
14
+def slowprint(s, logfile=None):
12 15
     for c in s+'\n':
13 16
         sys.stdout.write(c)
14 17
         sys.stdout.flush()
15 18
         sleep(0.01)
19
+    if logfile:
20
+        logfile.write(s+'\n')
16 21
 
17 22
 MODEL_NAME = "gpt-3.5-turbo-16k-0613"
18 23
 
@@ -40,17 +45,25 @@ conversation = ConversationChain(
40 45
 
41 46
 sys.stderr.write("{esc}[2J{esc}[H".format(esc=chr(27))) # Clear screen ;)
42 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 55
 slowprint("""=====================================================================
44 56
 Interactive Talk-Program loaded and started.
45 57
 Users:
46 58
 * [Doctor Kernel]
47 59
 * [JJ] <- you
48 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 64
 while True:
52 65
     try:
53
-        prompt = input("> ").strip()
66
+        prompt = input("JJ: > ").strip()
54 67
     except EOFError:
55 68
         prompt = ""
56 69
     if not prompt:
@@ -59,5 +72,6 @@ while True:
59 72
 End of Talk
60 73
 =====================================================================""")
61 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 Ver arquivo

@@ -5,7 +5,7 @@ cd "$(dirname "$0")"
5 5
 trap 'echo "Caught Ctrl-C"' INT
6 6
 while [ 1 ] ; do
7 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 9
     # We expect at least
10 10
     # * '<Enter>' in the header
11 11
     # * first '>' prompt

Carregando…
Cancelar
Salvar