Skip to content

Instantly share code, notes, and snippets.

@bentman
Created June 20, 2024 09:19
Show Gist options
  • Save bentman/72c528407df8ab290eb562f65e2276fd to your computer and use it in GitHub Desktop.
Save bentman/72c528407df8ab290eb562f65e2276fd to your computer and use it in GitHub Desktop.
<#
.SYNOPSIS
PowerShell script using ChatGPT API for interview preparation.
.DESCRIPTION
Collects user inputs (job title, industry, resume, company name, interviewer details)
and generates interview topics, skills, questions, answers, and more using the ChatGPT API.
.INPUTS
Job Title
Industry
Resume
Company Name
Interviewer Name
Interviewer Job Title
Interviewer Company
Interviewer Key Achievements
.OUTPUTS
Interview preparation information.
.EXAMPLE
.\Use-ChatGptInterviewPrep.ps1
Enter Job Title: Software Engineer
Enter Industry: Technology
Enter Resume: Experienced software engineer with a focus on web development...
Enter Company Name: TechCorp
Enter Interviewer Name: John Smith
Enter Interviewer Job Title: CTO
Enter Interviewer Company: TechCorp
Enter Interviewer Key Achievements: 20 years of experience, led major projects...
.NOTES
Replace [YOUR_API_KEY] with your OpenAI API key before running the script.
#>
# Replace with your OpenAI API key
$apiKey = "[YOUR_API_KEY]"
$url = "https://api.openai.com/v1/engines/davinci-codex/completions"
$headers = @{
"Content-Type" = "application/json"
"Authorization" = "Bearer $apiKey"
}
# Define prompts as constants or variables
$jobTitlePrompt = "Please provide the key qualities and skills that companies look for when interviewing for the role of a {0} in the {1} industry."
$skillsPrompt = "What are the three most important and in-demand skills for someone in the role of {0} within the {1} industry? Please provide detailed descriptions."
$questionsPrompt = "What are the top five common and critical questions companies in the {0} industry typically ask candidates interviewing for a {1} role? Provide detailed questions."
$answersPrompt = "Using the following resume details: {1}, draft a comprehensive and well-structured answer to the interview question: '{0}'."
$interviewerHighlightsPrompt = "Based on the information provided, what are the three most notable highlights and achievements of the interviewer: {0}, who is the {1} at {2} with the following key achievements: {3}?"
$myQuestionsPrompt = "What are five insightful and thoughtful questions I could ask an interviewer for a {0} role at {1}? These should reflect my interest in the company and the position."
# Custom function to send queries to ChatGPT API and return generated text
function Invoke-ChatGPTApi {
param (
[string]$prompt,
[string]$inputData
)
$body = @{
"prompt" = $prompt -f $inputData
"max_tokens" = 150
"n" = 1
"stop" = @("\n")
"temperature" = 0.7
} | ConvertTo-Json
try {
$response = Invoke-WebRequest -Method 'POST' -Uri $url -Headers $headers -Body $body
$responseContent = $response.Content | ConvertFrom-Json
return $responseContent.choices[0].text.Trim()
} catch {
Write-Host "Error: $($_.Exception.Message)"
return $null
}
}
# Function to get user input with validation
function Get-ValidatedInput {
param (
[string]$promptMessage
)
do {
$valInput = Read-Host $promptMessage
if (![string]::IsNullOrWhiteSpace($valInput)) {
return $valInput
} else {
Write-Host "Input cannot be empty. Please try again."
}
} while ($true)
}
# Collect user inputs
$JobTitle = Get-ValidatedInput "Enter Job Title:"
$Industry = Get-ValidatedInput "Enter Industry:"
$MyResume = Get-ValidatedInput "Enter Resume:"
$CompanyName = Get-ValidatedInput "Enter Company Name:"
$InterviewerName = Get-ValidatedInput "Enter Interviewer Name:"
$InterviewerJobTitle = Get-ValidatedInput "Enter Interviewer Job Title:"
$InterviewerCompany = Get-ValidatedInput "Enter Interviewer Company:"
$InterviewerAchievements = Get-ValidatedInput "Enter Interviewer Key Achievements:"
# Send queries to the ChatGPT API and store the results
$Top3Interview = Invoke-ChatGPTApi -prompt $jobTitlePrompt -inputData "$JobTitle, $Industry"
$Top3Skills = Invoke-ChatGPTApi -prompt $skillsPrompt -inputData "$JobTitle, $Industry"
$Top5Questions = Invoke-ChatGPTApi -prompt $questionsPrompt -inputData "$Industry, $JobTitle"
$Top3Interviewer = Invoke-ChatGPTApi -prompt $interviewerHighlightsPrompt -inputData "$InterviewerName, $InterviewerJobTitle, $InterviewerCompany, $InterviewerAchievements"
$MyTop5Questions = Invoke-ChatGPTApi -prompt $myQuestionsPrompt -inputData "$JobTitle, $CompanyName"
# Prepare answers for top questions
$Top5Answers = @()
$QuestionsArray = $Top5Questions -split "\n" | Where-Object { $_ -ne "" }
foreach ($question in $QuestionsArray[0..4]) {
$answer = Invoke-ChatGPTApi -prompt $answersPrompt -inputData "$question, $MyResume"
if ($null -ne $answer) {
$Top5Answers += @{"Question" = $question; "Answer" = $answer}
}
}
# Display the results
Write-Host "`nJob Title in $Industry`n"
Write-Host "Top 3 Interview Topics:`n$Top3Interview`n"
Write-Host "Top 3 Skills:`n$Top3Skills`n"
# Display questions and answers in Q1, A1 format
for ($i = 0; $i -lt $QuestionsArray.Length; $i++) {
Write-Host ("Q{0}: {1}" -f ($i + 1), $QuestionsArray[$i])
Write-Host ("A{0}: {1}" -f ($i + 1), $Top5Answers[$i].Answer)
}
Write-Host "`nTop 3 Interviewer Highlights:`n$Top3Interviewer`n"
Write-Host "My Top 5 Questions:`n$MyTop5Questions"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment