From bca7ca15bdb82a0b32f11d44b44cf1ba42c68869 Mon Sep 17 00:00:00 2001 From: Duy Lam Date: Sat, 9 Sep 2023 22:13:42 +0700 Subject: Include OpenAI Org ID from the token config --- README.md | 6 ++++++ py/utils.py | 25 ++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1ff7973..326d70c 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,14 @@ You only share and pay for what you specifically select, for prompts and chat co # save api key to `~/.config/openai.token` file echo "YOUR_OPENAI_API_KEY" > ~/.config/openai.token +# or save api key and org id to `~/.config/openai.token` file +#echo "YOUR_OPENAI_API_KEY,YOUR_OPENAI_ORG_ID" > ~/.config/openai.token + # alternatively set it as an environment variable export OPENAI_API_KEY="YOUR_OPENAI_API_KEY" + +# or set with org id +#export OPENAI_API_KEY="YOUR_OPENAI_API_KEY,YOUR_OPENAI_ORG_ID" ``` ### Using `vim-plug` diff --git a/py/utils.py b/py/utils.py index 76ae1e4..2e1f975 100644 --- a/py/utils.py +++ b/py/utils.py @@ -16,15 +16,26 @@ debug_log_file = vim.eval("g:vim_ai_debug_log_file") def load_api_key(): config_file_path = os.path.join(os.path.expanduser("~"), ".config/openai.token") - api_key = os.getenv("OPENAI_API_KEY") + api_key_param_value = os.getenv("OPENAI_API_KEY") try: with open(config_file_path, 'r') as file: - api_key = file.read() + api_key_param_value = file.read() except Exception: pass - if not api_key: + + if not api_key_param_value: raise Exception("Missing OpenAI API key") - return api_key.strip() + + # The text is in format of "," and the + # part is optional + elements = api_key_param_value.strip().split(",") + api_key = elements[0].strip() + org_id = None + + if len(elements) > 1: + org_id = elements[1].strip() + + return (api_key, org_id) def normalize_config(config): normalized = { **config } @@ -119,13 +130,17 @@ def printDebug(text, *args): OPENAI_RESP_DATA_PREFIX = 'data: ' OPENAI_RESP_DONE = '[DONE]' -OPENAI_API_KEY = load_api_key() +(OPENAI_API_KEY, OPENAI_ORG_ID) = load_api_key() def openai_request(url, data, options): headers = { "Content-Type": "application/json", "Authorization": f"Bearer {OPENAI_API_KEY}" } + + if OPENAI_ORG_ID is not None: + headers["OpenAI-Organization"] = f"{OPENAI_ORG_ID}" + request_timeout=options['request_timeout'] req = urllib.request.Request( url, -- cgit v1.2.3 From b86cb48fb8d20f3aacd24b157a2beec514b30ad6 Mon Sep 17 00:00:00 2001 From: Martin Bielik Date: Mon, 18 Sep 2023 17:07:32 +0200 Subject: compact org id docu --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 326d70c..216d238 100644 --- a/README.md +++ b/README.md @@ -32,14 +32,12 @@ You only share and pay for what you specifically select, for prompts and chat co # save api key to `~/.config/openai.token` file echo "YOUR_OPENAI_API_KEY" > ~/.config/openai.token -# or save api key and org id to `~/.config/openai.token` file -#echo "YOUR_OPENAI_API_KEY,YOUR_OPENAI_ORG_ID" > ~/.config/openai.token - # alternatively set it as an environment variable export OPENAI_API_KEY="YOUR_OPENAI_API_KEY" -# or set with org id -#export OPENAI_API_KEY="YOUR_OPENAI_API_KEY,YOUR_OPENAI_ORG_ID" +# or configure it with your organization id +echo "YOUR_OPENAI_API_KEY,YOUR_OPENAI_ORG_ID" > ~/.config/openai.token +export OPENAI_API_KEY="YOUR_OPENAI_API_KEY,YOUR_OPENAI_ORG_ID" ``` ### Using `vim-plug` -- cgit v1.2.3 From 8f8083ba0eed23150020b698e74d9302f7212c5d Mon Sep 17 00:00:00 2001 From: Martin Bielik Date: Tue, 26 Sep 2023 21:40:41 +0200 Subject: use gpt-3.5-turbo-instruct by default, closes #48 --- README.md | 4 ++-- autoload/vim_ai_config.vim | 4 ++-- doc/vim-ai.txt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 216d238..415927c 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,7 @@ Below are listed all available configuration options, along with their default v let g:vim_ai_complete = { \ "engine": "complete", \ "options": { -\ "model": "text-davinci-003", +\ "model": "gpt-3.5-turbo-instruct", \ "max_tokens": 1000, \ "temperature": 0.1, \ "request_timeout": 20, @@ -235,7 +235,7 @@ let g:vim_ai_complete = { let g:vim_ai_edit = { \ "engine": "complete", \ "options": { -\ "model": "text-davinci-003", +\ "model": "gpt-3.5-turbo-instruct", \ "max_tokens": 1000, \ "temperature": 0.1, \ "request_timeout": 20, diff --git a/autoload/vim_ai_config.vim b/autoload/vim_ai_config.vim index c501bbd..d60475d 100644 --- a/autoload/vim_ai_config.vim +++ b/autoload/vim_ai_config.vim @@ -1,7 +1,7 @@ let g:vim_ai_complete_default = { \ "engine": "complete", \ "options": { -\ "model": "text-davinci-003", +\ "model": "gpt-3.5-turbo-instruct", \ "max_tokens": 1000, \ "temperature": 0.1, \ "request_timeout": 20, @@ -14,7 +14,7 @@ let g:vim_ai_complete_default = { let g:vim_ai_edit_default = { \ "engine": "complete", \ "options": { -\ "model": "text-davinci-003", +\ "model": "gpt-3.5-turbo-instruct", \ "max_tokens": 1000, \ "temperature": 0.1, \ "request_timeout": 20, diff --git a/doc/vim-ai.txt b/doc/vim-ai.txt index 931d018..86965ee 100644 --- a/doc/vim-ai.txt +++ b/doc/vim-ai.txt @@ -24,7 +24,7 @@ Options: > let g:vim_ai_complete = { \ "engine": "complete", \ "options": { - \ "model": "text-davinci-003", + \ "model": "gpt-3.5-turbo-instruct", \ "max_tokens": 1000, \ "temperature": 0.1, \ "request_timeout": 20, @@ -48,7 +48,7 @@ Options: > let g:vim_ai_edit = { \ "engine": "complete", \ "options": { - \ "model": "text-davinci-003", + \ "model": "gpt-3.5-turbo-instruct", \ "max_tokens": 1000, \ "temperature": 0.1, \ "request_timeout": 20, -- cgit v1.2.3