Interview Prep
Interview questions, roadmaps and practice sets
Tutorials
Free tutorials on 30+ topics
Blog
Career guides, skills and interview tips
Free PDFs
Notes, cheat sheets and question banks
Certificates
Free skill tests and course certificates
Tools & Whiteboard
Free tools you can use right in the browser
Practice Tests
Mock tests, MCQs and quick Q&A
Free LMS
Learn on the Uncodemy LMS
Choose the best training program according to your career.
Improve the performance of your business with our innovative Industrial Training Program.
Read More →
Our instructor-led training classes are designed to make you an expert.
Read More →
Real-life case studies are a great way to demonstrate your practical knowledge.
Read More →
Explore blogs, latest technologies and industry updates with practical examples.
Read More →Browse all available training programs and choose the right one for your career.
Read More →Know more about who we are and what we stand for.
Discover our mission to equip individuals with essential IT skills and industry expertise.
Read More →
Free tutorials, interview questions, tools and calculators to help you learn.
Explore →Learn, practice and plan your career — bilkul free.
Book a free video counselling session and pick the right course for you.
Read More →Pasting code into the ChatGPT window and copying the answer back is helpful, but it is not automation. Automation starts when a script calls the model for you at a fixed point in your workflow: when you commit, when a pull request opens, when a build fails. This guide shows four such recipes using the OpenAI API from Python, plus the rules that keep them safe and cheap.
Every recipe below uses one small function. Install the SDK with pip install openai and set OPENAI_API_KEY as an environment variable (never commit the key).
# scripts/ai.py
from openai import OpenAI
client = OpenAI() # reads OPENAI_API_KEY from the environment
MODEL = "gpt-4o-mini" # example; use a current, low-cost model
def ask(system: str, user: str, max_chars: int = 20000) -> str:
"""Send one request; trims very large inputs to control cost."""
resp = client.chat.completions.create(
model=MODEL,
messages=[
{"role": "system", "content": system},
{"role": "user", "content": user[:max_chars]},
],
temperature=0.2,
)
return resp.choices[0].message.content.strip()
A low temperature keeps answers consistent from run to run, which is what you want in tooling.
# scripts/ai_commit_msg.py
import subprocess
from ai import ask
diff = subprocess.run(["git", "diff", "--staged"],
capture_output=True, text=True).stdout
if diff.strip():
print(ask(
"Write a git commit message: a summary line under 72 characters "
"in imperative mood, a blank line, then up to 4 bullet points. "
"Describe only what the diff shows.",
diff,
))
Hook it into Git with .git/hooks/prepare-commit-msg (make it executable with chmod +x):
#!/bin/sh
# $1 = path of the commit message file
# $2 = message source; empty for a plain "git commit"
if [ -z "$2" ]; then
python scripts/ai_commit_msg.py > "$1.ai" && cat "$1" >> "$1.ai" && mv "$1.ai" "$1"
fi
Now git commit opens your editor with a suggested message already filled in. You edit it or replace it; nothing is committed without you. The hook skips git commit -m, merges and amends, because Git sets $2 in those cases. If you are new to commits and staging, see version control basics.
A GitHub Actions workflow can post a plain-English summary on each new pull request, which helps reviewers start faster.
# .github/workflows/pr-summary.yml
name: PR summary
on:
pull_request:
types: [opened]
permissions:
contents: read
pull-requests: write
jobs:
summary:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install openai
- name: Build summary
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
BASE: ${{ github.base_ref }}
run: |
git diff "origin/$BASE...HEAD" > pr.diff
python scripts/pr_summary.py pr.diff > summary.md
- name: Comment on the PR
env:
GH_TOKEN: ${{ github.token }}
run: gh pr comment ${{ github.event.pull_request.number }} --body-file summary.md
# scripts/pr_summary.py
import sys
from ai import ask
diff = open(sys.argv[1], encoding="utf-8").read()
print(ask(
"Summarise this pull request for a reviewer. Sections: What changed, "
"Why it might matter, Files to review first, Possible risks. "
"Be specific and brief. Say 'unclear' rather than guessing.",
diff,
))
Store the API key under the repository's Actions secrets. For pull requests from forks, secrets are not available by default, so the job will not have a key there; that is a safety feature, not a bug.
The same structure works for a first-pass review comment; this guide on ChatGPT for code review covers what to ask for, and you can go further with an AI-powered review assistant.
# scripts/draft_tests.py usage: python scripts/draft_tests.py app/pricing.py
import sys, pathlib
from ai import ask
src = pathlib.Path(sys.argv[1]).read_text(encoding="utf-8")
print(ask(
"Write pytest tests for the functions in this module. Cover normal cases, "
"edge cases (empty input, zero, negative numbers, None) and expected "
"exceptions. Do not change the module. Output only Python code.",
src,
))
Redirect the output to a file such as tests/test_pricing_draft.py, run it, and read every test. Generated tests sometimes assert the current (buggy) behaviour as if it were correct, so a passing test is not proof of correct code. Keep the tests that make sense, fix or delete the rest.
# scripts/explain_log.py usage: python scripts/explain_log.py build.log
import sys
from ai import ask
log = open(sys.argv[1], encoding="utf-8", errors="ignore").read()
tail = log[-15000:] # the error is usually near the end
print(ask(
"This is the end of a failed CI log. Give: 1) the first real error line, "
"quoted; 2) the most likely cause; 3) two things to check. "
"If the log is not enough to tell, say so.",
tail,
))
Sending only the tail of the log keeps the request small, which saves money and time.
.env files, keys and customer data never appear in diffs or logs you send. A secret scanner in your pre-commit setup helps.Once these basics work, the same ask() helper can draft release notes from merged PR titles, convert API responses into TypeScript types, or explain a stack trace from a production alert. For prompts that work well in these scripts, see ChatGPT prompts for coding and debugging, and for automation beyond code, read about AI tools for daily IT workflows.
Sources: OpenAI API reference and openai-python README; Git documentation (githooks: prepare-commit-msg); GitHub Docs (workflow syntax, GITHUB_TOKEN permissions, gh pr comment).