Skip to content

Commit

Permalink
Merge branch 'main' into escape-system-prompt-from-file
Browse files Browse the repository at this point in the history
  • Loading branch information
0xacx committed May 16, 2023
2 parents 4395626 + e6c213f commit a69c998
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ This script relies on curl for the requests to the api and jq to parse the json
## Contributors
:pray: Thanks to all the people who used, tested, submitted issues, PRs and proposed changes:

[pfr-dev](https://www.github.com/pfr-dev), [jordantrizz](https://www.github.com/jordantrizz), [se7en-x230](https://www.github.com/se7en-x230), [mountaineerbr](https://www.github.com/mountaineerbr), [oligeo](https://www.github.com/oligeo), [biaocy](https://www.github.com/biaocy), [dmd](https://www.github.com/dmd), [goosegit11](https://www.github.com/goosegit11), [dilatedpupils](https://www.github.com/dilatedpupils), [direster](https://www.github.com/direster), [rxaviers](https://www.github.com/rxaviers), [Zeioth](https://www.github.com/Zeioth), [edshamis](https://www.github.com/edshamis), [nre-ableton](https://www.github.com/nre-ableton), [TobiasLaving](https://www.github.com/TobiasLaving), [RexAckermann](https://www.github.com/RexAckermann), [emirkmo](https://www.github.com/emirkmo), [np](https://www.github.com/np), [camAtGitHub](https://github.com/camAtGitHub)
[pfr-dev](https://www.github.com/pfr-dev), [jordantrizz](https://www.github.com/jordantrizz), [se7en-x230](https://www.github.com/se7en-x230), [mountaineerbr](https://www.github.com/mountaineerbr), [oligeo](https://www.github.com/oligeo), [biaocy](https://www.github.com/biaocy), [dmd](https://www.github.com/dmd), [goosegit11](https://www.github.com/goosegit11), [dilatedpupils](https://www.github.com/dilatedpupils), [direster](https://www.github.com/direster), [rxaviers](https://www.github.com/rxaviers), [Zeioth](https://www.github.com/Zeioth), [edshamis](https://www.github.com/edshamis), [nre-ableton](https://www.github.com/nre-ableton), [TobiasLaving](https://www.github.com/TobiasLaving), [RexAckermann](https://www.github.com/RexAckermann), [emirkmo](https://www.github.com/emirkmo), [np](https://www.github.com/np), [camAtGitHub](https://github.com/camAtGitHub), [keyboardsage](https://github.com/keyboardsage)

## Contributing
Contributions are very welcome!
Expand Down
10 changes: 5 additions & 5 deletions chatgpt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

GLOBIGNORE="*"

CHAT_INIT_PROMPT="You are ChatGPT, a Large Language Model trained by OpenAI. You will be answering questions from users. You answer as concisely as possible for each response (e.g. don’t be verbose). If you are generating a list, do not have too many items. Keep the number of items short. Before each user prompt you will be given the chat history in Q&A form. Output your answer directly, with no labels in front. Do not start your answers with A or Anwser. You were trained on data up until 2021. Today's date is $(date +%d/%m/%Y)"
CHAT_INIT_PROMPT="You are ChatGPT, a Large Language Model trained by OpenAI. You will be answering questions from users. You answer as concisely as possible for each response (e.g. don’t be verbose). If you are generating a list, do not have too many items. Keep the number of items short. Before each user prompt you will be given the chat history in Q&A form. Output your answer directly, with no labels in front. Do not start your answers with A or Anwser. You were trained on data up until 2021. Today's date is $(date +%m/%d/%Y)"

SYSTEM_PROMPT="You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible. Current date: $(date +%d/%m/%Y). Knowledge cutoff: 9/1/2021."
SYSTEM_PROMPT="You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible. Current date: $(date +%m/%d/%Y). Knowledge cutoff: 9/1/2021."

COMMAND_GENERATION_PROMPT="You are a Command Line Interface expert and your task is to provide functioning shell commands. Return a CLI command and nothing else - do not send it in a code block, quotes, or anything else, just the pure text CONTAINING ONLY THE COMMAND. If possible, return a one-line bash command or chain many commands together. Return ONLY the command ready to run in the terminal. The command should do the following:"

Expand Down Expand Up @@ -403,7 +403,7 @@ while $running; do
fi
add_assistant_response_to_chat_message "$(escape "$response_data")"

timestamp=$(date +"%d/%m/%Y %H:%M")
timestamp=$(date +"%Y-%m-%d %H:%M")
echo -e "$timestamp $prompt \n$response_data \n" >>~/.chatgpt_history

elif [[ "$MODEL" =~ ^gpt- ]]; then
Expand All @@ -425,7 +425,7 @@ while $running; do
fi
add_assistant_response_to_chat_message "$(escape "$response_data")"

timestamp=$(date +"%d/%m/%Y %H:%M")
timestamp=$(date +"%Y-%m-%d %H:%M")
echo -e "$timestamp $prompt \n$response_data \n" >>~/.chatgpt_history
else
# escape quotation marks, new lines, backslashes...
Expand Down Expand Up @@ -454,7 +454,7 @@ while $running; do
maintain_chat_context "$(escape "$response_data")"
fi

timestamp=$(date +"%d/%m/%Y %H:%M")
timestamp=$(date +"%Y-%m-%d %H:%M")
echo -e "$timestamp $prompt \n$response_data \n" >>~/.chatgpt_history
fi
done
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fi
curl -sS https://raw.githubusercontent.com/0xacx/chatGPT-shell-cli/main/chatgpt.sh -o /usr/local/bin/chatgpt

# Replace open image command with xdg-open for linux systems
if [[ "$OSTYPE" == "linux-gnu"* ]] || [[ "$OSTYPE" == "freebsd"* ]]; then
if [[ "$OSTYPE" == "linux"* ]] || [[ "$OSTYPE" == "freebsd"* ]]; then
sed -i 's/open "\${image_url}"/xdg-open "\${image_url}"/g' '/usr/local/bin/chatgpt'
fi
chmod +x /usr/local/bin/chatgpt
Expand Down
166 changes: 166 additions & 0 deletions internal_dev/debmaker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#!/bin/env bash
###############################################################################
# Purpose: The purpose of this script is to simply generate a .deb file.
# Once the .deb file is generated a copy is moved to /tmp.
#
# It can be installed and uninstalled like so:
# $ sudo apt -y install ./chatgpt-shell-cli_0.0.1_all.deb
# $ sudo apt -y remove chatgpt-shell-cli
###############################################################################

# Functions
make_directory() {
local filepath="$1"
local shouldRemake=$2

if [ $shouldRemake -ne 0 ]; then # delete old directory first if desired
rm -rf "$filepath"
fi

mkdir -p "$filepath"
}

add_installation_files() {
local ABSOLUTE_INSTALL_DIRECTORY="$1"
local PROGRAM_NAME="$2"
local ARCHITECTURE="$3"
local PROGRAM_FILEPATH="${ABSOLUTE_INSTALL_DIRECTORY}/${PROGRAM_NAME,,}"

# Place the files in the directory based on the architecture
#curl -sS https://raw.githubusercontent.com/0xacx/chatGPT-shell-cli/main/chatgpt.sh -o "$PROGRAM_FILEPATH"
cp ../chatgpt.sh "$PROGRAM_FILEPATH"

# Configure open image command with xdg-open for Linux systems (copied from install.sh)
if [[ "$OSTYPE" == "linux"* ]] || [[ "$OSTYPE" == "freebsd"* ]]; then
sed -i 's/open "${image_url}"/xdg-open "${image_url}"/g' "$PROGRAM_FILEPATH"
fi
}

set_attributes() {
local STARTING_DIRECTORY="$1"
local IN_DEB_PROGRAM_NAME="$2"

find "${STARTING_DIRECTORY}" -type d -exec chmod 0755 {} \; # set all dirs
find "${STARTING_DIRECTORY}" -type f -exec chmod 0644 {} \; # set all files
find "${STARTING_DIRECTORY}" -name "${IN_DEB_PROGRAM_NAME}" -type f -exec chmod 0755 {} \; # set executable
find "${STARTING_DIRECTORY}" -name "postinst" -type f -exec chmod 0755 {} \; # set postinst
}

add_control_file () {
local CONTROL_FILE="$1"

SECTION="utils"
DEPENDS="curl (>= 7.68), jq (>= 1.6)" # HELPFUL: Use `$ dpkg-query -W -f='${VERSION}\n' depNameHere` to find version info
MAINTAINER="Alwyn \"KeyboardSage\" Berkeley <[email protected]>"
HOMEPAGE="https://gptshell.cc"
DESCRIPTION="A simple, lightweight shell script to use OpenAI's chatGPT and
DALL-E from the terminal without installing python or node.js."
cat << EOF > "$CONTROL_FILE"
Package: $PACKAGE_NAME
Version: $PROGRAM_VERSION
Architecture: $ARCHITECTURES
Section: $SECTION
Essential: no
Priority: optional
Depends: $DEPENDS
Maintainer: $MAINTAINER
Homepage: $HOMEPAGE
Description: $DESCRIPTION
EOF
}

add_postinst_file () {
local POSTINST="$1"
ALIAS_NAME="chatgpt.sh"

cat << EOF > "$POSTINST"
#!/bin/env bash
# only continue if the file exists
if [ -f "/usr/bin/${PACKAGE_NAME}" ]; then
echo "File /usr/bin/${PACKAGE_NAME} exists."
# Make Alias (no sudo, already running as root)
ln -s /usr/bin/${PACKAGE_NAME} /usr/bin/${ALIAS_NAME}
# Show user message
echo "Installed $PACKAGE_NAME script to /usr/bin/${PACKAGE_NAME}"
echo "The OPENAI_KEY environment variable containing your key is necessary for the script to function."
echo -e "Add the line below to your shell profile with a valid key:\n"
echo "export OPENAI_KEY=\"your_key_here\""
echo -e "\nIf needed, detailed instructions are available:\nhttps://github.com/0xacx/chatGPT-shell-cli/tree/main#manual-installation"
fi
exit 0
EOF
}

# Main
cd `dirname $0` # Run from the directory that stores the script

# Remove the old .debs if there are any
PROGRAM_NAME="chatGPT-shell-cli"
PACKAGE_NAME="${PROGRAM_NAME,,}"
rm -f "${PACKAGE_NAME}*.deb" >/dev/null
sudo rm -f "/tmp/${PACKAGE_NAME}.deb" >/dev/null

# Stage directory
RELATIVE_STAGING_DIR="./debpkgs"
ABSOLUTE_STAGING_DIR=$(readlink --canonicalize "${RELATIVE_STAGING_DIR}")
make_directory "$ABSOLUTE_STAGING_DIR" 1 # remake staging directory

# Architectures
ABSOLUTE_ARCH_DIRECTORIES=()

PROGRAM_VERSION="0.0.1" # No versioning at the moment, 0.0.1 is a placeholder
ARCHITECTURES="all"
for arch in `echo $ARCHITECTURES`; do
architectureDirectory="${ABSOLUTE_STAGING_DIR}/${PACKAGE_NAME}_${PROGRAM_VERSION}_${arch}"
make_directory "$architectureDirectory" 0
ABSOLUTE_ARCH_DIRECTORIES+=("$architectureDirectory")
done

# Installation Directories and Installation Files
INSTALL_DIRECTORIES=("/usr/bin")
for (( i=0; i<${#ABSOLUTE_ARCH_DIRECTORIES[@]}; i++ )); do # For each arch directory...
for dir in "${INSTALL_DIRECTORIES[@]}"; do
# Create the install directories needed...
installDirectory="${ABSOLUTE_ARCH_DIRECTORIES[i]}${dir}"
make_directory "$installDirectory" 0
# DEBUG: echo "Architecture directory $((i+1)): ${ABSOLUTE_ARCH_DIRECTORIES[i]} processed and now has $installDirectory"

# Create the installation file(s) needed based on the install directory
add_installation_files "$installDirectory" "$PROGRAM_NAME" "${ABSOLUTE_ARCH_DIRECTORIES[i]##*_}"
done
done

# For each architecture directory make the...
for (( i=0; i<${#ABSOLUTE_ARCH_DIRECTORIES[@]}; i++ )); do
# ...DEBIAN directory
ABSOLUTE_DEBIAN_DIR="${ABSOLUTE_ARCH_DIRECTORIES[i]}/DEBIAN"
make_directory "${ABSOLUTE_DEBIAN_DIR}" 0

# ...Post installation file
add_postinst_file "${ABSOLUTE_DEBIAN_DIR}/postinst"

# ...Control file
add_control_file "${ABSOLUTE_DEBIAN_DIR}/control"

# ...then measure the staged size of the package and add that to the control file
STAGING_SIZE_IN_KB="$(du -s ${ABSOLUTE_ARCH_DIRECTORIES[i]} | awk '{print $1;}')"
echo "Installed-Size: ${STAGING_SIZE_IN_KB}" >> "${ABSOLUTE_DEBIAN_DIR}/control"
done

# Ensure proper file attributes on all files for all architectures
set_attributes "${ABSOLUTE_STAGING_DIR}" "${PROGRAM_NAME,,}"

# Build
for (( i=0; i<${#ABSOLUTE_ARCH_DIRECTORIES[@]}; i++ )); do
PROGRAM_ARCH="${ABSOLUTE_ARCH_DIRECTORIES[i]##*_}"
DEB_FILENAME="${PACKAGE_NAME}_${PROGRAM_VERSION}_${PROGRAM_ARCH}.deb"
dpkg-deb --root-owner-group --build "${ABSOLUTE_ARCH_DIRECTORIES[i]}" "$DEB_FILENAME"
chmod 644 "$DEB_FILENAME"
sudo cp "$DEB_FILENAME" /tmp # Copied to /tmp for testing since apt is not allowed to access /home/*
done

0 comments on commit a69c998

Please sign in to comment.