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!

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry πŸ‘€

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more β†’

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

πŸ‘₯ Ideal for solo developers, teams, and cross-company projects

Learn more

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay