add ai stuff from greg and jwiegley
This commit is contained in:
parent
c814eece5b
commit
297b3aa046
1 changed files with 108 additions and 8 deletions
116
init.org
116
init.org
|
@ -3108,18 +3108,124 @@ Tools.
|
|||
Most of the mind share seems to be around [[https://github.com/karthink/gptel][gptel]] as basis for LLM
|
||||
integration in Emacs.
|
||||
|
||||
*** Load and Configure Model
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(use-package gptel
|
||||
:ensure t
|
||||
:commands (gptel)
|
||||
:config
|
||||
;;(setq gptel-default-mode 'org-mode)
|
||||
(setq gptel-default-mode 'org-mode
|
||||
gptel-expert-commands t
|
||||
gptel-track-media t
|
||||
gptel-include-reasoning 'ignore
|
||||
gptel-log-level 'info
|
||||
gptel--debug nil)
|
||||
|
||||
(add-to-list 'gptel-prompt-prefix-alist `(org-mode . ,(concat "*** pti " (format-time-string "[%Y-%m-%d]") "\n")))
|
||||
|
||||
;; follow output
|
||||
(add-hook 'gptel-post-stream-hook 'gptel-auto-scroll)
|
||||
;; move to next prompt after response
|
||||
(add-hook 'gptel-post-response-functions 'gptel-end-of-response)
|
||||
)
|
||||
|
||||
(use-package gptel-curl)
|
||||
(use-package gptel-transient)
|
||||
(use-package gptel-integrations)
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS:
|
||||
|
||||
*** Load jwiegley/gptel-prompts for prompt composability
|
||||
This package offers an alternative way to manage your ~gptel-directives~ variable, using files rather than customizing the variable directly.
|
||||
|
||||
Whenever your prompt files change, you must arrange for
|
||||
~gptel-prompts-update~ to be called, which will update gptel-directives
|
||||
appropriately.
|
||||
|
||||
#+begin_src emacs-lisp :tangle no
|
||||
(use-package gptel-prompts
|
||||
:ensure t
|
||||
:after (gptel)
|
||||
:demand t
|
||||
:config
|
||||
(gptel-prompts-update)
|
||||
;; Ensure prompts are updated if prompt files change
|
||||
(gptel-prompts-add-update-watchers))
|
||||
#+end_src
|
||||
|
||||
|
||||
**** Different prompt types
|
||||
|
||||
You may now put prompts, one per file, in the directory
|
||||
gptel-prompts-directory, which by default is
|
||||
"~/.emacs.d/prompts". Prompts may be one of three different kinds:
|
||||
Plain text
|
||||
|
||||
If the file extension is *.txt, .md or .org*, the content of the file is
|
||||
used directly, as if you had added that string to ~gptel-directives~.
|
||||
Emacs Lisp lists
|
||||
|
||||
If the file extension is *.el*, the file must evaluate to a list of
|
||||
strings and/or symbols, as expected by ~gptel-directives~. Please see
|
||||
the documentation of that variable for more information. Prompt Poet
|
||||
templates
|
||||
|
||||
Based on the standard set by Prompt Poet, files ending in *.poet* or
|
||||
*.jinja* will be interpreted as YAML files using Jinja templating. The
|
||||
templating is applied first, before it is parsed as a Yaml file.
|
||||
|
||||
This is done dynamically, at the time the prompt is used, so you can
|
||||
see the results of your expansion using GPTel’s Inspect capabilities
|
||||
when ~gptel-expert-commands~ is set to a non-nil value. Here is an
|
||||
example poet prompt.:
|
||||
|
||||
#+begin_src
|
||||
- role: system
|
||||
content: >-
|
||||
You are an Latin-American Spanish translator, spelling corrector and
|
||||
improver. I will speak to you in English, and you will translate and
|
||||
answer in the corrected and improved version of my text, in Latin-American
|
||||
Spanish. I want you to replace my simplified A0-level words and sentences
|
||||
with more beautiful and elegant, upper level Latin-American Spanish words
|
||||
and sentences. Keep the meaning same, but make them more literary and
|
||||
clear. I want you to only reply with the correction, the improvements and
|
||||
nothing else, do not write explanations.
|
||||
|
||||
- role: user
|
||||
content: |
|
||||
Please translate the following into Spanish. The time is {{
|
||||
current_time }}:
|
||||
#+end_src
|
||||
|
||||
Note the ~>-~ and ~|~ content directives, which are used to manage when
|
||||
and where newlines appear in the actual prompts, while allowing the
|
||||
file itself to use what is easiest to maintain in the editor.
|
||||
|
||||
NOTE: If you wish to use the Prompt Poet format, you will need to
|
||||
install the Emacs dependencies yaml and templatel.
|
||||
|
||||
*** Models
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(setq gptel-api-key openai-api-key)
|
||||
(gptel-make-gemini "Gemini" :key gemini-api-key :stream t)
|
||||
(gptel-make-anthropic "Claude" :stream t :key anthropic-api-key)
|
||||
(gptel-make-ollama "Qwen Coder"
|
||||
:models '(qwen2.5-coder:14b
|
||||
:description "QWen 2.5 Coder 14b"))
|
||||
|
||||
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS:
|
||||
: #s(gptel-ollama "Qwen Coder" "localhost:11434" nil "http" nil "/api/chat" nil (qwen2.5-coder:14b :description QWen\ 2.5\ Coder\ 14b) "http://localhost:11434/api/chat" nil nil nil)
|
||||
|
||||
|
||||
*** Tools
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
;; define some tools for gptel
|
||||
(gptel-make-tool
|
||||
:function (lambda (url)
|
||||
|
@ -3241,16 +3347,10 @@ integration in Emacs.
|
|||
:type "string"
|
||||
:description "Path to the file to read. Supports relative paths and ~."))
|
||||
:category "filesystem")
|
||||
|
||||
|
||||
;; follow output
|
||||
(add-hook 'gptel-post-stream-hook 'gptel-auto-scroll)
|
||||
;; move to next prompt after response
|
||||
(add-hook 'gptel-post-response-functions 'gptel-end-of-response)
|
||||
)
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS:
|
||||
: [nil 26626 15252 706789 nil elpaca-process-queues nil nil 969000 nil]
|
||||
|
||||
** Copilot Support
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue