It seems that no matter how hard I try to program in Go, I have yet to actually make any Go script of mine work. I try to use it, everybody talks about its performance and whatnot, but I am always spending way more time debugging simple Go code than actually writing anything and making progress.
Anyways, I wanted to make a simple Go script to dump in a serverless architecture. Right now though, it’s just running on my computer. It’s pretty basic, almost straight from the docs:
func main() {
ctx := context.Background()
// Access your API key as an environment variable (see "Set up your API key" above)
client, err := genai.NewClient(ctx, option.WithAPIKey(os.Getenv("GEMINI_API_KEY")))
if err != nil {
log.Fatal(err)
}
defer client.Close()
// For text-only input, use the gemini-pro model
model := client.GenerativeModel("gemini-pro")
resp, err := model.GenerateContent(ctx, genai.Text("Write a story about a magic backpack."))
if err != nil {
log.Fatal(err)
}
fmt.Println(*resp)
}
It should return and print Gemini’s response. Instead, it returns this:
{[0xc0004eea00] <nil>}
I cannot understand why, nor if this is a me problem or an API problem.
If I print resp
and not *resp
, it just gives me the memory address of the exact thing above.
What’s interesting is that the code does wait for Gemini to run and complete the response. When it does, this is what it spits out.
I have also tried using the streaming version of it, and it does the same thing, but it’ll give 3-4 nil values. So, it’s gotta be something to do with the way it’s stored, handled, or passed.
I don’t have issues calling Gemini in languages like js with the API. This is specific to Go.
Anyone know what’s going on and/or what I did here?