0% found this document useful (0 votes)
2 views9 pages

Lecture 06 Calling Gemini and OpenAI APIs

The document provides an overview of algorithms, AI models, and APIs in AI, explaining their definitions and roles in processing data and making predictions. It includes examples of using Google Gemini and OpenAI APIs for text generation and vision capabilities. The document also encourages experimentation with Gemini APIs using an API key.

Uploaded by

rabiazubair577
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

Lecture 06 Calling Gemini and OpenAI APIs

The document provides an overview of algorithms, AI models, and APIs in AI, explaining their definitions and roles in processing data and making predictions. It includes examples of using Google Gemini and OpenAI APIs for text generation and vision capabilities. The document also encourages experimentation with Gemini APIs using an API key.

Uploaded by

rabiazubair577
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Calling Gemini & OpenAI APIs

By
Zafar Iqbal

https://www.youtube.com/@ZafarIqbal_IT_Trainer
Algorithms, Models and APIs in AI
Algorithm:
• Definition: A set of instructions or rules that a computer follows to perform a specific
task.
• In AI: Algorithms are used to process data, identify patterns, and learn from that data to
build AI models. Algorithms are the building blocks of AI, providing the "how" for a
machine to process information and make decisions.
AI Model:
• Definition: A learned representation of the data, trained by an algorithm.
• In AI: AI models are used to make predictions, decisions, or perform tasks based on
learned patterns.
API:
• Definition: A set of rules and protocols that allow different software applications to
interact.
• In AI: AI APIs enable developers to access and use AI models and algorithms without
needing to understand the underlying implementation details.

https://www.youtube.com/@ZafarIqbal_IT_Trainer
Client - API – Model
Algorithm 1 Data
API

Client Model Algorithm 2


Data
Application

Algorithm 3
Data

Algorithms are used to process data, identify patterns, and learn from that data to build
AI models.

AI models are used to make predictions, decisions, or perform tasks based on learned
patterns.

AI APIs enable developers to access and use AI models and algorithms without needing
to understand the underlying implementation details.
https://www.youtube.com/@ZafarIqbal_IT_Trainer
Text generation using Google API
1. Generate API Key using Google AI Studio

2. Call generate_Content function of genAI package by providing the API Key

from google import genai


client = genai.Client(api_key="GEMINI_API_KEY")
response = client.models.generate_content(model ="gemini-2.0-flash",

contents="Please define API" )


print(response.text)

https://www.youtube.com/@ZafarIqbal_IT_Trainer
Vision Capabilities using Google Gemini API
from google import genai
from google. genai import types
import requests
image_path = "https://goo.gle/instrument-img"
image = requests.get(image_path)
client = genai.Client(api_key="GEMINI_API_KEY")

response = client.models.generate_content(model ="gemini-2.0-flash-exp",contents


=["What is this
image?",types.Part.from_bytes(data=image.content,mime_type="image/jpeg")])
print(response.text)

https://www.youtube.com/@ZafarIqbal_IT_Trainer
Gemini – How it works
Google API
HTTP Request with Server
Gemini UI API Key + Params Model

“Please define
API” gemini-2.0-flash

“API stands for


….”

Response to UI

https://www.youtube.com/@ZafarIqbal_IT_Trainer
Text generation using OpenAI (ChatGPT)
import openai

openai.api_key = “your-api-key-here”

response = openai.ChatCompletion.create (
model = "gpt-4",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Write a short story about a cat who becomes a
detective."}
],
max_tokens=200,
temperature=0.7 )
Result= response.choices[0].message['content'].strip();
print(Result)

https://www.youtube.com/@ZafarIqbal_IT_Trainer
ChatGPT – How it works

HTTP Request with


ChatGPT.com API Key + Params
Model
Open AI API
"Write a short
Server
story about a
cat…” "gpt-4"

“In the quiet


town of
Mewville…..”

Response to UI

https://www.youtube.com/@ZafarIqbal_IT_Trainer
Aassignment

Experiment with Gemini APIs using your API Key.

https://www.youtube.com/@ZafarIqbal_IT_Trainer

You might also like