From c65619154eb37912be8af563de113e028665633c Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 1 Sep 2025 01:55:06 -0500 Subject: [PATCH] sub in the functions --- addResponse.go | 13 +++++++++++++ convertToPB.go | 12 ++++++++++++ doPlayback.go | 6 +++--- structs.go | 11 ++++++----- submitChat.go | 27 +++++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 addResponse.go create mode 100644 convertToPB.go create mode 100644 submitChat.go diff --git a/addResponse.go b/addResponse.go new file mode 100644 index 0000000..4c04c69 --- /dev/null +++ b/addResponse.go @@ -0,0 +1,13 @@ +package main + +import ( + "go.wit.com/log" + "google.golang.org/genai" +) + +func addResponse(resp *genai.GenerateContentResponse) { + pb := convertToPB(resp) + log.Info(resp) + me.lastChat.AppendEntry(pb) + me.chats.ConfigSave() +} diff --git a/convertToPB.go b/convertToPB.go new file mode 100644 index 0000000..3f87e34 --- /dev/null +++ b/convertToPB.go @@ -0,0 +1,12 @@ +package main + +import ( + "go.wit.com/lib/protobuf/chatpb" + "google.golang.org/genai" +) + +func convertToPB(resp *genai.GenerateContentResponse) *chatpb.ChatEntry { + pb := new(chatpb.ChatEntry) + // TODO: add the code to convert the response to the protobuf + return pb +} diff --git a/doPlayback.go b/doPlayback.go index 2db75ae..8482805 100644 --- a/doPlayback.go +++ b/doPlayback.go @@ -77,9 +77,9 @@ func listChats(chats *chatpb.Chats) { // Get the last chat numChats := len(chats.GetChats()) if numChats > 0 { - lastChat := chats.GetChats()[numChats-1] - log.Printf("The current Gemini API session is UUID: %s\n", lastChat.GetUuid()) - dumpchat(lastChat) + me.lastChat = chats.GetChats()[numChats-1] + log.Printf("The current Gemini API session is UUID: %s\n", me.lastChat.GetUuid()) + dumpchat(me.lastChat) } } diff --git a/structs.go b/structs.go index 16c63e9..f56498d 100644 --- a/structs.go +++ b/structs.go @@ -16,9 +16,10 @@ var me *mainType // this app's variables type mainType struct { - pp *arg.Parser // for parsing the command line args. Yay to alexf lint! - chats *chatpb.Chats // all our prior conversations with regex - myGui *gui.Node // the gui toolkit handle - client *genai.Client // the Google Gemini AI client variable - ctx context.Context + pp *arg.Parser // for parsing the command line args. Yay to alexf lint! + chats *chatpb.Chats // all our prior conversations with regex + myGui *gui.Node // the gui toolkit handle + client *genai.Client // the Google Gemini AI client variable + ctx context.Context // global context. what does this acutally mean? + lastChat *chatpb.Chat // the last chat. append to here } diff --git a/submitChat.go b/submitChat.go new file mode 100644 index 0000000..89e0160 --- /dev/null +++ b/submitChat.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + + "go.wit.com/log" + "google.golang.org/genai" +) + +func submitChat(content []*genai.Content) error { + resp, err := me.client.Models.GenerateContent(me.ctx, "gemini-2.5-flash", content, nil) + if err != nil { + return log.Errorf("error sending message: %v", err) + } + + log.Info("Response from API:") + for _, cand := range resp.Candidates { + if cand.Content != nil { + for _, part := range cand.Content.Parts { + fmt.Println(part) + } + } + } + // TODO: add the response to the protobuf + addResponse(resp) + return nil +}