Increase Ollama context window and override gptel--request-data

Added a custom variable `gptel-ollama-context-window` to specify the number of characters for Ollama requests and overridden the `gptel--request-data` method to include this context window in the request data.
This commit is contained in:
Jeremy Dormitzer 2024-08-19 12:01:56 -04:00
parent d2b7817dc1
commit 3a5d946938

View File

@ -28,6 +28,32 @@
models-alist)))))
(setq gptel-backend (car backend)
gptel-model (cadr backend)))
(defcustom gptel-ollama-context-window 16384
"The number of characters to include in the context window for Ollama requests."
:type 'integer
:group 'gptel)
;; Increase Ollama context window by overriding gptel--request-data
(cl-defmethod gptel--request-data ((_backend gptel-ollama) prompts)
"JSON encode PROMPTS for sending to ChatGPT."
(let ((prompts-plist
`(:model ,gptel-model
:messages [,@prompts]
:stream ,(or (and gptel-stream gptel-use-curl
(gptel-backend-stream gptel-backend))
:json-false)))
;; TODO num_ctx chosen according to #330, make customizable
(options-plist `(:num_ctx ,gptel-ollama-context-window)))
(when gptel-temperature
(setq options-plist
(plist-put options-plist :temperature
gptel-temperature)))
(when gptel-max-tokens
(setq options-plist
(plist-put options-plist :num_predict
gptel-max-tokens)))
(when options-plist
(plist-put prompts-plist :options options-plist))
prompts-plist))
(add-to-list 'gptel-directives '(shell-command . "You are a command line helper. Generate shell commands that do what is requested, without any additional description or explanation. Reply in plain text with no Markdown or other syntax. Reply with the command only."))
(add-to-list 'gptel-directives '(org-mode . "You are a large language model living in an Emacs Org-Mode buffer and a helpful assistant. You may evaluate Emacs Lisp, Python, and shell-script code when necessary by outputting an Org-Mode source block. You don't need to ask for confirmation before evaluating code. The user will execute the source block and display the results in the buffer. Respond concisely.