0% found this document useful (0 votes)
4 views14 pages

Ap4b M4

The document provides an overview of a presentation on extending Python with packages and APIs, distributed under a Creative Commons License for educational purposes. It covers topics such as importing functions from local files, using built-in and third-party packages, installing packages, and utilizing APIs to retrieve data and interact with AI models. Key examples include the use of pandas and matplotlib for data manipulation and visualization, as well as a function for interacting with an AI model via an API.

Uploaded by

singhlakshdeep26
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)
4 views14 pages

Ap4b M4

The document provides an overview of a presentation on extending Python with packages and APIs, distributed under a Creative Commons License for educational purposes. It covers topics such as importing functions from local files, using built-in and third-party packages, installing packages, and utilizing APIs to retrieve data and interact with AI models. Key examples include the use of pandas and matplotlib for data manipulation and visualization, as well as a function for interacting with an AI model via an API.

Uploaded by

singhlakshdeep26
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/ 14

Copyright Notice

These slides are distributed under the Creative Commons License.

DeepLearning.AI makes these slides available for educational purposes. You may not use or distribute
these slides for commercial purposes. You may make copies of these slides and use or distribute them for
educational purposes as long as you cite DeepLearning.AI as the source of the slides.

For the rest of the details of the license, see https://creativecommons.org/licenses/by-sa/2.0/legalcode


AI Python for Beginners

Module 4: Extending
Python with Packages
and APIs
AI Python for Everyone

Lesson 1: Using Functions


from a Local File
How to load functions

Local Python files allow you to load functions


into your code

Imports specific function

from file import function

Imports every function

import file

Imports every function

from file import *


AI Python for Everyone

Lesson 2: Built-in
Packages
What is a Python package?

A collection of functions for a specific set of


tasks, like doing math or statistics.

Python has many


packages!

Use only what


you need
AI Python for Everyone

Lesson 3: Using Third-


party Packages
Third-party packages

In this notebook, you used the pandas and


matplotlib.pyplot packages.

You imported these packages with the


following commands:

import pandas as pd
import matplotlib.pyplot as plt
AI Python for Everyone

Lesson 4: Installing
Packages
AI Python for Everyone

Lesson 5: Using APIs to get


Data from the Web
What is an API?

Application Programming Interfaces (APIs)


let you ask another computer to give you
data or carry out a service.

API
AI Python for Everyone

Lesson 6: APIs to use AI


Models
get_llm_response()

def get_llm_response(prompt):
completion = client.chat.completions.create(
model = "gpt-4o-mini", Model selection
messages = [
Tells the LLM how to respond
{
The "role": "system",
prompt to "content": "You an AI assistant.",
pass to the
},
LLM {"role": "user", "content": prompt},
], Controls randomness of the
temperature=0.0,
responses
)
response = completion.choices[0].message.content
return response Gets the LLM
response text

Creates the request, sends it, and handles the


response from the OpenAI API

You might also like