Skip to content

Commit

Permalink
feat: gemini api test
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmcguire1 committed Dec 14, 2023
1 parent 21e26fb commit 2cce81d
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions internal/dom/chatmodels/prompts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"testing"

"github.com/google/generative-ai-go/genai"
"github.com/sashabaranov/go-openai"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -23,8 +24,8 @@ func TestAutoComplete(t *testing.T) {
},
}
api.On("AutoComplete", mock.Anything, "steve").Return(mockResponse, nil)
c := Client{&Resources{Api: api}}
resp, err := c.AutoComplete(context.Background(), "steve")
c := Client{&Resources{GPTApi: api}}
resp, err := c.AutoComplete(context.Background(), "steve", CHAT_MODEL_GPT)
assert.NoError(t, err)
assert.EqualValues(t, "is the best", resp)
}
Expand All @@ -39,8 +40,36 @@ func TestAutoCompleteMissingChoices(t *testing.T) {
Choices: []openai.ChatCompletionChoice{},
}
api.On("AutoComplete", mock.Anything, "steve").Return(mockResponse, nil)
c := Client{&Resources{Api: api}}
_, err := c.AutoComplete(context.Background(), "steve")
c := Client{&Resources{GPTApi: api}}
_, err := c.AutoComplete(context.Background(), "steve", CHAT_MODEL_GPT)
assert.Error(t, err)
assert.Equal(t, "missing choices", err.Error())
}

func TestGeminiChat(t *testing.T) {
api := &mockAPI{}
part := genai.Text("is the best")
mockResponse := &genai.GenerateContentResponse{
Candidates: []*genai.Candidate{
&genai.Candidate{
Index: 0,
Content: &genai.Content{
Parts: []genai.Part{
part,
},
Role: "",
},
FinishReason: 0,
SafetyRatings: nil,
CitationMetadata: nil,
TokenCount: 0,
},
},
PromptFeedback: nil,
}
api.On("GoogleChat", mock.Anything, "steve").Return(mockResponse, nil)
c := Client{&Resources{GoogleAPI: api}}
resp, err := c.AutoComplete(context.Background(), "steve", CHAT_MODEL_GOOGLE)
assert.NoError(t, err)
assert.EqualValues(t, "is the best", resp)
}

0 comments on commit 2cce81d

Please sign in to comment.