Conversing with Computers: Getting Started with ChatGPT

Maya Kamath
WhatfixEngineeringBlog
6 min readJan 25, 2023

Have you ever wanted to have a conversation with a machine? ChatGPT is a state-of-the-art language model that allows you to do just that. Developed by OpenAI, ChatGPT is a variant of the GPT-3 language model that has been fine-tuned specifically for chatbot applications.

I bring about this blog post series where I explain the various experiments that I do with ChatGPT

In this blog post, we’ll go over how to use ChatGPT and some of the different ways it can be utilized.

Getting Started

To get started with ChatGPT, you’ll need to have an API key from OpenAI. If you don’t have one already, you can sign up for a free API key on the OpenAI website.

Once you have your API key, you can use one of the many libraries that have been developed to interact with the ChatGPT API. For example, you can use the openai Python library to send requests to the ChatGPT API and receive responses from the model.

Using ChatGPT

Using ChatGPT is as simple as sending a request to the API with a prompt and receiving a response. You can use ChatGPT for a variety of different applications, including:

Chatbots: You can use ChatGPT to build a chatbot that can hold a conversation with a user. Simply send the chatbot a message, and it will respond with a coherent response.

Text Generation: You can use ChatGPT to generate text based on a prompt. For example, you could use ChatGPT to write a story or poem based on a theme or topic you provide.

Language Translation: ChatGPT has the ability to translate text from one language to another. Simply provide it with a block of text in one language and specify the desired output language, and ChatGPT will do the rest.

Here is an example of how you might use the generated text with ChatGPT

To do it, you’ll need to send a request to the API with a prompt specifying the text you want the model to generate. The prompt should include the text that you want the model to use as a starting point, as well as any constraints or guidelines that you want the model to follow.

The example below uses the openai Python library

import openai
# Set the API key
openai.api_key = "YOUR_API_KEY"
# Set the prompt
prompt = "Write a story about a robot that falls in love with a human"
# Set the model
model = "text-davinci-002"
# Generate the text
completion = openai.Completion.create(
engine=model,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.7,
)
# Print the generated text
print(completion.text)

This code will send a request to the ChatGPT API with the specified prompt, and the API will return a response with a story about a robot falling in love with a human, generated by the model.

You can also specify additional parameters in the request, such as the max_tokens parameter, which specifies the maximum number of tokens (i.e., words and punctuation) that the model should generate in the response, and the temperature parameter, which controls the randomness of the response.

import openai
# First, you'll need to set your API key
openai.api_key = "YOUR_API_KEY"

# Next, you'll need to define your prompt. This is the text that you want the model to generate text based on.
# For example, if you want the model to generate a story,
# you might provide it with a setting and a character.
prompt = "Once upon a time, in a land far, far away, there lived a brave knight named Sir Robin. One day, Sir Robin set out on a quest to save the kingdom from a terrible dragon."

# Use the openai.Completion.create() function to generate text from the prompt
response = openai.Completion.create(engine="text-davinci-002", prompt=prompt)

# The response object will contain a "choices" list,
# which has one element in this case, that element is a dictionary
# containing the generated text.
generated_text = response.choices[0].text
print(generated_text)

Note that in the above example, the engine used is “text-davinci-002” which is one of the models provided by OpenAI which have similar capabilities as ChatGPT.

You may use other models as well based on your needs and availability

The above code will print out the generated text based on the prompt provided. The generated text will be in continuation of the prompt, picking up from the last full stop given in the prompt. You can set parameters like the length of the generated text and the temperature of the sampling method, to fine-tune the generated text.

Keep in mind that, since ChatGPT is a statistical model, the generated text may not always be coherent or make sense. With more fine-tuning, adjusting the parameters, and providing more specific and clear prompts, you can improve the quality of the generated text.

Now, Let’s try to use ChatGPT in play.

1. Using help write a novel

Suppose, XYZ wants to write a novel, and his request is

Me: “Develop a plot for a mystery novel where a disillusioned homicide detective hunts a clever serial killer who preys on musicians who perform the jazz standard Autumn Leaves”.

ChatGPT: Detective James Thompson is a seasoned veteran of the Homicide department, but lately, he’s been feeling burnt out and disillusioned. His latest case, the murder of a young jazz pianist who was found brutally killed in his home, only serves to deepen his sense of despair … (much more provided)

2. Naming things

Another use I thought of is naming ideas.

Me: Help me come up with a name for a new drink. It’s got White Rum, watermelon juice, vodka, Szechuan pepper, lime juice, and tabasco sauce.

ChatGPT: “How about “Spicy Melon Frenzy”? The name suggests a combination of sweet watermelon and a kick of heat from the Szechuan pepper and Tabasco sauce, with the addition of white rum and vodka adding to the overall excitement”.

Limitations/ What I have learnt so far?

As with any machine learning model, ChatGPT has its limitations. It is still a work in progress, and there may be instances where the model produces responses that are nonsensical or unrelated to the prompt.

There are also several limitations of ChatGPT from a technical standpoint, including:

  • Data bias: Like any machine learning model, ChatGPT is only as good as the data it was trained on. If the training data contains biases, the model will likely reproduce them in its responses.
  • Limited understanding of context: ChatGPT is designed to generate text based on a given prompt, but it does not have the ability to understand the full context of a conversation or maintain long-term memory of previous interactions.
  • Difficulty in answering questions that require external knowledge: ChatGPT is trained on a large corpus of text and may not have access to external knowledge, which can make it difficult to answer questions that require information not included in its training data.
  • Limited ability to generate original content: ChatGPT is a language model that generates text based on patterns it has learned from the training data, which means it may not be able to generate completely original content.
  • Computational costs are high and the model requires powerful hardware for real-time usage.
  • The model might be less accurate and less relevant for languages other than English.

Keep in mind that these limitations are not unique to ChatGPT, but apply to most Language Models.

Conclusion

ChatGPT is a powerful language model that can be used for a variety of applications. With an API key and one of the many libraries available, it is easy to start using ChatGPT in your own projects. While it is not perfect, ChatGPT is an exciting step towards more natural and intuitive communication with machines.

Some of the real-world use cases are:

  • Natural Language Processing (NLP) tasks, such as language translation, text summarization, and sentiment analysis.
  • Chatbots and virtual assistants: ChatGPT can be used to generate human-like responses in a conversational setting, making it well-suited for building chatbots and virtual assistants.
  • Language-based games and entertainment: ChatGPT can be used to generate responses for interactive fiction, games and other language-based entertainment.
  • Social Media response generation: ChatGPT can be used to generate responses to customer inquiries, complaints or feedback on social media platforms such as Twitter, Facebook and Instagram.
  • Email response generation: ChatGPT can be used to generate automatic responses to customer inquiries, complaints, or feedback via email.

Keep in mind that these are some examples and depending on the specific use case, and the application could require fine-tuning the model or even using the model as a component in a larger system.However, it’s worth noting that these are just examples and the use case-specific requirements and the final system could be different.

--

--

Maya Kamath
WhatfixEngineeringBlog

Mobile developer, Blogger, Technology/Product Management Enthusiast