Created
December 21, 2023 15:22
-
-
Save t04glovern/a4fd9a7f54824d117fdfed3c69f67d51 to your computer and use it in GitHub Desktop.
clippy create 10 files in my home directory called importantData[1-10].txt
This file contains 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 | |
# Take the text after the "clippy" command as the input | |
user_prompt="$*" | |
export HELPER="Return only the shell/bash command for the following request, only return the bash/shell that would work if passed to the shell/bash. nothing more. example could be 'list all the files in my home directory' which would return 'ls ~' and ONLY the command 'ls ~', absolutely no other text around it, just the command - the request is for for the following:" | |
# Send the POST request and process the response | |
response="" | |
is_done=false | |
while IFS= read -r line; do | |
# Extract the "response" and "done" values from the JSON response | |
part=$(echo $line | grep -oP '"response":"\K[^"]+') | |
done_status=$(echo $line | grep -oP '"done":\K\w+') | |
# Concatenate to the full response | |
response+=$part | |
# Check if the "done" status is true | |
if [[ $done_status == "true" ]]; then | |
is_done=true | |
break | |
fi | |
done < <(curl -s -X POST http://localhost:11434/api/generate -d "{\"model\": \"mistral\", \"prompt\":\"$HELPER $user_prompt\"}") | |
# Output the final response, extracting only the command between """bash and """ | |
if $is_done; then | |
echo $response | |
else | |
echo "Error: Stream ended before completion." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment