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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
let s:plugin_root = expand('<sfile>:p:h:h')
let g:vim_ai_complete_default = {
\ "engine": "complete",
\ "options": {
\ "model": "gpt-3.5-turbo-instruct",
\ "endpoint_url": "https://api.openai.com/v1/completions",
\ "max_tokens": 1000,
\ "temperature": 0.1,
\ "request_timeout": 20,
\ "enable_auth": 1,
\ "selection_boundary": "#####",
\ },
\ "ui": {
\ "paste_mode": 1,
\ },
\}
let g:vim_ai_edit_default = {
\ "engine": "complete",
\ "options": {
\ "model": "gpt-3.5-turbo-instruct",
\ "endpoint_url": "https://api.openai.com/v1/completions",
\ "max_tokens": 1000,
\ "temperature": 0.1,
\ "request_timeout": 20,
\ "enable_auth": 1,
\ "selection_boundary": "#####",
\ },
\ "ui": {
\ "paste_mode": 1,
\ },
\}
let s:initial_chat_prompt =<< trim END
>>> system
You are a general assistant.
If you attach a code block add syntax type after ``` to enable syntax highlighting.
END
let g:vim_ai_chat_default = {
\ "options": {
\ "model": "gpt-3.5-turbo",
\ "endpoint_url": "https://api.openai.com/v1/chat/completions",
\ "max_tokens": 1000,
\ "temperature": 1,
\ "request_timeout": 20,
\ "enable_auth": 1,
\ "selection_boundary": "",
\ "initial_prompt": s:initial_chat_prompt,
\ },
\ "ui": {
\ "open_chat_command": "preset_below",
\ "scratch_buffer_keep_open": 0,
\ "populate_options": 0,
\ "code_syntax_enabled": 1,
\ "paste_mode": 1,
\ },
\}
if !exists("g:vim_ai_open_chat_presets")
let g:vim_ai_open_chat_presets = {
\ "preset_below": "below new | call vim_ai#MakeScratchWindow()",
\ "preset_tab": "tabnew | call vim_ai#MakeScratchWindow()",
\ "preset_right": "rightbelow 55vnew | setlocal noequalalways | setlocal winfixwidth | call vim_ai#MakeScratchWindow()",
\}
endif
if !exists("g:vim_ai_debug")
let g:vim_ai_debug = 0
endif
if !exists("g:vim_ai_debug_log_file")
let g:vim_ai_debug_log_file = "/tmp/vim_ai_debug.log"
endif
if !exists("g:vim_ai_token_file_path")
let g:vim_ai_token_file_path = "~/.config/openai.token"
endif
if !exists("g:vim_ai_roles_config_file")
let g:vim_ai_roles_config_file = s:plugin_root . "/roles-example.ini"
endif
function! vim_ai_config#ExtendDeep(defaults, override) abort
let l:result = a:defaults
for [l:key, l:value] in items(a:override)
if type(get(l:result, l:key)) is v:t_dict && type(l:value) is v:t_dict
call vim_ai_config#ExtendDeep(l:result[l:key], l:value)
else
let l:result[l:key] = l:value
endif
endfor
return l:result
endfunction
function! s:MakeConfig(config_name) abort
let l:defaults = copy(g:[a:config_name . "_default"])
let l:override = exists("g:" . a:config_name) ? g:[a:config_name] : {}
let g:[a:config_name] = vim_ai_config#ExtendDeep(l:defaults, l:override)
endfunction
call s:MakeConfig("vim_ai_chat")
call s:MakeConfig("vim_ai_complete")
call s:MakeConfig("vim_ai_edit")
function! vim_ai_config#load()
" nothing to do - triggers autoloading of this file
endfunction
|