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: Enhancing ELisp for AI Work Date: Mon, 16 Dec 2024 19:26:09 +0300 Message-ID: References: <7290780.2375960.1734348492938.ref@mail.yahoo.com> <7290780.2375960.1734348492938@mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18711"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.2.12 (2023-09-09) Cc: help-gnu-emacs@gnu.org To: =?utf-8?B?VG9tw6HFoQ==?= Petit Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 16 18:31:30 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 1tNEwL-0004e1-VI for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 16 Dec 2024 18:31:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNEvu-00023l-4r; Mon, 16 Dec 2024 12:31:02 -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 1tNEvb-0001TD-CH for help-gnu-emacs@gnu.org; Mon, 16 Dec 2024 12:30:45 -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 1tNEvV-0002b3-2f for help-gnu-emacs@gnu.org; Mon, 16 Dec 2024 12:30:38 -0500 Original-Received: from localhost ([::ffff:197.239.10.219]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 000000000001BF39.00000000676063B9.00084F84; Mon, 16 Dec 2024 10:30:33 -0700 Mail-Followup-To: =?utf-8?B?VG9tw6HFoQ==?= Petit , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: 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_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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:148835 Archived-At: * Tomáš Petit [2024-12-16 17:57]: > Greetings, > > wouldn't Common Lisp or some Scheme dialect be better suited for this job > instead of Emacs Lisp? Emacs Lisp reaches out to many external environments, so it is portal to everything else. Even when I use externally Common Lisp, I may be invoking it from Emacs Lisp, some people live in Emacs, and anyway, whatever language, it can be still edited within Emacs, run, tested, it gets somehow similar feelings no matter which language runs. In my work I have to heavily work with text, and accessing HTTP endpoints to reach to some of Large Language Models (LLM), is not hard. Emacs Lisp does it. Let us say preparing the dataset, I have good tools within Emacs Lisp to find the data necessary for training of the LLM within seconds. Then it would need some preparation with external tools which are ready made for that task. But a lot may be done within Emacs. Here is simple function: (defun rcd-llm-response (response-buffer) "Parse LLM's RESPONSE-BUFFER and return decoded string." (when response-buffer (with-current-buffer response-buffer ;; Skip HTTP headers (goto-char (point-min)) (when (search-forward "\n\n" nil t) (let ((response (decode-coding-string (buffer-substring-no-properties (point) (point-max)) 'utf-8))) (kill-buffer response-buffer) ;; Parse JSON and extract the reply (let* ((json-response (json-parse-string response :object-type 'alist)) (choices (alist-get 'choices json-response)) (message (alist-get 'message (aref choices 0))) (message (decode-coding-string (alist-get 'content message) 'utf-8))) (string-replace "" "\n" message))))))) The model Qwen2.5-Coder-32B-Instruct is Apache 2.0. which is free software license. (defun rcd-llm-huggingface (prompt &optional memory rcd-llm-model temperature max-tokens top-p stream) "Send PROMPT to Hugging Face API with specified parameters. Optional MEMORY, RCD-LLM-MODEL, TEMPERATURE, MAX-TOKENS, TOP-P, and STREAM can be used." (let* ((rcd-llm-model (or rcd-llm-model "Qwen/Qwen2.5-Coder-32B-Instruct")) (temperature (or temperature 0.5)) (max-tokens (or max-tokens 2048)) (top-p (or top-p 0.7)) (stream (if stream t :json-false)) (url-request-method "POST") (url-request-extra-headers '(("Content-Type" . "application/json") ("Authorization" . "Bearer hf_YOUR-API-KEY"))) (url-request-data (encode-coding-string (setq rcd-llm-last-json (json-encode `((model . ,rcd-llm-model) (messages . [((role . "user") (content . ,prompt))]) (temperature . ,temperature) (max_tokens . ,max-tokens) (top_p . ,top-p) (stream . ,stream)))) 'utf-8)) (buffer (url-retrieve-synchronously "https://api-inference.huggingface.co/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions"))) (rcd-llm-response buffer))) The whole library then does everything I nee to interact with LLMs. Emacs is for text, LLM is for text, it must go hand in hand. But generation of the LLM is not yet workable through Emacs Lisp, even though for sure not impossible, it is just nobody yet tried to create it that way. -- Jean Louis