Skip to content

Commit

Permalink
test that streaming and final answer contain the same text. (#382)
Browse files Browse the repository at this point in the history
* test that streaming and final answer contain the same text.

This should already be the case, just testing it.

* Just use the one candidate to check streaming results
  • Loading branch information
randall77 authored Jun 10, 2024
1 parent 465c2f6 commit 9d5bc47
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion go/plugins/googleai/googleai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,21 @@ func TestLive(t *testing.T) {
out := ""
parts := 0
g := googleai.Model(generativeModel)
_, err = ai.Generate(ctx, g, req, func(ctx context.Context, c *ai.GenerateResponseChunk) error {
final, err := ai.Generate(ctx, g, req, func(ctx context.Context, c *ai.GenerateResponseChunk) error {
parts++
out += c.Content[0].Text
return nil
})
if err != nil {
t.Fatal(err)
}
out2 := ""
for _, p := range final.Candidates[0].Message.Content {
out2 += p.Text
}
if out != out2 {
t.Errorf("streaming and final should contain the same text.\nstreaming:%s\nfinal:%s", out, out2)
}
const want = "Golden"
if !strings.Contains(out, want) {
t.Errorf("got %q, expecting it to contain %q", out, want)
Expand Down

0 comments on commit 9d5bc47

Please sign in to comment.