diff options
| author | Martin Bielik <mx.bielik@gmail.com> | 2023-06-25 11:24:23 +0200 |
|---|---|---|
| committer | Martin Bielik <mx.bielik@gmail.com> | 2023-06-25 11:24:23 +0200 |
| commit | 924e3a390f043e979f16113f6b0a55f8c54b1f5e (patch) | |
| tree | 926e6c2d2c39d00fa3dc28f839b4e2dc4e35d84f | |
| parent | 531a1f646144d195fc58c2756d0109d793e0ae96 (diff) | |
| download | vim-ai-924e3a390f043e979f16113f6b0a55f8c54b1f5e.tar.gz | |
allow string in initial_prompt, closes #35
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | py/chat.py | 2 | ||||
| -rw-r--r-- | py/complete.py | 2 | ||||
| -rw-r--r-- | py/utils.py | 8 |
4 files changed, 11 insertions, 3 deletions
@@ -252,7 +252,7 @@ END " :AIChat " - options: openai config (see https://platform.openai.com/docs/api-reference/chat) -" - options.initial_prompt: prompt prepended to every chat request +" - options.initial_prompt: prompt prepended to every chat request (list of lines or string) " - options.request_timeout: request timeout in seconds " - options.selection_boundary: seleciton prompt wrapper (eliminates empty responses, see #20) " - ui.populate_options: put [chat-options] to the chat header @@ -2,7 +2,7 @@ plugin_root = vim.eval("s:plugin_root") vim.command(f"py3file {plugin_root}/py/utils.py") -config = vim.eval("l:config") +config = normalize_config(vim.eval("l:config")) config_options = config['options'] config_ui = config['ui'] prompt = vim.eval("l:prompt").strip() diff --git a/py/complete.py b/py/complete.py index fed66c4..c8d45fe 100644 --- a/py/complete.py +++ b/py/complete.py @@ -2,7 +2,7 @@ plugin_root = vim.eval("s:plugin_root") vim.command(f"py3file {plugin_root}/py/utils.py") -config = vim.eval("l:config") +config = normalize_config(vim.eval("l:config")) engine = config['engine'] config_options = config['options'] openai_options = make_openai_options(config_options) diff --git a/py/utils.py b/py/utils.py index 8539347..76ae1e4 100644 --- a/py/utils.py +++ b/py/utils.py @@ -26,6 +26,14 @@ def load_api_key(): raise Exception("Missing OpenAI API key") return api_key.strip() +def normalize_config(config): + normalized = { **config } + # initial prompt can be both a string and a list of strings, normalize it to list + if 'initial_prompt' in config['options'] and isinstance(config['options']['initial_prompt'], str): + normalized['options']['initial_prompt'] = normalized['options']['initial_prompt'].split('\n') + return normalized + + def make_openai_options(options): max_tokens = int(options['max_tokens']) return { |