Skip to content

Feat/add qdrant server #71

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

Merged
merged 4 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ var (
{},
{int(entity.EN), int(entity.JP)},
{int(entity.NormalFormat), int(entity.EmojiFormat), int(entity.PrefixFormat)},
{int(entity.Server), int(entity.Client)},
{int(entity.Server), int(entity.Client), int(entity.Qdrant), int(entity.Gemini)},
}
configOptionLabel = [][]string{
{},
{"English", "Japanese"},
{"Normal Format", "Emoji Format", "PrefixFormat"},
{"Wrap Server", "OpenAI API"},
{"Wrap Server", "OpenAI API", "Qdrant Database", "Gemini API"},
}
)

Expand Down
11 changes: 8 additions & 3 deletions cmd/suggest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package cmd

import (
"fmt"
"log"
"os"
"strings"

"github.com/cocoide/commitify/internal/entity"
"github.com/cocoide/commitify/internal/gateway"
"github.com/cocoide/commitify/internal/service"
"github.com/cocoide/commitify/internal/usecase"
"golang.org/x/net/context"
"log"
"os"
"strings"

"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/textinput"
Expand Down Expand Up @@ -135,6 +136,10 @@ func NewSuggestModel() *suggestModel {
commitMessageService = gateway.NewClientCommitMessageGateway(nlp)
case entity.Server:
commitMessageService = gateway.NewGrpcServerGateway()
case entity.Qdrant:
commitMessageService = gateway.NewQdrantServerGateway()
case entity.Gemini:
commitMessageService = gateway.NewGeminiServerGateway()
}
suggestCmdUsecase := usecase.NewSuggestCmdUsecase(commitMessageService, github)

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/sashabaranov/go-openai v1.15.2
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
go.uber.org/mock v0.3.0
golang.org/x/net v0.15.0
google.golang.org/grpc v1.58.0
google.golang.org/protobuf v1.31.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo=
go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down
9 changes: 8 additions & 1 deletion internal/entity/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package entity
import (
"encoding/json"
"fmt"
"os"

pb "github.com/cocoide/commitify/proto/gen"
"github.com/spf13/viper"
"os"
)

// コミットメッセージの言語の列挙型
Expand All @@ -31,6 +32,8 @@ type GptRequestLocation int
const (
Server GptRequestLocation = iota
Client
Qdrant
Gemini
)

type Config struct {
Expand Down Expand Up @@ -145,6 +148,10 @@ func (c *Config) GptRequestLocation() GptRequestLocation {
return Server
case 1:
return Client
case 2:
return Qdrant
case 3:
return Gemini
default:
return Server
}
Expand Down
56 changes: 56 additions & 0 deletions internal/gateway/gemini.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package gateway

import (
"encoding/json"

"github.com/cocoide/commitify/internal/entity"
"github.com/cocoide/commitify/internal/service"
"github.com/pkg/errors"
)

type geminiServerGateway struct {
client *HttpClient
}

func NewGeminiServerGateway() service.CommitMessageService {
c := NewHttpClient().
WithBaseURL("http://suwageeks.org:5215").
WithPath("/gemini").
WithHeader("Content-Type", "application/json")

return &geminiServerGateway{client: c}
}

func (qs *geminiServerGateway) GenerateCommitMessageList(diff string, conf entity.Config) ([]string, error) {
if diff == "" {
return nil, errors.New("ステージされた変更がありません。")
}

type geminiBody struct {
Diff string `json:"diff"`
}

body := &geminiBody{
Diff: diff,
}
b, err := json.Marshal(body)
if err != nil {
return nil, err
}

res, err := qs.client.WithBody(b).Execute(POST)
if err != nil {
return nil, err
}

type geminiResponse struct {
Messages []string `json:"messages"`
}

values := new(geminiResponse)
if err = json.Unmarshal(res, values); err != nil {
return nil, err
}

return values.Messages, nil
}
57 changes: 57 additions & 0 deletions internal/gateway/qdrant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package gateway

import (
"encoding/json"
"errors"

"github.com/cocoide/commitify/internal/entity"
"github.com/cocoide/commitify/internal/service"
)

type qdrantServerGateway struct {
client *HttpClient
}

func NewQdrantServerGateway() service.CommitMessageService {
c := NewHttpClient()

return &qdrantServerGateway{client: c}
}

func (qs *qdrantServerGateway) GenerateCommitMessageList(diff string, conf entity.Config) ([]string, error) {
if diff == "" {
return nil, errors.New("ステージされた変更がありません。")
}

type qdrantBody struct {
Diff string `json:"diff"`
}

body := &qdrantBody{
Diff: diff,
}
b, err := json.Marshal(body)
if err != nil {
return nil, err
}

res, err := qs.client.
WithBaseURL("http://suwageeks.org:5215").
WithPath("/search").
WithHeader("Content-Type", "application/json").
WithBody(b).Execute(POST)
if err != nil {
return nil, err
}

type qdrantResponse struct {
Messages []string `json:"messages"`
}

values := new(qdrantResponse)
if err = json.Unmarshal(res, values); err != nil {
return nil, err
}

return values.Messages, nil
}