Skip to content

Commit

Permalink
googleai: add test with BinaryPart image (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliben authored Jan 29, 2024
1 parent b54eb1f commit a7a7ad6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions llms/googleai/shared_test/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"reflect"
"runtime"
"strings"
Expand Down Expand Up @@ -69,7 +70,8 @@ var testFuncs = []testFunc{
testMultiContentText,
testGenerateFromSinglePrompt,
testMultiContentTextChatSequence,
testMultiContentImage,
testMultiContentImageLink,
testMultiContentImageBinary,
testEmbeddings,
testCandidateCountSetting,
testMaxTokensSetting,
Expand Down Expand Up @@ -168,7 +170,7 @@ func testMultiContentTextChatSequence(t *testing.T, llm llms.Model) {
assert.Regexp(t, "(?i)spain.*larger", c1.Content)
}

func testMultiContentImage(t *testing.T, llm llms.Model) {
func testMultiContentImageLink(t *testing.T, llm llms.Model) {
t.Helper()
t.Parallel()

Expand All @@ -191,6 +193,34 @@ func testMultiContentImage(t *testing.T, llm llms.Model) {
assert.Regexp(t, "(?i)parrot", c1.Content)
}

func testMultiContentImageBinary(t *testing.T, llm llms.Model) {
t.Helper()
t.Parallel()

b, err := os.ReadFile(filepath.Join("testdata", "parrot-icon.png"))
if err != nil {
t.Fatal(err)
}

parts := []llms.ContentPart{
llms.BinaryPart("image/png", b),
llms.TextPart("what does this image show? please use detail"),
}
content := []llms.MessageContent{
{
Role: schema.ChatMessageTypeHuman,
Parts: parts,
},
}

rsp, err := llm.GenerateContent(context.Background(), content, llms.WithModel("gemini-pro-vision"))
require.NoError(t, err)

assert.NotEmpty(t, rsp.Choices)
c1 := rsp.Choices[0]
assert.Regexp(t, "(?i)parrot", c1.Content)
}

func testEmbeddings(t *testing.T, llm llms.Model) {
t.Helper()
t.Parallel()
Expand Down Expand Up @@ -294,6 +324,6 @@ func testMaxTokensSetting(t *testing.T, llm llms.Model) {
assert.NotEmpty(t, rsp.Choices)
c1 := rsp.Choices[0]
assert.Regexp(t, "(?i)stop", c1.StopReason)
assert.Regexp(t, "(?i)dog|canid|canine", c1.Content)
assert.Regexp(t, "(?i)dog|breed|canid|canine", c1.Content)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a7a7ad6

Please sign in to comment.