Felpfe Inc.
Search
Close this search box.
call 24/7

+484 237-1364‬

Search
Close this search box.

Topic 2.2: Effective Use of ChatGPT – Exploration of the functionalities of ChatGPT and how to use them efficiently.

Once you’ve got started with ChatGPT, the next step is to learn how to use it effectively. Effective use of ChatGPT involves writing good prompts, understanding how to control the output length, making use of system and user instructions, managing tokens, and fine-tuning the model for specific tasks. Let’s dive into each of these aspects.

  1. Writing Good Prompts

Writing good prompts is a crucial aspect of effectively using ChatGPT. The prompt should provide enough context and be as explicit as possible. If you want a certain format of answer or have a specific requirement, include that in your prompt.

For example, if you want to generate a poem about autumn, your prompt could be as simple as “Write a poem about autumn.” But, it would be better to be more specific: “Write a sonnet about the feeling of walking through a forest in autumn.”

Python
response = openai.ChatCompletion.create(
  model="gpt-4.0-turbo",
  messages=[
        {"role": "system", "content": "You are a poetic assistant."},
        {"role": "user", "content": "Write a sonnet about the feeling of walking through a forest in autumn."},
    ]
)

print(response['choices'][0]['message']['content'])
  1. Controlling the Output Length

You can control the length of the output by setting the temperature and max tokens. Higher temperature values (e.g., 0.8) make the output more random, while lower values (e.g., 0.2) make it more deterministic. Max tokens limit the length of the generated output. However, setting it too low may result in cut-off sentences.

Python
response = openai.ChatCompletion.create(
  model="gpt-4.0-turbo",
  messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": "Summarize the plot of the Harry Potter series."},
    ],
  temperature=0.5,
  max_tokens=100
)

print(response['choices'][0]['message']['content'])
  1. Using System and User Instructions

System and user instructions can help in guiding the model’s responses. System messages set the behavior of the assistant, while user messages can provide more immediate instructions.

Python
response = openai.ChatCompletion.create(
  model="gpt-4.0-turbo",
  messages=[
        {"role": "system", "content": "You are an assistant that speaks like Shakespeare."},
        {"role": "user", "content": "Tell me a joke."},
    ]
)

print(response['choices'][0]['message']['content'])
  1. Managing Tokens

Both the input prompt and the output text consume tokens. If a conversation has too many tokens to fit into a model’s maximum limit (4096 tokens for gpt-4.0-turbo), you’ll have to truncate, omit, or shrink your text until it fits.

Python
# Estimating tokens in a text string without making an API call
tokens = openai.api.encode("How many tokens are in this string?")
print(f"Number of tokens: {len(tokens)}")
  1. Fine-Tuning the Model

While ChatGPT can perform a wide variety of tasks out of the box, for certain specific applications, you might want to fine-tune the model. Fine-tuning involves training the model on your own custom dataset and requires machine learning expertise.

Python
# This requires a custom training process, which is beyond the scope of this tutorial.

**Step

-by-step guide with code samples:**

  • Write good prompts that are explicit and provide enough context.
  • Control the output length using temperature and max tokens.
  • Use system and user instructions to guide the model’s responses.
  • Understand and manage your token usage.
  • For specific tasks, consider the possibility of fine-tuning the model.

In conclusion, using ChatGPT effectively requires a good understanding of how to communicate with the model and guide its responses. With the right prompts, settings, and token management, you can harness the power of this AI tool for a wide range of tasks, from content creation and text summarization to programming help and learning new topics. Keep in mind that while the model is powerful, it’s just a tool and should be used responsibly and ethically.

About Author
Ozzie Feliciano CTO @ Felpfe Inc.

Ozzie Feliciano is a highly experienced technologist with a remarkable twenty-three years of expertise in the technology industry.

kafka-logo-tall-apache-kafka-fel
Stream Dream: Diving into Kafka Streams
In “Stream Dream: Diving into Kafka Streams,”...
ksql
Talking in Streams: KSQL for the SQL Lovers
“Talking in Streams: KSQL for the SQL Lovers”...
spring_cloud
Stream Symphony: Real-time Wizardry with Spring Cloud Stream Orchestration
Description: The blog post, “Stream Symphony:...
1_GVb-mYlEyq_L35dg7TEN2w
Kafka Chronicles: Saga of Resilient Microservices Communication with Spring Cloud Stream
“Kafka Chronicles: Saga of Resilient Microservices...
kafka-logo-tall-apache-kafka-fel
Tackling Security in Kafka: A Comprehensive Guide on Authentication and Authorization
As the usage of Apache Kafka continues to grow in organizations...
1 2 3 58
90's, 2000's and Today's Hits
Decades of Hits, One Station

Listen to the greatest hits of the 90s, 2000s and Today. Now on TuneIn. Listen while you code.