-
Option A: Modify the Original Prompt (Most Common for a Single Request)
If you knew you wanted more technical details or references from the start, you would modify your initial "user" message to explicitly ask for them. This is often the most efficient way to get everything in one go.
completion = client.chat.completions.create(
model="gpt-4.1",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain the AMOC in some detail and how it may be a climate change tipping point. How is the strength of the AMOC measured? Please include technical details and relevant scientific references if possible."}
],
max_completion_tokens = 1500
)
print("\nAI says:")
print(completion.choices[0].message.content)
This way, the AI is prompted to include the information you desire in its initial response.
-
Option B: Implement a Conversational Loop (If you want true back-and-forth)
This is how the ChatGPT web UI works. You maintain a messages list that includes the entire conversation history. To "respond" to the AI's invitation, you'd add its previous response to the messages list, then add your new "user" message (e.g., "Yes, please provide more technical details."), and then call the API again with the updated messages list.
# Initialize an empty list to store the conversation history
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain the AMOC in some detail and how it may be a climate change tipping point. How is the strength of the AMOC measured?"}
]
# First request
completion = client.chat.completions.create(
model="gpt-4.1",
messages=messages,
max_completion_tokens = 1500
)
ai_response = completion.choices[0].message.content
print("\nAI says:")
print(ai_response)
# Add the AI's response to the conversation history
messages.append({"role": "assistant", "content": ai_response})
# --- Now, to "respond" to the AI's invitation ---
# Add your new user message
user_follow_up = "Yes, please provide more technical details about the AMOC measurement and any relevant references."
messages.append({"role": "user", "content": user_follow_up})
# Make a second request with the updated conversation history
completion_follow_up = client.chat.completions.create(
model="gpt-4.1",
messages=messages,
max_completion_tokens = 1500 # Adjust if you expect a very long follow-up
)
ai_follow_up_response = completion_follow_up.choices[0].message.content
print("\nAI follow-up says:")
print(ai_follow_up_response)
This approach consumes more tokens (because the AI re-processes the entire conversation history each time), but it allows for true multi-turn interactions.
-
Option C: Make a New, Specific Request (Simpler than a full loop)
If you don't need a full conversational flow, but just want to follow up on that specific point, you can just make a brand new API call with a prompt that refers back to the original topic.
# Assuming you already got the first response and printed it
# You would then run this as a new, separate API call
completion_new_request = client.chat.completions.create(
model="gpt-4.1",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Regarding the AMOC, please provide more technical details on how its strength is measured, and include scientific references."}
],
max_completion_tokens = 1000 # Adjust as needed
)
print("\nAI new request says:")
print(completion_new_request.choices[0].message.content)