-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
49 lines (37 loc) · 1.15 KB
/
main.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
#
# Author: Jose Cerrejon
# Email: contact at ulysess_.gmail_com
# License: MIT
#
import os
import signal
import sys
import typing
import unicodedata
from src.ai import AI
from src.helpers.dot_env_loader import DotenvLoader
from src.helpers.utils import Utils
DotenvLoader.load(".env")
APP_VERSION = "1.2.DEF"
BYE_MESSAGE = "\nBye! I hope I was helpful! Bzzz 🪰"
DEFAULT_LIBRARY = "openai"
MAX_INPUT_LENGTH = 255
def print_header() -> None:
print(Utils.get_header_message(APP_VERSION))
def signal_handler(sig: int, frame: typing.Any) -> None:
print(BYE_MESSAGE)
sys.exit(0)
def normalize_text(text: str) -> str:
return unicodedata.normalize("NFKC", text)
if __name__ == "__main__":
ai = AI(os.environ.get("USE_LIBRARY", DEFAULT_LIBRARY))
signal.signal(signal.SIGINT, signal_handler)
print_header()
while (prompt := input("\nBuzz: ")) != "exit":
if len(prompt) > MAX_INPUT_LENGTH:
raise ValueError("Input exceeds maximum allowed length.")
response = (
ai.answer(normalize_text(prompt)) if prompt != "imagine" else ai.draw()
) # type: ignore
print(response)
print(BYE_MESSAGE)