Repository navigation
Replies: 5 comments 15 replies
|
Thanks for the feedback. I'd like to make
Well, it's not encouraging if it's painful for simple things! Parameters/Hermeticity
You can let-bind or preset-bind everything. Is there something that must be specified as a parameter in the
What would be the values of the various gptel parameters in the hermetic mode? (
It's not clear what specifically you mean by a "clean slate" here? Whatever these clean slate values are to you, you can define a preset and then apply them? (gptel-make-preset 'hermetic
:use-context nil
:use-tools nil
:system nil
:include-reasoning nil)
(gptel-with-preset 'hermetic
(gptel-request ...))Structured Responses
The rest of this section is not describing JSON schemas/parsing, so I'm not sure what you mean.
I agree, but this is only slightly simpler than the current API, which folds the
Not ideal but not bad enough to be worth breaking the API either. One thing on my TODO list is to provide a helper (gptel-request prompt
:callback
(gptel-make-callback
:response #'handle-response
:reasoning #'handle-reasoning
:tool-call #'handle-calls
:tool-result #'handle-results
:abort #'handle-abort
:error #'handle-error))Where the
Futures/Promises
Yes, it should be easy to wrap gptel's callbacks into a futures/promises library without requiring any changes to gptel. gptel will not depend on any async executors that aren't part of Emacs. (And even there, I'm not going to use the
Me too.
I have been working on this now and then. See the I stopped working on it because I got ideas for a pretty different approach, but |
Parameters/Hermeticity(gptel-make-preset 'gptel-default
:use-tools t :tools nil
:use-context t :context nil
:max-tokens nil
:stream nil
:temperature nil
:track-media nil
:request-params nil
:system nil
:include-reasoning 'ignore)
(defun gptel-request-default (prompt &rest args)
"Run `gptel-request' with gptel's default settings.
PROMPT is the request prompt, and ARGS is a plist of
keyword arguments to `gptel-request'."
(gptel-with-preset 'gptel-default
(apply #'gptel-request prompt args)))I could add something like this to gptel, then Does this meet your needs? |
Parameters/HermeticityFor comparison with the other proposal(s), here is what the (cl-defun gptel-request
(&optional prompt &key
callback
model
backend
reasoning-effort ;not implemented yet, but coming to gptel
tools
cache
context ;value of gptel-context
request-params
max-tokens
num-messages-to-send
temperature
org-convert-response
proxy
track-media
track-response
use-curl
(buffer (current-buffer))
position
state ;callback state, previously `context'
dry-run
(stream nil)
(in-place nil)
(system gptel--system-message)
schema
transforms
(fsm (gptel-make-fsm))))Here is what it looks like if you also encode parameters relevant to the default callbacks (technically the purview of (cl-defun gptel-request
(&optional prompt &key
callback
model
backend
reasoning-effort ;not implemented yet, but coming to gptel
tools
cache
context ;value of gptel-context
request-params
num-messages-to-send
max-tokens
temperature
org-convert-response
proxy
track-media
track-response
use-curl
(buffer (current-buffer))
position
state ;callback state, previously `context'
dry-run
(stream nil)
(in-place nil)
(system gptel--system-message)
schema
transforms
(fsm (gptel-make-fsm))
;; UI-related gptel settings
include-reasoning
confirm-tool-calls
include-tool-results))And here is what it looks like if you move all the gptel variables to a plist (cl-defun gptel-request
(&optional prompt &key
callback
buffer
position
context
dry-run
in-place
transforms
state-or-preset))Note that this last one is equivalent to doing the following right now: (gptel-with-preset state-or-preset
(gptel-request prompt
:callback ...
:buffer ...
:position ...
:context ...
:dry-run nil
:in-place nil
:transforms ...)) |
|
In 00e7e12 I have added the ( :description "Use gptel's default configuration."
:context nil :use-context system
:tools nil :use-tools t
:temperature nil :max-tokens nil
:num-messages-to-send nil
:request-params nil
:org-convert-response t
:track-media nil
:track-response t
:system nil
:stream t
:cache nil)Note that it sets |
|
For completeness:
You've probably solved this already, but for the reader's reference, the recommended way to do this with gptel is to use Simple approach(gptel-with-preset
'( :parents gptel-default
:system "System message for tagging Org notes here"
:model model-for-org-tagging
:backend "SomeBackendName")
(gptel-request "Text of captured entry"
:callback #'org-tagging-callback))Or, if you register the preset ahead of time as (gptel-with-preset 'org-annotator
(gptel-request "Text of captured entry"
:callback #'org-tagging-callback))More sophisticated approachesStructured outputIf you want structured (JSON) output, you can add :schema "[tag]" ;get a JSON array of "tag"s and nothing elseor :schema "tags, todo_state, priority" ;get a JSON object with metadata for the Org noteSee Additional context, user-determinedIf you want to include additional context for the LLM, such as linked Org notes or the contents of the buffer in which the note is captured, you can append that context anywhere you want.
(gptel-with-preset
`( :parents gptel-default
:system ,(lambda ()
;; find and append note context to the system prompt
(concat
"System message for tagging Org notes here\n"
(get-additional-context-for-captured-note)))
:model model-for-org-tagging
:backend "SomeBackendName")
(gptel-request "Text of captured entry"
:callback #'org-tagging-callback))
(gptel-with-preset
`( :parents gptel-default
:system "System message for tagging Org notes here"
:model model-for-org-tagging
:backend "SomeBackendName"
:context (:function (lambda (_)
;; Include full buffer where captured note is filed
(list (current-buffer)))))
(gptel-request "Text of captured entry"
:callback #'org-tagging-callback
:transforms (list 'gptel--transform-add-context)))
;; ↑
;; unfortunately context addition has to be explicitly specified
;; as a prompt transformation right now
There is no preferred method, and it's usually not worth the headache of opimizing context placement. For simple tasks it doesn't matter much to most (non-tiny) LLMs where you include the context. Additional context, LLM-determinedIf you want the LLM to find context it needs for annotating the entry instead, you'll have to call it with some tools so it can explore your Org notes. It will be up to the tools to prevent access to notes you don't want to expose. Supposing you have the elisp gptel tools (gptel-with-preset
`( :parents gptel-default
:system "System message for tagging Org notes here
(Instruct it to use tools)"
:model model-for-org-tagging
:backend "SomeBackendName"
:tools ("get_org_entry_id" ;List of tool names/objects
"get_org_link_contents"
"get_org_lineage"
"get_org_backlinks"))
(gptel-request "Text of captured entry"
:callback #'org-tagging-callback))Note that you'll have to ensure these tools don't require user confirmation, OR handle tool confirmation explicitly in If you don't want to write your own tools and use an Elisp/Org-mode MCP server to provide them instead (there are dozens of these): (gptel-with-preset
`( :parents gptel-default
:pre (lambda () ;Start MCP server if required
(gptel-mcp-connect (list "org-roam-explorer") 'sync))
:system "System message for tagging Org notes here
(Instruct it to use tools)"
:model model-for-org-tagging
:backend "SomeBackendName"
:tools ("mcp-org-roam-explorer")) ;tools from MCP server "foo" are assigned
;the category "mcp-foo"
(gptel-request "Text of captured entry"
:callback #'org-tagging-callback))You'll have to register this server (path to executable, command-line flags etc) in |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I'm trying to use
gptel-requestfrom elisp. It's relativelypainfulpainless for simple things but I'm running into a few sharp edges.Parameters/Hermeticity
Having to let-bind some things and pass others as parameters is annoying, especially because there's no way to know if I've managed to catch everything. It would be nice if there were some form of "hermetic" mode.
gptel-use-tools, andgptel-toolsare especially problematic as I usually want to make specific tools available when writing customgptel-requesttools.gptel-use-contextis usually a per-request decision.gptel-backendandgptel-modelper request BUT I can see why falling back on defaults make sense here.It would be nice if I could make requests with specific presets and somehow specify whether a preset should apply on-top-of existing settings and/or if the preset should start from a clean state. However, I understand this would probably take a bit of work given that presets can modify arbitrary variables.
Structured Responses
This is a bit of a minor annoyance, but it would be nice if
gptel-requestparsed JSON responses when a schema is provided. Unfortunately, I can't think of a great way to do this without breaking changes to the API. With breaking changes, I'd change the callback arguments to(STATUS VALUE INFO):ok,error,abort,tool-call,reasoning, etc.)This would make it easy to handle responses with a simple pcase:
Futures/Promises
It would be great to have some kind of integration (possibly external) with Stefan's new futur library (or similar). I suggest Stefan's library because you could implement
futur-blocker-waitandfutur-blocker-abortforgptel-fsmwithout actually depending onfutur.When using
gptel-request, I've found myself needing to make multiple requests as a chain/graph. For example, when refiling org-mode notes.By structuring my request this way:
refiletool when done. However, especially with smaller models, this can easily go off the rails.Unfortunately, structuring a sequence (sometimes a graph) of async requests in Emacs lisp without library help is rather annoying. I was able to hack together something with
cl-labelsand some helper macros, but it was beyond ugly.All reactions