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!

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

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

πŸ‘‹ Kindness is contagious

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

Okay