Created
February 2, 2024 02:33
-
-
Save hwayne/8727a5231368a1c7cf3a455a2f257afe to your computer and use it in GitHub Desktop.
Youtube Summarizer
This file contains 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
function Ask { | |
Param ( | |
[PSDefaultValue(Help="*")] | |
[switch]$Fast, | |
[Parameter(Position=1)] | |
[Alias("M")] | |
[int]$Tokens=256, | |
[Alias("n")] | |
[int]$Results=1, | |
[Parameter(Mandatory=$true, Position=0)] | |
[string]$query, | |
[Alias("s")] | |
[string]$system | |
) | |
$engine = $Fast ? "gpt-3.5-turbo" : "gpt-4" | |
$query = "-g user ""${query}"" " | |
if($system) {$query = " -g system ""${system}"" " + $query} # does the system vs user order matter? | |
Invoke-Expression "openai.exe api chat_completions.create -m ${engine} --max-tokens ${tokens} -n ${results} ${query} -t 0.7" | |
} | |
function Invoke-YoutubeSummary { | |
Param ( | |
[switch]$test, | |
[Parameter(Position=1)] | |
[string] | |
$id | |
) | |
# handle both ids and urls | |
if ($id -match "/") { | |
$id = ($id -replace ".*v=(\w*)&?.*", '$1') # subst MUST use single quotes | |
} | |
# Write-Output $id | |
$transcript = (python -m youtube_transcript_api $id --format text) | |
if ($test) { | |
return $transcript | |
} | |
# TODO if ($transcript[1] -notmatch "^Could not retrieve a transcript" {code} | |
ask -system "Summarize this youtube transcript." ($transcript -join '`n') | |
} | |
new-alias -Name sumyt -value Invoke-YoutubeSummary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment