So I took a look at BardAPI
on Github and built a simple terminal chat using python
BardAPI : https://github.com/dsdanielpark/Bard-API
My Github : https://github.com/pj8912/terminal_chat
- Get the key as per the instruction on BARDAPI
- Create a
.env
on the root folder and assign that valueBARD_API_KEY
variable
Code
import os
from dotenv import load_dotenv
from bardapi import Bard
load_dotenv()
os.environ['_BARD_API_KEY'] = os.getenv("BARD_API_KEY")
bard = Bard()
print('\n','*'*50,'Terminal Chat with BARD','*'*50, '\n')
try:
while True:
user_input = input('\U0001F464 You: ')
print('')
print('\U0001F916 Bard:', bard.get_answer(user_input.strip())['content'])
print('-'*100, "\n")
except KeyboardInterrupt:
print('Ended Chat!')
except:
print('Ended Chat!')
As per the documentation the os.environ['_BARD_API_KEY']
is assigned the your BARD_API_KEY
Run
Run the script to start chatting with Bard
$ python app.py
Top comments (0)