When Using The ChatGPT API, Users Will Have To Manage The Context

Currently ChatGPT is powered by gpt-3.5-turbo-0301, the most advanced OpenAI language model. Whilst OpenAI has made the API available to this model, the API does not inherently perform conversation context management…

The ChatGPT models hold no memory of past requests, all relevant information must be supplied via the conversation.

pip install openai

import os
import openai
openai.api_key = "xxxxxxxxxxxxxxxxxxxxxxx"

completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages = [{"role": "system", "content" : "You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.\nKnowledge cutoff: 2021-09-01\nCurrent date: 2023-03-02"},
{"role": "user", "content" : "How are you?"},
{"role": "assistant", "content" : "I am doing well"},
{"role": "user", "content" : "How long does light take to travel from the sun to the eart?"}]
)
print(completion)
{
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "It takes about 8 minutes and 20 seconds for light to travel from the sun to the earth.",
"role": "assistant"
}
}
],
"created": 1678039126,
"id": "chatcmpl-6qmv8IVkCclnlsF5ODqlnx9v9Wm3X",
"model": "gpt-3.5-turbo-0301",
"object": "chat.completion",
"usage": {
"completion_tokens": 23,
"prompt_tokens": 89,
"total_tokens": 112
}
}
[{"role": "system", "content" : "You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.\nKnowledge cutoff: 2021-09-01\nCurrent date: 2023-03-02"},
{"role": "user", "content" : "How are you?"},
{"role": "assistant", "content" : "I am doing well"},
{"role": "user", "content" : "When was the last Formula One championship in South Africa?"}]
[
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "The last Formula One championship race held in South Africa was on October 17, 1993.",
"role": "assistant"
}
}
]
[{"role": "system", "content" : "You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.\nKnowledge cutoff: 2021-09-01\nCurrent date: 2023-03-02"},
{"role": "user", "content" : "How are you?"},
{"role": "assistant", "content" : "I am doing well"},
{"role": "user", "content" : "Who won the race in South Africa?"}]
{
"finish_reason": null,
"index": 0,
"message": {
"content": "I'm sorry, but I don't have access to up-to-date information on current events. My training data only goes up until September 2021, and I am not capable of browsing the internet or accessing real-time data.",
"role": "assistant"
}
}
[{"role": "system", "content" : "You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.\nKnowledge cutoff: 2021-09-01\nCurrent date: 2023-03-02"},
{"role": "user", "content" : "How are you?"},
{"role": "assistant", "content" : "I am doing well"},
{"role": "user", "content" : "When was the last Formula One championship in South Africa?"},
{"role": "assistant", "content" : "The last Formula One championship race held in South Africa was on October 17, 1993."},
{"role": "user", "content" : "Who won the race in South Africa?"}]
  {
"finish_reason": "stop",
"index": 0,
"message": {
"content": "The 1993 South African Grand Prix was won by Alain Prost of France, driving for the Williams-Renault team.",
"role": "assistant"
}
}

In Closing

  • By making the instructions more explicit
  • Specifying the answer format
  • Ask the model to think step by step or sequentially
https://www.linkedin.com/in/cobusgreyling
https://www.linkedin.com/in/cobusgreyling

--

--

Chief Evangelist @ HumanFirst. I explore and write about all things at the intersection of AI and language; NLP/NLU/LLM, Chat/Voicebots, CCAI. www.humanfirst.ai

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cobus Greyling

Chief Evangelist @ HumanFirst. I explore and write about all things at the intersection of AI and language; NLP/NLU/LLM, Chat/Voicebots, CCAI. www.humanfirst.ai