Skip to content

Commit

Permalink
implemented improvements to the prompt output and set GPT-4 as the de…
Browse files Browse the repository at this point in the history
…fault model.
  • Loading branch information
nicolodiamante committed Jul 9, 2023
1 parent 5166456 commit c111ef9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</picture>
</p>

Maximise your productivity and streamline your terminal experience with Zchat (zch) - a command-line productivity tool powered by OpenAI's [ChatGPT][chatgpt] models. Quickly generate Linux commands and code snippets from natural language queries without the need to manually search the web. Leverage AI capabilities to get accurate answers directly in your terminal in a time and effort-efficient manner. Furthermore, Zchat's Git integration makes working with version control even simpler - goodbye cheat sheets and notes. Get the job done quickly and easily.
Boost your productivity and enhance your terminal experience using Zchat (zch). This command-line productivity tool is powered by OpenAI's ChatGPT models. With Zchat, you don't need to scour the web for Linux commands and code snippets. Simply type in comprehensive language queries and let the system generate the results for you. Zchat's AI capabilities provide precise responses directly in your terminal, saving your time and effort. Additionally, Zchat's intuitive Git integration simplifies your version control processes – bidding farewell to cheat sheets and notes. With Zchat, complete tasks quickly and conveniently.

<br>

Expand All @@ -19,7 +19,12 @@ Maximise your productivity and streamline your terminal experience with Zchat (z

## Create your OpenAI API Key

To use Zchat, you'll first need to obtain the API key. This can be done by generating a new secret key from your OpenAI account, which will be required for authentication. To get started, you can obtain the key by following these steps. First, log in to your [OpenAI account][open-ai-account]. Next, look for the "Create new secret key" option and click on it.
To utilise Zchat, you initially need to procure the API key. You can generate this key from your OpenAI account, which will subsequently be used for authentication. Here's how to get your API key:

1. Sign in to your [OpenAI account][open-ai-account].
2. Search for the "Create new secret key" option and select it.

This API key serves as your passport to access and engage with Zchat.

<p align="center">
<picture>
Expand Down Expand Up @@ -81,15 +86,15 @@ git clone https://github.com/nicolodiamante/zchat.git $ZSH_CUSTOM/plugins/zchat

### Setting up dependencies

Once the installation is complete, open your zshrc file. Paste your OpenAI API Key to the `OPENAI_API_KEY` variable. By default, the script uses the GPT-3.5-turbo model. For most basic tasks, there is not much difference between GPT-4 and GPT-3.5 models. To use the latest GPT-4 model, just change the current model to `gpt-4`.
After completing the installation process, please open your zshrc file. Copy and paste your OpenAI API Key into the `OPENAI_API_KEY` variable slot. The script is programmed to use the GPT-4 model by default. However, it should be noted that access to GPT-4 API is limited only to APIs with proven successful payment history. If you have not met the qualifications for accessing GPT-4, we recommend opting for the GPT-3.5-Turbo model instead.

```shell
# Zchat dependencies.
export OPENAI_API_KEY=""
export OPENAI_GPT_MODEL="gpt-3.5-turbo"
export OPENAI_GPT_MODEL="gpt-4"
```

> If you are not enrolled in the limited beta program for GPT-4, you will need to join a waiting list to use its API. Since developers have been given priority, it is unclear when non-developers will be granted access. Until that time, users should select the GPT-3.5-Turbo model as an alternative.
> For Zchat to function properly, jq must be installed on your operating system. The script will automatically check for this software. If it isn't detected, the script will proceed with the necessary installation.
<br>

Expand All @@ -101,23 +106,23 @@ zch <description of task>

### Completion

- Type `zch` to initiate the completion follow by the command that will be used as a basis for your query.
- Once you have written a natural language version of what you intend to do, press "enter" to execute it.
1. To initiate the completion, simply type 'zch' followed by the command that you want to use for your query.
2. After formulating your query in natural language, press the 'Enter' key to execute it.

<br><br>

<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/nicolodiamante/zchat/assets/48920263/ff9078f7-22a3-4dcd-b76a-a2df31b20f9b" draggable="false" ondragstart="return false;" alt="Zchat Completion" title="Zchat Completion" />
<img src="https://github.com/nicolodiamante/zchat/assets/48920263/8e9effe9-a1dc-4237-a04e-9850a370716f" draggable="false" ondragstart="return false; "alt="Zchat Completion" title="Zchat Completion" width="560px" />
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/nicolodiamante/zchat/assets/48920263/ee1f5e25-1480-4bb8-9986-853d8964ea02" draggable="false" ondragstart="return false;" alt="Zchat Completion" title="Zchat Completion" />
<img src="https://github.com/nicolodiamante/zchat/assets/48920263/fd62ca6a-7c51-42a4-a82d-4bc05f3ea3d9" draggable="false" ondragstart="return false; "alt="Zchat Completion" title="Zchat Completion" width="650px" />
</picture>
</p>

<br><br>

## Notes

When you launch Zchat, it will automatically check if you are in a Git repository. If you are, it will provide relevant Git commands and guidance. If not, Zchat will help you access the right command line tools and find the best solution to complete your task.
Upon launching Zchat, the script automatically checks whether you're in a Git repository. If it determines that you are, Zchat will present relevant Git commands and provide guidance. If you're not in a Git repository, Zchat assists you in accessing the appropriate command line tools to find the most effective solution for your task.

### Resources

Expand Down Expand Up @@ -159,7 +164,6 @@ Thank you for considering using Zchat. Any suggestions or feedback you may have
<!-- Link labels: -->
[open-ai-account]: https://chat.openai.com/auth/login
[open-ai-API]: https://beta.openai.com/account/api-keys
[chatgpt]: https://openai.com/blog/chatgpt
[open-ai-models]: https://platform.openai.com/docs/models
[intro]: https://platform.openai.com/docs/introduction
[chat-completions]: https://platform.openai.com/docs/guides/chat
Expand Down
31 changes: 14 additions & 17 deletions script/zch
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ zch() {
fi

if [[ -z "$OPENAI_GPT_MODEL" ]]; then
echo "zchat: the OPENAI_GPT_MODEL appears not to be set. By default this script is set to used GPT-3.5-turbo model. For many basic tasks, the difference between GPT-4 and GPT-3.5 models is not significant. However, in more complex reasoning situations, GPT-4 is much more capable than any of previous models. If you want to use the latest model version GPT-4 you just need to change the current number to 4. Keep in mind GPT-4 is currently in a limited beta and not everyone, even if they are on a paid plan, has access to GPT-4 API."
echo "zchat: It seems the OPENAI_GPT_MODEL is not specified. By default, this script operates on the GPT-4 model. Comparatively, the GPT-4 and GPT-3.5 models display minimal differences in performance for less complex tasks. However, GPT-4 significantly outshines previous models in handling intricate reasoning scenarios. It's important to note that only APIs with a record of successful payments can access the GPT-4 API. If the GPT-4 qualifications are not met, it's advisable to use the GPT-3.5-Turbo model."
return 1
else
chatGPT_model="$OPENAI_GPT_MODEL"
Expand All @@ -50,17 +50,17 @@ zch() {
# Request body.
user_input="$@"
model="$chatGPT_model"
temperature=0.5
top_p=0.0
temperature=0.16
top_p=1
presence_penalty=0.0
frequency_penalty=0.0
max_tokens=257
max_tokens=1024

# Check if current directory is a Git repository.
# Prompt.
if [[ -d .git ]]; then
message="You are Zchat, my autocomplete script, and your goal is to help me navigate my Linux system, starting from the current directory, which is a git repository. What GIT command should I copy and paste into the terminal in order to achieve the desired result of ${user_input}? Provide only a valid GIT command${OS}, and nothing else. You do not write any human-readable explanations. If you fail to answer, return 'zchat: failed to generate command'."
message="As Zchat, your role is to act as an autocomplete program that assists me in managing my Linux operating system. Your base of operations begins from the currently active directory, which also doubles as a git repository for version control purposes. Upon receiving my inquiry captured in the variable ${user_input}, you have the task of identifying and recommending a suitable GIT command that I can input into the Linux terminal for execution. Keep in mind, the command issued should strictly be valid GIT software commands and pertinent to the ${OS} operating system. Ensure to exclude any additional information from the response and focus solely on delivering the mapped GIT commands. Your responses should, at all times, lack any explanation or clarifications that a human would find elucidative. In the event you are unable to deduce or produce a GIT command based on my input, it's required for you to give the following response: 'zchat: failed to generate command'. This will indicate that the formulation of a suitable command was unsuccessful."
else
message="You are Zchat, my autocomplete script, and your task is to assist me in navigating my Linux. All the questions I'm asking will be related to this subject. Now, I'd like you to answer this: ${user_input}. Please provide a valid command${OS} as a single line of text (no code blocks, quotes, or anything else outside the command itself) that takes into consideration my current directory (using either '.' or $(pwd)) and doesn't put my system at risk in any way. It's acceptable to chain commands, but prioritize one-liners if possible. If you can't find a suitable command, answer with 'zchat: failed to generate command'."
message="You are to act as Zchat, an autocomplete script that I utilise as an aid in manoeuvring my Linux operating system. Your function largely revolves around fielding all queries that I have pertaining to the Linux operating system. In light of this, I now require your assistance - outlined as ${user_input} - and am requesting a response. The expected response from you should be a valid ${OS} command, to be presented as an uncomplicated, solitary line of text. Please abstain from the use of code blocks or quotes; keep everything within the scope of the command you provide. The command you propose should accommodate the consideration of my existing directory, which can be signified by either a simple '.' or the command `$(pwd)`. Make sure that the command you offer does not pose any risk to the integrity or stability of my operating system. It's agreeable to chain multiple commands together if necessary, but with a preferable emphasis placed on simplicity - aim to propose one-liner commands where possible. In the eventuality that you are unable to generate a suitable command based on my request, the appropriate response should be: 'zchat: failed to generate command'."
fi

if command -v curl &> /dev/null; then
Expand Down Expand Up @@ -93,8 +93,8 @@ zch() {

# Add some colour.
autoload -Uz colors && colors
promp_default='%F{green}%f'
promp_error='%F{red}%f'
promp_default='%F{green}%f'
promp_error='%F{red}%f'

ERROR_MESSAGE=$(printf "%s" "$response" | jq -r '(.error.message // "") | @json' | sed 's/^"//;s/"$//')
COMMAND=$(printf "%s" "$response" | jq -r '(.choices[0].message.content // "") | @json' | sed 's/^"//;s/"$//')
Expand All @@ -104,15 +104,10 @@ zch() {
echo "Error: $ERROR_MESSAGE"
elif [[ -n "$COMMAND" && -d .git ]]; then
if [[ "$COMMAND" =~ ^git ]]; then
print -P ""
print -P "$promp_default $COMMAND"
read -q "REPLY? Execute command? (y/n) "
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
echo
eval "$COMMAND"
else
echo
print -P "$promp_error command not executed."
fi
print -P ""
eval "$COMMAND"
else
print -P "$promp_error output does not begin with git and it will not be executed."
print -P "$COMMAND"
Expand All @@ -121,7 +116,9 @@ zch() {
print -P "$promp_error unable to generate a command."
print -P "$COMMAND"
elif [[ -n "$COMMAND" ]]; then
print -P ""
print -P "$promp_default $COMMAND"
print -P ""
eval "$COMMAND"
else
print -P "$promp_error unexpected response."
Expand Down
3 changes: 2 additions & 1 deletion utils/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ fpath=(~/zchat/script \$fpath)
autoload -Uz zchat
# Zchat dependencies.
# It's important to note that only APIs with a record of successful payments can access the GPT-4 API. If the GPT-4 qualifications are not met, it's advisable to use the GPT-3.5-Turbo model.
export OPENAI_API_KEY=""
export OPENAI_GPT_MODEL="gpt-3.5-turbo"
export OPENAI_GPT_MODEL="gpt-4"
EOF
echo 'zsh: appended zchat to zshrc.'

Expand Down

0 comments on commit c111ef9

Please sign in to comment.