di-sukharev / opencommit

Generate conventional git commit messages with AI in 1 second 🤯🔫
https://www.npmjs.com/package/opencommit
MIT License
6.15k stars 329 forks source link

[Feature]: Support for Github Models (Github Marketplace) #410

Open kevin-valerio opened 2 months ago

kevin-valerio commented 2 months ago

Description

Currently opencommit doesn't support Github Models API calls. It would be nice to have the support for Github models, as they're free to use (if you get your access granted) and gives you free API key to request differents models, GPT 4o included

Suggested Solution

The user could provide a GITHUB_TOKEN (free) instead of the OpenAI (not free) API key for the LLM requests.

Usage :

import os
from openai import OpenAI

token = os.environ["GITHUB_TOKEN"]
endpoint = "https://models.inference.ai.azure.com"
model_name = "gpt-4o-mini"

client = OpenAI(
    base_url=endpoint,
    api_key=token,
)

response = client.chat.completions.create(
    messages=[
        {
            "role": "system",
            "content": "You are in charge to create a commit name for all those differences:",
        },
        {
            "role": "user",
            "content": "What is the capital of France?",
        }
    ],
    model=model_name,
    temperature=1.,
    max_tokens=1000,
    top_p=1.
)

print(response.choices[0].message.content)

Alternatives

No response

Additional Context

No response

di-sukharev commented 2 months ago

@kevin-valerio nice idea! do you want to contribute a PR? if yes — this should not take longer than 40 minutes to implement, follow OpenAiEngine example or simply this file