File size: 3,280 Bytes
954a2c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pyfiglet
from colorama import Fore, Style, init
import os
import requests
import re
from urllib.parse import quote_plus
import datetime
from AgGPT12.AgGPT12Pro import AgGPT12Pro

cot1 = "<thought>"
cot2 = "</thought>"
response1 = "<response>"
response2 = "</response>"


def AskAI(prompt):
    ag_gpt = AgGPT12Pro()
    answer = ag_gpt.AskAgGPT(prompt)
    return answer

init(autoreset=True)
os.system('cls' if os.name == 'nt' else 'clear')
       
def display_banner():
    banner = pyfiglet.figlet_format("AgGPT", font = "slant", width = 40)
    print(Fore.RED + Style.BRIGHT + banner)

def handleCommand(command: str):
    result = AskAI(command)
    cot_match = re.search(r'<thought>(.*?)</thought>', result, re.DOTALL)
    response_match = re.search(r'<response>(.*?)</response>', result, re.DOTALL)

    if cot_match:
        print(Fore.GREEN + Style.DIM + cot_match.group(1).strip())
    if response_match:
        print(Fore.RED + Style.BRIGHT + response_match.group(1).strip())

def handleActivationCommand(command):
    if command == "!help":
        print(Fore.YELLOW + "Available commands:\n"
              "!help - Show this help message\n"
              "!exit - Exit the CLI"
              "\n!code {instructions to generate code} - Generate code based on the instructions"
              )
    
    elif command == "!exit":
        print(Fore.RED + "Exiting the CLI. Goodbye!")
        exit(0)

    elif command.startswith("!code "):
        code_instruction = command[len("!code "):].strip()
        print(Fore.YELLOW + f"Generating code for: {code_instruction}")
        result = AskAI(code_instruction)
        cot_match = re.search(r'<thought>(.*?)</thought>', result, re.DOTALL)
        response_match = re.search(r'<response>(.*?)</response>', result, re.DOTALL)
        if cot_match:
            print(Fore.GREEN + Style.DIM + cot_match.group(1).strip())
        if response_match:
            print(Fore.RED + Style.BRIGHT + response_match.group(1).strip())
        response_text = response_match.group(1).strip() if response_match else ""
        code_blocks = re.findall(r'```(\w+)?\n(.*?)```', response_text, re.DOTALL)

        for lang, code in code_blocks:
            lang = lang.strip().lower() if lang else "txt"
            date_str = datetime.datetime.now().strftime("%Y%m%d")
            filename = f"{date_str}_AgGPT.{lang if lang != 'python' else 'py'}"
            with open(filename, "w", encoding="utf-8") as f:
                f.write(code.strip())
            print(Fore.CYAN + f"Code written to {filename}")
    else:
        print(Fore.RED + "Unknown command. Type !help for assistance.")


def main():
    display_banner()
    print(Fore.RED + "Welcome to the AgGPT CLI. Type 'exit' to depart.\n")
    while True:
        try:
            command = input(Fore.WHITE + Style.BRIGHT + ">>> ").strip().lower()
            if command == "exit":
                print(Fore.RED + "Farewell.")
                break
            elif command.startswith("!"):
                handleActivationCommand(command)
            else:
                handleCommand(command)
        except (KeyboardInterrupt, EOFError):
            print(Fore.RED + "\nSession interrupted. Good night.")
            break

if __name__ == "__main__":
    main()