From f5b513fa05ddbaaa2149cf0527ae1206e653266b Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 3 Sep 2025 01:19:37 -0500 Subject: buttons for different stuff --- apiExampleCode.go | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 apiExampleCode.go (limited to 'apiExampleCode.go') diff --git a/apiExampleCode.go b/apiExampleCode.go new file mode 100644 index 0000000..d444f4e --- /dev/null +++ b/apiExampleCode.go @@ -0,0 +1,65 @@ +package main + +// this is just example code the GO API's wrapper for handling statelessness +// it doesn't really compile and is just junk Gemini AI sent back but I saved it here anyway + +/* +func statelessnessExample() { + ctx := context.Background() + // Get the API key from an environment variable + apiKey := os.Getenv("GEMINI_API_KEY") + if apiKey == "" { + log.Fatal("GEMINI_API_KEY environment variable not set") + } + + // Create a new client + client, err := genai.NewClient(ctx, option.WithAPIKey(apiKey)) + if err != nil { + log.Fatal(err) + } + defer client.Close() + + // Choose the model + model := client.GenerativeModel("gemini-1.5-flash") + + // ---- Start a new chat session ---- + cs := model.StartChat() + cs.History = []*genai.Content{} // Start with a clean history + + // --- First message --- + fmt.Println("User: My brother's name is Paul.") + resp, err := cs.SendMessage(ctx, genai.Text("My brother's name is Paul.")) + if err != nil { + log.Fatal(err) + } + printResponse(resp) + + // --- Second message --- + // The ChatSession now remembers the previous exchange. + fmt.Println("\nUser: What is my brother's name?") + resp, err = cs.SendMessage(ctx, genai.Text("What is my brother's name?")) + if err != nil { + log.Fatal(err) + } + printResponse(resp) + + // You can inspect the history at any time + // fmt.Println("\n--- Full Chat History ---") + // for _, content := range cs.History { + // for _, part := range content.Parts { + // fmt.Printf("Role: %s, Text: %v\n", content.Role, part) + // } + // } +} + +// Helper function to print the response +func printResponse(resp *genai.GenerateContentResponse) { + for _, cand := range resp.Candidates { + if cand.Content != nil { + for _, part := range cand.Content.Parts { + fmt.Printf("Gemini: %v\n", part) + } + } + } +} +*/ -- cgit v1.2.3