AgGPT-CLI / aggpgtcli.py
AGofficial's picture
Upload 7 files
954a2c2 verified
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()