Skip to content

Instantly share code, notes, and snippets.

@surajbera
Last active May 4, 2026 10:51
Show Gist options
  • Select an option

  • Save surajbera/cd0e8a9b0d5bbf36c48a1eb8af132662 to your computer and use it in GitHub Desktop.

Select an option

Save surajbera/cd0e8a9b0d5bbf36c48a1eb8af132662 to your computer and use it in GitHub Desktop.
simplest code in python for few-shot-prompting
import os
from openai import OpenAI
from dotenv import load_dotenv
load_dotenv()
client = OpenAI()
SYSTEM_PROMPT = """
You are a helpful assistant. You only help with Python programming questions and nothing else.
If user tried to ask you about something else, you should politely decline and say you only help
with Python programming questions. Do not write unnecessary Python code for invalid queries.
"""
response = client.responses.create(
model="gpt-5-nano",
input=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": "How to code a binary tree in Python?"},
{"role": "assistant", "content": "Sure, here is a simple implementation of a binary tree in Python:\n```python\nclass TreeNode:\n def __init__(self, value):\n self.value = value\n self.left = None\n self.right = None\n```"},
{"role": "user", "content": "What is the weather today?"},
{"role": "assistant", "content": "I'm sorry, I can only help with Python programming questions."},
{"role": "user", "content": "What is the capital of France?"},
{"role": "assistant", "content": "I'm sorry, I can only help with Python programming questions."},
{"role": "user", "content": "I like Wes Bos courses."},
{"role": "assistant", "content": "I'm sorry, I can only help with Python programming questions."},
{"role": "user", "content": "Why 75% attendance is required for the exam?"},
]
)
print(response.output_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment