Skip to content

Commit

Permalink
Add test for completion with Google client
Browse files Browse the repository at this point in the history
  • Loading branch information
markuswustenberg committed Nov 29, 2024
1 parent 9d074a5 commit 6f956a9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
env:
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}
ANTHROPIC_TOKEN: ${{ secrets.ANTHROPIC_TOKEN }}
GOOGLE_TOKEN: ${{ secrets.GOOGLE_TOKEN }}

evaluate:
name: Evaluate
Expand Down
2 changes: 1 addition & 1 deletion anthropic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestNewAnthropicClient(t *testing.T) {
})
}

func TestAnthropicClientPrompt(t *testing.T) {
func TestAnthropicClientCompletion(t *testing.T) {
_ = env.Load(".env.test.local")

t.Run("can do a basic chat completion", func(t *testing.T) {
Expand Down
21 changes: 21 additions & 0 deletions google_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package llm_test

import (
"context"
"fmt"
"strings"
"testing"

"github.com/google/generative-ai-go/genai"
"maragu.dev/env"
"maragu.dev/is"

"maragu.dev/llm"
Expand All @@ -14,3 +19,19 @@ func TestNewGoogleClient(t *testing.T) {
is.NotNil(t, client)
})
}

func TestGoogleClientCompletion(t *testing.T) {
_ = env.Load(".env.test.local")

t.Run("can do a basic chat completion", func(t *testing.T) {
client := llm.NewGoogleClient(llm.NewGoogleClientOptions{Token: env.GetStringOrDefault("GOOGLE_TOKEN", "")})
is.NotNil(t, client)

model := client.Client.GenerativeModel("models/gemini-1.5-flash-latest")
model.SystemInstruction = genai.NewUserContent(genai.Text(`Only say the word "Hi", nothing more.`))
res, err := model.GenerateContent(context.Background(), genai.Text("Hi."))
is.NotError(t, err)
is.True(t, len(res.Candidates) > 0)
is.True(t, strings.Contains(fmt.Sprint(res.Candidates[0].Content.Parts), "Hi"))
})
}
2 changes: 1 addition & 1 deletion openai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestNewOpenAIClient(t *testing.T) {
})
}

func TestOpenAIClientPrompt(t *testing.T) {
func TestOpenAIClientCompletion(t *testing.T) {
_ = env.Load(".env.test.local")

t.Run("can do a basic chat completion", func(t *testing.T) {
Expand Down

0 comments on commit 6f956a9

Please sign in to comment.