This script is used to automate the process of getting back an AI result from Gemini to the given prompt.
#!/usr/bin/env bash
function ai() {
jq -n \
--arg content "$*" \
'{
"contents": [
{
"parts": [
{
"text": $content
}
]
}
]
}' | curl --silent \
--header 'Content-Type: application/json' \
--data @- \
--request POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=$GOOGLE_API" |
jq -c -r '.candidates[0].content.parts[0].text' |
while read -r line; do
echo "$line"
done
}
ai "$@"
- Create a new shell script in your root folder called
gemini.sh
- Copy the script above into the file
- Run
chmod +x gemini.sh
to make the file executable - Export your GOOGLE_API Key either to the terminal session using
export GOOGLE_API="your api key"
or add it at somewhere in your.bashrc
file. - Run
./gemini.sh "prompt"
to get an AI result
./gemini.sh "prompt"