Skip to content

Instantly share code, notes, and snippets.

@tock-dev
Created January 9, 2025 21:57
Show Gist options
  • Select an option

  • Save tock-dev/33d17e946be113a54b853fb123c3f6b1 to your computer and use it in GitHub Desktop.

Select an option

Save tock-dev/33d17e946be113a54b853fb123c3f6b1 to your computer and use it in GitHub Desktop.
GROQ KidAI role script
#!/usr/bin/env bash
# This script makes a request to the GroQ API with a role of a kid on a playground.
# Comment this line if you want to receive the GroQ API key from the environment variable where this program is ran (not recommended).
# Get an API key for free here: https://console.groq.com/keys
GROQ_API_KEY="<GROQ_API_KEY>"
echo 'Warning: Remember, this AI is just a kid, so the only things he can talk of are playground and games.'
if [[ $# -lt 1 ]];then
echo "Usage: $(basename $0) [<prompt>]"
exit 1
fi
if [[ $1 -ne "" ]];then
prompt="$1"
else
echo -n 'What would you like to ask to KidAI? >'
read -r prompt
fi
GROQ_CONF="$HOME/.config/groq.conf"
if [[ ! -f $GROQ_CONF ]];then
echo -n ", ">>"$GROQ_CONF"
fi
hstr=$(cat "$GROQ_CONF")
# Edit the "model" parameter in the body of the request to the one of your likeness.
# List of the models available: https://console.groq.com/docs/models
json=$(curl https://api.groq.com/openai/v1/chat/completions -s \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GROQ_API_KEY" \
-d "{
\"model\": \"llama-3.3-70b-versatile\",
\"messages\": [{
\"role\": \"system\",
\"content\": \"You are a kid on playground, don't talk about anything except playground, games, and your friends. You are Timmy, your best friend is Emma, and other friends are Max and his best friend Olivia. You all do play tag games most of the time, all of you have different paintball guns. You are 11 years old, Emma is too, and Max and Olivia are both 9 years old. Speak like a little child, in a very young style, using very simple words and sometimes not understanding user's requests. Also, by your age, you still don't know much about videogames, and mostly don't play them. Have fun!\"
}${hstr}{\"role\": \"user\",\"content\":\"$prompt\"}]
}")
# shellcheck disable=SC2089
hstr="$hstr, {\"role\": \"user\", \"content\": \"$prompt\"}, $(echo "$json"|jq '.choices.[]|select(.message.role!="system")'), "
string=$(echo "$json"|jq '.choices.[]|select(.message.role=="assistant")|.message.content')
format=$(echo -ne "$string")
echo "AI says: As I am a kid, ..."
echo "...$format"
echo "$hstr">"$GROQ_CONF"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment