diff options
Diffstat (limited to 'py')
| -rw-r--r-- | py/chat.py | 13 | ||||
| -rw-r--r-- | py/complete.py | 4 | ||||
| -rw-r--r-- | py/utils.py | 13 |
3 files changed, 22 insertions, 8 deletions
@@ -5,13 +5,20 @@ plugin_root = vim.eval("s:plugin_root") vim.command(f"py3file {plugin_root}/py/utils.py") options = make_options() -file_content = vim.eval('trim(join(getline(1, "$"), "\n"))') +request_options = make_request_options() openai.api_key = load_api_key() -lines = file_content.splitlines() +file_content = vim.eval('trim(join(getline(1, "$"), "\n"))') +initial_prompt = '\n'.join(options['initial_prompt']) +prompt = f"{initial_prompt}\n{file_content}" + +lines = prompt.splitlines() messages = [] +with open('/tmp/prompt.aichat', 'w') as f: + f.write(prompt) + for line in lines: if line.startswith(">>> system"): messages.append({"role": "system", "content": ""}) @@ -38,7 +45,7 @@ try: print('Answering...') vim.command("redraw") - response = openai.ChatCompletion.create(messages=messages, stream=True, **options) + response = openai.ChatCompletion.create(messages=messages, stream=True, **request_options) generating_text = False for resp in response: diff --git a/py/complete.py b/py/complete.py index e474580..40f6efb 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 = make_options() +request_options = make_request_options() openai.api_key = load_api_key() @@ -15,7 +15,7 @@ try: print('Completing...') vim.command("redraw") - response = openai.Completion.create(stream=True, prompt=prompt, **options) + response = openai.Completion.create(stream=True, prompt=prompt, **request_options) generating_text = False for resp in response: diff --git a/py/utils.py b/py/utils.py index 8366eec..3e5295a 100644 --- a/py/utils.py +++ b/py/utils.py @@ -15,7 +15,14 @@ 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 + +def make_request_options(): + options = make_options() + request_options = {} + request_options['model'] = options['model'] + request_options['max_tokens'] = int(options['max_tokens']) + request_options['temperature'] = float(options['temperature']) + request_options['request_timeout'] = float(options['request_timeout']) + return request_options + |