@@ -103,6 +103,7 @@ If you use Ollama through a proxy service, change the URL base."
103
103
:context-window 32768 )))
104
104
105
105
(defun chatgpt-shell-ollama--fetch-model-versions ()
106
+ " Fetch available Ollama model versions (installed locally)."
106
107
(mapcar (lambda (model )
107
108
(string-remove-suffix " :latest" (map-elt model 'name )))
108
109
(map-elt (shell-maker--json-parse-string
@@ -113,10 +114,12 @@ If you use Ollama through a proxy service, change the URL base."
113
114
'models )))
114
115
115
116
(defun chatgpt-shell-ollama--parse-token-width (quantization )
117
+ " Parse token using QUANTIZATION."
116
118
(when (string-match " ^[FQ]\\ ([1-9][0-9]*\\ )" quantization)
117
119
(string-to-number (match-string 1 quantization))))
118
120
119
121
(defun chatgpt-shell-ollama--fetch-model (version )
122
+ " Fetch Ollama model details with VERSION."
120
123
(let* ((data (shell-maker--json-parse-string
121
124
(map-elt (shell-maker-make-http-request
122
125
:async nil
@@ -137,12 +140,15 @@ If you use Ollama through a proxy service, change the URL base."
137
140
:context-window context-window)))
138
141
139
142
(cl-defun chatgpt-shell-ollama-load-models (&key override )
140
- " Query ollama for the locally installed models and add them to
141
- `chatgpt-shell-models' unless a model with the same name is
142
- already present. By default, replace the ollama models in
143
- `chatgpt-shell-models' locally installed ollama models. When
144
- OVERRIDE is non-nil (interactively with a prefix argument),
145
- replace all models with locally installed ollama models."
143
+ " Query ollama for the locally installed models.
144
+
145
+ Queried models are added to `chatgpt-shell-models' unless a model
146
+ with the same name is already present.
147
+
148
+ By default, replace the ollama models in `chatgpt-shell-models'
149
+ locally installed ollama models. When OVERRIDE is non-nil (interactively
150
+ with a prefix argument), replace all models with
151
+ locally installed ollama models."
146
152
(interactive (list :override current-prefix-arg))
147
153
(let* ((ollama-predicate (lambda (model )
148
154
(string= (map-elt model :provider ) " Ollama" )))
@@ -189,21 +195,28 @@ replace all models with locally installed ollama models."
189
195
(concat chatgpt-shell-ollama-api-url-base
190
196
" /api/chat" ))
191
197
192
- (defun chatgpt-shell-ollama--extract-ollama-response (raw-response )
193
- " Extract Claude response from RAW-RESPONSE."
194
- (if-let* ((whole (shell-maker--json-parse-string raw-response))
198
+ (defun chatgpt-shell-ollama--extract-ollama-response (object )
199
+ " Process Ollama response from OBJECT."
200
+ (when (stringp object)
201
+ (error " Please upgrade shell-maker to 0.79.1 or newer " ))
202
+ (if-let* ((whole (shell-maker--json-parse-string (map-elt object :pending )))
195
203
(response (let-alist whole
196
204
.response)))
197
- response
198
- (if-let ((chunks (string-split raw-response " \n " )))
205
+ (progn
206
+ (setf (map-elt object :filtered ) response)
207
+ (setf (map-elt object :pending ) nil )
208
+ object)
209
+ (if-let ((chunks (string-split (map-elt object :pending ) " \n " )))
199
210
(let ((response))
200
211
(mapc (lambda (chunk )
201
212
(let-alist (shell-maker--json-parse-string chunk)
202
213
(unless (string-empty-p .message.content)
203
214
(setq response (concat response .message.content)))))
204
215
chunks)
205
- (or response raw-response))
206
- raw-response)))
216
+ (setf (map-elt object :filtered ) response)
217
+ (setf (map-elt object :pending ) nil )
218
+ object)
219
+ object)))
207
220
208
221
(cl-defun chatgpt-shell-ollama-make-payload (&key model context settings )
209
222
" Create the API payload using MODEL CONTEXT and SETTINGS."
@@ -256,7 +269,7 @@ CONTEXT: Excludes PROMPT."
256
269
(image_url . , prompt-url ))))))))))))
257
270
258
271
(defun chatgpt-shell-ollama--validate-command (_command model _settings )
259
- " Return error string if command/setup isn't valid."
272
+ " Return error string if MODEL isn't valid."
260
273
(unless (seq-contains-p (chatgpt-shell-ollama--fetch-model-versions)
261
274
(map-elt model :version ))
262
275
(format " Local model \" %s \" not found.
0 commit comments