Skip to Main Content

Build Your Own AI Chatbot

Google Gemini

  • LLM selected for Chatbot workshop.
  • It has a robust free level!

Setup steps

  • You will need to log into a Google account.
    • SJSU or Personal accounts should both work.
  • You will need to create an API key for the Google Gemini API/Google AI Studio.

API  = Application Programming interface - a way for one piece of software or code to interact with another.

Create an API Key

  • Click the "Get API Key in Google AI Studio" button.

Get API Key in Google AI Studio

API Keys - Gemini

Use your API keys securely. Do not share them or embed them in code the public can view.

Create API keys securely - Gemini

Copy your key to Streamlit

  • Go back to Streamlit.
  • Copy your new key.
  • Go back to Streamlit.
  • Open your app's settings.
  • Add the key:
    • google_gemini_key = " your key here"

google_gemini_key = " your key here" - Screenshot

Run your app

It will take a minute to start.

Let's pause for trouble shooting here.

If you're a little ahead

Review of Steps so Far:

We are using a Retrieval Augmented Generation (RAG ) model.

Changing Documents

1. Go to your GitHub repository.

GitHub repository

2. Go to the folder data. Documents in this folder are available to the chatbot.

Chatbot folder data

Add file --> Upload Files

Chatbot Upload Files

Add a commit message

Add a commit message - GitHub

Commit Message:

In Git a commit records a snapshot of your code - you might think of it as a saved version.

It is highly recommended that a descriptive message be included with each commit. Think of this as the name of the saved state you are creating.

Commit Message ChatBot Workshop

Delete tagore.txt

Delete tagore.txt Screenshot

Commit your changes

Commit your changes Chatbot Workshop

Commit message

Commit message - Delete data/tagore.txt

Where's my data folder?

On GitHub, if you delete all the files in a folder, it will disappear.

Don't worry, we will recreate it.

chatbot-workshop-part-2 data folder

Works of Rabindranath Tagore

Change the system prompt - at line 31

systen_prompt"""You are an expert on the work of Rabindrath Tagore, and you love to use quotations from his books to illustrate your points.

Answer the question using the provided documents, which contain relevant excerpts from the work of Rabindrath Tagore.

The context for all questions is the work of Rabindrath Tagore. Whenever possible, include a quotation from the provided excerpts of his works to illustrate your point.

Respond using a florid but direct tone, typical of an early modernist writer.

Keep your answers under 100 words. """,

Edit files on GitHub

Edit files on GitHub Screenshot

Try a different prompt

Gemini Prompt

No reboot required!

Commit your change and refresh Streamlit.

Can you notice a change in the response?

Let's change the text on the page

Title is on lines 7 and 8.

Prompt lines 7 and 8

User prompt - line 15

Prompt line 15

Change embeddings settings

Chunk size - the number of characters in each chunk of text.

Chunk overlap - how many characters the chunks overlap by.

Small chunk sizes can make the embedding step very slow.

Embeddings settings

Change the temperature - line 30

Change temperature Line 30

Temperature

The amount of randomness in the LLM.

Range is typically 0 to 1, with 0 being the least random.

Questions and further discussion

  • What issues are you running into?
  • Does the chatbot work the way you expected?
  • What questions do you have?