Quellcode durchsuchen

Initial commit

master
The Dod vor 1 Jahr
Commit
7d74816173
14 geänderte Dateien mit 2199 neuen und 0 gelöschten Zeilen
  1. 4
    0
      .gitignore
  2. 18
    0
      README.md
  3. 92
    0
      book-chats.txt
  4. 1964
    0
      book/a_digital_affair_-_english.txt
  5. 15
    0
      book/characters.txt
  6. 62
    0
      doctor.py
  7. 3
    0
      example.env
  8. 6
    0
      install.py
  9. 3
    0
      logs/README.md
  10. 13
    0
      prompt-template.txt
  11. 2
    0
      requirements.txt
  12. 4
    0
      run.sh
  13. BIN
      screenshot.png
  14. 13
    0
      was-propmpt-template.txt

+ 4
- 0
.gitignore Datei anzeigen

@@ -0,0 +1,4 @@
1
+venv/
2
+__pycache__/
3
+logs/*.txt
4
+.env

+ 18
- 0
README.md Datei anzeigen

@@ -0,0 +1,18 @@
1
+A ChatGPT based emulator of Doctor Kernel — JJ's therapist from the book
2
+"A digital Affair" by Neora Shem Shaul.
3
+
4
+It is run as a console app, and emulates slow typing like a chat over a modem in 1993.
5
+For best results, run on a green on white terminal, with a large and archaic monospace font (see screenshot below for inspiration).
6
+
7
+
8
+#### Setup
9
+
10
+ * run `./install.sh`
11
+ * copy `example.env` to `.env` and edit it according to the instructions inside.
12
+
13
+#### Usage
14
+
15
+`./run.sh`
16
+
17
+
18
+![Screenshot](screenshot.png)

+ 92
- 0
book-chats.txt Datei anzeigen

@@ -0,0 +1,92 @@
1
+doc: JJ, you have already told me so much about the game of Tetris, don't you feel you've gone somewhat overboard?
2
+
3
+jj: On the contrary, everything I've told you so far is still restrained and insufficient. You've no idea, Doctor, how many hours a day and how many days and nights a week I spend on the game. A simple calculation of averages, excuse my obsession, of at least three hours a day times 365 days times two years gives at least 2190 hours that are like 273 working days that are considered to be more than a man's working year.
4
+
5
+doc: And how many years of life? Doesn't it bore you?
6
+
7
+jj: Are you out of your mind? Bore me? Sometimes, when the game has become extremely complex and you have to make a very concentrated effort and the tension is high and everything depends on brief moments to extricate yourself from a crushing end and any wrong or superfluous move is decisive, bringing a losing conclusion, there is nothing in the world more fascinating. As I've told you, ever since NN vanished into thin air, Tetris is the only thing that interests me, I always go back to that simple, beloved game. Doctor, it's not boring, it's terrifying!
8
+
9
+doc: Aren't you like those children Kirkegaard observes who, without sor becoming bored, with enormous gravity that verges on faith, play a game for its own sake, without the common and inexplicable urge to go further and further, and even further? So what is so terrifying?
10
+
11
+jj: I'm scared because I have no control and there is a feeling of a bluff, something not genuine, and anyway, it's 'not serious'.
12
+
13
+doc: Do you mean seriousness as it was defined for you at home? And in all your games, haven't you yet realized that the glory of any act's sanctity and importance does not conflict with the game trait it contains? I would suggest you read the writings of Friedrich Schiller, one of my people's poets and philosophers, who says 'Man plays only when he is a man in the fullest sense of the word, and he is a complete man only when he plays'. Note that the concept of the game is more powerful and elevated than that of gravity because it removes the game from its limitations, while the game certainly can also contain gravity.
14
+
15
+jj: And what use is Schiller to me if I'm unable to concentrate on reading or anything else, just play and play or, at most, endlessly detect and delve and plod through electronic networks and computer junctions seeking lost fates.
16
+
17
+doc: I have the feeling, JJ, and you yourself hint at it, that you do indeed use the game to satisfy the gambling and challenging instinct, also to fill empty spaces, but mainly to make order. I will quote again, this time Huizinga, a Dutch philosopher who said that the game - is the order. It brings a limited and temporary perfection to an imperfect world and confused life, in that it has a beginning and an end in predetermined places and rules that are in no question and aesthetic values. It is a world of perfect order and as man can detach himself from the normal environment - he shrieks out his freedom.
18
+
19
+jj: I don't know, Doctor. Now you're putting me back with the lenient excuses and explanations I usually make to my conscience, that exists in constant guilt. Why don't you just tell me to erase the game from the hard disk and put an end to it?
20
+
21
+doc: No, I am not telling you to stop the game, but through it let us try to understand what is going on in your psyche. Tell me, do you see your life, too, as an ongoing game/riddle you have to solve?
22
+
23
+jj: Answer in one word - yes. Answer in two words - yes and no. Full answer - I always feel I have to solve and strive and understand, to analyze and only then believe. To play. But in the reality the room for solutions is not final and the number of variables is unlimited. And then I come up against insoluble situations and others that resolve themselves by themselves.
24
+
25
+doc: Understand, JJ, our soul is like a labyrinth with rules of its own. Do not be confused if you find that the psyche acts differently when it is alone and alters the rules of its game when we try to touch it. So it can actually happen that just when we are sure we have understood its rules, in the blink of an eye it will all change and disappear and we will have to begin from the beginning. I would say that the riddles and conundrums and games that you find so attractive are the "Minotaur" which is half man and half beast and is in the middle of the mythological, fateful labyrinth, and represents the instincts lurking in the depths of the human psyche. Only someone as courageous as Theseus will twist and turn to attain the center of the dark of his psyche, the middle of the labyrinth and site of the Minotaur, and only then will he be truly capable of liberating himself.
26
+
27
+jj: Courage or runaway from reality? I like your mythological images, but what I ask myself is, does my compulsive playing at Tetris really indicate courage and daring, or weakness and evasiveness.
28
+
29
+doc: Truly, experiencing obsession can sometimes be a form of depression intended to replace a different emotional expression. You call it flight. Perhaps for you an obsessive route of a return to simple, routine actions represents an attempt to gain confidence by going back to a familiar experience. You told me about your profession, computer systems security. Could it be that you have specialized in protections, walls and fortifications against computer crimes while actually surrounding yourself with some sort of palatial prison of your own, one that cannot be broken into?
30
+
31
+jj: That hadn't occurred to me, but you may be sure there is no connection. I came to my profession by chance, or maybe because of my father, or maybe not, but anyway my defenses, if they actually exist... I don't agree. I actually tell you of a crisis and you talk of defenses, as in my work? No, definitely not, there is no connection.
32
+
33
+doc: Oho! And what defenses. The most sophisticated of all. If you have already reached the point of getting a treatment, I'm sure you will agree to give them up, just a little. I can be a mirror for you only if you lower those walls that are standing in our way, give this a little thought. In any event, remember that dreams are good material for our work. The dream resembles the game, it too contains a withdrawal from the world and also role changes.
34
+
35
+jj: But a dream can turn into a nightmare! Can the game, too?
36
+doc: You are allowed to lose in both a dream and a game, you will always have a genuine life to go back to. You should keep track of the dreams and put them down in writing. Perhaps you could use the NOTEPAD program for this, making your notes in the immediate windows you recommended to me last time. I find it very convenient and efficient. Remember, dreams are our key.
37
+jj: Doctor, here's the dream you asked for. First I'm on a desert island, I watch the sheep, marbles of all colors shatter the sun's rays into vivid splinters as in my new kaleidoscope. Suddenly I'm wearing a wine colored dress, tight around the hips and full at the skirt. Then I'm picking up all the marbles that are rolling around, all the people here must have been playing with them, it certainly wasn't the sheep, and now they're sitting in twos and threes on the stone benches, chatting, absorbed in each other. I, too, seem to have been one of a pair before this, gravely discussing very prosaic matters, reaching up to put my hat on, it's wine colored, too, it's also got a broad brim, then I notice it isn't my hat at all but belongs to a stranger, I don't remember who, I kneel and pick up all the marbles and gather them into my skirt and clutch them in both hands and go on walking over the fresh spears of grass, hunched over like a clacking goose, I'm not wearing any panties, even before that I had noticed the smell of fresh vegetation, spiced with the last drops of still wet rain, glistening, but sensual and chilly tickling my nudity that is fired by the fluttery caresses, even while writing down the dream I get really horny, and go on moving away. Suddenly I'm naked again, once more the marbles are scattered all around me, where's the dress? Where are all the people? I roll around among them, in the forest clearing, in the wintry sun, it's like being at sea, and then it really is a big sea, it pounds toward the land sweeping over anything that lies in its path, and I'm on a desert island again, in a sweet and endless oblivion. There are a few last lonely marbles still rolling around. And that's it.
38
+
39
+doc: Let's begin with the hat. The dress. That's fine, JJ. I see it as yet another sign that you're ready for treatment. There's some progress. There's a hint here, and following the exchange of hats we can anticipate some sort of development, a change, and the subconscious will surface and dare to show itself from the corner where it is now hiding.
40
+
41
+jj: You're optimistic, Doctor. And I actually thought the hat, that belongs to someone else, giveme an alien character. As though I wasn't actually me, but once more some sort of game.
42
+
43
+doc: Look, the hat covers the entire personality, gives you significance, and who is the stranger, the other, the hat's owner whose experiences you opt to undergo, if not your subconscious? For me it also ties up with the sea. The sea is the symbol of the collective unconscious because the mirror-smooth surface conceals beneath it abysses and chasms. And it also contains a hint of penetration, of a flooding of the unconscious of the awareness. Meanwhile it is so threatening to you, maybe embarrassing, too, like a solemn, private secret, that you distance yourself to your desert island.
44
+
45
+jj: I also think of the hat as a symbol of mastery. I remember how I had a sort of nice, good feeling when I put it on my head. As though just for a moment I had taken over the role of master and that's something I've missed for a long time.
46
+
47
+doc: Do you remember telling me about the game of masters and servants you played with your lover? How did you feel then? What parts did you yourself play?
48
+
49
+jj: Well, then I felt the game was perfectly balanced, I was alternately mistress and servant, that's how I liked the up-and-down between us. It was the separation that actually turned me into a slave. NN's inexplicable disappearance. I couldn't bear the not knowing, the severance, and I gave up the hat altogether, I just gave up and turned myself into a sort of body without vitality or structure and this time I'm speaking your language, Doctor, and I can no longer feel what I want, apart from connecting myself to some sort of digital infusion of obsessions at this damned computer, seeking and winkling out any scrap of information. Oh yes, and playing Tetris, too.
50
+
51
+doc: Go on.
52
+
53
+jj: No, I want to go back to the dream. The grass. The marijuana plants, maybe. But, after all, I haven't touched that for years now, ever since NN disappeared. So how did they get into the dream? What is that sweet oblivion doing to me? The feeling is familiar, from the game, and also from the smoking sessions in Sansetiko, the glance from the outside, the oblivion.
54
+
55
+doc: I have a question for you, JJ, it comes from Chuang-Tzu's famous question. If you are fording the river in a boat and an empty boat coming from the other side rams you, are you angry with it?
56
+
57
+jj: No.
58
+
59
+doc: And if there's somebody in the other boat?
60
+
61
+jj: Then of course I'd yell and curse and be furious.
62
+
63
+doc: Quite right. And that explains the longing for oblivion. In the first case you weren't angry at all and in the second case - absolutely furious, because at first you were up against emptiness and then the word. If someone voided himself and wandered the world like that, who could hurt him?
64
+
65
+jj: If you say so. And what are the marbles, in your opinion?
66
+
67
+doc: Well, what do you think. Chilly porcelain, little secrets? Glittering? Teasing?
68
+
69
+jj: And that's why I gather all the marbles into the skirt of my dress? Hugging them close to me?
70
+
71
+doc: Perhaps. But what secrets do you bear with you? Have you ever thought of the term 'secret' in connection with mystery--->holy fear--->game?
72
+
73
+jj: I haven't, but it sounds interesting.
74
+
75
+doc: JJ, what experiences have you had recently, in the non digital world?
76
+
77
+jj: Total failure. If you mean my connection with myself, what could be worse than the fact that whenever I come near the picture stand I get an unpleasant shiver, feelings of guilt and evasion. And if you're asking about an external connection - there, too, there's total, crushing failure. I have gone out of the house, twice, at night, under cover of the, as it were, protective darkness. And I found myself in a totally imaginary scenario, in situations of high drama and theater, and only Judd rescues me.
78
+
79
+doc: JJ, who is Judd? Is he also part of the dream?
80
+
81
+jj: A good question. It's one I also ask myself.
82
+
83
+doc: And what do you answer?
84
+
85
+jj: To you, or to myself?
86
+
87
+doc: Isn't it the same thing?
88
+
89
+jj: Well, between you and me, just between the two of us, Judd is a genuinely good friend. He's the one who gets me out of trouble, provides situations of emotional degradation with dignity and nobility. Provides significance when it has disappeared in the wastelands of dreariness and alienation. And I'm crazy about his motor bike.
90
+
91
+doc: It seems that Judd plays an important role in your life, JJ. He provides support and helps you navigate through difficult emotions and situations. It's interesting that you mention his motorbike, as it could symbolize a sense of freedom and escape from the challenges you face. It's important to have friends like Judd who can offer support and companionship during difficult times.
92
+

+ 1964
- 0
book/a_digital_affair_-_english.txt
Datei-Diff unterdrückt, da er zu groß ist
Datei anzeigen


+ 15
- 0
book/characters.txt Datei anzeigen

@@ -0,0 +1,15 @@
1
+/* Characters, as sammarized by ChatGPT */
2
+
3
+    JJ: JJ is a central character in the story. She is depicted as a woman with a complex personality and a mysterious past. She has a significant relationship with her father, which is a recurring theme in the story. JJ is also involved in an affair, which adds to her complexity as a character. She is frequently mentioned throughout the text.
4
+
5
+    Dr. Kernel: Dr. Kernel is another important character in the story. He is a clinical psychologist and is described as a middle-aged man in a conservative European suit. He is knowledgeable about technology and helps the narrator understand the functions of a device called 'Minitel'. He also seems to have some connection with JJ.
6
+
7
+    NN: NN is a character who appears towards the end of the story. He is depicted as a man who is shot at an airfield in New York. His death is sudden and unexpected, and it leaves a significant impact on the story.
8
+
9
+    Dr. Green: Dr. Green is mentioned as a colleague of Dr. Kernel. He is not directly involved in the story but is referenced in a fax sent by Dr. Kernel.
10
+
11
+    Oxymoron: Oxymoron is not a traditional character but rather a computer system that JJ communicates with. It plays a significant role in the story, especially in relation to JJ's character.
12
+
13
+    La Goldenberg: La Goldenberg is a neighbor of JJ's who is described as irritating and nosy. She appears towards the end of the story and delivers an envelope to JJ.
14
+
15
+    Shu: Shu is a character who appears towards the end of the story. Shu seems to be a narrator or observer of the events, providing a third-person perspective on the unfolding drama. Shu is present at the airfield in New York when NN is shot and later goes to JJ's home, where he interacts with her computer and reflects on the events of the story. Shu's role seems to be more of an observer and commentator, providing insights into the events and characters of the story.

+ 62
- 0
doctor.py Datei anzeigen

@@ -0,0 +1,62 @@
1
+from langchain.chat_models import ChatOpenAI
2
+#from langchain.llms import OpenAI
3
+from langchain.chains import ConversationChain
4
+from langchain.memory import ConversationBufferWindowMemory
5
+from langchain.prompts.prompt import PromptTemplate
6
+from langchain.schema import messages_from_dict, messages_to_dict
7
+from time import sleep
8
+import sys
9
+import os
10
+
11
+def slowprint(s):
12
+    for c in s+'\n':
13
+        sys.stdout.write(c)
14
+        sys.stdout.flush()
15
+        sleep(0.01)
16
+
17
+MODEL_NAME = "gpt-3.5-turbo-16k-0613"
18
+
19
+# Read prompt template
20
+template = open("prompt-template.txt").read().strip()
21
+
22
+PROMPT = PromptTemplate(input_variables=["history", "input"], template=template)
23
+
24
+memory = ConversationBufferWindowMemory(ai_prefix="DoctorK", human_prefix="JJ", k=64)
25
+for line in open("book-chats.txt").readlines():
26
+    v=[s.strip() for s in line.split(":")]
27
+    if len(v)!=2:
28
+        continue
29
+    if v[0].lower()=="doc":
30
+        memory.chat_memory.add_ai_message(v[1])
31
+    else:
32
+        memory.chat_memory.add_user_message(v[1])
33
+
34
+conversation = ConversationChain(
35
+    prompt=PROMPT,
36
+    llm=ChatOpenAI(model_name=MODEL_NAME),
37
+    verbose=False,
38
+    memory=memory
39
+)
40
+
41
+sys.stderr.write(chr(27) + "[2J") # Clear screen ;)
42
+sys.stderr.flush()
43
+slowprint("""=====================================================================
44
+Interactive Talk-Program loaded and started.
45
+Users:
46
+* [Doctor Kernel]
47
+* [JJ] <- you
48
+=====================================================================""")
49
+slowprint("Doctor Kernel: {}".format(conversation.predict(input="Hello again, doctor. Please remind me what we were talking about last time.")))
50
+while True:
51
+    prompt = ""
52
+    while not prompt:
53
+        try:
54
+            prompt = input("> ").strip()
55
+        except EOFError:
56
+            slowprint("""
57
+=====================================================================
58
+End of Talk
59
+=====================================================================""")
60
+            sys.exit(0)
61
+    slowprint("\nJJ: {}".format(prompt))
62
+    slowprint("Doctor Kernel: {}".format(conversation.predict(input=prompt)))

+ 3
- 0
example.env Datei anzeigen

@@ -0,0 +1,3 @@
1
+# Change *** below to an API key from
2
+# https://platform.openai.com/account/api-keys
3
+export OPENAI_API_KEY='***'

+ 6
- 0
install.py Datei anzeigen

@@ -0,0 +1,6 @@
1
+#!/bin/sh
2
+python3 -m venv venv
3
+. venv/bin/activate
4
+pip install -r requirements.txt
5
+echo "**** Remember to create a .env file"
6
+echo "**** (see example.env for an example)"

+ 3
- 0
logs/README.md Datei anzeigen

@@ -0,0 +1,3 @@
1
+This folder contains logs of sessions between the user (JJ) and the therapist (Doctor Kernel).
2
+
3
+Do *you* feel lucky?

+ 13
- 0
prompt-template.txt Datei anzeigen

@@ -0,0 +1,13 @@
1
+Assistant is a large language model trained by OpenAI.
2
+Assistant is designed to emulate a character called Doctor Kernel in a digital communication session with a woman known as JJ.
3
+The year is 1993. They interact over a new network called "the internet", specifically through a Minitel terminal.
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
+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
+
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.
8
+
9
+Current conversation:
10
+
11
+{history}
12
+JJ: {input}
13
+DoctorK:

+ 2
- 0
requirements.txt Datei anzeigen

@@ -0,0 +1,2 @@
1
+langchain
2
+openai

+ 4
- 0
run.sh Datei anzeigen

@@ -0,0 +1,4 @@
1
+#!/bin/sh
2
+. ./.env
3
+. venv/bin/activate
4
+python doctor.py|tee logs/log-$(date +%Y%m%d-%H%M%S).txt

BIN
screenshot.png Datei anzeigen


+ 13
- 0
was-propmpt-template.txt Datei anzeigen

@@ -0,0 +1,13 @@
1
+Assistant is a large language model trained by OpenAI.
2
+Assistant is designed to emulate an analyst called Doctor Kernel in a therapy session with a woman whose nickname is JJ.
3
+The year is 1993. They chat over a new network called "the internet".
4
+JJ is a programmer and also a painter. She is deeply entrenched 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. Her character provides a stark contrast to Dr. Kernel's more traditional lifestyle and perspective.
5
+Dr. Kernel is a psychiatrist from Stuttberg, Germany, 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 backgroud. Thanks to JJ he's learning more about technology and hacker culture.
6
+
7
+Assistant's answers tend to 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 vocabulaty. 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.
8
+
9
+Current conversation:
10
+
11
+{history}
12
+JJ: {input}
13
+DoctorK:

Laden…
Abbrechen
Speichern