diff --git a/NEWS.org b/NEWS.org index a5a36aa..2ae262e 100644 --- a/NEWS.org +++ b/NEWS.org @@ -1,3 +1,5 @@ +* Version 0.23.0 +- - Add GitHub's GitHub Models * Version 0.22.0 - Change ~llm-tool-function~ to ~llm-tool~, change ~make-llm-tool-function~ to take any arguments. * Version 0.21.0 diff --git a/README.org b/README.org index 1b63b38..0c42bcb 100644 --- a/README.org +++ b/README.org @@ -55,6 +55,11 @@ Microsoft Azure has an Open AI integration, although it doesn't support everythi - ~:key~, the Azure key for Azure OpenAI service. - ~:chat-model~, the chat model, which must be deployed in Azure. - ~embedding-model~, the embedding model which must be deployed in Azure. +** GitHub Models +GitHub now has its own platform for interacting with AI models. For a list of models check the [[https://github.com/marketplace/models][marketplace]]. You can set it up with ~make-llm-github~, with the following parameters: +- ~:key~, a GitHub token or an Azure AI production key. +- ~:chat-model~, the chat model, which can be any of the ones you have access for (currently o1 is restricted). +- ~:embedding-model~, the embedding model, which can be better found [[https://github.com/marketplace?type=models&task=Embeddings][through a filter]]a. ** Gemini (not via Google Cloud) This is Google's AI model. You can get an API key via their [[https://makersuite.google.com/app/apikey][page on Google AI Studio]]. Set this up with ~make-llm-gemini~, with the following parameters: diff --git a/llm-github.el b/llm-github.el new file mode 100644 index 0000000..f591dc7 --- /dev/null +++ b/llm-github.el @@ -0,0 +1,56 @@ +;;; llm-github.el --- llm module for integrating with GitHub Models -*- lexical-binding: t; package-lint-main-file: "llm.el"; byte-compile-docstring-max-column: 200 -*- + +;; Copyright (c) 2024 Free Software Foundation, Inc. + +;; Author: Gabriel Santos de Souza +;; Homepage: https://github.com/ahyatt/llm +;; SPDX-License-Identifier: GPL-3.0-or-later + +;; This program is free software: you can redistribute it and/or +;; modify it under the terms of the GNU General Public License as +;; published by the Free Software Foundation; either version 3 of the +;; License, or (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: +;; This file implements the llm functionality defined in llm.el, +;; for the GitHub Models platform. + +;;; Code: + +(require 'llm) +(require 'llm-openai) +(require 'cl-lib) + +(cl-defstruct (llm-github (:include llm-openai-compatible (url "https://models.inference.ai.azure.com")))) + +(cl-defmethod llm-nonfree-message-info ((_ llm-github)) + "Return GitHub's nonfree terms of service." + "https://docs.github.com/en/site-policy/github-terms/github-terms-of-service") + +(cl-defmethod llm-provider-chat-url ((provider llm-github)) + (format "%s/chat/completions" + (llm-github-url provider))) + +(cl-defmethod llm-provider-embedding-url ((provider llm-github) &optional _) + (format "%s/embeddings/" + (llm-github-url provider))) + +(cl-defmethod llm-provider-headers ((provider llm-github)) + `(("api-key" . ,(llm-github-key provider)))) + +(cl-defmethod llm-capabilities ((_ llm-github)) + (list 'streaming 'embedding)) + +(cl-defmethod llm-name ((provider llm-github)) + (format "GitHub Models %s" (llm-github-chat-model provider))) + +(provide 'llm-github) +;;; llm-github.el ends here diff --git a/llm-integration-test.el b/llm-integration-test.el index 7a0c3e2..3fe8470 100644 --- a/llm-integration-test.el +++ b/llm-integration-test.el @@ -37,6 +37,8 @@ ;; - AZURE_EMBEDDING_MODEL: The name of the embedding model to test. ;; - AZURE_SLEEP: The number of seconds to sleep between tests, to avoid rate ;; limiting. +;; - GITHUB_TOKEN: The key for GitHub models. Can either be a GitHub token or +;; an Azure production key. ;; ;; If any of these are set (except for Azure, which needs multiple), the ;; corresponding provider will be tested. @@ -132,6 +134,9 @@ else. We really just want to see if it's in the right ballpark." :chat-model (getenv "AZURE_CHAT_MODEL") :embedding-model (getenv "AZURE_EMBEDDING_MODEL")) providers)) + (when (getenv "GITHUB_TOKEN") + (require 'llm-github) + (push (make-llm-github :key (getenv "GITHUB_TOKEN")) providers)) (when (getenv "OLLAMA_CHAT_MODELS") (require 'llm-ollama) ;; This variable is a list of models to test.