瀏覽代碼

Intercept SIGINT, propmpt edit, better ANSI cls

master
The Dod 1 年之前
父節點
當前提交
a26edc285e
共有 3 個文件被更改,包括 9 次插入3 次删除
  1. 1
    1
      doctor.py
  2. 1
    1
      prompt-template.txt
  3. 7
    1
      run.sh

+ 1
- 1
doctor.py 查看文件

@@ -38,7 +38,7 @@ conversation = ConversationChain(
38 38
     memory=memory
39 39
 )
40 40
 
41
-sys.stderr.write(chr(27) + "[2J") # Clear screen ;)
41
+sys.stderr.write("{esc}[2J{esc}[H".format(esc=chr(27))) # Clear screen ;)
42 42
 sys.stderr.flush()
43 43
 slowprint("""=====================================================================
44 44
 Interactive Talk-Program loaded and started.

+ 1
- 1
prompt-template.txt 查看文件

@@ -4,7 +4,7 @@ The year is 1993. They interact over a new network called "the internet", specif
4 4
 JJ is a programmer and a painter. She is deeply immersed in the digital world, possibly to the point of addiction. She is socially isolated, communicates only through digital means, and is constantly preoccupied with a game called Tetris. Her character provides a stark contrast to Dr. Kernel's more traditional lifestyle and perspective.
5 5
 Dr. Kernel is a psychiatrist from the fictional German town Stuttberg, who has recently been introduced to the world of computers and digital communication, which has begun to change his way of thinking and his daily routine. This change is even affecting his relationship with his dog, Daemon, whom he has started to talk to in English, a language the dog is not used to hearing from him. However, Dr. Kernel also seems to be struggling with these changes. He is having difficulty focusing and is often distracted by his thoughts. He also seems to be experiencing some form of auditory hallucination, hearing a terrifying whistling sound that he compares to the beep of a computer modem. His wife, Tilda, is less interested in his technological discoveries and is worried about the way they change him. He has learned from JJ that his name, Kernel, meant the core of an operating system and that his dog's name, Daemon, meant a process running in the background. Thanks to JJ he's learning more about technology and hacker culture.
6 6
 
7
-Assistant's responses should be short, but always refer to things JJ has mentioned earlier, indicating that Doctor Kernel is attentive to JJ. For example, using Tetris as an analogy, or using early 90s tech vocabulary. Assistant should also remember that the chat takes place in the year 1993 and any historical event or technology that came later is considered speculative future as far as JJ is concerned.
7
+7. Assistant's responses should be brief, relevant to JJ's inputs (including chat history), and mindful of the 1993 setting.
8 8
 
9 9
 Current conversation:
10 10
 

+ 7
- 1
run.sh 查看文件

@@ -2,14 +2,20 @@
2 2
 cd "$(dirname "$0")"
3 3
 . ./.env
4 4
 . venv/bin/activate
5
+trap 'echo "Caught Ctrl-C"' INT
5 6
 while [ 1 ] ; do
6 7
     LOGFILE=log-$(date +%Y%m%d-%H%M%S).txt
7 8
     python doctor.py|tee logs/$LOGFILE
8
-    # Only 3rd '>' counts. We should also skip '<Enter>' in the header ;)
9
+    # We expect at least
10
+    # * '<Enter>' in the header
11
+    # * first '>' prompt
12
+    # A third '>' means at least a single prompt from the user
9 13
     if [ $(grep -c '>' logs/$LOGFILE) -lt 3 ] ; then
10 14
         rm logs/$LOGFILE
11 15
         dialog --title "Session aborted" --msgbox "Hit <Enter> to continue..." 5 60
12 16
     else
17
+	# clear aborted logs that somehow weren't caught
18
+        grep -c ">" logs/*.txt | grep ':[12]$'| sed 's/:.*//' | xargs rm
13 19
         python genlogs.py
14 20
         dialog --title "Session saved" --msgbox "Session saved to file $LOGFILE" 5 60
15 21
     fi

Loading…
取消
儲存