## scripts/ask.py
import sys
import requests
from config import load_config

def ask(prompt):
    cfg = load_config()
    if cfg["provider"] == "ollama":
        payload = {"model": cfg["model"], "prompt": prompt, "stream": False}
        response = requests.post(cfg["url"], json=payload)
        print(response.json().get("response", "❌ No response"))
    else:
        headers = {
            "Authorization": f"Bearer {cfg['api_key']}",
            "Content-Type": "application/json"
        }
        payload = {
            "model": cfg["model"],
            "messages": [{"role": "user", "content": prompt}]
        }
        response = requests.post(cfg["url"], headers=headers, json=payload)
        print(response.json().get("choices", [{}])[0].get("message", {}).get("content", "❌ No content"))

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python ask.py 'your message'")
        sys.exit(1)
    ask(sys.argv[1])
