summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-02 01:21:48 -0500
committerJeff Carr <[email protected]>2025-09-02 01:21:48 -0500
commitaebfe325d63a947d936c069a8cffd3b2d631aeae (patch)
tree2a19e7287ca08d84b5d375b7b753498364497471
parent49ad81bc279a8b1669f68e5d02c95d2a66a5cb4b (diff)
functions to double check the sanity of JSON Marshal
-rw-r--r--addChat.go22
-rw-r--r--helpers.go32
2 files changed, 47 insertions, 7 deletions
diff --git a/addChat.go b/addChat.go
index 972bb42..f33650f 100644
--- a/addChat.go
+++ b/addChat.go
@@ -6,7 +6,6 @@ import (
"time"
"go.wit.com/log"
- timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)
// returns true if the pb was added
@@ -15,14 +14,23 @@ func (c *Chat) AddGeminiRequest(fname string, age time.Time, pb *GeminiRequest)
for _, e := range c.GetEntries() {
if e.GetContentFile() == fname {
log.Info("fname already here", fname)
+ if iContent, iParts, ok := e.VerifyGeminiRequest(pb); ok {
+ log.Info("pb is already here with same size", iContent, iParts)
+ return false
+ } else {
+ log.Info("pb is already here but things don't match", iContent, iParts)
+ }
return false
}
}
- e := new(ChatEntry)
- e.Ctime = timestamppb.New(age)
- e.From = Who_USER
- e.ContentFile = fname
- e.GeminiRequest = pb
- c.AppendEntry(e)
+ log.Info("not sure if c.Entries == pb for real. need to read Content & Parts")
+ /*
+ e := new(ChatEntry)
+ e.Ctime = timestamppb.New(age)
+ e.From = Who_USER
+ e.ContentFile = fname
+ e.GeminiRequest = pb
+ c.AppendEntry(e)
+ */
return true
}
diff --git a/helpers.go b/helpers.go
index 35acf88..27f6a73 100644
--- a/helpers.go
+++ b/helpers.go
@@ -101,3 +101,35 @@ func (x *Chat) AppendEntry(y *ChatEntry) {
x.Entries = append(x.Entries, proto.Clone(y).(*ChatEntry))
}
+
+// returns true if the pb is probably the same
+func (c *ChatEntry) VerifyGeminiRequest(pb *GeminiRequest) (int, int, bool) {
+ if c.GeminiRequest == nil {
+ log.Warn("There is no GeminiRequest in the chat protobuf")
+ return -1, -1, false
+ }
+ if pb == nil {
+ log.Warn("There is no GeminiRequest in the passed in protobuf")
+ return -1, -1, false
+ }
+ if len(c.GeminiRequest.GetContents()) != len(pb.GetContents()) {
+ log.Warn("c != pb", len(c.GeminiRequest.GetContents()), len(pb.GetContents()))
+ return -1, -1, false
+ }
+ var cCount int // # of Parts in all the Contents
+ var pbCount int // # of Parts in all the Contents
+ for _, grc := range c.GeminiRequest.GetContents() {
+ cCount += len(grc.GetParts())
+
+ }
+ for _, grc := range pb.GetContents() {
+ pbCount += len(grc.GetParts())
+
+ }
+ if cCount != pbCount {
+ log.Warn("c != pb", cCount, pbCount)
+ return len(c.GeminiRequest.GetContents()), cCount, false
+ }
+ log.Info("EVERYTHING MATCHED", cCount, pbCount, len(c.GeminiRequest.GetContents()), len(pb.GetContents()))
+ return len(c.GeminiRequest.GetContents()), cCount, true
+}