which-command-GPT.psm1

$script:OpenAI_Key="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";function Wc{$key=$script:openai_key;$url="https://api.openai.com/v1/chat/completions";$phraseTuner="give me a command in only one line for the following:";$body=[pscustomobject]@{"model"="gpt-3.5-turbo";"messages"=@(;@{"role"="system";"content"="You are an assistant"};)};$header=@{"Authorization"="Bearer $key";"Content-Type"="application/json"};$message=Read-Host "Prompt";$body.messages+=@{"role"="user";"content"=$phraseTuner+" "+$message};$bodyJSON=($body|ConvertTo-Json -Compress);try{$res=Invoke-WebRequest -Headers $header -Body $bodyJSON -Uri $url -method post;$output=($res.content|convertfrom-json).choices.message;Write-Host "";write-host $output.content -ForegroundColor Green;$body.messages+=$output;Write-Host ""}catch{Write-Error $error[-1];return $res}};Export-ModuleMember -Function Wc;