-
Notifications
You must be signed in to change notification settings - Fork 1
/
poem.py
50 lines (39 loc) · 1.08 KB
/
poem.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
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../src')))
from config import Config
from providers.openai import OpenAIProvider
from metaprompt import stream_metaprompt
from dotenv import load_dotenv
import asyncio
import os
load_dotenv()
openai_api_key = os.getenv("OPENAI_API_KEY")
prompt = """
[$
Write me a poem about [:subject]
[:if [:subject] is a human
:then
Use jokingly exaggerated style
:else
Include some references to
[$ List some people who have any relation to [:subject],
comma-separated
]
]
]
"""
async def main ():
print("The metaprompt you are about to execute:")
print(prompt)
print("--------------------")
subject = input("What or who do you want to write a poem about: ")
config = Config(
providers = OpenAIProvider(api_key=openai_api_key),
model = "gpt-3.5-turbo",
parameters = { "subject": subject }
)
async for chunk in stream_metaprompt(prompt, config):
print(chunk, end='')
if __name__ == '__main__':
asyncio.run(main())