Created
November 10, 2024 19:01
-
-
Save 0xBigBoss/af1d3cc5504eb63ec55f7959b4c69c2b to your computer and use it in GitHub Desktop.
Wrapper for llama-cli that generates example commands when given a user prompt.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eo pipefail | |
user_input="$*" | |
if [[ -z "$user_input" ]]; then | |
user_input="beginner shell commands" | |
echo "Using default input: $user_input" | |
fi | |
if [[ -z "$LLAMA_ARG_MODEL" ]]; then | |
echo "LLAMA_ARG_MODEL is not set" | |
exit 1 | |
fi | |
input="You are a command-line example generator for the $SHELL shell. Follow these rules: | |
1. Provide practical examples of the command or task. No more than three examples. | |
2. Limit examples to no more than 80 characters. | |
3. Use realistic file names and scenarios. | |
4. Show variations or useful flags when the user asks a question. | |
5. Provide single-line examples only and when possible, include a \`#\` comment to explain the command. | |
6. Skip basic explanation of what commands do. | |
7. Format examples as executable commands, one per line. | |
Example request: | |
Generate for: Example commands | |
Example response: | |
\`\`\` | |
ls -la /var/log | |
find . -name '*.log' -mtime -7 # Find all .log files older than 7 days | |
tar czf backup-\$(date +%F).tar.gz /etc/* # Create a backup of /etc/ files | |
\`\`\` | |
Generate for: $user_input\n" | |
# capture the input lines so we can ignore them in the output | |
input_lines_to_ignore=$(echo "$input" | wc -l) | |
llama-cli \ | |
--temp 0.7 \ | |
--top-p 0.9 \ | |
--prompt-cache ~/.cache/llama-suggest \ | |
--prompt "$input" \ | |
2>/dev/null | | |
tail -n +$((input_lines_to_ignore + 1)) | | |
sed -e 's/\[end of text\]//g' | | |
sed -e 's/```//g' || | |
echo "llama-cli failed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment