diff options
| author | Martin Bielik <mx.bielik@gmail.com> | 2024-03-09 18:32:45 +0100 |
|---|---|---|
| committer | Martin Bielik <mx.bielik@gmail.com> | 2024-03-09 18:32:45 +0100 |
| commit | bdd1069562967bd07921e75873d54eb75d62144d (patch) | |
| tree | 270a4e3fe06122e57994d384bff2d3a245d0a714 | |
| parent | b0f7e3b8d92289d1a8086e3eed206f8b5757328b (diff) | |
| download | vim-ai-bdd1069562967bd07921e75873d54eb75d62144d.tar.gz | |
parse role options
Diffstat (limited to '')
| -rw-r--r-- | py/chat.py | 3 | ||||
| -rw-r--r-- | py/complete.py | 3 | ||||
| -rw-r--r-- | py/utils.py | 28 |
3 files changed, 27 insertions, 7 deletions
@@ -8,7 +8,8 @@ prompt, role_options = parse_prompt_and_role(vim.eval("l:prompt")) config = normalize_config(vim.eval("l:config")) config_options = { **config['options'], - **role_options, + **role_options['options_default'], + **role_options['options_chat'], } config_ui = config['ui'] diff --git a/py/complete.py b/py/complete.py index 453ef46..f340e96 100644 --- a/py/complete.py +++ b/py/complete.py @@ -10,7 +10,8 @@ engine = config['engine'] prompt, role_options = parse_prompt_and_role(vim.eval("l:prompt")) config_options = { **config['options'], - **role_options, + **role_options['options_default'], + **role_options['options_complete'], } openai_options = make_openai_options(config_options) http_options = make_http_options(config_options) diff --git a/py/utils.py b/py/utils.py index 7a1a574..52e538d 100644 --- a/py/utils.py +++ b/py/utils.py @@ -269,19 +269,37 @@ def load_role_config(role): roles.read(roles_config_path) if not role in roles: raise KnownError(f"Role {role} not found") # TODO handle errors - return roles[role] + + options = roles[f"{role}.options"] if f"{role}.options" in roles else {} + options_complete =roles[f"{role}.options-complete"] if f"{role}.options-complete" in roles else {} + options_chat = roles[f"{role}.options-chat"] if f"{role}.options-chat" in roles else {} + + return { + 'role': dict(roles[role]), + 'options': { + 'options_default': dict(options), + 'options_complete': dict(options_complete), + 'options_chat': dict(options_chat), + }, + } + +empty_role_options = { + 'options_default': {}, + 'options_complete': {}, + 'options_chat': {}, +} def parse_prompt_and_role(raw_prompt): prompt = raw_prompt.strip() role = re.split(' |:', prompt)[0] if not role.startswith('/'): # does not require role - return (prompt, {}) + return (prompt, empty_role_options) prompt = prompt[len(role):].strip() role = role[1:] - role_config = load_role_config(role) + config = load_role_config(role) delim = '' if prompt.startswith(':') else ':\n' - prompt = role_config['prompt'] + delim + prompt - return (prompt, {}) + prompt = config['role']['prompt'] + delim + prompt + return (prompt, config['options']) |