From 2a418adca13bc7f8d4b35a4a1ec83fe0e5aedd91 Mon Sep 17 00:00:00 2001 From: Martin Bielik Date: Mon, 16 Dec 2024 23:13:35 +0100 Subject: new role syntax --- tests/context_test.py | 5 ++- tests/deprecated_role_syntax_test.py | 83 ++++++++++++++++++++++++++++++++++++ tests/resources/roles.ini | 33 ++++++++++---- tests/roles_test.py | 10 +++++ 4 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 tests/deprecated_role_syntax_test.py create mode 100644 tests/roles_test.py (limited to 'tests') diff --git a/tests/context_test.py b/tests/context_test.py index 869215d..1e179f1 100644 --- a/tests/context_test.py +++ b/tests/context_test.py @@ -1,7 +1,7 @@ -import vim from context import make_ai_context, make_prompt default_config = { + "engine": "chat", "options": { "model": "gpt-4o", "endpoint_url": "https://api.openai.com/v1/chat/completions", @@ -81,6 +81,7 @@ def test_role_config_different_commands(): assert 'preset_tab' == actual_config['ui']['open_chat_command'] assert 'hello' == actual_prompt assert 'https://localhost/chat' == actual_config['options']['endpoint_url'] + assert 'chat' == actual_config['engine'] context = make_ai_context({ **base, 'command_type': 'complete' }) actual_config = context['config'] @@ -89,6 +90,7 @@ def test_role_config_different_commands(): assert '0' == actual_config['ui']['paste_mode'] assert 'hello' == actual_prompt assert 'https://localhost/complete' == actual_config['options']['endpoint_url'] + assert 'complete' == actual_config['engine'] context = make_ai_context({ **base, 'command_type': 'edit' }) actual_config = context['config'] @@ -97,6 +99,7 @@ def test_role_config_different_commands(): assert '0' == actual_config['ui']['paste_mode'] assert 'hello' == actual_prompt assert 'https://localhost/edit' == actual_config['options']['endpoint_url'] + assert 'complete' == actual_config['engine'] def test_multiple_role_configs(): context = make_ai_context({ diff --git a/tests/deprecated_role_syntax_test.py b/tests/deprecated_role_syntax_test.py new file mode 100644 index 0000000..19744b9 --- /dev/null +++ b/tests/deprecated_role_syntax_test.py @@ -0,0 +1,83 @@ +from context import make_ai_context, make_prompt + +default_config = { + "options": { + "model": "gpt-4o", + "endpoint_url": "https://api.openai.com/v1/chat/completions", + "max_tokens": "0", + "max_completion_tokens": "0", + "temperature": "1", + "request_timeout": "20", + "stream": "1", + "enable_auth": "1", + "token_file_path": "", + "selection_boundary": "", + "initial_prompt": "You are a general assistant.", + }, + "ui": { + "open_chat_command": "preset_below", + "scratch_buffer_keep_open": "0", + "populate_options": "0", + "code_syntax_enabled": "1", + "paste_mode": "1", + }, +} + +def test_role_config(): + context = make_ai_context({ + 'config_default': default_config, + 'config_extension': {}, + 'user_instruction': '/deprecated-test-role-simple user instruction', + 'user_selection': 'selected text', + 'command_type': 'chat', + }) + actual_config = context['config'] + actual_prompt = context['prompt'] + assert 'o1-preview' == actual_config['options']['model'] + assert 'simple role prompt:\nuser instruction:\nselected text' == actual_prompt + +def test_role_config_different_commands(): + base = { + 'config_default': default_config, + 'config_extension': {}, + 'user_instruction': '/deprecated-test-role hello', + 'user_selection': '', + } + context = make_ai_context({ **base, 'command_type': 'chat' }) + actual_config = context['config'] + actual_prompt = context['prompt'] + assert 'model-common' == actual_config['options']['model'] + assert '0' == actual_config['ui']['paste_mode'] + assert 'preset_tab' == actual_config['ui']['open_chat_command'] + assert 'hello' == actual_prompt + assert 'https://localhost/chat' == actual_config['options']['endpoint_url'] + + context = make_ai_context({ **base, 'command_type': 'complete' }) + actual_config = context['config'] + actual_prompt = context['prompt'] + assert 'model-common' == actual_config['options']['model'] + assert '0' == actual_config['ui']['paste_mode'] + assert 'hello' == actual_prompt + assert 'https://localhost/complete' == actual_config['options']['endpoint_url'] + + context = make_ai_context({ **base, 'command_type': 'edit' }) + actual_config = context['config'] + actual_prompt = context['prompt'] + assert 'model-common' == actual_config['options']['model'] + assert '0' == actual_config['ui']['paste_mode'] + assert 'hello' == actual_prompt + assert 'https://localhost/edit' == actual_config['options']['endpoint_url'] + +def test_multiple_role_configs(): + context = make_ai_context({ + 'config_default': default_config, + 'config_extension': {}, + 'user_instruction': '/deprecated-test-role /deprecated-test-role-simple hello', + 'user_selection': '', + 'command_type': 'chat', + }) + actual_config = context['config'] + actual_prompt = context['prompt'] + assert 'o1-preview' == actual_config['options']['model'] + assert 'https://localhost/chat' == actual_config['options']['endpoint_url'] + assert 'simple role prompt:\nhello' == actual_prompt diff --git a/tests/resources/roles.ini b/tests/resources/roles.ini index 66b77ca..16335d3 100644 --- a/tests/resources/roles.ini +++ b/tests/resources/roles.ini @@ -1,18 +1,35 @@ [test-role-simple] prompt = simple role prompt -[test-role-simple.options] -model = o1-preview +config.options.model = o1-preview [test-role] -[test-role.options] +config.options.model = model-common +config.ui.paste_mode = 0 +[test-role.chat] +config.options.endpoint_url = https://localhost/chat +config.ui.open_chat_command = preset_tab +[test-role.complete] +config.engine = complete +config.options.endpoint_url = https://localhost/complete +[test-role.edit] +config.engine = complete +config.options.endpoint_url = https://localhost/edit + +[deprecated-test-role-simple] +prompt = simple role prompt +[deprecated-test-role-simple.options] +model = o1-preview + +[deprecated-test-role] +[deprecated-test-role.options] model = model-common -[test-role.options-chat] +[deprecated-test-role.options-chat] endpoint_url = https://localhost/chat -[test-role.options-complete] +[deprecated-test-role.options-complete] endpoint_url = https://localhost/complete -[test-role.options-edit] +[deprecated-test-role.options-edit] endpoint_url = https://localhost/edit -[test-role.ui] +[deprecated-test-role.ui] paste_mode = 0 -[test-role.ui-chat] +[deprecated-test-role.ui-chat] open_chat_command = preset_tab diff --git a/tests/roles_test.py b/tests/roles_test.py new file mode 100644 index 0000000..3230329 --- /dev/null +++ b/tests/roles_test.py @@ -0,0 +1,10 @@ +from roles import load_ai_role_names + +def test_role_completion(): + role_names = load_ai_role_names() + assert role_names == [ + 'test-role-simple', + 'test-role', + 'deprecated-test-role-simple', + 'deprecated-test-role', + ] -- cgit v1.2.3