1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
|