Skip to content

Commit

Permalink
Add GitHub Models support
Browse files Browse the repository at this point in the history
  • Loading branch information
gs-101 committed Jan 12, 2025
1 parent 8351ee9 commit dc4073a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.org
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* Version 0.21.0
- Add GitHub's GitHub Models
- Add ~llm-models-add~ as a convenience method to add a model to the known list.
* Version 0.20.0
- Add ability to output according to a JSON spec.
Expand Down
5 changes: 5 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
56 changes: 56 additions & 0 deletions llm-github.el
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
;; 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 <https://www.gnu.org/licenses/>.

;;; 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
5 changes: 5 additions & 0 deletions llm-integration-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -138,6 +140,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.
Expand Down

0 comments on commit dc4073a

Please sign in to comment.