-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
75 lines (61 loc) · 2.44 KB
/
main.py
File metadata and controls
75 lines (61 loc) · 2.44 KB
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
from rich import print
from rich.console import Console
from rich.panel import Panel
from rich.markdown import Markdown
import sys
import time
import config
from llm_interface import llm
import logging
console = Console()
class RichConsoleHandler(logging.StreamHandler):
def emit(self, record):
if record.levelno >= logging.CRITICAL:
console.print(f"[bold magenta]CRITICAL:[/bold magenta] {record.getMessage()}")
elif record.levelno >= logging.ERROR:
console.print(f"[bold red]ERROR:[/bold red] {record.getMessage()}")
elif record.levelno >= logging.WARNING:
console.print(f"[bold yellow]WARNING:[/bold yellow] {record.getMessage()}")
# elif record.levelno >= logging.INFO:
# console.print(f"[bold blue]INFO:[/bold blue] {record.getMessage()}")
# elif record.levelno >= logging.DEBUG:
# console.print(f"[bold green]DEBUG:[/bold green] {record.getMessage()}")
def main(logger):
logger.info('Application Started')
language_model = llm(logger)
while True:
llm_prompt = language_model.get_llm_prompt()
if llm_prompt.lower() in config.EXIT_STRINGS:
sys.exit()
start = time.time()
llm_reply = language_model.ask_model(llm_prompt)
logger.info(f"LLM Reply: {llm_reply}")
handled_response = language_model.handle_llm_reply(llm_reply)
logger.info(f"Handled Response: {handled_response}")
logger.info(f"Response equals original: {handled_response == llm_reply}")
if handled_response != llm_reply:
output = language_model.tool_response(prompt=f'''Your original Request was: {llm_prompt},
This is the tool reply: {handled_response}
Make a markdown format reply, using fun emojis.
''')
elif handled_response == llm_reply:
output = handled_response
elapsed = time.time() - start
panel_narrow = Panel(Markdown(output),
title="LLM Reply",
subtitle=f"Response time: {elapsed:.2f}s",
expand=False,
)
console.print(panel_narrow)
if __name__ == "__main__":
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('app.log')
]
)
logger = logging.getLogger(__name__)
logger.addHandler(RichConsoleHandler())
logger.info("Logging Instantiated")
main(logger)