Using GPT-3 in our applications
Tags: technologyindustrytr
Published: 2023-03-03 10:14:10

---
title: Using GPT-3 in our applications
published: true
date: 2023-03-02 08:33:07 UTC
tags: Technologyindustrytr
canonical_url: https://apiumhub.com/tech-blog-barcelona/using-gpt-3-in-our-applications/
---

Welcome to a new installment on artificial intelligence. As I explained in my [previous article](https://dev.to/apium_hub/gpt-3-playground-the-ai-that-can-write-for-you-4h45), GPT-3 (Generative Pretrained Transformer 3) is a state-of-the-art language processing model developed by OpenAI. It has been trained on a large amount of data and can generate human-like text on a wide range of topics. One of the ways to access GPT-3’s capabilities is through its API, which allows developers to easily integrate GPT-3 into their applications.

In this article, we will provide a detailed guide on how to use the GPT-3 API, including how to set up your API key, generate responses, and access the generated text. By the end of this article, we will have a foundation of how to use GPT-3 in our own projects and applications.

## Step-by-step guide

To use GPT-3 with Python, we will have to use the [OpenAI](https://github.com/openai/openai-python) library, which is the official Python library to interact with its API.

### Configuring your API key

First, we will need to register for an OpenAI API key. This key will allow us to access the GPT-3 API and use it in our Python scripts. You can register for an [API key](https://platform.openai.com/account/api-keys) at the [OpenAI](https://platform.openai.com/overview)website.

![VxYOJ44JohWCd rqchoQxLHBahtVvb1Ay um hPOAJkSWMrYRWsEwODbQc0SMW10LYLhhedNU3FvHwmmuNaVa 3swv6sCgm jjDfETPnQ3leJVs3xwB5wuD7UjbBxuwcxDJ YVtSKm egVBbOV0Xt4](https://lh4.googleusercontent.com/_VxYOJ44JohWCd-rqchoQxLHBahtVvb1Ay_um_hPOAJkSWMrYRWsEwODbQc0SMW10LYLhhedNU3FvHwmmuNaVa-3swv6sCgm-jjDfETPnQ3leJVs3xwB5wuD7UjbBxuwcxDJ_YVtSKm-egVBbOV0Xt4 "Using GPT-3 in our applications 8")

Once we have the API key, we will need to install the **OpenAI** library. This can be done using [pip](https://pypi.org/project/pip/), the Python package manager. To install the library, open a terminal and run the following command:

![LccCttk9BpMjSeLv8UK FARRsgTJ45QHDw6IuN4Mtww3qScwVAlI4WCq](https://lh5.googleusercontent.com/LccCttk9BpMjSeLv8UK-FARRsgTJ45QHDw6IuN4Mtww3qScwVAlI4WCq-oDh5Q2RRdLxIY27dLGjKKWtO_5KerLk24OvHUSK3egcun2Tgz_qUpITQnN5QrE453esxhHTsSKaUHNq55vUGut0UiRdI64 "Using GPT-3 in our applications 9")

After the installation is complete, we can import it into our Python project using the following code:

![lW5AGOY9dSG9iVABiet0d0ROrLMjlqZzg9Iz fsZyWBFnMko3r6DJ8CulXAQaciNJSw2QaLZWlc8roN1CF40TBlktrsVmrMhw6J ncUF6Z6cY0LlC p7RwumngFZ OrZ PlLTPesvTnnb9SpzzSaDKk](https://lh4.googleusercontent.com/lW5AGOY9dSG9iVABiet0d0ROrLMjlqZzg9Iz-fsZyWBFnMko3r6DJ8CulXAQaciNJSw2QaLZWlc8roN1CF40TBlktrsVmrMhw6J-ncUF6Z6cY0LlC_p7RwumngFZ_OrZ-PlLTPesvTnnb9SpzzSaDKk "Using GPT-3 in our applications 10")

Once we have imported the **OpenAI** package, we can configure our API key as follows:

![lzv2p38cgxLXVywzBzOtQZAl7b0EYYzHw4JqHSC8U7q1o3LMCxzlHwkt63twPHvQAqHtkLd 7nv9Kqw1OX63bi4dhwPYFa SzyNgLxnJBsaFcUZ](https://lh4.googleusercontent.com/lzv2p38cgxLXVywzBzOtQZAl7b0EYYzHw4JqHSC8U7q1o3LMCxzlHwkt63twPHvQAqHtkLd-7nv9Kqw1OX63bi4dhwPYFa_SzyNgLxnJBsaFcUZ-XCHu1XHLusaf4AxPA37gkjE8IPeKgnDuvkUOQf4 "Using GPT-3 in our applications 11")

### Generating completions with GPT-3

With the **OpenAI** package imported and its API key configured, we are now ready to start programming our test. The **Completion** class takes a number of parameters, including the model to be used, the **prompt** to be completed and the **maximum number of tokens** (individual text units) to be generated.

GPT-3 has several different model versions, each with different sizes and capacities. For this example, we will use the **text-davinci-002** model.

For example, to generate three finalizations of up to 50 tokens each with the text-davinci-002 model, we could use the following code:

![7aQTa8pWITA](https://lh6.googleusercontent.com/7aQTa8pWITA-YErwRnHldWMOXrYoHJrD_F6AGIwpDUbbfmbjJcFG4iNzXnIRa3reVphmzql2lK2IWL1UN3p2_EKQlvdjk9SnAzErDz5PurUaOVW_eRcpi2octzW3MMpxdxOGck5rIFA9YcqW6Ia_WqM "Using GPT-3 in our applications 12")

The **Completion** object returned contains a list of **Completion** objects, each of which has a text field with the generated response. We can access the text of each **Completion** through a **for** loop:

![7SwbBA31nASmzayCn1pYDZpEfJc0JYWR4d z9RvY7KaA02qA3trx4RkfJw7yTvCH1rQp8ywUcJOnfdY7vDvrZnlordB5JuG69PIS2](https://lh6.googleusercontent.com/7SwbBA31nASmzayCn1pYDZpEfJc0JYWR4d-z9RvY7KaA02qA3trx4RkfJw7yTvCH1rQp8ywUcJOnfdY7vDvrZnlordB5JuG69PIS2-TZu39EN9Qbf13nKj1J8xoyItv8jd0phBv0ZLfoffvi2zlCDvI "Using GPT-3 in our applications 13")

This code will print each of the **Completions** generated in our console.

You can pass additional parameters such as **temperature** to control the level of randomness in the text, **max\_tokens** to set the maximum number of tokens to generate, among others. If you want to know more about the parameters, I remind you that in our [previous article](https://dev.to/apium_hub/gpt-3-playground-the-ai-that-can-write-for-you-4h45), we talked in detail about the most important ones.

The following code is similar to the previous example, but with some additional parameters:

![](https://lh6.googleusercontent.com/Z8f2q2qaN8e2X_ut9A2UznjKqFyShkyPdZzEcAjBnAlCJFhKoSw1H6YmlL56nIZQ4ONx2pPp4iGOkPHOLiJJIYPlYNe3n_OiIyvqJeFZjkBhHe8rnGtXJ1BAk7tI0wk6usl_38WsAwguLoR8XhvsaK4 "Using GPT-3 in our applications 14")

Note that we will have to replace “ **your\_api\_key\_here** ” with the API key we have obtained before from OpenAI.

If you are curious and want to learn more about its API and how to use it, you can access its [documentation,](https://platform.openai.com/docs/api-reference/introduction) which is very well explained.

## How does GPT-3 affect the workplace?

While GPT-3 is a language processing model, it is generally not used as a direct hiring capability. Rather, it is a tool that developers and researchers can use to help them in their jobs.

One potential use of GPT-3 is in the field of **natural language processing** (NLP), which can be used to develop applications, such as sentiment analysis, and generate human-like text. **Software engineers** , for example, use it to develop chatbots or language translation tools, with the goal of generating text that they can use in their applications, such as responses to user input or content that is generated automatically.

There are other jobs that involve the use of GPT-3 such as **data scientists** , who often use it to generate product descriptions or article summaries.

Finally, another example is **copywriters** who generally use it to generate human-like text for their writing, such as product descriptions or marketing copy.

Overall, although GPT-3 is not currently a direct hiring motive, it has the potential to be used in a wide range of fields. Rather, it is a tool that helps people in some work settings get their work done faster.

## Conclusion

In conclusion, GPT-3 is a powerful language processing model that can be used in a variety of applications, including games. To give you an idea, let me give you an example.

One potential use of GPT-3 in a game could be to generate a dialog with an NPC (Non-Player Character) based on the player’s actions and choices. For example, if the player chooses to help a character, the NPC could respond with gratitude and offer a reward. On the other hand, if the player chooses to steal from the NPC, the NPC might respond with anger and hostility. The great thing about this is that for each player, situation, day, and time the response would be different, and that would make the interaction with the video game world more real.

Overall, GPT-3’s ability to generate human-like text makes it a valuable tool for many fields, and, little by little, we will see it becoming more and more established in our workplaces.