dotfiles

My ~/.config directory

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
from IPython.core.magic import register_line_magic
import requests

@register_line_magic
def nl(line):
    """
    Natural language input for Sage using Ollama

    Do not use with untrusted input!

    Example usage:
    %nl "Invert the 4x4 matrix with 0s on the diagonal and 1s off diagonal"
    """
    r = requests.post("http://localhost:11434/api/generate", json={
        "model": "gemma3:27b",
        "prompt": f"Translate this request directly into SageMath code. Be very concise and don't output Markdown code blocks or anything extraneous, only output the raw SageMath code. Request: {line}",
        "stream": false
    })
    code = r.json()["response"]
    print(code)
    if input("Run? (y/N) ") == "y":
        shell = get_ipython()
        shell.run_cell(code)