-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathconfigure_model_parameters.go
More file actions
45 lines (39 loc) · 972 Bytes
/
configure_model_parameters.go
File metadata and controls
45 lines (39 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package examples
import (
"context"
"os"
"log"
"google.golang.org/genai"
)
func ConfigureModelParameters() (*genai.GenerateContentResponse, error) {
// [START configure_model_parameters]
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig{
APIKey: os.Getenv("GEMINI_API_KEY"),
Backend: genai.BackendGeminiAPI,
})
if err != nil {
log.Fatal(err)
}
// Create local variables for parameters.
candidateCount := int32(1)
maxOutputTokens := int32(20)
temperature := float32(1.0)
response, err := client.Models.GenerateContent(
ctx,
"gemini-2.5-flash",
genai.Text("Tell me a story about a magic backpack."),
&genai.GenerateContentConfig{
CandidateCount: candidateCount,
StopSequences: []string{"x"},
MaxOutputTokens: maxOutputTokens,
Temperature: &temperature,
},
)
if err != nil {
log.Fatal(err)
}
printResponse(response)
// [END configure_model_parameters]
return response, err
}