diff options
| author | Martin Bielik <mx.bielik@gmail.com> | 2023-03-13 18:07:01 +0100 |
|---|---|---|
| committer | Martin Bielik <mx.bielik@gmail.com> | 2023-03-13 18:07:01 +0100 |
| commit | 882ac0476b71642694e764d81df2fb215238c65d (patch) | |
| tree | 8b413325b91f810398a62043c72bf723fb0de052 /py/complete.py | |
| parent | 0faae7b1fbec281f5a645f25e5012d9deb307f56 (diff) | |
| download | vim-ai-882ac0476b71642694e764d81df2fb215238c65d.tar.gz | |
chat streaming, more py3 integration
Diffstat (limited to 'py/complete.py')
| -rw-r--r-- | py/complete.py | 39 |
1 files changed, 12 insertions, 27 deletions
diff --git a/py/complete.py b/py/complete.py index 409d47f..c37cbd0 100644 --- a/py/complete.py +++ b/py/complete.py @@ -1,33 +1,18 @@ -import requests -import sys -import os +import openai -prompt = vim.eval("prompt") - -config_file_path = os.path.join(os.path.expanduser("~"), ".config/openai.token") +# import utils +plugin_root = vim.eval("s:plugin_root") +vim.command(f"py3file {plugin_root}/py/utils.py") -api_key = os.getenv("OPENAI_API_KEY") - -try: - with open(config_file_path, 'r') as file: - api_key = file.read() -except Exception: - pass +prompt = vim.eval("prompt") -api_key = api_key.strip() +openai.api_key = load_api_key() -url = "https://api.openai.com/v1/completions" -headers = { - 'Content-Type': 'application/json', - 'Authorization': f"Bearer {api_key}" -} -data = { - "model": "text-davinci-003", - "prompt":prompt, - "max_tokens": 1000, - "temperature": 0.1 -} -response = requests.post(url, headers=headers, json=data) -response = response.json() +response = openai.Completion.create( + model="text-davinci-003", + prompt=prompt, + max_tokens=1000, + temperature=0.1 +) output = response['choices'][0]['text'] |