GPT-4 tutorial: How to integrate GPT-4 into your website

GPT-4 is here!

GPT-4 is a new large multimodal model from OpenAI. It is the fourth generation of the GPT language model. GPT-4 outperforms GPT-3 in many tasks. Thanks to its broad general knowledge it’s better to use it instead of previous models. In this tutorial, we will show you how to integrate GPT-4 into a streamlit project.

How to get access to GPT-4?

GPT-4 API is not available for everyone, it’s still in a limited beta. You can apply for access on OpenAI’s website. To do so, you need to fill out a form with your data and answer some questions. If you will be accepted, you will receive an email with the invitation to the GPT-4 beta.

How to change GPT-3 to GPT-4?

Changing GPT-3 to GPT-4 is a little bit tricky. GPT-4 like gpt-3.5-turbo model, is optimized for chat completion, not text completion. Thanks to its wide general knowledge, it also works well for traditional text completion. Because of that, we should change our completion functions to chat completion. In this tutorial, we will use Python SDK and lablab.ai’s GPT-3 Streamlit Boilerplate.

unnamed file

Clone our repository

First of all, we need to clone our repository. You can do it by running this command:

Let’s go to the project directory:

Install dependencies

Now we need to install all dependencies. You can do it by running:

See also  Craiyon tutorial: text-to-image generation prompt guide

GPT-3 -> GPT-4

To do so we need to open model.py. We should take care of GeneralModel class. To be able to use GPT-4, we need to change openai.Completion.create to openai.ChatCompletion.create. We also need to adjust kwargs params to fit GPT-4 needs. Also in the create function itself we have to add model parameter, change prompt keyword to messages, and extract content from the final response differently.

Feel free to change parameters passed to the model (e.g. temperature) and see how it affects the output.

BEFORE

AFTER

Run the project

Now we can run the project. You can do it by running:

Let’s try to generate a poem!

Result!

So is GPT-4 API worth implementing?

unnamed file 1

Yeah, sure! Changing GPT-3 to GPT-4 is not hard, it requires only a few changes, you can find them in this tutorial or OpenAI’s tutorials and documentation. It’s worth trying it because GPT-4 is a great model and it’s at least worth trying it! And as you may have read, it has much more power, hallucinates less, has new amazing features (like image inputs) and more!

It’s up to you, what you will build on top of it, but you just got a new powerful tool to use. As you’re currently building with Whisper and ChatGPT API, you might consider upgrading your project with the GPT-4 API.

And if you want to build with AI, we encourage you to join the lablab.ai community

or

Join our upcoming Whisper and ChatGPT AI Hackathon, or any other using cutting edge AI technology.

See also  17+ Of The Best ChatGPT Plugins To Help Speed Your Life Up

Build a working prototype and accelerate it with our slingshot program.

Shape the world with AI Change your life with lablab.ai

Thank you for your time! – Jakub Misiło @newnative