help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Including AI into Emacs


From: Jean Louis
Subject: Re: Including AI into Emacs
Date: Sat, 7 Dec 2024 13:30:56 +0300
User-agent: Mutt/2.2.12 (2023-09-09)

* Bruno Barbier <brubar.cs@gmail.com> [2024-12-07 12:32]:
> > I was using in invalidated manner the emacs-chatgpt but in general I
> > can do myself Curl and http requests. My usage is totally specific, I
> > have memories, various memories that I select from Dynamic Knowledge
> > Repository, then I can replace region with the information, or add new
> > information into buffer.
> >
> > I could not try gptel, it doesn't work. But will try in future.

I found out why, tried it out and it works. But programming, inside,
is for me too difficult as I am not used to that type of
programming. I am used for functions which always return something,
but gptel is more than that. Actually I just see too many
complications for my uses.

I need to be able to get result without complications. Synchronous
request is fine and better, rather than asynchronous, where it is
vague what is going to happen with the buffer information.

This is how I prefer it:

(defun rcd-chatgpt-shell (prompt memory model)
  (chatgpt-shell-post :context (list (cons memory nil) (cons prompt nil) ) 
:version model))

or

(defun rcd-llamafile (prompt memory model)
  "Return answer by using llamafile."
  (let ((model)
        (buffer (let ((url-request-method "POST")
                      (url-request-extra-headers
                       '(("Content-Type" . "application/json")
                         ("Authorization" . "Bearer no-key")))
                      (url-request-data
                       (json-encode
                        `((model . "LLaMA_CPP")
                          (messages . [
                                       ((role . "system")
                                        (content . "You are my AI assistant."))
                                       ((role . "user") 
                                       (content . ,prompt))
                                    ])))))
                  (url-retrieve-synchronously
                   "http://localhost:8080/v1/chat/completions";))))
    (when buffer
      (let* ((json-response (setq my-json (rcd-parse-http-json-string 
(buffer-to-string buffer))))
             (content (cdr (assoc 'content (cdr (assoc 'message (aref (cdr 
(assq 'choices my-json)) 0))))))
             (content (string-replace "</s>" "\n" content)))
        content))))

and 3-4 functions replace all of the catch-all functions in gptel

I have tried understanding gptel code, but I don't. And it doesn't look like I 
should be going into it.

Yes, it works, but I do not know how to get clear, easy to capture
response, to be returned for easy database logging.

Another issue, I don't see why I need too many files, whole package with many 
models, not needed.

Like for llamafile, I can easily change the model and same function can work, 
as above.

-- 
Jean Louis



reply via email to

[Prev in Thread] Current Thread [Next in Thread]