GPT API applied to shell via bash script
Run the setup script in order to configurate script:
$ ./setup.sh
Reload your shell configuration file:
EX (zsh):
$ source ~/.zshrc
To run the script, use the ask command followed by your promp
$ ask "who are you?"
"I am a helpful Linux shell assistant here to assist you with any questions or problems you may have. I can provide information, guidance, and execute commands in the Linux shell environment. How can I assist you today?"
There are optional flags for overwriting some configuration fields
- -t: Changes max tokens returned by request (MAX_TOKENS)
- -m: Changes model used in request (MODEL)
- -T: Changes temperature for promp processing (TEMPERATURE)
- -r: Returns raw code, without any extra information or formatting
the -h flag can be used to read about available flags directly from the script.
$ ask -t 300 -m gpt-4 -T 0.7 "tell me about linux"
The script will append stdin to the prompt, yielding results as following:
$ cat gptask.sh | ask "what is this?"
or
$ ask "what is this?" < gptask.sh
"This is a bash script that interacts with the OpenAI API to generate responses based on user input. The script reads from standard input or command line arguments, sends a request to the OpenAI API, and prints the response. It also handles configuration variables, provides help information, and logs previous interactions."
Using the -r
flag, code can easily be outputed to a file.
$ ask -r "javascript code for consuming an SSE route, including imports" > sse_connection.js
You can repeat the last answer to stdout with the command
ask rpt
Configuration options are stored in the config
file, created during the setup process. If any configuration is missing from the config
file, the one contained in config.example
will be used instead.
Configuration parameters are:
- KEY: OpenAI API key
- MODEL: Model used in the request
- MAX_TOKENS: Limit of generated response tokens
- TEMPERATURE: Response temperature
- MAX_CHAT_MEMORY: Number of exchanged kept during the conversation for context
- KNOW_CURRENT_DIR: Defines if current dir will be informed durring conversation
Configuration variables from config
and/or config.example
files are always overwriten by flags sent when calling the script.
Besides editing the config
file directly, you can also use the CLI to do it.
Run the command
ask config
to automatically open your default terminal editor and make changes to your configuration file.
You can also just check the current configuration with the command:
ask config ls
which returns every configurations besides your secret key:
MODEL=gpt-4o
MAX_TOKENS=200
TEMPERATURE=0.2
MAX_CHAT_MEMORY=5
KNOW_CURRENT_DIR=true
Or use the flag -a
, which also returns the key:
KEY=[YOUR SECRET KEY]
MODEL=gpt-4o
MAX_TOKENS=200
TEMPERATURE=0.2
MAX_CHAT_MEMORY=5
KNOW_CURRENT_DIR=true
ask allows multiple chats to be created and managed, besides the default chat1
.
Through this command you can change your current used chat. If a chat whith that name does not exist, it will be created.
ask hist ch [CHAT_NAME]
ask hist ls
ask hist show [CHAT_NAME=CURRENT_CHAT]
Previous promps and responses are kept in the 'hist/[YOUR CURRENT SESSION].json' file. You can clean all previous conversations by deleting the file or simply running the command
ask cln [CHAT_NAME=CURRENT_CHAT]`