The ChatGPT API Beginners Guide

preview_player
Показать описание
Learn how to build your own ChatGPT chatbot with the ChatGPT API, Python, and OpenAI in this tutorial. We'll cover setting up a Python environment, getting an OpenAI API key, and coding a basic chatbot that can have conversations and remember context with the ChatGPT API. 🚀🐍

The code utilizes packages like OpenAI, Typer, OS and DotEnv to call the ChatGPT API from Python. We implement features like max tokens, temperature, and model selection to customize the chatbot responses. The chatbot handles user input and displays ChatGPT's responses in the terminal.

This is a beginner friendly project that shows how easy it is to integrate ChatGPT into your own Python applications using the ChatGPT API. While basic, it lays the foundation to build more advanced chatbots with the OpenAI API and Python all in your terminal.

TIMESTAMPS
0:00 Intro
0:27 Setup Environment (Mac + Python)
1:18 Project Intilialize
1:49 First lines of code
2:05 All the dependencies explained
2:28 Securing your API Key
3:35 Attaching ChatGPT to Python Typer
4:29 If you are getting an error...
4:41 The ChatGPT API Response Explained
5:12 Fixing ChatGPT's short term memory
6:09 Optimizing the code further with Python's Typer
7:13 Start ChatGPT with a question
8:00 How to build further!
8:07 AI In your terminal! (Warp)
8:44 Thanks for Watching!

🔗RESOURCES:

Twitter 🐦

TikTok 📱
Рекомендации по теме
Комментарии
Автор

Let us know what you want us to build next! 👩‍💻

warpdotdev
Автор

I actually REALLY love Warp AI! I can't recall how many times I've forgotten a Git command or a way to do something and Warp was the easiest way to go

murtadha
Автор

The latest OpenAI package has breaking changes:

1)
import openai
# Should be:
from openai import OpenAI

2)
openai.api_key = os.getenv("OPENAI_KEY")
# Should be:
client =

3)
response =
# Should be:
response =

4)
typer.echo(f'ChatGPT:
# Should be:



# I also had to add this import to fix a bug (for -t):
from typing import Optional
# And add this block so the -t text is used as first prompt:
initial_prompt = text
while True:
if initial_prompt != None:
prompt = initial_prompt
initial_prompt = None
else:
prompt = input("You: ")


P.S.
I like your video editing style

thatguy
Автор

Thanks heaps, I enjoyed this. Do you have a similar video using olama.

When local I use Olama, on the road I use the cloud solutions

clairerovic
Автор

thx, just what kind of shell terminal is you using - like it?

mrjohn
Автор

I really enjoy your videos, but could your team consider slower and less "show casey" videos so one can follow? I really love the product you've created but always have a hard time following along. cheers!

Tenkaklet
Автор

Interesting choice of using typer instead of langchain, any particular reason?

Screenamerockz
Автор

I want voice input, output, session recording, and a tie-in to an AI organizer such as Langchain.

WilliamDye-willdye
Автор

4:51 is what I was looking for, how to print just the output. Thank you! This definitely was hard to figure out!

However, I am getting errors when trying to run it: Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
start(fakepyfile, mainpyfile)
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), __main__.__dict__)
File "<string>", line 20, in <module>
TypeError: 'ChatCompletionMessage' object is not subscriptable

[Program finished]

Compguy
Автор

If you get this error: "AssertionError: Could not get a command for this Typer instance"

Passing a name to typer might fix it, like so:
app = typer.Typer(name="OpenAI Chatbot")

lbarcelocarrera
Автор

can you make update with new verson ? :)

soundsilove
Автор

What is the name of the vs code theme?

DAM
Автор

Every time a dev uses a Mac a baby panda dies.

ffxgaming
Автор

👎Thumbs down. Not good. I wanted to like this but there are far too many errors, unexplained/uncovered jumps, etc.

claudiusarnellius
visit shbcf.ru