-
-
Notifications
You must be signed in to change notification settings - Fork 10
3. Extending Navi ‐ Custom Scripts
So you want to develop custom scripts. It is actually pretty straight forward. Lets get into it.
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.
Put simply a custom chip is a piece of python code designed to give Navi more capability than it has out
of the box.
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.
- copy paste that into a new file in the
/opt/Navi/commands/
directory Lets call itnavi_hello.py
- Open the file in your preferred code editor.
- 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.
To test your scripts do the following.
- Save your script
- Start navi -
navi
- show help menu -
--help
- Look for navi_hello in the list.
- run the script using one of the aliases we setup -
--hello
You should get an AI generated greeting from Navi like below:
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!