From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: Including AI into Emacs Date: Sat, 7 Dec 2024 13:30:56 +0300 Message-ID: References: <61ffb7417fcfe6fc0c1291aa53d1398b.support1@rcdrun.com> <67533f62.5d0a0220.74bfb.65e6@mx.google.com> <67541628.050a0220.1c50f6.91ff@mx.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37458"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.2.12 (2023-09-09) Cc: help-gnu-emacs@gnu.org To: Bruno Barbier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 07 11:32:37 2024 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tJs73-0009fA-FO for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 07 Dec 2024 11:32:37 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJs6K-0002vx-Pe; Sat, 07 Dec 2024 05:31:53 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tJs6J-0002vU-2P for help-gnu-emacs@gnu.org; Sat, 07 Dec 2024 05:31:51 -0500 Original-Received: from stw1.rcdrun.com ([217.170.207.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tJs6H-0004qq-Ht for help-gnu-emacs@gnu.org; Sat, 07 Dec 2024 05:31:50 -0500 Original-Received: from localhost ([::ffff:41.75.190.82]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 000000000013FC17.00000000675423F0.003C9A5E; Sat, 07 Dec 2024 03:31:12 -0700 Mail-Followup-To: Bruno Barbier , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <67541628.050a0220.1c50f6.91ff@mx.google.com> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:148648 Archived-At: * Bruno Barbier [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 "" "\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