Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save theoknock/b89e9a1f505d28f34d8669b851573d3f to your computer and use it in GitHub Desktop.

Select an option

Save theoknock/b89e9a1f505d28f34d8669b851573d3f to your computer and use it in GitHub Desktop.
Sends a user prompt to the GPT-4 API with a system role defining assistant behavior. It extracts and prints only the assistant’s response, omitting all metadata and token usage details. Clean and ready for direct terminal output or integration into larger apps.
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4-1106-preview",
messages=[
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": "List 3 countries and their capitals."}
],
temperature=0,
max_tokens=64
)
# Only print the assistant's reply text
print(response.choices[0].message.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment