Lecture 06 Calling Gemini and OpenAI APIs
Lecture 06 Calling Gemini and 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
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
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")
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
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
Response to UI
https://www.youtube.com/@ZafarIqbal_IT_Trainer
Aassignment
https://www.youtube.com/@ZafarIqbal_IT_Trainer