· last year · Nov 07, 2023, 12:50 PM
1#!/data/data/com.termux/files/use/bin/bash
2
3# Set the API key and prompt
4API_KEY="AIzaSyBCjs52Ge752uS0_jwhONKt-fSB82jG1lE"
5PROMPT="What would you like to talk about?"
6
7# Check if the API key is set
8if [ -z "$API_KEY" ]; then
9 echo "Please set the API_KEY environment variable."
10 exit 1
11fi
12
13# Check if the prompt is set
14if [ -z "$PROMPT" ]; then
15 echo "Please set the PROMPT environment variable."
16 exit 1
17fi
18
19# Send the prompt to the Bard AI API and get the response
20RESPONSE=$(curl -X POST https://api.bard.ai/v1/chatbot \
21 -H "Authorization: Bearer $API_KEY" \
22 -H "Content-Type: application/json" \
23 -d "{\"prompt\":\"$PROMPT\"}" \
24 | jq -r '.response.messages[0].text')
25
26# Print the response to the console
27echo $RESPONSE
28
29# Check if the user wants to continue the conversation
30while true; do
31 read -p "Continue the conversation? (y/n) " CONTINUE
32
33 case $CONTINUE in
34 y|Y)
35 break
36 ;;
37 n|N)
38 echo "Exiting the conversation."
39 exit 0
40 ;;
41 *)
42 echo "Please enter y or n."
43 ;;
44 esac
45done
46
47# Get the next prompt from the user
48read -p "Enter your next prompt: " NEXT_PROMPT
49
50# Send the next prompt to the Bard AI API and get the response
51NEXT_RESPONSE=$(curl -X POST https://api.bard.ai/v1/chatbot \
52 -H "Authorization: Bearer $API_KEY" \
53 -H "Content-Type: application/json" \
54 -d "{\"prompt\":\"$NEXT_PROMPT\"}" \
55 | jq -r '.response.messages[0].text')
56
57# Print the response to the console
58echo $NEXT_RESPONSE
59