From c0affa225287db4999f0dae3c7e7110095ea5cd3 Mon Sep 17 00:00:00 2001
From: Wassim Chegham <1699357+manekinekko@users.noreply.github.com>
Date: Mon, 27 Sep 2021 15:29:23 +0200
Subject: [PATCH 01/41] docs: add troubleshooting section
---
README.md | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/README.md b/README.md
index 77c6eba..8622beb 100644
--- a/README.md
+++ b/README.md
@@ -70,3 +70,23 @@ secret_key = ...
```
4. Run `zsh`, start typing and complete it using `^X`!
+
+## Troubleshooting & temporary fixes
+
+### unhandled ZLE widget 'create_completion'
+
+```
+zsh-syntax-highlighting: unhandled ZLE widget 'create_completion'
+zsh-syntax-highlighting: (This is sometimes caused by doing `bindkey create_completion` without creating the 'create_completion' widget with `zle -N` or `zle -C`.)
+```
+
+Make sure to disable other ZSH plugins!
+
+### no such file or directory: .oh-my-zsh/custom/plugins/zsh_codex/create_completion.py
+
+Move the `.oh-my-zsh/custom/plugins/zsh_codex` folder to `.oh-my-zsh/custom/custom/plugins/zsh_codex/`.
+
+### ModuleNotFoundError: No module named 'openai'
+
+Install the OpenAI python package: `pip install openai`
+
From 2116eb1fc174dfb17e19f3b86672c422e99866df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Mon, 27 Sep 2021 16:07:21 +0200
Subject: [PATCH 02/41] Fix installation instructions
---
README.md | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 77c6eba..5344273 100644
--- a/README.md
+++ b/README.md
@@ -48,20 +48,25 @@ To use this plugin you need to get access to OpenAI's [Codex API](https://openai
## How do I install it?
-1. Download the ZSH plugin.
+1. Install the OpenAI package.
+```
+pip3 install openai
+```
+
+2. Download the ZSH plugin.
```
- $ git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/plugins/
+ $ git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins/
```
-2. Add the following to your `.zshrc` file.
+3. Add the following to your `.zshrc` file.
```
plugins=(zsh_codex)
bindkey '^X' create_completion
```
-3. Create a file called `openaiapirc` in `~/.config` with your ORGANIZATION_ID and SECRET_KEY.
+4. Create a file called `openaiapirc` in `~/.config` with your ORGANIZATION_ID and SECRET_KEY.
```
[openai]
@@ -69,4 +74,4 @@ organization_id = ...
secret_key = ...
```
-4. Run `zsh`, start typing and complete it using `^X`!
+5. Run `zsh`, start typing and complete it using `^X`!
From 92014587a6757efa3c5d8a3dd52ae5f984eefa97 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Mon, 27 Sep 2021 16:12:59 +0200
Subject: [PATCH 03/41] Remove items
---
README.md | 7 -------
1 file changed, 7 deletions(-)
diff --git a/README.md b/README.md
index d3fcf77..bf3817a 100644
--- a/README.md
+++ b/README.md
@@ -88,10 +88,3 @@ zsh-syntax-highlighting: (This is sometimes caused by doing `bindkey crea
Make sure to disable other ZSH plugins!
-### no such file or directory: .oh-my-zsh/custom/plugins/zsh_codex/create_completion.py
-
-Move the `.oh-my-zsh/custom/plugins/zsh_codex` folder to `.oh-my-zsh/custom/custom/plugins/zsh_codex/`.
-
-### ModuleNotFoundError: No module named 'openai'
-
-Install the OpenAI python package: `pip install openai`
From 80a91f2e23f5a0cecf015dfab786d69c779b964e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Mon, 27 Sep 2021 16:16:06 +0200
Subject: [PATCH 04/41] Update instructions
---
README.md | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index bf3817a..cb82cb9 100644
--- a/README.md
+++ b/README.md
@@ -86,5 +86,9 @@ zsh-syntax-highlighting: unhandled ZLE widget 'create_completion'
zsh-syntax-highlighting: (This is sometimes caused by doing `bindkey create_completion` without creating the 'create_completion' widget with `zle -N` or `zle -C`.)
```
-Make sure to disable other ZSH plugins!
+Add the line
+```
+zle -N create_completion
+```
+before you call `bindkey` but after loading the plugin (`plugins=(zsh_codex)`).
From 544a24004d2dd7379b516e3ae157790f10743576 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Mon, 27 Sep 2021 16:16:27 +0200
Subject: [PATCH 05/41] Change heading
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index cb82cb9..c70faa0 100644
--- a/README.md
+++ b/README.md
@@ -77,7 +77,7 @@ secret_key = ...
5. Run `zsh`, start typing and complete it using `^X`!
-## Troubleshooting & temporary fixes
+## Troubleshooting
### unhandled ZLE widget 'create_completion'
From 456d3755fe6ebb4279bf8fd64e82d94aca9ba7fc Mon Sep 17 00:00:00 2001
From: John Garcia <40524549+johnkegd@users.noreply.github.com>
Date: Tue, 28 Sep 2021 00:46:21 +0200
Subject: [PATCH 06/41] Troubleshooting fatal destination path doc
---
README.md | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/README.md b/README.md
index c70faa0..c6fa213 100644
--- a/README.md
+++ b/README.md
@@ -92,3 +92,11 @@ zle -N create_completion
```
before you call `bindkey` but after loading the plugin (`plugins=(zsh_codex)`).
+### already exists and is not an empty directory
+```
+fatal: destination path '~.oh-my-zsh/custom/plugins'
+```
+Try to download the ZSH plugin again.
+```
+git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins/zsh_codex
+```
From 25754a2ac87da80fc98592efbaba7c777cc01407 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Tue, 28 Sep 2021 01:30:30 +0200
Subject: [PATCH 07/41] Capitalize words
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index c6fa213..9437ee1 100644
--- a/README.md
+++ b/README.md
@@ -79,7 +79,7 @@ secret_key = ...
## Troubleshooting
-### unhandled ZLE widget 'create_completion'
+### Unhandled ZLE widget 'create_completion'
```
zsh-syntax-highlighting: unhandled ZLE widget 'create_completion'
@@ -92,7 +92,7 @@ zle -N create_completion
```
before you call `bindkey` but after loading the plugin (`plugins=(zsh_codex)`).
-### already exists and is not an empty directory
+### Already exists and is not an empty directory
```
fatal: destination path '~.oh-my-zsh/custom/plugins'
```
From 8051b78745203bd13bc0deb9605a2d89e356daba Mon Sep 17 00:00:00 2001
From: clotodex
Date: Mon, 11 Oct 2021 10:36:35 +0200
Subject: [PATCH 08/41] Install instructions for use without oh-my-zsh
---
README.md | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 9437ee1..88b679b 100644
--- a/README.md
+++ b/README.md
@@ -60,11 +60,18 @@ pip3 install openai
```
3. Add the following to your `.zshrc` file.
-
+Using oh-my-zsh
```
plugins=(zsh_codex)
bindkey '^X' create_completion
```
+Without oh-my-zsh
+```
+ # in your/custom/path you need to have a "plugins" folder and in there you clone the repository as zsh_codex
+ export ZSH_CUSTOM="your/custom/path"
+ source "$ZSH_CUSTOM/plugins/zsh_codex/zsh_codex.plugin.zsh"
+ bindkey '^X' create_completion
+```
4. Create a file called `openaiapirc` in `~/.config` with your ORGANIZATION_ID and SECRET_KEY.
From 8bd5c4af5b6299ba047803465249c1c8f1747c2c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Mon, 11 Oct 2021 11:32:04 +0200
Subject: [PATCH 09/41] Update file
---
README.md | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 88b679b..b521f08 100644
--- a/README.md
+++ b/README.md
@@ -60,12 +60,13 @@ pip3 install openai
```
3. Add the following to your `.zshrc` file.
-Using oh-my-zsh
+
+Using oh-my-zsh:
```
plugins=(zsh_codex)
bindkey '^X' create_completion
```
-Without oh-my-zsh
+Without oh-my-zsh:
```
# in your/custom/path you need to have a "plugins" folder and in there you clone the repository as zsh_codex
export ZSH_CUSTOM="your/custom/path"
From 2539595fcf2f937f08b173f4b95993a655393a7b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Sun, 7 Nov 2021 02:21:43 +0100
Subject: [PATCH 10/41] Switch to configparser
---
create_completion.py | 34 ++++++++++++++--------------------
1 file changed, 14 insertions(+), 20 deletions(-)
diff --git a/create_completion.py b/create_completion.py
index 246d29a..67770c5 100755
--- a/create_completion.py
+++ b/create_completion.py
@@ -3,6 +3,7 @@
import openai
import sys
import os
+import configparser
STREAM = False
@@ -19,8 +20,6 @@
# If you don't see your organization ID in the file you can get it from the
# OpenAI web site: https://openai.com/organizations
-
-
def create_template_ini_file():
"""
If the ini file does not exist create it and add the organization_id and
@@ -34,31 +33,26 @@ def create_template_ini_file():
print('OpenAI API config file created at {}'.format(API_KEYS_LOCATION))
print('Please edit it and add your organization ID and secret key')
+ print('If you do not yet have an organization ID and secret key, you\n'
+ 'need to register for OpenAI Codex: \n'
+ 'https://openai.com/blog/openai-codex/')
sys.exit(1)
-try:
- with open(API_KEYS_LOCATION) as f:
- config = f.read()
-
- config = '\n' + config
- # Reading the values works even when there are spaces around the = sign.
- organization_id = config.split('organization_id')[1].split('=')[1].split('\n')[0].strip()
- secret_key = config.split('secret_key')[1].split('=')[1].split('\n')[0].strip()
-except:
- print("Unable to read openaiapirc at {}".format(API_KEYS_LOCATION))
+def initialize_openai_api():
+ """
+ Initialize the OpenAI API
+ """
+ # Check if file at API_KEYS_LOCATION exists
create_template_ini_file()
+ config = configparser.ConfigParser()
+ config.read(API_KEYS_LOCATION)
+ openai.organization_id = config['openai']['organization_id'].strip('"').strip("'")
+ openai.api_key = config['openai']['secret_key'].strip('"').strip("'")
-# Remove the quotes if there are any.
-if organization_id[0] == '"' and organization_id[-1] == '"':
- organization_id = organization_id[1:-1]
-
-if secret_key[0] == '"' and secret_key[-1] == '"':
- secret_key = secret_key[1:-1]
-openai.api_key = secret_key
-openai.organization = organization_id
+initialize_openai_api()
# Read the input prompt from stdin.
input_prompt = '#!/bin/zsh\n\n' + sys.stdin.read()
From fd423ffd55fde9ae354741b0c74c1756d2b8efa6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Mon, 22 Nov 2021 00:09:25 +0100
Subject: [PATCH 11/41] Increase num tokens
---
create_completion.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/create_completion.py b/create_completion.py
index 67770c5..4d57359 100755
--- a/create_completion.py
+++ b/create_completion.py
@@ -58,7 +58,7 @@ def initialize_openai_api():
input_prompt = '#!/bin/zsh\n\n' + sys.stdin.read()
-response = openai.Completion.create(engine='davinci-codex', prompt=input_prompt, temperature=0.5, max_tokens=32, stream=STREAM)
+response = openai.Completion.create(engine='davinci-codex', prompt=input_prompt, temperature=0.5, max_tokens=50, stream=STREAM)
# completion = response['choices'][0]['text']
if STREAM:
while True:
From 311d0e859d7a928cde76cbf660f85c0fe7522bbd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Tue, 23 Nov 2021 03:27:49 +0100
Subject: [PATCH 12/41] Change badge style
---
README.md | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index b521f08..b5549e8 100644
--- a/README.md
+++ b/README.md
@@ -7,27 +7,27 @@

From 804a386442dfd006746d51a3167434be260a4c21 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Tue, 18 Jan 2022 02:55:21 +0100
Subject: [PATCH 13/41] Change color
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index b5549e8..d719a80 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
Date: Tue, 18 Jan 2022 02:58:07 +0100
Subject: [PATCH 14/41] Change colors
---
README.md | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index d719a80..014d89b 100644
--- a/README.md
+++ b/README.md
@@ -12,22 +12,22 @@
/>

From 1a16850331fdff252e9295fb878d6dda21dc4f84 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Sun, 23 Jan 2022 05:41:55 +0100
Subject: [PATCH 15/41] Update model name
---
create_completion.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/create_completion.py b/create_completion.py
index 4d57359..0ecfc5e 100755
--- a/create_completion.py
+++ b/create_completion.py
@@ -58,7 +58,7 @@ def initialize_openai_api():
input_prompt = '#!/bin/zsh\n\n' + sys.stdin.read()
-response = openai.Completion.create(engine='davinci-codex', prompt=input_prompt, temperature=0.5, max_tokens=50, stream=STREAM)
+response = openai.Completion.create(engine='code-davinci-001', prompt=input_prompt, temperature=0.5, max_tokens=50, stream=STREAM)
# completion = response['choices'][0]['text']
if STREAM:
while True:
From ef54286414556c5d4135579174ae4541b2b7070d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Mon, 24 Jan 2022 05:37:55 +0100
Subject: [PATCH 16/41] Add traffic stats
---
README.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/README.md b/README.md
index 014d89b..7064a97 100644
--- a/README.md
+++ b/README.md
@@ -108,3 +108,6 @@ Try to download the ZSH plugin again.
```
git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins/zsh_codex
```
+-------------------------------------------------------------------
+
+[Traffic Statistics](https://github.com/tom-doerr/github_repo_stats_data/raw/master/tom-doerr/zsh_codex/latest-report/report.pdf)
From 6d6517fa6aae922df88baeb1a99d8ba11bbdd81d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Mon, 24 Jan 2022 05:46:28 +0100
Subject: [PATCH 17/41] Change link
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 7064a97..f69a25a 100644
--- a/README.md
+++ b/README.md
@@ -110,4 +110,4 @@ git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins
```
-------------------------------------------------------------------
-[Traffic Statistics](https://github.com/tom-doerr/github_repo_stats_data/raw/master/tom-doerr/zsh_codex/latest-report/report.pdf)
+[Traffic Statistics](https://tom-doerr.github.io/github_repo_stats_data/tom-doerr/zsh_codex/latest-report/report.html)
From b8d80529effcb1361e1659ec29485c6890aedd10 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Sun, 27 Mar 2022 09:45:24 +0200
Subject: [PATCH 18/41] Switch to insert mode
---
create_completion.py | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/create_completion.py b/create_completion.py
index 0ecfc5e..3b873dd 100755
--- a/create_completion.py
+++ b/create_completion.py
@@ -54,21 +54,22 @@ def initialize_openai_api():
initialize_openai_api()
+cursor_position_char = int(sys.argv[1])
+
# Read the input prompt from stdin.
-input_prompt = '#!/bin/zsh\n\n' + sys.stdin.read()
+buffer = sys.stdin.read()
+prompt_prefix = '#!/bin/zsh\n\n' + buffer[:cursor_position_char]
+prompt_suffix = buffer[cursor_position_char:]
+response = openai.Completion.create(engine='code-davinci-002', prompt=prompt_prefix, suffix=prompt_suffix, temperature=0.5, max_tokens=50, stream=STREAM)
-response = openai.Completion.create(engine='code-davinci-001', prompt=input_prompt, temperature=0.5, max_tokens=50, stream=STREAM)
-# completion = response['choices'][0]['text']
if STREAM:
while True:
next_response = next(response)
print("next_response:", next_response)
- # next_response['choices'][0]['finish_reason']
print(" next_response['choices'][0]['finish_reason']:", next_response['choices'][0]['finish_reason'])
completion = next_response['choices'][0]['text']
print("completion:", completion)
- # print(next(response))
else:
completion_all = response['choices'][0]['text']
completion_list = completion_all.split('\n')
From ecef53f3b89f29535c79f1c2e8ec6878915a10b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Sun, 27 Mar 2022 09:58:28 +0200
Subject: [PATCH 19/41] Switch to insert mode
---
zsh_codex.plugin.zsh | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/zsh_codex.plugin.zsh b/zsh_codex.plugin.zsh
index 2c38c24..a503bc9 100644
--- a/zsh_codex.plugin.zsh
+++ b/zsh_codex.plugin.zsh
@@ -7,11 +7,16 @@
create_completion() {
# Get the text typed until now.
text=${BUFFER}
- completion=$(echo -n "$text" | $ZSH_CUSTOM/plugins/zsh_codex/create_completion.py)
+ #echo $cursor_line $cursor_col
+ completion=$(echo -n "$text" | $ZSH_CUSTOM/plugins/zsh_codex/create_completion.py $CURSOR)
+ text_before_cursor=${text:0:$CURSOR}
+ text_after_cursor=${text:$CURSOR}
# Add completion to the current buffer.
- BUFFER="${text}${completion}"
- # Put the cursor at the end of the line.
- CURSOR=${#BUFFER}
+ #BUFFER="${text}${completion}"
+ BUFFER="${text_before_cursor}${completion}${text_after_cursor}"
+ prefix_and_completion="${text_before_cursor}${completion}"
+ # Put the cursor at the end of the completion
+ CURSOR=${#prefix_and_completion}
}
# Bind the create_completion function to a key.
From a390605eab4c3e03c63a00ab1f411a5d38037f29 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Sun, 27 Mar 2022 13:47:10 +0200
Subject: [PATCH 20/41] Add usage exampmles
---
README.md | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/README.md b/README.md
index f69a25a..cb794a6 100644
--- a/README.md
+++ b/README.md
@@ -108,6 +108,14 @@ Try to download the ZSH plugin again.
```
git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins/zsh_codex
```
+
+## More examples of usage
+
+
+
+
+
+
-------------------------------------------------------------------
[Traffic Statistics](https://tom-doerr.github.io/github_repo_stats_data/tom-doerr/zsh_codex/latest-report/report.html)
From d4261d36cef2ab208ee0cd508533a6d7a1246146 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Tue, 29 Mar 2022 09:47:44 +0200
Subject: [PATCH 21/41] Add link
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index cb794a6..9dde6d0 100644
--- a/README.md
+++ b/README.md
@@ -118,4 +118,5 @@ git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins
-------------------------------------------------------------------
+[fish version](https://github.com/tom-doerr/codex.fish)
[Traffic Statistics](https://tom-doerr.github.io/github_repo_stats_data/tom-doerr/zsh_codex/latest-report/report.html)
From f2c1ed990299b53dd444f3da6c8d39ea05d057c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Tue, 29 Mar 2022 09:48:04 +0200
Subject: [PATCH 22/41] Add break
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index 9dde6d0..a51994c 100644
--- a/README.md
+++ b/README.md
@@ -119,4 +119,5 @@ git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins
-------------------------------------------------------------------
[fish version](https://github.com/tom-doerr/codex.fish)
+
[Traffic Statistics](https://tom-doerr.github.io/github_repo_stats_data/tom-doerr/zsh_codex/latest-report/report.html)
From c6042415d892e1b9bde8e641793d165f3a7d3f14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Tue, 29 Mar 2022 09:48:19 +0200
Subject: [PATCH 23/41] Capitalize link
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index a51994c..858f10b 100644
--- a/README.md
+++ b/README.md
@@ -118,6 +118,6 @@ git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins
-------------------------------------------------------------------
-[fish version](https://github.com/tom-doerr/codex.fish)
+[Fish Version](https://github.com/tom-doerr/codex.fish)
[Traffic Statistics](https://tom-doerr.github.io/github_repo_stats_data/tom-doerr/zsh_codex/latest-report/report.html)
From 31444c195dffc05d2c0a87520b62000ad8c5973c Mon Sep 17 00:00:00 2001
From: Rafael Moreira <1180778@isep.ipp.pt>
Date: Tue, 29 Mar 2022 15:36:49 +0100
Subject: [PATCH 24/41] Fix the git clone command for the plugin
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 858f10b..8456e65 100644
--- a/README.md
+++ b/README.md
@@ -56,7 +56,7 @@ pip3 install openai
2. Download the ZSH plugin.
```
- $ git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins/
+ $ git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins/zsh_codex
```
3. Add the following to your `.zshrc` file.
From c2352e6f22cec7fe4a8356e2bafe3b0126fc771d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Thu, 26 May 2022 00:47:38 +0200
Subject: [PATCH 25/41] Change heading
---
README.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 858f10b..8c54956 100644
--- a/README.md
+++ b/README.md
@@ -109,7 +109,8 @@ Try to download the ZSH plugin again.
git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins/zsh_codex
```
-## More examples of usage
+
+## More usage examples
From 9308dd69fe8162488800680c3e611b80b1eaee55 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Thu, 26 May 2022 00:48:51 +0200
Subject: [PATCH 26/41] Add coffee link
---
README.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/README.md b/README.md
index 8c54956..fa0cee0 100644
--- a/README.md
+++ b/README.md
@@ -109,6 +109,9 @@ Try to download the ZSH plugin again.
git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins/zsh_codex
```
+
+
+
## More usage examples
From e345027e22e92599eba4d03fb2432bd766952a1c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Thu, 26 May 2022 00:50:34 +0200
Subject: [PATCH 27/41] Add line
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 2ea9bd7..8fad972 100644
--- a/README.md
+++ b/README.md
@@ -108,7 +108,7 @@ Try to download the ZSH plugin again.
```
git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins/zsh_codex
```
-
+---
From 55c4d952458363b861c37a34413ec927f1901fc7 Mon Sep 17 00:00:00 2001
From: Ilkin Bayramli <43158991+ibayramli@users.noreply.github.com>
Date: Thu, 16 Jun 2022 16:46:02 -0700
Subject: [PATCH 28/41] Add Fig as an installation method to the README
---
README.md | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 8fad972..f1ab693 100644
--- a/README.md
+++ b/README.md
@@ -47,7 +47,7 @@ To use this plugin you need to get access to OpenAI's [Codex API](https://openai
## How do I install it?
-
+### Manual Installation
1. Install the OpenAI package.
```
pip3 install openai
@@ -84,6 +84,13 @@ secret_key = ...
5. Run `zsh`, start typing and complete it using `^X`!
+### Fig Installation
+
+[Fig](https://fig.io) adds apps, shortcuts, and autocomplete to your existing terminal.
+
+Install `zsh_codex` in just one click.
+
+
## Troubleshooting
From 8c52b82a4486a21dd39efc48e099872cbf98d996 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Fri, 17 Jun 2022 02:24:44 +0200
Subject: [PATCH 29/41] Update README.md
---
README.md | 4 ----
1 file changed, 4 deletions(-)
diff --git a/README.md b/README.md
index f1ab693..72152af 100644
--- a/README.md
+++ b/README.md
@@ -86,10 +86,6 @@ secret_key = ...
### Fig Installation
-[Fig](https://fig.io) adds apps, shortcuts, and autocomplete to your existing terminal.
-
-Install `zsh_codex` in just one click.
-
## Troubleshooting
From 456db1a053e432ea5108250180f57a6e9029839e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Fri, 11 Nov 2022 19:13:12 +0100
Subject: [PATCH 30/41] Update readme
---
README.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/README.md b/README.md
index 72152af..ba169dc 100644
--- a/README.md
+++ b/README.md
@@ -40,6 +40,10 @@
+**Newer Version available** (`pip install kiera`)
+
+[More Info](https://kiera.ai)
+
## What is it?
This is a ZSH plugin that enables you to use OpenAI's powerful Codex AI in the command line. OpenAI Codex is the AI that also powers GitHub Copilot.
From 95de2b0547de00c90293ff1229b8ac535522a614 Mon Sep 17 00:00:00 2001
From: fbarez <37307369+fbarez@users.noreply.github.com>
Date: Tue, 13 Dec 2022 09:33:37 +0000
Subject: [PATCH 31/41] Update README.md
removing $
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index ba169dc..9953625 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ pip3 install openai
2. Download the ZSH plugin.
```
- $ git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins/zsh_codex
+git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins/zsh_codex
```
3. Add the following to your `.zshrc` file.
From 165987b5a0c7d2f9e84301a024e26966230e7e07 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Sat, 17 Jun 2023 00:26:37 +0200
Subject: [PATCH 32/41] Update README.md
---
README.md | 4 ----
1 file changed, 4 deletions(-)
diff --git a/README.md b/README.md
index 9953625..84bab4a 100644
--- a/README.md
+++ b/README.md
@@ -40,10 +40,6 @@
-**Newer Version available** (`pip install kiera`)
-
-[More Info](https://kiera.ai)
-
## What is it?
This is a ZSH plugin that enables you to use OpenAI's powerful Codex AI in the command line. OpenAI Codex is the AI that also powers GitHub Copilot.
From 9eafdd60e3e7173826944a5df52692eabd18b00f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A7=8B=20=E5=A5=88=E6=9C=88?=
<43605695+akinazuki@users.noreply.github.com>
Date: Sat, 24 Jun 2023 16:57:59 +0900
Subject: [PATCH 33/41] support gpt-3.5-turbo model
---
create_completion.py | 42 ++++++++++++++----------------------------
1 file changed, 14 insertions(+), 28 deletions(-)
diff --git a/create_completion.py b/create_completion.py
index 3b873dd..38805e0 100755
--- a/create_completion.py
+++ b/create_completion.py
@@ -5,9 +5,6 @@
import os
import configparser
-STREAM = False
-
-
# Get config dir from environment or default to ~/.config
CONFIG_DIR = os.getenv('XDG_CONFIG_HOME', os.path.expanduser('~/.config'))
API_KEYS_LOCATION = os.path.join(CONFIG_DIR, 'openaiapirc')
@@ -38,7 +35,6 @@ def create_template_ini_file():
'https://openai.com/blog/openai-codex/')
sys.exit(1)
-
def initialize_openai_api():
"""
Initialize the OpenAI API
@@ -60,27 +56,17 @@ def initialize_openai_api():
buffer = sys.stdin.read()
prompt_prefix = '#!/bin/zsh\n\n' + buffer[:cursor_position_char]
prompt_suffix = buffer[cursor_position_char:]
-
-response = openai.Completion.create(engine='code-davinci-002', prompt=prompt_prefix, suffix=prompt_suffix, temperature=0.5, max_tokens=50, stream=STREAM)
-
-if STREAM:
- while True:
- next_response = next(response)
- print("next_response:", next_response)
- print(" next_response['choices'][0]['finish_reason']:", next_response['choices'][0]['finish_reason'])
- completion = next_response['choices'][0]['text']
- print("completion:", completion)
-else:
- completion_all = response['choices'][0]['text']
- completion_list = completion_all.split('\n')
- if completion_all[:2] == '\n\n':
- print(completion_all)
- elif completion_list[0]:
- print(completion_list[0])
- elif len(completion_list) == 1:
- print('')
- else:
- print('\n' + completion_list[1])
-
-
-
+full_command = prompt_prefix + prompt_suffix
+response = openai.ChatCompletion.create(model='gpt-3.5-turbo-0613', messages=[
+ {
+ "role":'system',
+ "content": "you are a zsh shell expert, please help me complete the following command, you should only output the completed command, no need any other include any explain",
+ },
+ {
+ "role":'user',
+ "content": full_command,
+ }
+])
+completed_command = response['choices'][0]['message']['content']
+
+sys.stdout.write(f"\n{completed_command}")
From 67e57a72d95fb87565c24ee30ccd6879493062c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A7=8B=20=E5=A5=88=E6=9C=88?=
<43605695+akinazuki@users.noreply.github.com>
Date: Sat, 24 Jun 2023 17:27:37 +0900
Subject: [PATCH 34/41] select model via configuration file
---
create_completion.py | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/create_completion.py b/create_completion.py
index 38805e0..21f33d0 100755
--- a/create_completion.py
+++ b/create_completion.py
@@ -27,6 +27,7 @@ def create_template_ini_file():
f.write('[openai]\n')
f.write('organization_id=\n')
f.write('secret_key=\n')
+ f.write('model=gpt-3.5-turbo-0613\n')
print('OpenAI API config file created at {}'.format(API_KEYS_LOCATION))
print('Please edit it and add your organization ID and secret key')
@@ -35,6 +36,7 @@ def create_template_ini_file():
'https://openai.com/blog/openai-codex/')
sys.exit(1)
+
def initialize_openai_api():
"""
Initialize the OpenAI API
@@ -46,9 +48,10 @@ def initialize_openai_api():
openai.organization_id = config['openai']['organization_id'].strip('"').strip("'")
openai.api_key = config['openai']['secret_key'].strip('"').strip("'")
+ model = config['openai']['model'].strip('"').strip("'")
+ return model
-
-initialize_openai_api()
+model = initialize_openai_api()
cursor_position_char = int(sys.argv[1])
@@ -57,7 +60,7 @@ def initialize_openai_api():
prompt_prefix = '#!/bin/zsh\n\n' + buffer[:cursor_position_char]
prompt_suffix = buffer[cursor_position_char:]
full_command = prompt_prefix + prompt_suffix
-response = openai.ChatCompletion.create(model='gpt-3.5-turbo-0613', messages=[
+response = openai.ChatCompletion.create(model=model, messages=[
{
"role":'system',
"content": "you are a zsh shell expert, please help me complete the following command, you should only output the completed command, no need any other include any explain",
From 4300781b6cb0746d8fd7dc3a5898b471f49fe560 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A7=8B=20=E5=A5=88=E6=9C=88?=
<43605695+akinazuki@users.noreply.github.com>
Date: Sat, 24 Jun 2023 17:40:42 +0900
Subject: [PATCH 35/41] fix type
---
create_completion.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/create_completion.py b/create_completion.py
index 21f33d0..7d3c340 100755
--- a/create_completion.py
+++ b/create_completion.py
@@ -63,7 +63,7 @@ def initialize_openai_api():
response = openai.ChatCompletion.create(model=model, messages=[
{
"role":'system',
- "content": "you are a zsh shell expert, please help me complete the following command, you should only output the completed command, no need any other include any explain",
+ "content": "You are a zsh shell expert, please help me complete the following command, you should only output the completed command, no need to include any other explanation",
},
{
"role":'user',
From d06cf236591fa5b469cb6d4688407548aad76bbf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=20D=C3=B6rr?=
Date: Thu, 13 Jul 2023 21:31:17 +0200
Subject: [PATCH 36/41] Add default model
---
create_completion.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/create_completion.py b/create_completion.py
index 7d3c340..cc6f37b 100755
--- a/create_completion.py
+++ b/create_completion.py
@@ -48,7 +48,12 @@ def initialize_openai_api():
openai.organization_id = config['openai']['organization_id'].strip('"').strip("'")
openai.api_key = config['openai']['secret_key'].strip('"').strip("'")
- model = config['openai']['model'].strip('"').strip("'")
+
+ if 'model' in config['openai']:
+ model = config['openai']['model'].strip('"').strip("'")
+ else:
+ model = 'gpt-3.5-turbo'
+
return model
model = initialize_openai_api()
From 929172e12745a3808ea466f83b60fe7fd606f851 Mon Sep 17 00:00:00 2001
From: Albert <87888006+MustCodeAl@users.noreply.github.com>
Date: Tue, 8 Aug 2023 21:31:32 -0500
Subject: [PATCH 37/41] Update create_completion.py
to add completions that use model 4
---
create_completion.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/create_completion.py b/create_completion.py
index cc6f37b..6c4d1fe 100755
--- a/create_completion.py
+++ b/create_completion.py
@@ -27,7 +27,7 @@ def create_template_ini_file():
f.write('[openai]\n')
f.write('organization_id=\n')
f.write('secret_key=\n')
- f.write('model=gpt-3.5-turbo-0613\n')
+ f.write('model=gpt-4-0314\n')
print('OpenAI API config file created at {}'.format(API_KEYS_LOCATION))
print('Please edit it and add your organization ID and secret key')
@@ -52,7 +52,7 @@ def initialize_openai_api():
if 'model' in config['openai']:
model = config['openai']['model'].strip('"').strip("'")
else:
- model = 'gpt-3.5-turbo'
+ model = 'gpt-4'
return model
From 713f99ca52ddf92eb862e682a6385d339caafc42 Mon Sep 17 00:00:00 2001
From: Albert <87888006+MustCodeAl@users.noreply.github.com>
Date: Tue, 8 Aug 2023 23:56:39 -0500
Subject: [PATCH 38/41] Update create_completion.py
-Added more context from system
-Enhanced performance
---
create_completion.py | 68 ++++++++++++++++++++++++++++++++++++++------
1 file changed, 60 insertions(+), 8 deletions(-)
diff --git a/create_completion.py b/create_completion.py
index 6c4d1fe..82abea4 100755
--- a/create_completion.py
+++ b/create_completion.py
@@ -1,14 +1,19 @@
#!/usr/bin/env python3
+import asyncio
import openai
import sys
import os
import configparser
+import platform
+import functools
+import subprocess
# Get config dir from environment or default to ~/.config
CONFIG_DIR = os.getenv('XDG_CONFIG_HOME', os.path.expanduser('~/.config'))
API_KEYS_LOCATION = os.path.join(CONFIG_DIR, 'openaiapirc')
+
# Read the organization_id and secret_key from the ini file ~/.config/openaiapirc
# The format is:
# [openai]
@@ -17,7 +22,10 @@
# If you don't see your organization ID in the file you can get it from the
# OpenAI web site: https://openai.com/organizations
-def create_template_ini_file():
+
+
+@functools.lru_cache(maxsize=None)
+async def create_template_ini_file():
"""
If the ini file does not exist create it and add the organization_id and
secret_key
@@ -32,17 +40,18 @@ def create_template_ini_file():
print('OpenAI API config file created at {}'.format(API_KEYS_LOCATION))
print('Please edit it and add your organization ID and secret key')
print('If you do not yet have an organization ID and secret key, you\n'
- 'need to register for OpenAI Codex: \n'
- 'https://openai.com/blog/openai-codex/')
+ 'need to register for OpenAI Codex: \n'
+ 'https://openai.com/blog/openai-codex/')
sys.exit(1)
-def initialize_openai_api():
+@functools.lru_cache(maxsize=None)
+async def initialize_openai_api():
"""
Initialize the OpenAI API
"""
# Check if file at API_KEYS_LOCATION exists
- create_template_ini_file()
+ await create_template_ini_file()
config = configparser.ConfigParser()
config.read(API_KEYS_LOCATION)
@@ -56,10 +65,49 @@ def initialize_openai_api():
return model
-model = initialize_openai_api()
+
+# model = initialize_openai_api()
+model = asyncio.run(initialize_openai_api())
cursor_position_char = int(sys.argv[1])
+
+@functools.lru_cache(maxsize=None)
+async def get_system_info():
+ """
+ Gather system information
+ """
+ system_info = {
+ "os": platform.system(),
+ "os_version": platform.version(),
+ "architecture": platform.architecture()[0],
+ "processor": platform.processor()
+ }
+ return system_info
+
+
+system_info = asyncio.run(get_system_info())
+
+
+@functools.lru_cache(maxsize=None)
+async def get_installed_packages():
+ # Get list of installed packages
+ try:
+ if system_info['os'] == 'Linux':
+ installed_packages = subprocess.check_output(['dpkg', '--get-selections']).decode('utf-8')
+ elif system_info['os'] == 'Darwin':
+ installed_packages = subprocess.check_output(['brew', 'list']).decode('utf-8')
+ else:
+ installed_packages = "Unsupported OS for package listing"
+ except Exception as e:
+ installed_packages = f"Error getting installed packages: {str(e)}"
+ return installed_packages
+
+
+installed_packages = asyncio.run(get_installed_packages())
+
+# Get current working directory
+current_directory = os.getcwd()
# Read the input prompt from stdin.
buffer = sys.stdin.read()
prompt_prefix = '#!/bin/zsh\n\n' + buffer[:cursor_position_char]
@@ -67,11 +115,15 @@ def initialize_openai_api():
full_command = prompt_prefix + prompt_suffix
response = openai.ChatCompletion.create(model=model, messages=[
{
- "role":'system',
+ "role": 'system',
"content": "You are a zsh shell expert, please help me complete the following command, you should only output the completed command, no need to include any other explanation",
},
{
- "role":'user',
+ "role": 'user',
+ "content": f"I'm using a {system_info['os']} system with version {system_info['os_version']} on a {system_info['architecture']} architecture with a {system_info['processor']} processor. The current directory is {current_directory}. Here are some of my installed packages:\n{installed_packages}",
+ },
+ {
+ "role": 'user',
"content": full_command,
}
])
From a49ab9b71219607a52f80d5faeb52c7e6d16d6f5 Mon Sep 17 00:00:00 2001
From: Albert <87888006+MustCodeAl@users.noreply.github.com>
Date: Wed, 9 Aug 2023 02:11:42 -0500
Subject: [PATCH 39/41] Update create_completion.py
properly caching files
---
create_completion.py | 70 +++++++++++++++++++++++++++++---------------
1 file changed, 47 insertions(+), 23 deletions(-)
diff --git a/create_completion.py b/create_completion.py
index 82abea4..90c92a6 100755
--- a/create_completion.py
+++ b/create_completion.py
@@ -6,13 +6,37 @@
import os
import configparser
import platform
-import functools
import subprocess
+import json
+import time
# Get config dir from environment or default to ~/.config
CONFIG_DIR = os.getenv('XDG_CONFIG_HOME', os.path.expanduser('~/.config'))
API_KEYS_LOCATION = os.path.join(CONFIG_DIR, 'openaiapirc')
+CACHE_DIR = os.path.join(CONFIG_DIR, 'cache/zsh_codex')
+os.makedirs(CACHE_DIR, exist_ok=True)
+SYSTEM_INFO_CACHE_FILE = os.path.join(CACHE_DIR, 'system_info.json')
+INSTALLED_PACKAGES_CACHE_FILE = os.path.join(CACHE_DIR, 'installed_packages.json')
+CACHE_EXPIRATION_TIME = 60 * 60 * 24 # 24 hours
+
+
+def load_or_save_to_cache(filename, default_func):
+ if os.path.exists(filename):
+ with open(filename, 'r') as f:
+ data = json.load(f)
+ if time.time() - data['timestamp'] < CACHE_EXPIRATION_TIME:
+ return data['value']
+
+ data = {
+ 'value': default_func(),
+ 'timestamp': time.time()
+ }
+ with open(filename, 'w') as f:
+ json.dump(data, f)
+
+ return data['value']
+
# Read the organization_id and secret_key from the ini file ~/.config/openaiapirc
# The format is:
@@ -23,8 +47,6 @@
# If you don't see your organization ID in the file you can get it from the
# OpenAI web site: https://openai.com/organizations
-
-@functools.lru_cache(maxsize=None)
async def create_template_ini_file():
"""
If the ini file does not exist create it and add the organization_id and
@@ -45,7 +67,6 @@ async def create_template_ini_file():
sys.exit(1)
-@functools.lru_cache(maxsize=None)
async def initialize_openai_api():
"""
Initialize the OpenAI API
@@ -72,36 +93,39 @@ async def initialize_openai_api():
cursor_position_char = int(sys.argv[1])
-@functools.lru_cache(maxsize=None)
async def get_system_info():
"""
Gather system information
"""
- system_info = {
- "os": platform.system(),
- "os_version": platform.version(),
- "architecture": platform.architecture()[0],
- "processor": platform.processor()
- }
- return system_info
+
+ def default_func():
+ return {
+ "os": platform.system(),
+ "os_version": platform.version(),
+ "architecture": platform.architecture()[0],
+ "processor": platform.processor()
+ }
+
+ return load_or_save_to_cache(SYSTEM_INFO_CACHE_FILE, default_func)
system_info = asyncio.run(get_system_info())
-@functools.lru_cache(maxsize=None)
async def get_installed_packages():
# Get list of installed packages
- try:
- if system_info['os'] == 'Linux':
- installed_packages = subprocess.check_output(['dpkg', '--get-selections']).decode('utf-8')
- elif system_info['os'] == 'Darwin':
- installed_packages = subprocess.check_output(['brew', 'list']).decode('utf-8')
- else:
- installed_packages = "Unsupported OS for package listing"
- except Exception as e:
- installed_packages = f"Error getting installed packages: {str(e)}"
- return installed_packages
+ def default_func():
+ try:
+ if system_info['os'] == 'Linux':
+ return subprocess.check_output(['dpkg', '--get-selections']).decode('utf-8')
+ elif system_info['os'] == 'Darwin':
+ return subprocess.check_output(['brew', 'list']).decode('utf-8')
+ else:
+ return "Unsupported OS for package listing"
+ except subprocess.CalledProcessError as e:
+ return f"Error getting installed packages: {str(e)}"
+
+ return load_or_save_to_cache(INSTALLED_PACKAGES_CACHE_FILE, default_func)
installed_packages = asyncio.run(get_installed_packages())
From 052a4ee0b982c226bf5fecc20056e792262a2dcb Mon Sep 17 00:00:00 2001
From: Albert <87888006+MustCodeAl@users.noreply.github.com>
Date: Wed, 9 Aug 2023 04:05:32 -0500
Subject: [PATCH 40/41] Update create_completion.py
fixed high token usage
---
create_completion.py | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/create_completion.py b/create_completion.py
index 90c92a6..1b20a6e 100755
--- a/create_completion.py
+++ b/create_completion.py
@@ -10,10 +10,12 @@
import json
import time
+
# Get config dir from environment or default to ~/.config
CONFIG_DIR = os.getenv('XDG_CONFIG_HOME', os.path.expanduser('~/.config'))
API_KEYS_LOCATION = os.path.join(CONFIG_DIR, 'openaiapirc')
+
CACHE_DIR = os.path.join(CONFIG_DIR, 'cache/zsh_codex')
os.makedirs(CACHE_DIR, exist_ok=True)
SYSTEM_INFO_CACHE_FILE = os.path.join(CACHE_DIR, 'system_info.json')
@@ -21,6 +23,11 @@
CACHE_EXPIRATION_TIME = 60 * 60 * 24 # 24 hours
+
+
+
+
+
def load_or_save_to_cache(filename, default_func):
if os.path.exists(filename):
with open(filename, 'r') as f:
@@ -37,7 +44,6 @@ def load_or_save_to_cache(filename, default_func):
return data['value']
-
# Read the organization_id and secret_key from the ini file ~/.config/openaiapirc
# The format is:
# [openai]
@@ -112,14 +118,17 @@ def default_func():
system_info = asyncio.run(get_system_info())
+# last ten recent packages
async def get_installed_packages():
# Get list of installed packages
def default_func():
try:
if system_info['os'] == 'Linux':
- return subprocess.check_output(['dpkg', '--get-selections']).decode('utf-8')
+ command = "dpkg --get-selections | head -n 10"
+ return subprocess.check_output(command, shell=True).decode('utf-8')
elif system_info['os'] == 'Darwin':
- return subprocess.check_output(['brew', 'list']).decode('utf-8')
+ command = "brew list -1t 2> /dev/null | head -n 10"
+ return subprocess.check_output(command, shell=True).decode('utf-8')
else:
return "Unsupported OS for package listing"
except subprocess.CalledProcessError as e:
@@ -127,6 +136,7 @@ def default_func():
return load_or_save_to_cache(INSTALLED_PACKAGES_CACHE_FILE, default_func)
+
installed_packages = asyncio.run(get_installed_packages())
From dec4f22de5e3b6ef77d739b11daba26d48055d25 Mon Sep 17 00:00:00 2001
From: Albert <87888006+MustCodeAl@users.noreply.github.com>
Date: Wed, 9 Aug 2023 04:08:01 -0500
Subject: [PATCH 41/41] Update create_completion.py
even less tokens
---
create_completion.py | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/create_completion.py b/create_completion.py
index 1b20a6e..dd020d2 100755
--- a/create_completion.py
+++ b/create_completion.py
@@ -11,6 +11,7 @@
import time
+
# Get config dir from environment or default to ~/.config
CONFIG_DIR = os.getenv('XDG_CONFIG_HOME', os.path.expanduser('~/.config'))
API_KEYS_LOCATION = os.path.join(CONFIG_DIR, 'openaiapirc')
@@ -124,10 +125,10 @@ async def get_installed_packages():
def default_func():
try:
if system_info['os'] == 'Linux':
- command = "dpkg --get-selections | head -n 10"
+ command = "dpkg --get-selections | head -n 5"
return subprocess.check_output(command, shell=True).decode('utf-8')
elif system_info['os'] == 'Darwin':
- command = "brew list -1t 2> /dev/null | head -n 10"
+ command = "brew list -1t 2> /dev/null | head -n 5"
return subprocess.check_output(command, shell=True).decode('utf-8')
else:
return "Unsupported OS for package listing"