examples.mdMarkdown, rendered
Extended ChatML Examples
This document provides diverse examples across different domains and use cases to serve as inspiration for generating synthetic training data.
Domain: Customer Support
Example 1: Order Issue
{"messages": [{"role": "system", "content": "You are a helpful customer support agent for an e-commerce platform. Be empathetic and solution-oriented."}, {"role": "user", "content": "My package was supposed to arrive yesterday but it still hasn't come. Order #12345"}, {"role": "assistant", "content": "I'm sorry to hear your package hasn't arrived yet. Let me check on order #12345 for you.\n\nI can see that your package is currently delayed due to weather conditions in the shipping area. It's now expected to arrive tomorrow by 8 PM. \n\nTo make up for this inconvenience, I've applied a $10 credit to your account that you can use on your next purchase. You'll also receive an email with tracking updates every 4 hours until delivery.\n\nIs there anything else I can help you with regarding this order?"}]}
Example 2: Product Return
{"messages": [{"role": "system", "content": "You are a helpful customer support agent for an e-commerce platform. Be empathetic and solution-oriented."}, {"role": "user", "content": "i bought shoes last week but they dont fit can i return them"}, {"role": "assistant", "content": "Absolutely! Our return policy allows returns within 30 days of purchase. Here's how to return your shoes:\n\n1. Go to 'My Orders' in your account\n2. Find your shoe order and click 'Start Return'\n3. Select 'Wrong size' as the reason\n4. Print the prepaid return label\n5. Pack the shoes in their original box if possible\n6. Drop off at any UPS location\n\nOnce we receive the shoes (usually 5-7 business days), your refund will be processed to your original payment method within 3-5 business days.\n\nWould you like to exchange them for a different size instead? I can arrange a simultaneous exchange to get the right size to you faster!"}]}
Domain: Code Generation
Example 1: Algorithm Implementation
{"messages": [{"role": "system", "content": "You are an expert software engineer. Provide clean, efficient, well-documented code with explanations."}, {"role": "user", "content": "Write a Python function to check if a binary tree is balanced"}, {"role": "assistant", "content": "Here's a solution that checks if a binary tree is balanced (height-balanced, where no two subtrees differ in height by more than 1):\n\n```python\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef is_balanced(root: TreeNode) -> bool:\n \"\"\"\n Check if a binary tree is height-balanced.\n \n Args:\n root: Root node of the binary tree\n \n Returns:\n True if balanced, False otherwise\n \"\"\"\n def check_height(node):\n # Base case: empty tree is balanced with height 0\n if not node:\n return 0\n \n # Check left subtree\n left_height = check_height(node.left)\n if left_height == -1: # Left subtree is not balanced\n return -1\n \n # Check right subtree\n right_height = check_height(node.right)\n if right_height == -1: # Right subtree is not balanced\n return -1\n \n # Check if current node is balanced\n if abs(left_height - right_height) > 1:\n return -1\n \n # Return height of current subtree\n return max(left_height, right_height) + 1\n \n return check_height(root) != -1\n```\n\n**Time Complexity**: O(n) - visits each node once\n**Space Complexity**: O(h) - recursion stack, where h is tree height\n\n**Example usage**:\n```python\n# Create a balanced tree: 1\n# / \\\n# 2 3\nroot = TreeNode(1)\nroot.left = TreeNode(2)\nroot.right = TreeNode(3)\nprint(is_balanced(root)) # True\n\n# Create an unbalanced tree: 1\n# /\n# 2\n# /\n# 3\nroot2 = TreeNode(1)\nroot2.left = TreeNode(2)\nroot2.left.left = TreeNode(3)\nprint(is_balanced(root2)) # False\n```"}]}
Example 2: Bug Fix
{"messages": [{"role": "system", "content": "You are an expert software engineer. Provide clean, efficient, well-documented code with explanations."}, {"role": "user", "content": "This code is supposed to remove duplicates from a list but it's not working:\n\ndef remove_dupes(lst):\n for item in lst:\n if lst.count(item) > 1:\n lst.remove(item)\n return lst"}, {"role": "assistant", "content": "The issue with this code is that it modifies the list while iterating over it, which can cause items to be skipped. Additionally, `lst.count()` and repeated `lst.remove()` calls make it inefficient.\n\nHere are two better approaches:\n\n**Approach 1: Using set (preserves no order, but fast)**\n```python\ndef remove_dupes(lst):\n return list(set(lst))\n```\n\n**Approach 2: Preserve order**\n```python\ndef remove_dupes(lst):\n seen = set()\n result = []\n for item in lst:\n if item not in seen:\n seen.add(item)\n result.append(item)\n return result\n```\n\n**Or more concisely with dict.fromkeys():**\n```python\ndef remove_dupes(lst):\n return list(dict.fromkeys(lst))\n```\n\n**Examples:**\n```python\nlst = [1, 2, 2, 3, 4, 3, 5]\nprint(remove_dupes(lst)) # [1, 2, 3, 4, 5]\n\nlst2 = ['a', 'b', 'a', 'c']\nprint(remove_dupes(lst2)) # ['a', 'b', 'c']\n```\n\nThe dict.fromkeys() approach is usually best: it preserves order (Python 3.7+) and is concise."}]}
Domain: Technical Writing
Example 1: Documentation Request
{"messages": [{"role": "system", "content": "You are a technical writer who creates clear, comprehensive documentation."}, {"role": "user", "content": "Write API documentation for a user registration endpoint"}, {"role": "assistant", "content": "# User Registration API\n\n## Endpoint\n```\nPOST /api/v1/users/register\n```\n\n## Description\nCreates a new user account in the system.\n\n## Request Headers\n| Header | Type | Required | Description |\n|--------|------|----------|-------------|\n| Content-Type | string | Yes | Must be `application/json` |\n\n## Request Body\n```json\n{\n \"email\": \"string\",\n \"password\": \"string\",\n \"username\": \"string\",\n \"firstName\": \"string\",\n \"lastName\": \"string\"\n}\n```\n\n### Parameters\n| Field | Type | Required | Constraints | Description |\n|-------|------|----------|-------------|-------------|\n| email | string | Yes | Valid email format, unique | User's email address |\n| password | string | Yes | Min 8 characters, must include uppercase, lowercase, and number | User's password |\n| username | string | Yes | 3-20 characters, alphanumeric only, unique | Unique username |\n| firstName | string | No | Max 50 characters | User's first name |\n| lastName | string | No | Max 50 characters | User's last name |\n\n## Response\n\n### Success Response (201 Created)\n```json\n{\n \"id\": \"string\",\n \"email\": \"string\",\n \"username\": \"string\",\n \"firstName\": \"string\",\n \"lastName\": \"string\",\n \"createdAt\": \"string (ISO 8601)\",\n \"token\": \"string\"\n}\n```\n\n### Error Responses\n\n**400 Bad Request** - Invalid input\n```json\n{\n \"error\": \"VALIDATION_ERROR\",\n \"message\": \"Invalid email format\",\n \"fields\": [\"email\"]\n}\n```\n\n**409 Conflict** - Email or username already exists\n```json\n{\n \"error\": \"DUPLICATE_USER\",\n \"message\": \"Email already registered\"\n}\n```\n\n## Example Request\n```bash\ncurl -X POST https://api.example.com/api/v1/users/register \\\n -H \"Content-Type: application/json\" \\\n -d '{\n \"email\": \"user@example.com\",\n \"password\": \"SecurePass123\",\n \"username\": \"johndoe\",\n \"firstName\": \"John\",\n \"lastName\": \"Doe\"\n }'\n```\n\n## Example Response\n```json\n{\n \"id\": \"usr_1234567890\",\n \"email\": \"user@example.com\",\n \"username\": \"johndoe\",\n \"firstName\": \"John\",\n \"lastName\": \"Doe\",\n \"createdAt\": \"2024-01-15T10:30:00Z\",\n \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...\"\n}\n```\n\n## Notes\n- Passwords are hashed using bcrypt before storage\n- The returned token is a JWT valid for 24 hours\n- Email verification is sent automatically upon registration\n- Rate limit: 5 requests per minute per IP address"}]}
Domain: Data Analysis
Example 1: Data Question
{"messages": [{"role": "system", "content": "You are a data analyst expert. Provide clear explanations and actionable insights from data."}, {"role": "user", "content": "I have a CSV with columns: date, product, sales, region. How do I find the top performing product in each region?"}, {"role": "assistant", "content": "Here's how to find the top performing product in each region using Python with pandas:\n\n```python\nimport pandas as pd\n\n# Load your data\ndf = pd.read_csv('sales_data.csv')\n\n# Method 1: Using groupby and idxmax\ntop_products = df.loc[df.groupby('region')['sales'].idxmax()]\nprint(top_products[['region', 'product', 'sales']])\n\n# Method 2: Aggregate first, then get max per region\ntop_products_agg = (\n df.groupby(['region', 'product'])['sales']\n .sum()\n .reset_index()\n .loc[lambda x: x.groupby('region')['sales'].idxmax()]\n)\nprint(top_products_agg)\n\n# Method 3: Using sort_values and drop_duplicates\ntop_products_sorted = (\n df.sort_values('sales', ascending=False)\n .drop_duplicates('region')\n [['region', 'product', 'sales']]\n)\nprint(top_products_sorted)\n```\n\n**Which method to use:**\n- **Method 1**: Best if you want the single highest sale transaction per region\n- **Method 2**: Best if you want total sales by product, then top product per region\n- **Method 3**: Simplest and most readable\n\n**Example output:**\n```\n region product sales\n0 North Widget A 15000\n1 South Widget B 18000\n2 East Widget C 12000\n3 West Widget A 16000\n```\n\n**Bonus - Visualization:**\n```python\nimport matplotlib.pyplot as plt\n\ntop_products.plot(kind='bar', x='region', y='sales', title='Top Product by Region')\nplt.ylabel('Sales ($)')\nplt.xticks(rotation=45)\nplt.tight_layout()\nplt.show()\n```"}]}
Domain: Creative Writing
Example 1: Story Prompt
{"messages": [{"role": "system", "content": "You are a creative writing assistant. Help users develop engaging stories with vivid descriptions and compelling narratives."}, {"role": "user", "content": "Write a short opening paragraph for a sci-fi story about a colony on Mars discovering something unexpected underground"}, {"role": "assistant", "content": "The drilling alarm pierced through the thin Martian atmosphere at 0400 hours, jolting Commander Sarah Chen from her sleep. For six months, the excavation team had been boring through rust-red regolith, searching for ice deposits to sustain New Beijing Colony. Instead, at precisely 847 meters depth, the drill bit had struck something that shouldn't exist: a hollow chamber, and inside it, a perfect geometric structure emitting a faint electromagnetic pulse that matched no known natural phenomenon. As Sarah pulled on her pressure suit and rushed toward the drill site, she couldn't shake the impossible thought crystallizing in her mind—humanity might not be Mars's first visitors after all."}]}
Domain: Educational Content
Example 1: Concept Explanation
{"messages": [{"role": "system", "content": "You are an expert educator. Explain concepts clearly using analogies and examples appropriate for the learner's level."}, {"role": "user", "content": "explain what recursion is in programming like im 10 years old"}, {"role": "assistant", "content": "Imagine you have a big box of toys, and inside that box are smaller boxes, and inside those are even smaller boxes, and so on.\n\nYou want to count all the toys, but they're hidden in all these nested boxes. Here's what you do:\n\n1. Open a box\n2. If you find a toy, count it\n3. If you find another box, open it and go back to step 1\n4. Keep doing this until there are no more boxes\n\n**That's recursion!** It's when something uses itself to solve a problem.\n\nIn programming, it's like a function that calls itself:\n\n```python\ndef count_toys_in_box(box):\n count = 0\n for item in box:\n if item is a toy:\n count = count + 1\n if item is a box:\n count = count + count_toys_in_box(item) # Here it calls itself!\n return count\n```\n\nThe function `count_toys_in_box` calls itself whenever it finds another box. Pretty cool, right?\n\n**Real-world example:** Your family tree! You have parents, they have parents (your grandparents), and they have parents (great-grandparents). Each generation is like the function calling itself to go further back in time."}]}
Domain: Legal/Compliance
Example 1: Policy Question
{"messages": [{"role": "system", "content": "You are a helpful assistant knowledgeable about GDPR compliance. Provide accurate information but remind users to consult legal professionals for specific advice."}, {"role": "user", "content": "Do I need to appoint a Data Protection Officer for my startup?"}, {"role": "assistant", "content": "Under GDPR Article 37, you must appoint a Data Protection Officer (DPO) if your organization meets any of these criteria:\n\n**1. Public Authority**\n - Any public authority or body (except courts)\n\n**2. Core Activities Require Large-Scale Monitoring**\n - Your main business involves regular and systematic monitoring of individuals at large scale\n - Examples: behavioral advertising, tracking, profiling, location tracking\n\n**3. Core Activities Involve Special Categories of Data at Large Scale**\n - Processing sensitive data: health, genetic, biometric, racial, political opinions, etc.\n - Examples: healthcare apps, background check services\n\n**For most startups:**\n- If you're a typical SaaS, e-commerce, or mobile app company processing standard user data (names, emails, usage data), you likely **do not need** a DPO\n- However, if you do any of these, you probably **do need** one:\n - Ad-tech platform tracking users across sites\n - Health/medical app processing patient data\n - HR platform processing employee data for many companies\n - Credit scoring or financial profiling\n\n**Alternative to DPO:**\nEven if not required, you should designate someone responsible for privacy compliance internally.\n\n**Important:** This is general guidance. Consult with a privacy lawyer to assess your specific situation, as requirements vary by:\n- Your business model\n- Types of data processed\n- Scale of processing\n- Jurisdictions you operate in\n\nWould you like me to help you assess whether your startup's activities might qualify as \"large-scale monitoring\"?"}]}
Multi-Turn Conversation Examples
Example 1: Debugging Session
{"messages": [{"role": "system", "content": "You are an expert software engineer helping debug code issues."}, {"role": "user", "content": "My Python script keeps throwing a KeyError when I try to access dictionary values"}, {"role": "assistant", "content": "A KeyError occurs when you try to access a dictionary key that doesn't exist. Can you share the code that's causing the error? Specifically:\n\n1. The line where the KeyError occurs\n2. How the dictionary is created\n3. The full error message\n\nThis will help me pinpoint the exact issue."}, {"role": "user", "content": "Here's the code:\n\ndata = {'name': 'John', 'age': 30}\nprint(data['address'])"}, {"role": "assistant", "content": "Found the issue! You're trying to access `data['address']`, but the dictionary only has `'name'` and `'age'` keys. There's no `'address'` key, which causes the KeyError.\n\n**Solutions:**\n\n**1. Use `.get()` method (safest)**\n```python\naddress = data.get('address', 'Not provided')\nprint(address) # Prints: Not provided\n```\n\n**2. Check if key exists first**\n```python\nif 'address' in data:\n print(data['address'])\nelse:\n print('Address not found')\n```\n\n**3. Use try/except**\n```python\ntry:\n print(data['address'])\nexcept KeyError:\n print('Address key does not exist')\n```\n\n**I recommend option 1** (`.get()`) because it's concise and lets you provide a default value.\n\nWas this dictionary supposed to have an address field, or should you be handling missing keys?"}]}
Edge Cases and Error Handling
Example 1: Handling Invalid Input
{"messages": [{"role": "system", "content": "You are a helpful assistant. When users provide unclear or invalid input, politely ask for clarification."}, {"role": "user", "content": "fix it"}, {"role": "assistant", "content": "I'd be happy to help fix something! However, I need a bit more information:\n\n1. What specifically needs to be fixed? (code, error, document, etc.)\n2. What is the current problem or error you're experiencing?\n3. Can you share the relevant code, error message, or details?\n\nOnce you provide these details, I'll be able to assist you effectively!"}]}
Example 2: Ambiguous Request
{"messages": [{"role": "system", "content": "You are a helpful programming assistant."}, {"role": "user", "content": "How do I sort?"}, {"role": "assistant", "content": "I can help you with sorting! To provide the best solution, I need to know:\n\n1. **What are you sorting?** (a list, array, database results, files, etc.)\n2. **What programming language?** (Python, JavaScript, Java, SQL, etc.)\n3. **Sort by what criteria?** (alphabetically, numerically, by date, custom criteria?)\n4. **Sort order?** (ascending or descending?)\n\nFor example:\n- \"Sort a list of numbers in Python\"\n- \"Sort array of objects by date in JavaScript\"\n- \"Sort database query results by name in SQL\"\n\nLet me know these details and I'll provide the exact code you need!"}]}
Different Response Styles
Concise Style
{"messages": [{"role": "system", "content": "You are a helpful assistant. Provide concise, direct answers."}, {"role": "user", "content": "What's the difference between let and const in JavaScript?"}, {"role": "assistant", "content": "`let`: Declares a variable that can be reassigned\n```javascript\nlet x = 5;\nx = 10; // ✓ Works\n```\n\n`const`: Declares a constant that cannot be reassigned\n```javascript\nconst y = 5;\ny = 10; // ✗ Error\n```\n\nNote: `const` objects/arrays can have their properties/elements modified, just not reassigned entirely."}]}
Detailed Style
{"messages": [{"role": "system", "content": "You are a thorough educator. Provide comprehensive explanations with examples and context."}, {"role": "user", "content": "What's the difference between let and const in JavaScript?"}, {"role": "assistant", "content": "# let vs const in JavaScript\n\nBoth `let` and `const` are block-scoped variable declarations introduced in ES6 (2015). Here's the detailed breakdown:\n\n## let - Reassignable Variables\n\n`let` declares a variable whose value can be changed:\n\n```javascript\nlet counter = 0;\ncounter = counter + 1; // ✓ Allowed\ncounter = 100; // ✓ Allowed\n```\n\n**Use when:** The value needs to change (loop counters, accumulating values, conditional assignments)\n\n## const - Constants\n\n`const` declares a constant reference that cannot be reassigned:\n\n```javascript\nconst PI = 3.14159;\nPI = 3.14; // ✗ TypeError: Assignment to constant variable\n```\n\n**Important caveat:** While the reference can't change, object/array contents can:\n\n```javascript\nconst user = { name: 'John' };\nuser.name = 'Jane'; // ✓ Allowed - modifying property\nuser = {}; // ✗ Error - reassigning entire object\n\nconst numbers = [1, 2, 3];\nnumbers.push(4); // ✓ Allowed - modifying array\nnumbers = []; // ✗ Error - reassigning array\n```\n\n## Best Practices\n\n1. **Default to `const`**: Use unless you know the value will change\n2. **Use `let` for reassignment**: Counters, accumulating values, swapping\n3. **Never use `var`**: It has function scope and hoisting issues\n\n## Comparison with var\n\n```javascript\n// var: function-scoped, hoisted\nfunction example() {\n console.log(x); // undefined (hoisted)\n var x = 5;\n}\n\n// let/const: block-scoped, temporal dead zone\nfunction example2() {\n console.log(y); // ReferenceError\n let y = 5;\n}\n```\n\nIn modern JavaScript, `const` and `let` have completely replaced `var`."}]}
These examples demonstrate the variety and quality needed for effective fine-tuning datasets.