-
Notifications
You must be signed in to change notification settings - Fork 24
/
main.py
89 lines (70 loc) · 2.57 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
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
import logging
import os
import sys
sys.path.insert(0, "src")
from functools import partial
from typing import List
from steamship import Steamship, SteamshipError, Block
from steamship.cli.ship_spinner import ship_spinner
from termcolor import colored
from api import GirlfriendGPT
def show_results(response_messages: List[Block]):
print(colored("\nResults: ", "blue", attrs=["bold"]))
for message in response_messages:
if message.mime_type:
print(message.url, end="\n\n")
else:
print(message.text, end="\n\n")
class LoggingDisabled:
"""Context manager that turns off logging within context."""
def __enter__(self):
logging.disable(logging.CRITICAL)
def __exit__(self, exit_type, exit_value, exit_traceback):
logging.disable(logging.NOTSET)
def main():
Steamship()
with Steamship.temporary_workspace() as client:
run = partial(
run_agent,
agent=GirlfriendGPT(
client=client,
config={
"bot_token": "test",
"elevenlabs_voice_id": os.environ.get("ELEVENLABS_VOICE_ID"),
"elevenlabs_api_key": os.environ.get("ELEVENLABS_API_KEY"),
},
),
)
print(f"Starting Agent...")
print(
f"If you make code changes, you will need to restart this client. Press CTRL+C to exit at any time.\n"
)
count = 1
while True:
print(f"----- Agent Run {count} -----")
prompt = input(colored(f"Prompt: ", "blue"))
run(
# client,
prompt=prompt,
)
count += 1
def run_agent(agent, prompt: str, as_api: bool = False) -> None:
# For Debugging
message = Block(text=prompt)
message.set_chat_id("123")
if not agent.is_verbose_logging_enabled(): # display progress when verbose is False
print("Running: ", end="")
with ship_spinner():
response = agent.create_response(incoming_message=message)
else:
response = agent.create_response(incoming_message=message)
show_results(response)
if __name__ == "__main__":
# when running locally, we can use print statements to capture logs / info.
# as a result, we will disable python logging to run. this will keep the output cleaner.
with LoggingDisabled():
try:
main()
except SteamshipError as e:
print(colored("Aborting! ", "red"), end="")
print(f"There was an error encountered when running: {e}")