Created
August 24, 2024 18:04
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 | |
read -p "Enter command: " input | |
api_key="YOUR_OPENAI_API_KEY_HERE" | |
prompt="\n\nHuman: please analyze the input text: '$input', \ | |
and provide only the text that would fit directly into an osascript -e command to perform this action. \ | |
DO NOT INCLUDE osascript -e itself and DO NOT return whitespace in front of the answer and DO NOT RETURN new line \ | |
DO NOT add string escape for slash or double quote or single quote at all \ | |
\n\nAssistant:" | |
response=$(curl -s https://api.openai.com/v1/chat/completions \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer $api_key" \ | |
-d '{ | |
"model": "gpt-4o", | |
"messages": [{"role": "user", "content": "'"${prompt}"'"}], | |
"max_tokens": 300, | |
"temperature": 0.1 | |
}') | |
# Save the response to a file | |
echo "$response" > invoke-model-output.txt | |
# Extract the completion using jq | |
extractCMD=$(cat invoke-model-output.txt | jq -r .choices[0].message.content) | |
echo "$extractCMD" > extractCMD.applescript | |
# Execute the extracted command with osascript | |
osascript -e "$extractCMD" | |
# Or read from file | |
# osascript extractCMD.applescript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment