Skip to content

3. Extending Navi ‐ Custom Scripts

Alex Kollar edited this page Jun 26, 2024 · 1 revision

Introduction

So you want to develop custom scripts. It is actually pretty straight forward. Lets get into it.

Disclaimer

Saints Security Group LLC holds no responsibility it you damage a system be it yours or someone else's
during the use of Navi or its systems.

What is a custom scripts

Put simply a custom chip is a piece of python code designed to give Navi more capability than it has out
of the box.

Building a custom script

Enough with the details and legal jargon. Lets show off what we can do. Below you will find the code for
script template. Feel free to copy and paste it into your respective code editor. As per usual I use nvim.

#!/bin/python3
import subprocess
from typing import List
from navi_shell import tr, get_ai_name, llm_chat, get_user
from navi import get_ip_address, get_hostname, get_parameters, get_command_path


command = "NameHere"
use = "Description Here"
aliases = ['Command_Aliases_here']


def run(arguments=None):
    #code here
    return

This above is the basic outline of a Navi custom script. Here is how to set it up.

  1. copy paste that into a new file in the /opt/Navi/commands/ directory Lets call it navi_hello.py
  2. Open the file in your preferred code editor.
  3. Make edits. Here is our example code:
#!/bin/python3
import subprocess
from typing import List
from navi_shell import tr, get_ai_name, llm_chat, get_user
from navi import get_ip_address, get_hostname, get_parameters, get_command_path


command = "Navi Hello"
use = "Navi hello!"
aliases = ['navi_hello', '--hello']

def navi_hello():
    response_message = llm_chat("Give me a greeting. Dont include commands or references to operating systems.")
    clean_text = str(response_message).replace("(", "").replace(")", "").replace(", 200", "").replace("\"", "").replace("\\n", "")
    tr(f"{get_ai_name()} {clean_text}")

def run(arguments=None):
    navi_hello()
    return 

The clean_text variable is set so when you get an output it is not adding extra elements to it and making it look bad.

Testing your scripts

To test your scripts do the following.

  1. Save your script
  2. Start navi - navi
  3. show help menu - --help
  4. Look for navi_hello in the list.
  5. run the script using one of the aliases we setup - --hello

You should get an AI generated greeting from Navi like below: image

Closing

These are just some basic guidelines on how to work with extending Navi.
Largely speaking, if it works in python it should be able to get turned into a chip.
With that in mind, go have fun. Enjoy it!