summaryrefslogtreecommitdiff
path: root/dumpchat.go
blob: 2f479ae65515bd34ba38a920705e4145fc905b39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main

import (
	"go.wit.com/lib/protobuf/chatpb"
	"go.wit.com/log"
)

func dumpEntry(entry *chatpb.ChatEntry) {
	log.Printf(entry.FormatTEXT())
}

func dumpchat(chat *chatpb.Chat) error {
	entries := chat.GetEntries()
	var lastEntry *chatpb.ChatEntry
	if len(entries) > 0 {
		lastEntry = entries[len(entries)-1]
	} else {
		return log.Errorf("no entries")
	}
	if argv.Playback.Last != nil {
		dumpEntry(lastEntry)
	}
	if argv.Playback.Submit != nil {
		if lastEntry.GeminiRequest == nil {
			return log.Errorf("lastEntry.GeminiRequest == nil")
		}
		aichat, err := convertToGenai(lastEntry.GeminiRequest)
		if err != nil {
			log.Info("convertToGenai() returned with error", err)
			return err
		}
		err = submitChat(aichat)
		if err != nil {
			log.Info("submitChat() returned with error", err)
			return err
		}
	}
	return nil
}