@@ -18,28 +18,27 @@ import (
1818//go:embed commitmsg.prompt.yml
1919var commitmsgPromptYAML []byte
2020
21- // PromptConfig represents the structure of the prompt configuration file
22- // It includes the model parameters and the messages to be sent to the model.
21+ // PromptConfig represents the structure of the prompt configuration file.
2322type PromptConfig struct {
2423 Name string `yaml:"name"`
2524 Description string `yaml:"description"`
2625 ModelParameters ModelParameters `yaml:"modelParameters"`
2726 Messages []PromptMessage `yaml:"messages"`
2827}
2928
30- // ModelParameters defines the parameters for the model
29+ // ModelParameters defines the parameters for the large language model.
3130type ModelParameters struct {
3231 Temperature float64 `yaml:"temperature"`
3332 TopP float64 `yaml:"topP"`
3433}
3534
36- // PromptMessage represents a single message in the prompt configuration
35+ // PromptMessage represents a single message in the prompt configuration.
3736type PromptMessage struct {
3837 Role string `yaml:"role"`
3938 Content string `yaml:"content"`
4039}
4140
42- // Request represents the structure of the request to the GitHub Models API
41+ // Request represents the request payload for the GitHub Models API.
4342type Request struct {
4443 Messages []Message `json:"messages"`
4544 Model string `json:"model"`
@@ -48,13 +47,13 @@ type Request struct {
4847 Stream bool `json:"stream"`
4948}
5049
51- // Message represents a single message in the request to the GitHub Models API
50+ // Message represents a single message in the request payload.
5251type Message struct {
5352 Role string `json:"role"`
5453 Content string `json:"content"`
5554}
5655
57- // Response represents the structure of the response from the GitHub Models API
56+ // Response represents the response payload from the GitHub Models API.
5857type Response struct {
5958 Choices []struct {
6059 Message struct {
@@ -68,8 +67,8 @@ type Client struct {
6867 token string
6968}
7069
71- // NewClient initializes a new GitHub Models API client
72- // It retrieves the GitHub token from the environment installed by the `gh` CLI tool .
70+ // NewClient initializes a new GitHub Models API client.
71+ // It retrieves the GitHub token using gh auth token command .
7372func NewClient () (* Client , error ) {
7473 fmt .Print (" Checking GitHub token... " )
7574
@@ -100,6 +99,7 @@ func (c *Client) GenerateCommitMessage(
10099 }
101100 fmt .Println ("Done" )
102101
102+ // Build messages from the prompt config, replacing template variables
103103 selectedModel := model
104104 selectedLanguage := language
105105
@@ -125,6 +125,7 @@ func (c *Client) GenerateCommitMessage(
125125 }
126126 }
127127
128+ // Prepare the request for the GitHub Models API
128129 request := Request {
129130 Messages : messages ,
130131 Model : selectedModel ,
@@ -141,6 +142,7 @@ func (c *Client) GenerateCommitMessage(
141142 }
142143 fmt .Println ("Done" )
143144
145+ // Extract the generated commit message from the response
144146 if len (response .Choices ) == 0 {
145147 return "" , fmt .Errorf ("no response generated from the model" )
146148 }
0 commit comments