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!

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

👋 Kindness is contagious

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

Okay