diff --git a/modules/home/programs/terminal/bash/config/hey-intern.sh b/modules/home/programs/terminal/bash/config/hey-intern.sh new file mode 100644 index 0000000..4aa1c58 --- /dev/null +++ b/modules/home/programs/terminal/bash/config/hey-intern.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +MODEL="qwen3-coder-next-80b-instruct" +SYSTEM_PROMPT="You are a shell command expert. Given a natural language query, generate a single shell command that accomplishes the task." + +# Colors +CYAN='\033[0;36m' +YELLOW='\033[1;33m' +GREEN='\033[0;32m' +RESET='\033[0m' + +hey-intern() { + local query="$*" + + # Help + if [ -z "$query" ]; then + echo "Usage: hey-intern \"your query here\"" >&2 + return 1 + fi + + # Execute LLM Request + response=$(curl -s -X POST "https://llm-api.va.reichard.io/v1/chat/completions" \ + -H "Content-Type: application/json" \ + -d "$(jq -n \ + --arg model "$MODEL" \ + --arg system "$SYSTEM_PROMPT" \ + --arg user "$query" \ + '{ + model: $model, + temperature: 0.2, + messages: [ + {role: "system", content: $system}, + {role: "user", content: $user} + ], + tools: [{ + type: "function", + function: { + name: "generate_shell_command", + description: "Generate a shell command to answer a query", + parameters: { + type: "object", + properties: { + command: {type: "string", description: "The shell command to execute"} + }, + required: ["command"] + } + } + }] + }')" | jq -r '.choices[0].message.tool_calls[0].function.arguments // empty') + + # Extract Command + local command=$(echo "$response" | jq -r '.command // empty') + + if [ -n "$command" ]; then + echo -e "\n ${CYAN}${command}${RESET}\n" + + read -p "$(echo -e "${YELLOW}Would you like to run this command? [y/N]${RESET} ")" -n 1 -r + echo "" + + if [[ $REPLY =~ ^[Yy]$ ]]; then + echo -e "${GREEN}Running...${RESET}\n" + history -s "$command" + eval "$command" + fi + else + echo "Failed to generate a valid command from the response." >&2 + echo "Raw response: $response" >&2 + return 1 + fi +} + +# Export Script +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + hey-intern "$@" +fi diff --git a/modules/home/programs/terminal/bash/default.nix b/modules/home/programs/terminal/bash/default.nix index 3f4644b..7cf46ab 100755 --- a/modules/home/programs/terminal/bash/default.nix +++ b/modules/home/programs/terminal/bash/default.nix @@ -47,6 +47,8 @@ in fi [[ -f ~/.bash_custom ]] && . ~/.bash_custom + + source ${./config/hey-intern.sh} ''; };