nuwa-terminal-chat is a program to chat with LLM in a terminal, this tool based on the LLM and aim to make terminal more intelligent. this terminal can help users to use natural language to execute commands or tasks, also it can be a terminal intelligent assistant, you can ask any question about software development.
$ ./nuwa-terminal ███ ██ ██ ██ ██ ██ █████ ████████ ███████ ██████ ███ ███ ██ ███ ██ █████ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ █ ██ ███████ ██ █████ ██████ ██ ████ ██ ██ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██████ ███ ███ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ████ ██ ██ ███████
As programmers, we actually spend only a small portion of our time writing code. Most of our time is spent analyzing requirements, reading documentation, debugging code, fixing bugs, and communicating with others. A significant part of this process involves using the terminal to complete various tasks, such as:
Many of these tasks are repetitive, and programmers often need to refer to various documents, Linux man pages, etc., which significantly reduces work efficiency. Frequent context switching lowers focus on a single task. This is especially true for complex tasks, such as writing shell scripts. Since shell scripting is not something programmers use every day—mostly only when needed, especially for testing—not everyone is proficient in it. It often requires additional time to learn and complete.
However, large language models store vast amounts of knowledge, and some models are particularly adept at software development, Linux, and open-source technologies. With the help of large language models, it becomes easy to generate Linux command-line instructions or shell scripts using natural language.
Therefore, leveraging AI-powered models to enhance the terminal can make a programmer's work much easier, allowing them to stay focused on their current tasks.
The architecture of Nuwa Terminal is very simple. It uses Langchaingo as the foundational library to interact with large language models. Langchaingo is a Golang port of Langchain. Nuwa Terminal follows a single AI agent architecture, executing tasks by invoking commands and scripts.
Nuwa Terminal has four working modes:
Chat Mode functions as an intelligent operations assistant. You can chat with it, ask various questions, and it will help you answer them while generating code or shell commands.
In Command Mode, you can generate and execute Linux commands using natural language. Similarly, in Task Mode, you can create and execute shell scripts using natural language.
Agent Mode is still an experimental feature. In this mode, Nuwa can handle more complex tasks, such as identifying the cause of high system load and pinpointing the responsible process.
Here are some usage examples:
# Using Chat Mode to generate a script for retrieving logs of all K8s pods in a specified namespace nuwa-terminal-chat@ Generate a script to retrieve logs of all K8s pods in a specified namespace. You: Generate a script to retrieve logs of all K8s pods in a specified namespace. NUWA: Sure, I can generate a script to fetch logs for all pods in a specified Kubernetes namespace. This script will use the `kubectl` command to retrieve the logs. @get_pods_logs.sh@ #!/bin/bash # Check if a namespace parameter is provided if [ -z "$1" ]; then echo "Usage: $0 <namespace>" exit 1 fi NAMESPACE=$1 # Get all pods in the specified namespace PODS=$(kubectl get pods -n $NAMESPACE -o jsonpath='{.items[*].metadata.name}') # Iterate through each pod and fetch logs for POD in $PODS; do echo "Fetching logs for pod: $POD" kubectl logs $POD -n $NAMESPACE done ### Usage: 1. Save the script as `get_pods_logs.sh`. 2. Grant execution permissions: `chmod +x get_pods_logs.sh`. 3. Run the script with the specified namespace: `./get_pods_logs.sh <namespace>`. This script will output the logs of all pods in the specified namespace. If you need further processing, you can add additional logic to the script.
# Default mode is Chat Mode. Switch to Command Mode and describe commands in natural language. nuwa-terminal-chat@ cmdmode You: cmdmode 2025-01-11 21:26:03 INFO NUWA TERMINAL: Mode is cmdmode nuwa-terminal-chat# Get processes with high CPU usage You: Get processes with high CPU usage NUWA: execute command: ps aux --sort=-%cpu | head -n 10 time=2025-01-11T21:26:47.635+08:00 level=INFO msg=Matched: "match content"="ps aux --sort=-%cpu | head -n 10" USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 245519 2.1 0.1 6258356 30852 pts/5 Sl+ 21:25 0:01 ./nuwa-terminal root 1 1.0 0.0 167020 12400 ? Ss 11:33 6:03 /sbin/init root 781 0.4 0.2 43388 36800 ? S 11:33 2:37 python3 /snap/ubuntu-desktop-installer/1286/usr/bin/cloud-init status --wait
# Switch to Task Mode, generate a shell script, and execute it. You: taskmode 2025-01-11 21:31:09 INFO NUWA TERMINAL: Mode is taskmode nuwa-terminal-chat> Check current memory usage and find the top 5 processes consuming the most memory. You: Check current memory usage and find the top 5 processes consuming the most memory. NUWA: Here is a shell script to check current memory usage and list the top 5 memory-consuming processes: #!/bin/bash # Get memory usage, sort, and display the top 5 processes ps aux --sort=-%mem | head -n 6 ### Explanation: - `ps aux`: Displays detailed information about all processes. - `--sort=-%mem`: Sorts processes in descending order by memory usage (%MEM). - `head -n 6`: Displays the top 6 lines (including the header), i.e., the top 5 processes. After running this script, you will see detailed information about the top 5 memory-consuming processes in the system. time=2025-01-11T21:33:12.748+08:00 level=INFO msg="Adding file to source file dict" content="``` shell\n#!/bin/bash\n\n# Get memory usage, sort, and display the top 5 processes\nps aux --sort=-%mem | head -n 6\n```" time=2025-01-11T21:33:12.748+08:00 level=INFO msg=Matched: "match_content "="#!/bin/bash\n\n# Get memory usage, sort, and display the top 5 processes\nps aux --sort=-%mem | head -n 6" 2025-01-11 21:33:12 INFO NUWA TERMINAL: script file saved to │ .nuwa-terminal/scripts/39ea4f03-79d9-4cc4-8ea4-1cb338ce9314.sh 2025-01-11 21:33:12 INFO NUWA TERMINAL: script output └ output: + ps aux --sort=-%mem + head -n 6 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND 2025-01-11 21:33:12 INFO NUWA TERMINAL: script file removed
There are no datasets linked
There are no datasets linked