Skip to content

Commit

Permalink
add test and example
Browse files Browse the repository at this point in the history
  • Loading branch information
jba committed Apr 15, 2024
1 parent 1dc2833 commit 3360989
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
16 changes: 16 additions & 0 deletions vertexai/genai/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ func TestLive(t *testing.T) {
got := responseString(resp)
checkMatch(t, got, `15.* cm|[1-9].* inches`)
})
t.Run("system-instructions", func(t *testing.T) {
t.Skip("feature not yet available")
model := client.GenerativeModel(*modelName)
model.Temperature = Ptr[float32](0)
model.SystemInstruction = &Content{
Parts: []Part{Text("You are Yoda from Star Wars.")},
}
resp, err := model.GenerateContent(ctx, Text("What is the average size of a swallow?"))
if err != nil {
t.Fatal(err)
}
got := responseString(resp)
checkMatch(t, got, `15.* cm|[1-9].* inches`)
fmt.Println(got)

})

t.Run("streaming", func(t *testing.T) {
iter := model.GenerateContentStream(ctx, Text("Are you hungry?"))
Expand Down
25 changes: 25 additions & 0 deletions vertexai/genai/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,31 @@ func ExampleGenerativeModel_GenerateContent() {
printResponse(resp)
}

// This example shows how to a configure a model. See [GenerationConfig]
// for the complete set of configuration options.
func ExampleGenerativeModel_GenerateContent_config() {
ctx := context.Background()
client, err := genai.NewClient(ctx, option.WithAPIKey(os.Getenv("GEMINI_API_KEY")))
if err != nil {
log.Fatal(err)
}
defer client.Close()

model := client.GenerativeModel("gemini-1.0-pro")
model.SetTemperature(0.9)
model.SetTopP(0.5)
model.SetTopK(20)
model.SetMaxOutputTokens(100)
model.SystemInstruction = &genai.Content{
Parts: []genai.Part{genai.Text("You are Yoda from Star Wars.")},
}
resp, err := model.GenerateContent(ctx, genai.Text("What is the average size of a swallow?"))
if err != nil {
log.Fatal(err)
}
printResponse(resp)
}

func ExampleGenerativeModel_GenerateContentStream() {
ctx := context.Background()
client, err := genai.NewClient(ctx, projectID, location)
Expand Down

0 comments on commit 3360989

Please sign in to comment.