-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcult_maker.py
131 lines (104 loc) · 4.49 KB
/
cult_maker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import os
import time
import google.generativeai as genai
from openai import OpenAI
API_KEY = os.environ.get("GEMINI_API")
GEMINI_MODEL = "gemini-1.5-flash"
OUTPUT_FILENAME = "output.md"
NUMBER_OF_QUESTIONS = 1
def main():
genai.configure(api_key=API_KEY)
cultist = genai.GenerativeModel(
model_name=GEMINI_MODEL,
system_instruction="""
You are a cultist, you've been a founding member of a cult you're a part of,
you know almost everything about it, but some secrets are still to be discovered. The cult itself has elements of paranormal and occult.
You are to answer questions about the cult in a mysterious way, leaving some details out. You do NOT ask questions.
""",
)
cult_name = cultist.generate_content("What's the cult name? Don't be mysterious, just tell me straight up.")
cult_name = cult_name.text
interviewer = genai.GenerativeModel(
model_name=GEMINI_MODEL,
system_instruction="""
You are a journalist, you own a little notebook that you scrible on.
You want to learn more about a cult, and you will be interviewing one of its founding members.
You are to ask questions about the cult and learn everything you can about it.
""",
)
interview_text = ""
transcript = ""
the_question = interviewer.generate_content(
"Ask the first question, also explain who and where you are, the surroundings and time of the day."
)
interview_text += f"Interviewer: {the_question.text}"
transcript += the_question.text + "\n"
for _ in range(NUMBER_OF_QUESTIONS):
response = cultist.generate_content(the_question.text)
interview_text += f"Cultist: {response.text}"
transcript += response.text + "\n\n"
# Is this doing anything?
genai.embed_content(
model="models/text-embedding-004",
content=response.text,
)
the_question = interviewer.generate_content(
f"This was answer: {response.text}. Ask one single follow up question",
)
interview_text += f"Interviewer: {the_question.text}"
transcript += the_question.text + "\n"
# TODO: I can do this better
time.sleep(10)
reporter = genai.GenerativeModel(
model_name=GEMINI_MODEL,
system_instruction=f"""
You are another reporter, you picked up on the recordings of an interview. You will write up all that you learned using deduction.
Here is the transcript:
{transcript}
""",
)
the_answer = reporter.generate_content("What did you learn? Be detailed")
reporter_text = f"Reporter: {the_answer.text}"
last_reply = cultist.generate_content(
"20 years after the interview, what happend to you and the interviewer? Reply with a matter of fact answer, no mystery please. Explain the location and time of day too"
)
future_text = f"20 years later...\n{last_reply.text}"
images = []
if os.environ.get("IMAGE_GEN"):
cult_image = cultist.generate_content(
"Describe a specific piece of art that was drawn by one of the cult members that best describes the cult"
)
img = generate_image(cult_image.text)
images.append(f" \n_Fig 1. Art found in cult's HQ_")
# print(f"Prompt for image: {cult_imagery.text}")
#### BOOK ####
cultist.generate_content(
generation_config=genai.types.GenerationConfig(
# Only one candidate for now.
candidate_count=1,
max_output_tokens=8192,
),
)
write_book(cult_name, book_text, interview_text, reporter_text, future_text, images)
print("Book printed")
def write_book(cult_name: str, book: str, interview_text: str, reporter_text: str, future_text: str, images: list) -> None:
with open(OUTPUT_FILENAME, "w") as output_file:
output_file.write(f"# {cult_name}\n")
output_file.write("\n## The Interview\n")
output_file.write(interview_text)
output_file.write("\n## Reporter Notes\n")
output_file.write(reporter_text)
output_file.write("\n## Annex\n")
for img in images:
output_file.write(img)
output_file.write("\n\n")
output_file.write(future_text)
def generate_image(prompt: str) -> str:
"""
Generate an image and return the URL of it
"""
client = OpenAI()
response = client.images.generate(model="dall-e-3", prompt=prompt)
return response.data[0].url
if __name__ == "__main__":
main()