LibCoder

Beginning ChatGPT for Python: Build Intelligent Applications with OpenAI APIs

1C Agda GPT/AI/ИИ
Beginning ChatGPT for Python: Build Intelligent Applications with OpenAI APIs
Дата выхода: 2024
Издательство: Apress Media, LLC.
Количество страниц: 202
Размер файла: 2,7 МБ
Тип файла: PDF
Добавил: LibCoder
Оглавление
About the Authors .................................................................................................... ixAbout the Technical Reviewer ................................................................................. xiChapter 1: Introducing ChatGPT for Python Developers ....1Who Is This Book For? ....1Overview ....2Download the Code Now! ....2So, What Exactly Is ChatGPT and Why Do I Need to Use the OpenAI APIs? ....2Regex vs. ChatGPT: Fight! ....5Analysis Question #1: Who Didn’t Get Any Ice Cream, and Why? ....6Analysis Question #2: Which Kid Was Probably Left Sad? ....7Let’s Unlearn Some Words in Order to Learn More About the ChatGPT API ....8Models. Models? Models!!! ....8When We Talk About Tokens, Don’t Think About Access Tokens ....12Temperature Is All About Creativity ....13Getting Started with the OpenAI Playground ....131. Model ....162. System ....163. User/Assistant ....174. Add (Optional) ....175. Temperature (Optional) ....176. Maximum Tokens (Optional) ....177. Code (Optional) ....18Try It Now! Experimenting with the “System” Role ....18Conclusion ....18Chapter 2: Using ChatGPT As Your Python Pair-Programmer ....21Overview ....21Installing (or Updating) the OpenAI Library with pip ....21Three Ways to Set Your API Key ....22Option #1: Setting a System-Wide Environment Variable ....22Option #2: Creating a .env File ....24Option #3: Hard-Coding the API Key Directly in Your Application (Take with Caution) ....25Creating Your First Python ChatGPT App: model_lister.py ....26Using OpenAI.models.list() to Get a List of Available Models ....26Handling the Response ....27Using Your API Key to Get a List of Available Models with the OpenAI API ....27Getting a Prettier List of Models ....29Wait, How Many Tokens Are in My Prompt? ....30Using ChatGPT As a Pair-Programmer to Build a Weather Application ....31Setting Up the Prompt ....32Creating accuweather_forecaster.py with the AccuWeather API ....33Refining Our Prompt with Prompt Engineering ....36Using ChatGPT As a Pair-Programmer to Build an Application That Estimates Distanceand Arrival Time ....45Creating a Project with Google Maps Platform API ....45Using ChatGPT to Take a cURL Command and Make It Useable in Python:The Flexible Programmer’s Approach ....50Using ChatGPT to Avoid Reading a Lot of Documentation and Having to DecipherThrough Any cURL Code ....54Conclusion ....56Chapter 3: Creating a Basic ChatGPT Client in Python ....57Creating Our ChatGPT Chat Completion Application, chatgpt_client.py ....57Using OpenAI.chat.completions.create() to Send Messages to ChatGPT ....58Examining the Method Parameters ....59There Are Four Types of Messages ....66System Message (Dictionary) ....66User Message (Dictionary) ....67Assistant Message (Dictionary) ....68Tool Message (Dictionary) ....69Running chatgpt_client.py ....69Handling the Response (ChatCompletion) ....71ChatCompletionMessage ....72Conclusion ....73Chapter 4: Using AI in the Enterprise! Creating a Text Summarizer forSlack Messages ....75So, What Is Prompt Engineering? ....76ChatGPT Is Here to Take Away Everyone’s Jobs (Not Really) ....76Examining a Real-World Problem: Customer Support for a Software Company ....76Prompt Engineering 101: Text Summarization ....80Prompt #1: “tl;dr” ....80Prompt #2: “Explain This in Three Sentences or Less” ....81Prompt #3: “I’m a Manager. Explain to Me What Happened” ....82Prompt #4: “Give Me Suggestions on Next Steps” ....84Let’s Talk About Real Prompt Engineering ....86Registering a Slack Bot App ....86Specifying What Your Bot Can (and Can’t) Do by Setting the Scope ....89Confirming Your Settings ....90Viewing the OAuth & Permissions Page ....91Installing Your Slack Bot App to Your Workspace ....92Getting Your Slack Bot (Access) Token ....94Inviting Your Bot to Your Channel ....94Finding the Channel ID of Your Channel ....95Using Your Slack Bot App to Automatically Grab Messages from a Channel ....96Programmatically Reading Messages from Slack with slack_chat_reader_bot.py ....96Exercises Left for the Reader ....99Conclusion ....99Chapter 5: Multimodal AI: Creating a Podcast Visualizer with Whisper andDALL·E 3 ....101Introducing the Whisper Model by OpenAI ....103Features and Limitations of the Whisper Model ....106Using OpenAI.audio.transcriptions.create() to Transcribe Audio ....108Examining the Method Parameters ....109Creating a Utility App to Split Audio Files: audio_splitter.py ....110Creating the Audio Transcriber: whisper_transcriber.py ....113Having a Little Fun and Trying Things Out with a Podcast ....115Going Meta: Prompt Engineering GPT-4 to Write a Prompt for DALL·E ....117Using OpenAI.images.generate() to Create Images ....118Examining the Method Parameters ....119Handling the Response ....121Creating the Image Generator: dalle_client.py ....121DALL·E Prompt Engineering and Best Practices ....123DALL·E Golden Rule #1: Get Familiar with the Types of Images That DALL·ECan Generate ....124DALL·E Golden Rule #2: Be Descriptive with What You Want in the Foreground andBackground ....125Let’s Play Around with Prompts to DALL·E ....126Conclusion ....131Exercises Left for the Reader ....132Chapter 6: Creating an Automated Community Manager Bot with Discordand Python ....133Choosing Discord as Your Community Platform ....134Creating a More Advanced Bot Than Our Slack Bot ....134Creating a More Advanced Bot Than Any Typical Discord Bot ....135Understanding the Roles for the Bots ....135Our Example Bank: Crook’s Bank ....136First Things First: Create Your Own Discord Server ....136Create the Q&A Channel ....138Registering a New Discord Bot App with Discord ....138Specifying General Info for the Bot ....140Specifying OAuth2 Parameters for the Bot ....141Invite Your Bot to Your Server ....144Getting the Discord ID Token for Your Bot and Setting the Gateway Intents ....145Creating a Q&A Bot App in Python to Answer Questions from a Channel:tech_support_bot_dumb.py ....148Handling Messages Sent to the Discord Server ....150Success! Running Your First Discord Bot: tech_support_bot_dumb.py ....150Streamlining the Process of Registering Our Next Discord Bot App with Discord ....151Registering a New Discord Bot App with Discord ....151Specifying General Info for the Bot ....152Specifying OAuth2 Parameters for the Bot ....152Invite Your Bot to Your Server ....153Getting the Discord ID Token for Your Bot and Setting the Gateway Intents ....153Creating The Next Discord Bot: content_moderator_bot_dumb.py ....153Handling Messages Sent to the Discord Server ....155Success Again! Running Your Second Discord Bot: content_moderator_bot_dumb.py ....155Conclusion ....156Exercises Left for the Reader ....156Chapter 7: Adding Intelligence to Our Discord Bots, Part 1: Usingthe Chat Model for Q&A ....157Making tech_support_bot.py More Intelligent ....158Important Changes to Note from the Previous Version of the Tech Support Bot ....162Updates to the on_message(message) Function ....163Analyzing chatgpt_client_for_qa_and_moderation.py ....164Breaking Down the ChatGPTClient Class in Python So Our Bot Can Utilize ChatGPT ....165Running Our Intelligent Q&A Bot: tech_support_bot.py ....166We Have a Monumental Achievement…with One Slight Flaw ....168Update the System Message to ChatGPT, and Let’s Try Again ....169Conclusion ....171Chapter 8: Adding Intelligence to Our Discord Bots, Part 2: Using Chat andModerations Models for Content Moderation ....173Using OpenAI.moderations.create() to Moderate Content ....175Examining the Method Parameters ....175Handling the Response ....176Moderation (Dictionary) ....176Creating Our Client for the Moderations Model: moderation_client.py ....179Making content_moderator_bot.py More Intelligent ....180Updates to the on_message(message) Function ....184Running Our Intelligent Content Moderator Bot: content_moderator_bot.py ....185Conclusion ....186Exercises Left for the Reader ....186Appendix 1: List of OpenAI Models ....189Index ....191

Описание

Коротко и по делу о том, что важно знать про chatgpt.

Unlock the future of software development and empower yourself to elevate your Python applications by harnessing the power of AI as this field continues to grow and evolve. Perfect for beginner to intermediate Python programmers, this book breaks down the essentials of using ChatGPT and OpenAI APIs.

Each chapter includes hands-on exercises that bring concepts to life, demonstrating different API functionalities and practical applications. You'll start with the basics, learning to authenticate, send prompts, generate responses, test in the Playground, and handle errors with ease. You'll master models like GPT-4o, GPT-4, GPT-3.5, Whisper, and DALL-E, enabling you to enhance your applications with cutting-edge AI.

Leverage ChatGPT’s powerful Natural Language Processing (NLP) capabilities to handle various formats of unstructured text within your Python apps. Discover how generative AI tools like ChatGPT can automate tedious tasks rather than replace jobs. Quickly see how easy it is to use ChatGPT as your AI-pair programmer, boosting your productivity and speed.

This step-by-step guide will have you creating intelligent chatbots that can automatically process messages from Slack or Discord. With Beginning ChatGPT for Python, you'll master the ChatGPT and OpenAI APIs, building intelligent applications that offer a personalized and engaging user experience.

What You’ll LearnConnect with the ChatGPT and OpenAI APIs and send effective prompts.

Harness parameters like temperature and top_p to create unique and engaging responses from ChatGPT.

Create an intelligent assistant bot for Slack that automates tasks and enhances productivity.

Develop a bot that can moderate conversations and manage communities on Discord.

Add context to your prompts to get more accurate and relevant responses.

Who This Book Is ForPython developers and enthusiasts who aspire to employ OpenAI and ChatGPT in the creation of intelligent applications to enhance productivity.

На этом основные моменты по теме закрыты.

chatgpt applications your python intelligent openai that apis

Частые вопросы

Можно ли скачать «Beginning ChatGPT for Python: Build Intelligent Applications with OpenAI APIs» бесплатно?

Да, «Beginning ChatGPT for Python: Build Intelligent Applications with OpenAI APIs» доступна для бесплатного скачивания на нашем сайте в формате PDF. Ссылка на файл находится на этой странице.

В каком формате и какого размера файл?

Книга предоставляется в формате PDF, размер файла 2,7 МБ.

Кто автор и когда вышла книга?

автор — Evelyn Lydia , Hopkins Bruce Jr., издательство Apress Media, LLC., год выпуска 2024, 202 страниц.

О чём книга «Beginning ChatGPT for Python: Build Intelligent Applications with OpenAI APIs»?

Unlock the future of software development and empower yourself to elevate your Python applications by harnessing the power of AI as this field continues to grow and evolve.

Похожие материалы