Skip to content

Commit a69c998

Browse files
committed
Merge branch 'main' into escape-system-prompt-from-file
2 parents 4395626 + e6c213f commit a69c998

File tree

4 files changed

+173
-7
lines changed

4 files changed

+173
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ This script relies on curl for the requests to the api and jq to parse the json
163163
## Contributors
164164
:pray: Thanks to all the people who used, tested, submitted issues, PRs and proposed changes:
165165

166-
[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)
166+
[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)
167167

168168
## Contributing
169169
Contributions are very welcome!

chatgpt.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
GLOBIGNORE="*"
44

5-
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)"
5+
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)"
66

7-
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."
7+
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."
88

99
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:"
1010

@@ -403,7 +403,7 @@ while $running; do
403403
fi
404404
add_assistant_response_to_chat_message "$(escape "$response_data")"
405405

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

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

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

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

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fi
4040
curl -sS https://raw.githubusercontent.com/0xacx/chatGPT-shell-cli/main/chatgpt.sh -o /usr/local/bin/chatgpt
4141

4242
# Replace open image command with xdg-open for linux systems
43-
if [[ "$OSTYPE" == "linux-gnu"* ]] || [[ "$OSTYPE" == "freebsd"* ]]; then
43+
if [[ "$OSTYPE" == "linux"* ]] || [[ "$OSTYPE" == "freebsd"* ]]; then
4444
sed -i 's/open "\${image_url}"/xdg-open "\${image_url}"/g' '/usr/local/bin/chatgpt'
4545
fi
4646
chmod +x /usr/local/bin/chatgpt

internal_dev/debmaker.sh

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#!/bin/env bash
2+
###############################################################################
3+
# Purpose: The purpose of this script is to simply generate a .deb file.
4+
# Once the .deb file is generated a copy is moved to /tmp.
5+
#
6+
# It can be installed and uninstalled like so:
7+
# $ sudo apt -y install ./chatgpt-shell-cli_0.0.1_all.deb
8+
# $ sudo apt -y remove chatgpt-shell-cli
9+
###############################################################################
10+
11+
# Functions
12+
make_directory() {
13+
local filepath="$1"
14+
local shouldRemake=$2
15+
16+
if [ $shouldRemake -ne 0 ]; then # delete old directory first if desired
17+
rm -rf "$filepath"
18+
fi
19+
20+
mkdir -p "$filepath"
21+
}
22+
23+
add_installation_files() {
24+
local ABSOLUTE_INSTALL_DIRECTORY="$1"
25+
local PROGRAM_NAME="$2"
26+
local ARCHITECTURE="$3"
27+
local PROGRAM_FILEPATH="${ABSOLUTE_INSTALL_DIRECTORY}/${PROGRAM_NAME,,}"
28+
29+
# Place the files in the directory based on the architecture
30+
#curl -sS https://raw.githubusercontent.com/0xacx/chatGPT-shell-cli/main/chatgpt.sh -o "$PROGRAM_FILEPATH"
31+
cp ../chatgpt.sh "$PROGRAM_FILEPATH"
32+
33+
# Configure open image command with xdg-open for Linux systems (copied from install.sh)
34+
if [[ "$OSTYPE" == "linux"* ]] || [[ "$OSTYPE" == "freebsd"* ]]; then
35+
sed -i 's/open "${image_url}"/xdg-open "${image_url}"/g' "$PROGRAM_FILEPATH"
36+
fi
37+
}
38+
39+
set_attributes() {
40+
local STARTING_DIRECTORY="$1"
41+
local IN_DEB_PROGRAM_NAME="$2"
42+
43+
find "${STARTING_DIRECTORY}" -type d -exec chmod 0755 {} \; # set all dirs
44+
find "${STARTING_DIRECTORY}" -type f -exec chmod 0644 {} \; # set all files
45+
find "${STARTING_DIRECTORY}" -name "${IN_DEB_PROGRAM_NAME}" -type f -exec chmod 0755 {} \; # set executable
46+
find "${STARTING_DIRECTORY}" -name "postinst" -type f -exec chmod 0755 {} \; # set postinst
47+
}
48+
49+
add_control_file () {
50+
local CONTROL_FILE="$1"
51+
52+
SECTION="utils"
53+
DEPENDS="curl (>= 7.68), jq (>= 1.6)" # HELPFUL: Use `$ dpkg-query -W -f='${VERSION}\n' depNameHere` to find version info
54+
MAINTAINER="Alwyn \"KeyboardSage\" Berkeley <sagedev@leaflesstree.com>"
55+
HOMEPAGE="https://gptshell.cc"
56+
DESCRIPTION="A simple, lightweight shell script to use OpenAI's chatGPT and
57+
DALL-E from the terminal without installing python or node.js."
58+
cat << EOF > "$CONTROL_FILE"
59+
Package: $PACKAGE_NAME
60+
Version: $PROGRAM_VERSION
61+
Architecture: $ARCHITECTURES
62+
Section: $SECTION
63+
Essential: no
64+
Priority: optional
65+
Depends: $DEPENDS
66+
Maintainer: $MAINTAINER
67+
Homepage: $HOMEPAGE
68+
Description: $DESCRIPTION
69+
EOF
70+
}
71+
72+
add_postinst_file () {
73+
local POSTINST="$1"
74+
ALIAS_NAME="chatgpt.sh"
75+
76+
cat << EOF > "$POSTINST"
77+
#!/bin/env bash
78+
79+
# only continue if the file exists
80+
if [ -f "/usr/bin/${PACKAGE_NAME}" ]; then
81+
82+
echo "File /usr/bin/${PACKAGE_NAME} exists."
83+
84+
# Make Alias (no sudo, already running as root)
85+
ln -s /usr/bin/${PACKAGE_NAME} /usr/bin/${ALIAS_NAME}
86+
87+
# Show user message
88+
echo "Installed $PACKAGE_NAME script to /usr/bin/${PACKAGE_NAME}"
89+
echo "The OPENAI_KEY environment variable containing your key is necessary for the script to function."
90+
echo -e "Add the line below to your shell profile with a valid key:\n"
91+
echo "export OPENAI_KEY=\"your_key_here\""
92+
echo -e "\nIf needed, detailed instructions are available:\nhttps://github.com/0xacx/chatGPT-shell-cli/tree/main#manual-installation"
93+
94+
fi
95+
96+
exit 0
97+
EOF
98+
}
99+
100+
# Main
101+
cd `dirname $0` # Run from the directory that stores the script
102+
103+
# Remove the old .debs if there are any
104+
PROGRAM_NAME="chatGPT-shell-cli"
105+
PACKAGE_NAME="${PROGRAM_NAME,,}"
106+
rm -f "${PACKAGE_NAME}*.deb" >/dev/null
107+
sudo rm -f "/tmp/${PACKAGE_NAME}.deb" >/dev/null
108+
109+
# Stage directory
110+
RELATIVE_STAGING_DIR="./debpkgs"
111+
ABSOLUTE_STAGING_DIR=$(readlink --canonicalize "${RELATIVE_STAGING_DIR}")
112+
make_directory "$ABSOLUTE_STAGING_DIR" 1 # remake staging directory
113+
114+
# Architectures
115+
ABSOLUTE_ARCH_DIRECTORIES=()
116+
117+
PROGRAM_VERSION="0.0.1" # No versioning at the moment, 0.0.1 is a placeholder
118+
ARCHITECTURES="all"
119+
for arch in `echo $ARCHITECTURES`; do
120+
architectureDirectory="${ABSOLUTE_STAGING_DIR}/${PACKAGE_NAME}_${PROGRAM_VERSION}_${arch}"
121+
make_directory "$architectureDirectory" 0
122+
ABSOLUTE_ARCH_DIRECTORIES+=("$architectureDirectory")
123+
done
124+
125+
# Installation Directories and Installation Files
126+
INSTALL_DIRECTORIES=("/usr/bin")
127+
for (( i=0; i<${#ABSOLUTE_ARCH_DIRECTORIES[@]}; i++ )); do # For each arch directory...
128+
for dir in "${INSTALL_DIRECTORIES[@]}"; do
129+
# Create the install directories needed...
130+
installDirectory="${ABSOLUTE_ARCH_DIRECTORIES[i]}${dir}"
131+
make_directory "$installDirectory" 0
132+
# DEBUG: echo "Architecture directory $((i+1)): ${ABSOLUTE_ARCH_DIRECTORIES[i]} processed and now has $installDirectory"
133+
134+
# Create the installation file(s) needed based on the install directory
135+
add_installation_files "$installDirectory" "$PROGRAM_NAME" "${ABSOLUTE_ARCH_DIRECTORIES[i]##*_}"
136+
done
137+
done
138+
139+
# For each architecture directory make the...
140+
for (( i=0; i<${#ABSOLUTE_ARCH_DIRECTORIES[@]}; i++ )); do
141+
# ...DEBIAN directory
142+
ABSOLUTE_DEBIAN_DIR="${ABSOLUTE_ARCH_DIRECTORIES[i]}/DEBIAN"
143+
make_directory "${ABSOLUTE_DEBIAN_DIR}" 0
144+
145+
# ...Post installation file
146+
add_postinst_file "${ABSOLUTE_DEBIAN_DIR}/postinst"
147+
148+
# ...Control file
149+
add_control_file "${ABSOLUTE_DEBIAN_DIR}/control"
150+
151+
# ...then measure the staged size of the package and add that to the control file
152+
STAGING_SIZE_IN_KB="$(du -s ${ABSOLUTE_ARCH_DIRECTORIES[i]} | awk '{print $1;}')"
153+
echo "Installed-Size: ${STAGING_SIZE_IN_KB}" >> "${ABSOLUTE_DEBIAN_DIR}/control"
154+
done
155+
156+
# Ensure proper file attributes on all files for all architectures
157+
set_attributes "${ABSOLUTE_STAGING_DIR}" "${PROGRAM_NAME,,}"
158+
159+
# Build
160+
for (( i=0; i<${#ABSOLUTE_ARCH_DIRECTORIES[@]}; i++ )); do
161+
PROGRAM_ARCH="${ABSOLUTE_ARCH_DIRECTORIES[i]##*_}"
162+
DEB_FILENAME="${PACKAGE_NAME}_${PROGRAM_VERSION}_${PROGRAM_ARCH}.deb"
163+
dpkg-deb --root-owner-group --build "${ABSOLUTE_ARCH_DIRECTORIES[i]}" "$DEB_FILENAME"
164+
chmod 644 "$DEB_FILENAME"
165+
sudo cp "$DEB_FILENAME" /tmp # Copied to /tmp for testing since apt is not allowed to access /home/*
166+
done

0 commit comments

Comments
 (0)