Created
July 29, 2025 19:29
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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