Skip to content

Commit

Permalink
Add multi-turn tests for new GenerateContent capabilities (#501)
Browse files Browse the repository at this point in the history
For both openai and googleai providers
  • Loading branch information
eliben authored Jan 8, 2024
1 parent bab173f commit 869463f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
27 changes: 27 additions & 0 deletions llms/googleai/googleai_llm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ func TestMultiContentText(t *testing.T) {
assert.Regexp(t, "dog|canid|canine", strings.ToLower(c1.Content))
}

func TestMultiContentTextChatSequence(t *testing.T) {
t.Parallel()
llm := newClient(t)

content := []llms.MessageContent{
{
Role: schema.ChatMessageTypeHuman,
Parts: []llms.ContentPart{llms.TextContent{Text: "Name some countries"}},
},
{
Role: schema.ChatMessageTypeAI,
Parts: []llms.ContentPart{llms.TextContent{Text: "Spain and Lesotho"}},
},
{
Role: schema.ChatMessageTypeHuman,
Parts: []llms.ContentPart{llms.TextContent{Text: "Which if these is larger?"}},
},
}

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

assert.NotEmpty(t, rsp.Choices)
c1 := rsp.Choices[0]
assert.Regexp(t, "spain.*larger", strings.ToLower(c1.Content))
}

func TestMultiContentImage(t *testing.T) {
t.Parallel()
llm := newClient(t)
Expand Down
27 changes: 27 additions & 0 deletions llms/openai/multicontent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@ func TestMultiContentText(t *testing.T) {
assert.Regexp(t, "dog|canid", strings.ToLower(c1.Content))
}

func TestMultiContentTextChatSequence(t *testing.T) {
t.Parallel()
llm := newChatClient(t)

content := []llms.MessageContent{
{
Role: schema.ChatMessageTypeHuman,
Parts: []llms.ContentPart{llms.TextContent{Text: "Name some countries"}},
},
{
Role: schema.ChatMessageTypeAI,
Parts: []llms.ContentPart{llms.TextContent{Text: "Spain and Lesotho"}},
},
{
Role: schema.ChatMessageTypeHuman,
Parts: []llms.ContentPart{llms.TextContent{Text: "Which if these is larger?"}},
},
}

rsp, err := llm.GenerateContent(context.Background(), content)
require.NoError(t, err)

assert.NotEmpty(t, rsp.Choices)
c1 := rsp.Choices[0]
assert.Regexp(t, "spain.*larger", strings.ToLower(c1.Content))
}

func TestMultiContentImage(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 869463f

Please sign in to comment.