How to ask Open AI Chatbot from Windows Terminal
The aim of this page📝 is to duplicate the great idea from “howdoi” just instead of curated answers from Stack Overflow, I am using an Open AI chatbot.
2 min readFeb 23, 2023
Implementation
- For notes on the simple activation of chatGPT API in python, see OpenAI /ChatGPT — How to Use it With Python | by Tony | Jan, 2023 | Dev Genius
- The following is a primitive Python Script
- The last line makes a first argument from CLI a prompt to
- I am also auto-copying this to the clipboard using pyclip · PyPI
- For joining the prompt written in the terminal into a single variable, I’m using a bit of PowerShell in located in
$profile
- that defines the function
ask
that I call when I need it
function ask {
$prompt = ""
$args | % {$prompt += $_ + " "}
python <path\script.py> $prompt
}
Comparison
howdoi
works perfectly and deterministically and has proper attributes (use-a
to get a full answer from StackOverflow)- the following are calls directly from Windows Terminal, but porting this to Mac should be a matter of a few lines in zsh profile
howdoi format date in Postgres to yyyy-mm-dd
>>> SELECT to_char("date", 'DD/MM/YYYY') FROM mytable;
- openAI gives me a similar answer, though
▶ ask how to format date to YYYY-MM-DD in Redshift
You can use the TO_CHAR function to format a date to YYYY-MM-DD in Redshift. The syntax is as follows:
TO_CHAR(date_expression, 'YYYY-MM-DD')
For example:
SELECT TO_CHAR(CURRENT_DATE, 'YYYY-MM-DD');