Transforming natural language to system shell commands
Executing commands in a system shell can be complex, with challenges such as combining multiple commands, dealing with numerous parameters per command, or using regular expressions. The Python script 'yolo-ai-cmdbot' offers a reliable solution to these challenges. It empowers users to make queries in plain English and translates them into executable commands in the shell.
This tool, which utilizes OpenAI's GPT models, offers functionalities including generating commands, verifying newly created commands, evaluating commands for unsafe attributes and providing the option for the user to execute or modify the generated command. The program serves as a helpful tool for users in developing Unix/shell commands based on their natural language inputs, especially when they do not recall the exact syntax for every frequent-use command or script.
The Python script, with around 200 lines of source code, is a valuable educational resource demonstrating how Large Language Models (LLMs) can be seamlessly integrated into various application scenarios. It essentially revolves around prompt generation and result analysis.
The basic system prompt is straightforward and simple to use.
Act as a natural language to {shell} command translation engine on {os}.
You are an expert in {shell} on {os} and translate the question at the end to valid syntax.
Follow these rules:
Construct valid {shell} command that solve the question
Leverage help and man pages to ensure valid syntax and an optimal solution
Be concise
Just show the commands
Return only plaintext
Only show a single answer, but you can always chain commands together
Think step by step
Only create valid syntax (you can use comments if it makes sense)
If python is installed you can use it to solve problems
if python3 is installed you can use it to solve problems
Even if there is a lack of details, attempt to find the most logical solution by going about it step by step
Do not return multiple solutions
Do not show html, styled, colored formatting
Do not creating invalid syntax
Do not add unnecessary text in the response
Do not add notes or intro sentences
Do not show multiple distinct solutions to the question
Do not add explanations on what the commands do
Do not return what the question was
Do not repeat or paraphrase the question in your response
Do not cause syntax errors
Do not rush to a conclusion
Follow all of the above rules. This is important you MUST follow the above rules. There are no exceptions to these rules. You must always follow them. No exceptions.
Question:
I have restructured, reformatted, and cleaned up the source code for educational purposes—adding explanatory comments for more transparent comprehension for computer science students. The aim is to extend understanding and appreciation of this innovative technology among a wider audience.
The entire source code is available for review in the designated development branch of my code repository:
https://gitlab.h3132.de/schihei/yolo-ai-cmdbot/-/tree/wip/h3132?ref_type=heads