feat: interactive compiler startup AI Engine setup prompt and CLI options
This commit is contained in:
1 parent
590d2917fd
commit
e8b93c7d7e
3 files changed
+52
-2
No files matched your search
+27
@@ -116,12 +116,22 @@ def run_file(filepath):
|
||||
if not os.path.exists(filepath):
|
||||
print(f"\033[1;31m[!] Error: File '{filepath}' not found.\033[0m")
|
||||
sys.exit(1)
|
||||
try:
|
||||
from stdlib_modules import check_and_prompt_ai_engine
|
||||
check_and_prompt_ai_engine()
|
||||
except Exception:
|
||||
pass
|
||||
with open(filepath, "r", encoding="utf-8") as f:
|
||||
code = f.read()
|
||||
run_code(code)
|
||||
|
||||
def start_repl():
|
||||
print(ASCII_BANNER)
|
||||
try:
|
||||
from stdlib_modules import check_and_prompt_ai_engine
|
||||
check_and_prompt_ai_engine()
|
||||
except Exception:
|
||||
pass
|
||||
evaluator = Evaluator()
|
||||
buffer = []
|
||||
|
||||
@@ -223,6 +233,8 @@ Creator: {AUTHOR}
|
||||
airalang run <script.aira> Execute an AiraLang script
|
||||
airalang build <file.aira> [-o out] Compile script to standalone executable
|
||||
airalang new <project_name> Create a new AiraLang project scaffold
|
||||
airalang --ai-setup Configure Aira AI Engine API key (interactive)
|
||||
airalang --set-key <key> [provider] Set API key for provider (OpenRouter/Groq/OpenAI/Gemini)
|
||||
airalang -v, --version Display version information
|
||||
airalang -h, --help Show this help message
|
||||
""")
|
||||
@@ -234,6 +246,21 @@ def main():
|
||||
print(f"AiraLang v{VERSION} | Creator: {AUTHOR}")
|
||||
elif arg1 in ("-h", "--help"):
|
||||
print_help()
|
||||
elif arg1 in ("--ai-setup", "--setup-ai"):
|
||||
from stdlib_modules import prompt_developer_for_ai_key
|
||||
prompt_developer_for_ai_key()
|
||||
sys.exit(0)
|
||||
elif arg1 == "--set-key":
|
||||
if len(sys.argv) > 2:
|
||||
from stdlib_modules import create_ai_module
|
||||
ai_mod = create_ai_module()
|
||||
prov = sys.argv[3] if len(sys.argv) > 3 else None
|
||||
ai_mod.methods["set_key"](sys.argv[2], provider=prov)
|
||||
print(f"\033[1;32m✓ API Key successfully configured and saved to config!\033[0m")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print("\033[1;31m[!] Error: Specify API key: airalang --set-key <key> [provider]\033[0m")
|
||||
sys.exit(1)
|
||||
elif arg1 == "run":
|
||||
if len(sys.argv) > 2:
|
||||
run_file(sys.argv[2])
|
||||
|
||||
+11
-1
@@ -47,8 +47,18 @@ class Parser:
|
||||
RESET = "\033[0m"
|
||||
BOLD = "\033[1m"
|
||||
|
||||
ai_tag = ""
|
||||
try:
|
||||
from stdlib_modules import _GLOBAL_AI_STATE
|
||||
has_key = any(v for k, v in _GLOBAL_AI_STATE["keys"].items() if k != "ollama" and v)
|
||||
if has_key:
|
||||
active_p = _GLOBAL_AI_STATE.get("active_provider", "ai").upper()
|
||||
ai_tag = f" [AI Engine: {active_p}]"
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
warning = (
|
||||
f"\n{CYAN}✨ [Aira Compiler Auto-Fix]:{RESET}\n"
|
||||
f"\n{CYAN}✨ [Aira Compiler Auto-Fix{ai_tag}]:{RESET}\n"
|
||||
f"{YELLOW}Hey there! I am Aira From Aira Group Of Technology by Adam Eehan.{RESET}\n"
|
||||
f"Heyyy, here you missed a semicolon (;) at {BOLD}line {line}{RESET}!\n"
|
||||
f"Please concentrate on your code, now you can relax, I've put it automatically.\n"
|
||||
|
||||
+14
-1
@@ -533,15 +533,28 @@ def prompt_developer_for_ai_key():
|
||||
cfg["keys"] = {}
|
||||
cfg["keys"][detected_provider] = user_key
|
||||
cfg["active_provider"] = detected_provider
|
||||
cfg["ai_prompted"] = True
|
||||
save_airalang_config(cfg)
|
||||
|
||||
print(f"{GREEN}✓ Aira AI Engine activated! Provider auto-detected as '{detected_provider}'.{RESET}")
|
||||
print(f"{CYAN}Identity: Aira AI by Adam Eehan. Saved to ~/.config/airalang/config.json{RESET}\n")
|
||||
return True
|
||||
else:
|
||||
print(f"{YELLOW}ℹ️ Skipped. Aira AI running in offline mode.{RESET}\n")
|
||||
cfg = load_airalang_config()
|
||||
cfg["ai_prompted"] = True
|
||||
save_airalang_config(cfg)
|
||||
print(f"{YELLOW}ℹ️ Skipped. Aira AI running in offline mode. (Run 'airalang --ai-setup' anytime to activate){RESET}\n")
|
||||
return False
|
||||
|
||||
def check_and_prompt_ai_engine(force=False):
|
||||
cfg = load_airalang_config()
|
||||
has_key = any(v for k, v in _GLOBAL_AI_STATE["keys"].items() if k != "ollama" and v)
|
||||
if has_key and not force:
|
||||
return True
|
||||
if cfg.get("ai_prompted") and not force:
|
||||
return False
|
||||
return prompt_developer_for_ai_key()
|
||||
|
||||
def create_ai_module():
|
||||
state = _GLOBAL_AI_STATE
|
||||
|
||||
|
||||
Reference in new issue
Block a user