DEV Community

Cover image for Terminal Chat with Bard using bardAPI and Python
John Pinto
John Pinto

Posted on • Edited on

2 1

Terminal Chat with Bard using bardAPI and Python

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 value BARD_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!')
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Image

ENJOY!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay