summaryrefslogtreecommitdiff
path: root/py/complete.py
diff options
context:
space:
mode:
Diffstat (limited to 'py/complete.py')
-rw-r--r--py/complete.py39
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']