Compare commits

...

8 Commits

Author SHA1 Message Date
Achilleas 939f09cef7 Update comment 1 year ago
0xacx f49ec79a65
Merge pull request #63 from emirkmo/add_zshrc 1 year ago
0xacx 2bd33ab7b7
Update README.md 1 year ago
0xacx 63aa4e4c8f
Update README.md 1 year ago
0xacx 752d7b38ce
Merge pull request #81 from 0xacx/add-markdown-support 1 year ago
Achilleas 5fed80d6fa Print with markdown if glow is installed 1 year ago
Achilleas 762704073f Add newline 1 year ago
Emir Karamehmetoglu 1b352249ca
Add .zshrc to install script 1 year ago
  1. 3
      README.md
  2. 26
      chatgpt.sh
  3. 8
      install.sh

@ -72,6 +72,8 @@ This script relies on curl for the requests to the api and jq to parse the json
```
* An OpenAI API key. Create an account and get a free API Key at [OpenAI](https://beta.openai.com/account/api-keys)
* Optionally, you can install [glow](https://github.com/charmbracelet/glow) to render responses in markdown
### Installation
To install, run this in your terminal and provide your OpenAI API key when asked.
@ -157,6 +159,7 @@ This script relies on curl for the requests to the api and jq to parse the json
## Contributing
Contributions are very welcome!
If you have ideas or need help to get started join the [Discord server](https://discord.gg/fwfYAZWKqu)

@ -10,7 +10,7 @@ COMMAND_GENERATION_PROMPT="Return a one-line bash command with the functionality
CHATGPT_CYAN_LABEL="\n\033[36mchatgpt \033[0m"
PROCESSING_LABEL="\033[90mprocessing... \033[0m"
PROCESSING_LABEL="\n\033[90mProcessing... \033[0m"
if [[ -z "$OPENAI_KEY" ]]; then
echo "You need to set your OPENAI_KEY to use this script"
@ -375,8 +375,14 @@ while $running; do
handle_error "$response"
response_data=$(echo "$response" | jq -r '.choices[].message.content')
echo -e "${CHATGPT_CYAN_LABEL}${response_data}" | fold -s -w $COLUMNS
# if glow installed, print parsed markdown
if command -v glow &>/dev/null; then
formatted_text=$(echo "${response_data}" | glow)
echo -e "${CHATGPT_CYAN_LABEL}"
echo -e "${formatted_text}"
else
echo -e "${CHATGPT_CYAN_LABEL}${response_data}" | fold -s -w $COLUMNS
fi
escaped_response_data=$(echo "$response_data" | sed 's/"/\\"/g')
add_assistant_response_to_chat_message "$chat_message" "$escaped_response_data"
@ -394,8 +400,18 @@ while $running; do
request_to_completions "$request_prompt"
handle_error "$response"
response_data=$(echo "$response" | jq -r '.choices[].text' | sed '1,2d; s/^A://g')
echo -e "${CHATGPT_CYAN_LABEL}${response_data}" | fold -s -w $COLUMNS
response_data=$(echo "$response" | jq -r '.choices[].text')
# if glow installed, print parsed markdown
if command -v glow &>/dev/null; then
formatted_text=$(echo "${response_data}" | glow)
echo -e "${CHATGPT_CYAN_LABEL}"
echo -e "${formatted_text}"
else
# else remove empty lines and print
formatted_text=$(echo "${response_data}" | sed '1,2d; s/^A://g')
echo -e "${CHATGPT_CYAN_LABEL}${formatted_text}" | fold -s -w $COLUMNS
fi
if [ "$CONTEXT" = true ]; then
escaped_response_data=$(echo "$response_data" | sed 's/"/\\"/g')

@ -62,6 +62,14 @@ if [ "$answer" == "Yes" ] || [ "$answer" == "yes" ] || [ "$answer" == "y" ] || [
fi
echo "OpenAI key and chatgpt path added to ~/.zprofile"
source ~/.zprofile
# zshrc profile for debian
elif [ -f ~/.zshrc ]; then
echo "export OPENAI_KEY=$key" >>~/.zshrc
if [[ ":$PATH:" == *":/usr/local/bin:"* ]]; then
echo 'export PATH=$PATH:/usr/local/bin' >>~/.zshrc
fi
echo "OpenAI key and chatgpt path added to ~/.zshrc"
source ~/.zshrc
# bash profile mac
elif [ -f ~/.bash_profile ]; then
echo "export OPENAI_KEY=$key" >>~/.bash_profile

Loading…
Cancel
Save