-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GitHub Models support #113
base: main
Are you sure you want to change the base?
Conversation
2af31f7
to
95029aa
Compare
Some changes to see what CI tells me. EDIT: Nice, but Ellama still tells me that the request was timed out. Here's how I configured it: (use-package ellama
:bind ("C-z ," . ellama-transient-main-menu)
:demand t
:ensure t
:init
(setopt ellama-language "English")
(require 'llm-github)
(setopt ellama-provider
(make-llm-github
:chat-model "meta-llama-3.1-405b-instruct"
:key "GITHUB_TOKEN"
:embedding-model "text-embedding-3-large"
:url "models.inference.ai.azure.com/"))
(setopt ellama-summarization-provider
(make-llm-github
:chat-model "meta-llama-3.1-405b-instruct"
:key "GITHUB_TOKEN"
:embedding-model "text-embedding-3-large"
:url "models.inference.ai.azure.com/"))
(setopt ellama-coding-provider
(make-llm-github
:chat-model "meta-llama-3.1-405b-instruct"
:key "GITHUB_TOKEN"
:embedding-model "text-embedding-3-large"
:url "models.inference.ai.azure.com/"))
(setopt ellama-naming-provider
(make-llm-github
:chat-model "meta-llama-3.1-405b-instruct"
:key "GITHUB_TOKEN"
:embedding-model "text-embedding-3-large"
:url "models.inference.ai.azure.com/"))
(setopt ellama-naming-scheme 'ellama-generate-name-by-llm)
(setopt ellama-translation-provider
(make-llm-github
:chat-model "meta-llama-3.1-405b-instruct"
:key "GITHUB_TOKEN"
:embedding-model "text-embedding-3-large"
:url "models.inference.ai.azure.com/"))) I still need to figure out how to set |
Thanks for this PR! Let me know when you get your FSF paperwork finished, and I can merge this in. If you are having any issues with it, please inform me so I can ask the maintainers. |
95029aa
to
1e3a468
Compare
On this, does it take long? I sent my request to [email protected] last saturday (2024-11-23). |
Have they replied? It usually is fast for them to reply, but from the time for them to send and receive your signed paperwork can take weeks. |
No, not yet. But I sent it during the weekend so I think it's fair of them to take their time. I'll wait and if there's no response this saturday I think I'll try to contact them again. |
Hey, just getting back on this. I just got my paper signed! If it applies beyond Emacs core source code (I need to check on ELPA for this), then this PR can be merged. |
(require 'llm-openai) | ||
(require 'cl-lib) | ||
|
||
(cl-defstruct (llm-github (:include llm-openai-compatible (url "https://models.inference.ai.azure.com")))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that this is an Azure URL. Can or should we base it off of the azure provider instead? Perhaps it could just be a Azure provider with a different default value for the URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that this is an Azure URL. Can or should we base it off of the azure provider instead? Perhaps it could just be a Azure provider with a different default value for the URL.
It could be, as it also supports the Azure SDK:
Python Example on the page:
import os
from azure.ai.inference import ChatCompletionsClient
from azure.ai.inference.models import SystemMessage, UserMessage
from azure.core.credentials import AzureKeyCredential
endpoint = "https://models.inference.ai.azure.com"
model_name = "Meta-Llama-3.1-405B-Instruct"
token = os.environ["GITHUB_TOKEN"]
client = ChatCompletionsClient(
endpoint=endpoint,
credential=AzureKeyCredential(token),
)
response = client.complete(
messages=[
SystemMessage(content="You are a helpful assistant."),
UserMessage(content="What is the capital of France?"),
],
temperature=1.0,
top_p=1.0,
max_tokens=1000,
model=model_name
)
print(response.choices[0].message.content)
For basing it off (as in, making a new file like I did), I don't think it would be necessary, as it already works (the page on the screenshot only has the Azure example, but I was able to make a request with the current configuration).
But, if we were to expand the Azure provider to support Github Models, that would require setting the chat and embedding URL as arguments, or add a conditional to change the formatting URL.
Example with chat URL:
(cl-defmethod llm-provider-chat-url ((provider llm-azure))
- (format "%s/openai/deployments/%s/chat/completions?api-version=2024-08-01-preview"
- (llm-azure-url provider)
- (llm-azure-chat-model provider)))
(cl-defmethod llm-provider-chat-url ((provider llm-azure))
+ (if (llm-azure-github t)
+ (format "%s/chat/completions"
+ (llm-azure-url provider))
+ (format "%s/openai/deployments/%s/chat/completions?api-version=2024-08-01-preview"
+ (llm-azure-url provider)
+ (llm-azure-chat-model provider))))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need to do the if, though, you could have your struct include the llm-azure
struct, and then you could keep your code as normal.
(cl-defmethod llm-provider-chat-url ((provider llm-github))
(format "%s/chat/completions" (llm-azure-url provider))))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need to do the if, though, you could have your struct include the
llm-azure
struct, and then you could keep your code as normal.
Thanks, sorry about that, I don't know much about Common Lisp.
I tried both of these:
-(require 'llm-openai)
+(require 'llm-azure)
-(cl-defstruct (llm-github (:include llm-openai-compatible (url "https://models.inference.ai.azure.com"))))
+(cl-defstruct (llm-github (:include llm-azure (url "https://models.inference.ai.azure.com"))))
-(require 'llm-openai)
+(require 'llm-azure)
-(cl-defstruct (llm-github (:include llm-openai-compatible (url "https://models.inference.ai.azure.com"))))
+(cl-defstruct (llm-github (:include llm-azure (url "https://models.inference.ai.azure.com"))))
(cl-defmethod llm-provider-chat-url ((provider llm-github))
(format "%s/chat/completions"
- (llm-github-url provider)))
+ (llm-azure-url provider)))
(cl-defmethod llm-provider-embedding-url ((provider llm-github) &optional _)
(format "%s/embeddings/"
- (llm-github-url provider)))
+ (llm-azure-url provider)))
But my requests timed out.
This is fantastic, thanks for going through that! With that in mind, I've finally looked at your change and left a few comments. |
1e3a468
to
bea8036
Compare
bea8036
to
dc4073a
Compare
Github Models
Some points I'd like to address here:
With your experience I think you could easily spot the issue here, but I'll take a look at the other providers to see if I can fix it myself.
My gptel configuration, which works with this provider:
gptel-api-key
gets the key from.authinfo.gpg
, formated as:machine models.inference.ai.azure.com login apiKey password GITHUB_TOKEN