Hi, I am a new to jetson andcurrently working on implementing an end-to-end speech model using NanoLLM on an Orin NX 8GB device running JetPack 6.2.
While following the documentation, I couldn’t find a clear example of where to place and execute a Python script. As a test, I ran a test.py script inside the NanoLLM Docker image at /opt/voice_assistant/test.py. Below is the example code. : "import os
import json
from typing import List, Dict, Any, Optional
from datetime import datetime
import numpy as np
from nano_llm import NanoLLM, ChatHistory, BotFunctions, bot_function
from nano_llm.agents.voice_chat import VoiceChat
Define custom bot functions for company-specific tasks
@bot_function
def GET_DATE():
"""Returns the current date."""
return datetime.now().strftime("%A, %B %-d %Y")
@bot_function
def GET_TIME():
"""Returns the current time."""
return datetime.now().strftime("%-I:%M %p")
class CompanyVoiceAssistant:
def init(self,
model_name: str = "meta-llama/Llama-3.2-1B",
quantization: str = None,
api: str = "mlc",
device: str = "cuda"):
"""
Initialize the company voice assistant.
Args:
model_name: Name of the LLM model to use
quantization: Quantization method for the model
api: Backend API for model inference
device: Device to run inference on ('cuda' or 'cpu')
"""
print(f"Initializing voice assistant with {model_name}...")
# Initialize the LLM model
self.model = NanoLLM.from_pretrained(
model=model_name,
quantization=quantization,
api=api,
device=device
)
# Create function calling system
self.functions = BotFunctions()
# Create system prompt with function documentation
self.system_prompt = """
You are a helpful company assistant that can answer questions about the company.
Be concise and professional in your responses.
""" + BotFunctions.generate_docs()
# Create voice chat agent with custom STT and TTS
self.voice_chat = VoiceChat(
model=self.model,
stt="whisper_trt", # Use whisper_trt for speech recognition
tts="piper", # Use PiperTTS for speech synthesis
system_prompt=self.system_prompt,
functions=self.functions,
hotword="assistant", # Wake word to activate the assistant
continuous=True, # Keep listening for commands
vad=True # Voice activity detection
)
def run(self):
"""Start the voice assistant"""
print("Starting company voice assistant...")
print("Say 'assistant' to activate, then ask your question")
self.voice_chat.run()
if name == "main":
import argparse
parser = argparse.ArgumentParser(description="Company Voice Assistant")
parser.add_argument("--model", type=str, default="meta-llama/Llama-3.2-1B", help="LLM model name")
parser.add_argument("--quantization", type=str, default=None, help="Model quantization")
args = parser.parse_args()
assistant = CompanyVoiceAssistant(
model_name=args.model,
quantization=args.quantization
)
assistant.run()"
Hi, I am a new to jetson andcurrently working on implementing an end-to-end speech model using NanoLLM on an Orin NX 8GB device running JetPack 6.2.
While following the documentation, I couldn’t find a clear example of where to place and execute a Python script. As a test, I ran a test.py script inside the NanoLLM Docker image at /opt/voice_assistant/test.py. Below is the example code. : "import os
import json
from typing import List, Dict, Any, Optional
from datetime import datetime
import numpy as np
from nano_llm import NanoLLM, ChatHistory, BotFunctions, bot_function
from nano_llm.agents.voice_chat import VoiceChat
Define custom bot functions for company-specific tasks
@bot_function
def GET_DATE():
"""Returns the current date."""
return datetime.now().strftime("%A, %B %-d %Y")
@bot_function
def GET_TIME():
"""Returns the current time."""
return datetime.now().strftime("%-I:%M %p")
class CompanyVoiceAssistant:
def init(self,
model_name: str = "meta-llama/Llama-3.2-1B",
quantization: str = None,
api: str = "mlc",
device: str = "cuda"):
"""
Initialize the company voice assistant.
if name == "main":
import argparse