summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--py/chat.py15
-rw-r--r--py/complete.py11
-rw-r--r--py/utils.py9
3 files changed, 15 insertions, 20 deletions
diff --git a/py/chat.py b/py/chat.py
index eb80e92..294ae63 100644
--- a/py/chat.py
+++ b/py/chat.py
@@ -4,11 +4,11 @@ import openai
plugin_root = vim.eval("s:plugin_root")
vim.command(f"py3file {plugin_root}/py/utils.py")
-openai.api_key = load_api_key()
-
-options = vim.eval("options")
+options = make_options()
file_content = vim.eval('trim(join(getline(1, "$"), "\n"))')
+openai.api_key = load_api_key()
+
lines = file_content.splitlines()
messages = []
@@ -38,14 +38,7 @@ try:
print('Answering...')
vim.command("redraw")
- response = openai.ChatCompletion.create(
- messages=messages,
- stream=True,
- model=options['model'],
- max_tokens=int(options['max_tokens']),
- temperature=float(options['temperature']),
- request_timeout=float(options['request_timeout']),
- )
+ response = openai.ChatCompletion.create(messages=messages, stream=True, **options)
generating_text = False
for resp in response:
diff --git a/py/complete.py b/py/complete.py
index f469592..f82707a 100644
--- a/py/complete.py
+++ b/py/complete.py
@@ -5,7 +5,7 @@ plugin_root = vim.eval("s:plugin_root")
vim.command(f"py3file {plugin_root}/py/utils.py")
prompt = vim.eval("prompt")
-options = vim.eval("options")
+options = make_options()
openai.api_key = load_api_key()
@@ -15,14 +15,7 @@ try:
print('Completing...')
vim.command("redraw")
- response = openai.Completion.create(
- stream=True,
- prompt=prompt,
- model=options['model'],
- max_tokens=int(options['max_tokens']),
- temperature=float(options['temperature']),
- request_timeout=float(options['request_timeout']),
- )
+ response = openai.Completion.create(stream=True, prompt=prompt, **options)
generating_text = False
for resp in response:
diff --git a/py/utils.py b/py/utils.py
index c9e88f2..8366eec 100644
--- a/py/utils.py
+++ b/py/utils.py
@@ -10,3 +10,12 @@ def load_api_key():
except Exception:
pass
return api_key.strip()
+
+def make_options():
+ options_default = vim.eval("options_default")
+ options_user = vim.eval("options")
+ options = {**options_default, **options_user}
+ options['request_timeout'] = float(options['request_timeout'])
+ options['temperature'] = float(options['temperature'])
+ options['max_tokens'] = int(options['max_tokens'])
+ return options