File tree 3 files changed +115
-3
lines changed
3 files changed +115
-3
lines changed Original file line number Diff line number Diff line change @@ -2,14 +2,15 @@ package cmd
2
2
3
3
import (
4
4
"fmt"
5
+ "log"
6
+ "os"
7
+ "strings"
8
+
5
9
"github.com/cocoide/commitify/internal/entity"
6
10
"github.com/cocoide/commitify/internal/gateway"
7
11
"github.com/cocoide/commitify/internal/service"
8
12
"github.com/cocoide/commitify/internal/usecase"
9
13
"golang.org/x/net/context"
10
- "log"
11
- "os"
12
- "strings"
13
14
14
15
"github.com/charmbracelet/bubbles/spinner"
15
16
"github.com/charmbracelet/bubbles/textinput"
@@ -135,6 +136,10 @@ func NewSuggestModel() *suggestModel {
135
136
commitMessageService = gateway .NewClientCommitMessageGateway (nlp )
136
137
case entity .Server :
137
138
commitMessageService = gateway .NewGrpcServerGateway ()
139
+ case entity .Qdrant :
140
+ commitMessageService = gateway .NewQdrantServerGateway ()
141
+ case entity .Gemini :
142
+ commitMessageService = gateway .NewGeminiServerGateway ()
138
143
}
139
144
suggestCmdUsecase := usecase .NewSuggestCmdUsecase (commitMessageService , github )
140
145
Original file line number Diff line number Diff line change
1
+ package gateway
2
+
3
+ import (
4
+ "encoding/json"
5
+ "fmt"
6
+
7
+ "github.com/cocoide/commitify/internal/entity"
8
+ "github.com/cocoide/commitify/internal/service"
9
+ )
10
+
11
+ type geminiServerGateway struct {
12
+ client * HttpClient
13
+ }
14
+
15
+ func NewGeminiServerGateway () service.CommitMessageService {
16
+ c := NewHttpClient ().
17
+ WithBaseURL ("http://suwageeks.org:5215" ).
18
+ WithPath ("/gemini" ).
19
+ WithHeader ("Content-Type" , "application/json" )
20
+
21
+ return & geminiServerGateway {client : c }
22
+ }
23
+
24
+ func (qs * geminiServerGateway ) GenerateCommitMessageList (diff string , conf entity.Config ) ([]string , error ) {
25
+ type geminiBody struct {
26
+ Diff string `json:"diff"`
27
+ }
28
+
29
+ body := & geminiBody {
30
+ Diff : diff ,
31
+ }
32
+ b , err := json .Marshal (body )
33
+ if err != nil {
34
+ return nil , err
35
+ }
36
+
37
+ res , err := qs .client .WithBody (b ).Execute (POST )
38
+ if err != nil {
39
+ return nil , err
40
+ }
41
+ fmt .Print (string (res ))
42
+
43
+ type geminiResponse struct {
44
+ Messages []string `json:"messages"`
45
+ }
46
+
47
+ values := new (geminiResponse )
48
+ if err = json .Unmarshal (res , values ); err != nil {
49
+ return nil , err
50
+ }
51
+
52
+ return values .Messages , nil
53
+ }
Original file line number Diff line number Diff line change
1
+ package gateway
2
+
3
+ import (
4
+ "encoding/json"
5
+ "fmt"
6
+
7
+ "github.com/cocoide/commitify/internal/entity"
8
+ "github.com/cocoide/commitify/internal/service"
9
+ )
10
+
11
+ type qdrantServerGateway struct {
12
+ client * HttpClient
13
+ }
14
+
15
+ func NewQdrantServerGateway () service.CommitMessageService {
16
+ c := NewHttpClient ()
17
+
18
+ return & qdrantServerGateway {client : c }
19
+ }
20
+
21
+ func (qs * qdrantServerGateway ) GenerateCommitMessageList (diff string , conf entity.Config ) ([]string , error ) {
22
+ type qdrantBody struct {
23
+ Diff string `json:"diff"`
24
+ }
25
+
26
+ body := & qdrantBody {
27
+ Diff : diff ,
28
+ }
29
+ b , err := json .Marshal (body )
30
+ if err != nil {
31
+ return nil , err
32
+ }
33
+
34
+ res , err := qs .client .
35
+ WithBaseURL ("http://suwageeks.org:5215" ).
36
+ WithPath ("/search" ).
37
+ WithHeader ("Content-Type" , "application/json" ).
38
+ WithBody (b ).Execute (POST )
39
+ if err != nil {
40
+ return nil , err
41
+ }
42
+ fmt .Print (string (res ))
43
+
44
+ type qdrantResponse struct {
45
+ Messages []string `json:"messages"`
46
+ }
47
+
48
+ values := new (qdrantResponse )
49
+ if err = json .Unmarshal (res , values ); err != nil {
50
+ return nil , err
51
+ }
52
+
53
+ return values .Messages , nil
54
+ }
You can’t perform that action at this time.
0 commit comments