144
144
`(progn
145
145
(openai--pop-to-buffer codegpt-buffer-name) ; create it
146
146
(openai--with-buffer codegpt-buffer-name
147
- (codegpt-mode)
148
- (erase-buffer )
149
- (insert , instruction " \n\n " )
150
- ,@body )))
147
+ (codegpt-mode)
148
+ (erase-buffer )
149
+ (insert , instruction " \n\n " )
150
+ ,@body )))
151
151
152
152
(defun codegpt--fill-region (start end )
153
153
" Like function `fill-region' (START to END), improve readability."
@@ -169,43 +169,43 @@ boundaries of that region in buffer."
169
169
(let ((text (string-trim (buffer-substring start end)))
170
170
(original-window (selected-window )))
171
171
(codegpt--ask-in-buffer instruction
172
- (insert text " \n\n " )
173
- (funcall
174
- (cl-case codegpt-tunnel
175
- (`completion #'openai-completion )
176
- (`chat #'openai-chat ))
177
- (cl-case codegpt-tunnel
178
- (`completion (buffer-string ))
179
- (`chat `[((" role" . " user" )
180
- (" content" . ,(buffer-string )))]))
181
- (lambda (data )
182
- (setq codegpt-requesting-p nil )
183
- (codegpt-mode--cancel-timer)
184
- (openai--with-buffer codegpt-buffer-name
185
- (openai--pop-to-buffer codegpt-buffer-name)
186
- (let ((original-point (point )))
187
- (cl-case codegpt-tunnel
188
- (`completion
189
- (let* ((choices (openai--data-choices data))
190
- (result (openai--get-choice choices)))
191
- (insert (string-trim result) " \n " )))
192
- (`chat
193
- (let ((choices (let-alist data .choices))
194
- (result))
195
- (mapc (lambda (choice )
196
- (let-alist choice
197
- (let-alist .message
198
- (setq result (string-trim .content)))))
199
- choices)
200
- (insert (string-trim result) " \n " ))))
201
- (codegpt--fill-region original-point (point ))))
202
- (unless codegpt-focus-p
203
- (select-window original-window)))
204
- :model codegpt-model
205
- :max-tokens codegpt-max-tokens
206
- :temperature codegpt-temperature)
207
- (unless codegpt-focus-p
208
- (select-window original-window)))))
172
+ (insert text " \n\n " )
173
+ (funcall
174
+ (cl-case codegpt-tunnel
175
+ (`completion #'openai-completion )
176
+ (`chat #'openai-chat ))
177
+ (cl-case codegpt-tunnel
178
+ (`completion (buffer-string ))
179
+ (`chat `[((" role" . " user" )
180
+ (" content" . ,(buffer-string )))]))
181
+ (lambda (data )
182
+ (setq codegpt-requesting-p nil )
183
+ (codegpt-mode--cancel-timer)
184
+ (openai--with-buffer codegpt-buffer-name
185
+ (openai--pop-to-buffer codegpt-buffer-name)
186
+ (let ((original-point (point )))
187
+ (cl-case codegpt-tunnel
188
+ (`completion
189
+ (let* ((choices (openai--data-choices data))
190
+ (result (openai--get-choice choices)))
191
+ (insert (string-trim result) " \n " )))
192
+ (`chat
193
+ (let ((choices (let-alist data .choices))
194
+ (result))
195
+ (mapc (lambda (choice )
196
+ (let-alist choice
197
+ (let-alist .message
198
+ (setq result (string-trim .content)))))
199
+ choices)
200
+ (insert (string-trim result) " \n " ))))
201
+ (codegpt--fill-region original-point (point ))))
202
+ (unless codegpt-focus-p
203
+ (select-window original-window)))
204
+ :model codegpt-model
205
+ :max-tokens codegpt-max-tokens
206
+ :temperature codegpt-temperature)
207
+ (unless codegpt-focus-p
208
+ (select-window original-window)))))
209
209
210
210
;;;### autoload
211
211
(defun codegpt-doc (start end )
0 commit comments