Module 2: AI IntegrationsLesson 2 of 2

Integrating Large Language Model APIs

Duration: 25:40
Watch Lesson VideoIntegrating Large Language Model APIs

Integrating Large Language Model APIs

Now that you understand Python variables and operations, let's connect to the Google Gemini API to build a simple interactive chat assistant.

Setting Up Google Gemini SDK

Install the Google generative AI library:

bash lang-bash
1
pip install google-generativeai

Writing the Code

Make sure you set your API key as an environment variable: export GEMINI_API_KEY="your-api-key" (or set on Windows).

python lang-python
1
2
3
4
5
6
7
8
9
10
11
12
13
import os
import google.generativeai as genai
# Load API key from env
api_key = os.environ.get("GEMINI_API_KEY")
genai.configure(api_key=api_key)
# Initialize model
model = genai.GenerativeModel('gemini-1.5-flash')
# Prompt model
response = model.generate_content("Give me a 3-word slogan for CourseDock.")
print(response.text)