generated from kyoh86/denops-boilerplate.vim
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ollama.txt
346 lines (287 loc) · 11.5 KB
/
ollama.txt
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
*ollama.txt* A Vim plugin as to chat with Ollama.
*ollama* *denops-ollama.vim* *denops-ollama.txt*
Author: kyoh86 <[email protected]>
License: MIT License
==============================================================================
*ollama-contents*
Contents ~
Install |ollama-install|
Customize |ollama-custom|
Function |ollama-function|
Commands |ollama-commands|
Keymaps |ollama-keymaps|
Denops commands |ollama-denops-commands|
Other references |ollama-references|
==============================================================================
*ollama-install*
Install ~
You need to install |denops.vim| and ollama.ai as dependencies.
* vim-denops/denops.vim https://github.com/vim-denops/denops.vim
* ollama https://ollama.ai
If you want to use it, run ollama background with a model you like in local. >
$ ollama pull codellama
$ ollama serve
<
Ollama provides systemd unit for Linux, so if you are using it in Linux, you
can start it with `systemctl`. >
$ systemctl start ollama
<
See: |ollama-faq|
Then, you can call |ollama#start_chat()| with the model name. >
call ollama#start_chat({'model': 'codellama'})
<
==============================================================================
*ollama-custom*
Customize ~
This plugin only provides some vim functions and commands like
|ollama#start_chat()| that have simple and flexible interface.
But also they are not convenience to use naively for each time.
So we may some customize them with following methods.
- Create commands or keymaps to call functions instantly, for example: >
command! Codellama call ollama#start_chat({'model': 'codellama'})
<
- Pre-set arguments for each functions using |ollama#custom#set_func_arg()|
and |ollama#custom#patch_args()|.
For example, we can pre-set "model" argument of the |ollama#start_chat()|: >
call ollama#custom#set_func_arg("start_chat", "model", "codellama")
<
Then, calling it without the argument: >
call ollama#start_chat({})
<
is equivalent to calling it like this: >
call ollama#start_chat({"model": "codellama"})
<
Using |ollama#custom#patch_args()|, we can pre-set some arguments at once: >
call ollama#custom#patch_args({
\ 'start_chat': {
\ 'model': 'codellama',
\ 'opener': 'new',
\ },
\ 'open_log': {
\ 'opener': 'tabnew',
\ }
\ })
<
And |ollama#custom#patch_args()| can accept `'_'` as a function name: >
call ollama#custom#patch_args({
\ '_': { 'baseUrl': 'http://localhost:33256/' }
\ })
<
It applies arguments across all functions.
==============================================================================
*ollama-function*
Function ~
*ollama#open_log()*
ollama#open_log({args})
Open Ollama log file.
{args} is a dictionary having fields in below.
- opener (Optional) How the new window be placed:
tabnew (DEFAULT) open a new tab
split, new open a new split
vsplit, vnew open a new vertical split
edit open in the current window
Example 1: Open log >
:call ollama#open_log({})
<
Example 2: Open log in new window (split horizontal)>
:call ollama#open_log({'opener': 'new'})
<
*ollama#start_chat()*
ollama#start_chat({args})
Start chat with Ollama
{args} is a dictionary having fields in below.
- model Ollama model name. |ollama-api-definition|
- opener (Optional) How the new window be placed:
tabnew (DEFAULT) open a new tab
split, new open a new split
vsplit, vnew open a new vertical split
edit open in the current window
- timeout (Optional) Time limit.
- baseUrl (Optional) The base of the URL to request.
(Default: "http://localhost:11434")
- message (Optional) Prompt to be passed to Ollama.
When this is specified, Ollama takes it
immediately and begins its reply.
- images (Optional) A list of base64-encoded images
(for multimodal models such as llava)
- options (Optional) Additional model parameters listed in the
documentation for the Modelfile such as temperature
- system (Optional) System message to (overrides what is
defined in the Modelfile)
Example 1: Start a chat with the local Ollama server with
"codellama" model. >
call ollama#start_chat({'model': 'codellama'})
<
Example 2: Start a new chat with the remote Ollama server. >
call ollama#start_chat({
\ 'model': 'codellama',
\ 'baseUrl': 'http://your-remote-server'})
<
Example 3: Start a chat with a initial prompt. >
call ollama#start_chat({
\ 'model': 'codellama',
\ 'message': 'What is your favorite color?'})
<
*ollama#start_chat_in_ctx()*
ollama#start_chat_in_ctx({args})
Start chat with Ollama with the context.
{args} is a dictionary having fields in below.
- model Ollama model name. |ollama-api-definition|
- context Specifies what kind of context should be passed to
Ollama in advance. It supports the following entries:
- headMessage A first message to be sent.
- selection If the selection be sent.
- currentBuffer If the current buffer be sent.
- buffers A list of the bufinfo. It accepts
buffer number or name (see |bufnr()|)
or objects from |getbufinfo()| that
has "bufnr" and "name" fields.
- lastMessage A last message to be sent.
- opener (Optional) How the new window be placed:
tabnew (Default) open a new tab
split, new open a new split
vsplit, vnew open a new vertical split
edit open in the current window
- timeout (Optional) Time limit.
- baseUrl (Optional) The base of the URL to request.
(Default: "http://localhost:11434")
- message (Optional) Prompt to be passed to Ollama. When this is
specified, Ollama takes it immediately and
begins its reply.
- options (Optional) Additional model parameters listed in the
documentation for the Modelfile such as temperature
Example 1: Start a new chat based on the selection text. >
call ollama#start_chat({
\ 'model': 'codellama',
\ 'context': {'selection': v:true}})
<
Example 2: Start a new chat on the current buffer. >
call ollama#start_chat({
\ 'model': 'codellama',
\ 'context': {'currentBuffer': v:true}})
<
Example 3: Start a new chat on the listed buffers. >
call ollama#start_chat_in_ctx({
\ 'model': 'codellama',
\ 'context': {
\ 'buffers': getbufinfo({'buflisted': v:true})->map({
\ _, val -> #{bufnr: val.bufnr, name: val.name}
\ })
\ }})
<
Example 4: Start a new chat on the listed "normal" buffers. >
call ollama#start_chat_in_ctx({
\ 'model': 'codellama',
\ 'context': {
\ 'buffers': getbufinfo({'buflisted': v:true})->filter({
\ _, val -> getbufvar(val.bufnr, '&buftype', '') == '' && val.name != ''
\ })->map({
\ _, val -> #{bufnr: val.bufnr, name: val.name}
\ })
\ }})
<
*ollama#complete()*
ollama#complete({args})
Get completion for the current buffer around the cursor with codellama
model.
{args} is a dictionary having fields in below.
- model Ollama model name supporting completion (like
codellama). |ollama-api-definition|
- callback A function should take response.
- timeout (Optional) Time limit.
- baseUrl (Optional) The base of the URL to request.
(Default: "http://localhost:11434")
- images (Optional) A list of base64-encoded images
(for multimodal models such as llava)
- options (Optional) Additional model parameters listed in the
documentation for the Modelfile such as temperature
- system (Optional) System message to (overrides what is
defined in the Modelfile)
Example: Request completion and echo it. >
:call ollama#complete({
\ 'model': 'codellama',
\ 'callback': {msg -> execute("echomsg " .. msg)}})
<
*ollama#list_models()*
ollama#list_models({args})
Show list models in local.
{args} is a dictionary having fields in below.
- timeout (Optional) Time limit.
- baseUrl (Optional) The base of the URL to request.
(Default: "http://localhost:11434")
Example: >
:call ollama#list_models({})
<
*ollama#pull_model()*
ollama#pull_model({args})
Pull a model from the library.
{args} is a dictionary having fields in below.
- name Ollama model name. |ollama-api-definition|
- insecure (Optional) If it is true, allow insecure connections
to the library.
- timeout (Optional) Time limit.
- baseUrl (Optional) The base of the URL to request.
(Default: "http://localhost:11434")
Example: >
:call ollama#pull_model({'model': 'codellama'})
<
*ollama#delete_model()*
ollama#delete_model({args})
Delete a model in local.
{args} is a dictionary having fields in below.
- name Ollama model name. |ollama-api-definition|
- timeout (Optional) Time limit.
- baseUrl (Optional) The base of the URL to request.
(Default: "http://localhost:11434")
Example: >
:call ollama#delete_model({'model': 'codellama'})
<
==============================================================================
*ollama-commands*
Commands ~
==============================================================================
*ollama-keymaps*
Keymaps ~
==============================================================================
*ollama-common-options*
Common options ~
You can set args for each functions before calling it.
For example, you can call "start_chat" with a model "codellama", you can set
the "model" arg with |ollama#custom#set_func_arg| >
call ollama#custom#set_func_arg('start_chat', 'model', 'codellama')
call ollama#start_chat({})
# it equals to calling with "model" arg like this:
# call ollama#start_chat(`{'model': 'codellama'})
<
*ollama#custom#set_func_arg*
ollama#custom#set_func_arg({function_name}, {arg_name}, {value})
Set an argument value for a function.
But also you can set them for all function with using `'_'` for
{function_name}. >
call ollama#custom#set_func_arg('_', 'model', 'codellama')
# It means that the 'model' arg for all functions is
# 'codellama'
<
*ollama#custom#patch_func_args*
ollama#custom#patch_func_args({function_name}, {args})
Patch all argument values for a function.
But also you can set them for all function with using `'_'` for
{function_name}. >
call ollama#custom#set_func_arg('_', {
'model': 'codellama',
'baseUrl': 'http://example.com:11434',
})
# It specifies that the 'model' and 'baseUrl' arguments
# should use the specified values for all functions.
<
==============================================================================
*ollama-references*
Other references ~
*ollama-api-definition*
API definitions ~
See https://github.com/jmorganca/ollama/blob/main/docs/api.md
*ollama-faq*
Ollama FAQ ~
See https://github.com/ollama/ollama/blob/main/docs/faq.md
==============================================================================
" vim:tw=78:ts=8:sw=8:ft=help:norl:noet:fen: