@
pike0002 var client *genai.Client
//
geminiOnce.Do(func() {
client, err = genai.NewClient(ctx, option.WithAPIKey(string(apiKey)))
if err != nil {
log.Fatal(err)
}
model := client.GenerativeModel("gemini-1.5-flash-latest")
model.SetTemperature(0.1)
resp, err := model.GenerateContent(ctx, genai.Text("Translate 'Hello world' to Chinese"))
if err != nil {
log.Printf("Error generating content: %v", err)
return "", err
}
for _, candidate := range resp.Candidates {
if candidate != nil {
if candidate.Content.Parts != nil {
log.Printf("Output: %s", string(candidate.Content.Parts[0].(genai.Text)))
}
}
}