Skip to content

Commit

Permalink
gptel-ollama: Merge request options correctly (#473, #490)
Browse files Browse the repository at this point in the history
* gptel-ollama.el (gptel--request-data): Merge request options for
an Ollama request specified by the model/backend configuration and
gptel options (like `gptel-temperature') correctly.
  • Loading branch information
andrewdea authored Dec 13, 2024
1 parent 4b784cb commit 859e7c7
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions gptel-ollama.el
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,27 @@ Intended for internal use only.")
(push (list :role "system"
:content gptel--system-message)
prompts))
(let ((prompts-plist
`(:model ,(gptel--model-name gptel-model)
:messages [,@prompts]
:stream ,(or (and gptel-stream gptel-use-curl
(gptel-backend-stream gptel-backend))
:json-false)))
options-plist)
(when gptel-temperature
(let* ((prompts-plist
(gptel--merge-plists
`(:model ,(gptel--model-name gptel-model)
:messages [,@prompts]
:stream ,(or (and gptel-stream gptel-use-curl
(gptel-backend-stream gptel-backend))
:json-false))
(gptel-backend-request-params gptel-backend)
(gptel--model-request-params gptel-model)))
;; the initial options (if any) from request params
(options-plist (plist-get prompts-plist :options)))

;; if the temperature and max-tokens aren't set as
;; backend/model-specific, use the global settings
(when (and gptel-temperature (not (plist-get options-plist :temperature)))
(setq options-plist
(plist-put options-plist :temperature
gptel-temperature)))
(when gptel-max-tokens
(plist-put options-plist :temperature gptel-temperature)))
(when (and gptel-max-tokens (not (plist-get options-plist :num_predict)))
(setq options-plist
(plist-put options-plist :num_predict
gptel-max-tokens)))
;; FIXME: These options will be lost if there are model/backend-specific
;; :options, since `gptel--merge-plists' does not merge plist values
;; recursively.
(when options-plist
(plist-put prompts-plist :options options-plist))
;; Merge request params with model and backend params.
(gptel--merge-plists
prompts-plist
(gptel-backend-request-params gptel-backend)
(gptel--model-request-params gptel-model))))
(plist-put options-plist :num_predict gptel-max-tokens)))
(plist-put prompts-plist :options options-plist)))

(cl-defmethod gptel--parse-list ((_backend gptel-ollama) prompt-list)
(cl-loop for text in prompt-list
Expand Down

0 comments on commit 859e7c7

Please sign in to comment.