diff options
| author | Castor Gemini <[email protected]> | 2025-08-22 11:47:00 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-08-22 11:47:00 -0500 |
| commit | 40243de35b208238e58441d7a9f6973caafaf0d9 (patch) | |
| tree | f56c2df2b6918e558e9a19378304529749edd11a /doImport.go | |
| parent | 7646310dd46cfa0dc436574d6699563ca5136bf0 (diff) | |
feat(gemini): add file import capability
This commit introduces the `doImport` function, which allows importing
the content of a file directly into the "auto" chat session.
The imported content is added as a `ChatEntry` from GEMINI, structured
as a `ToolCall` with the name "Shell" and the file content as the input.
This allows external command outputs to be seamlessly integrated into
the chat history for context.
Diffstat (limited to 'doImport.go')
| -rw-r--r-- | doImport.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/doImport.go b/doImport.go new file mode 100644 index 0000000..ec9edb3 --- /dev/null +++ b/doImport.go @@ -0,0 +1,56 @@ +package main + +import ( + "io/ioutil" + "time" + + "go.wit.com/lib/protobuf/chatpb" + "go.wit.com/log" + "google.golang.org/protobuf/types/known/timestamppb" +) + +func doImport(filename string) { + content, err := ioutil.ReadFile(filename) + if err != nil { + log.Warn("Error reading import file:", err) + return + } + + s := string(content) + + // Load the existing chats. + all := chatpb.NewChats() + if err := all.ConfigLoad(); err != nil { + log.Warn("Error loading config, can't add to auto chat:", err) + return + } + + // Find the "auto" chat. + var autoChat *chatpb.Chat + for _, chat := range all.GetChats() { + if chat.GetChatName() == "auto" { + autoChat = chat + break + } + } + + // If the "auto" chat is found, add the new entry. + if autoChat != nil { + newEntry := &chatpb.ChatEntry{ + From: chatpb.Who_GEMINI, + Ctime: timestamppb.New(time.Now()), + ToolCalls: []*chatpb.ToolCall{ + { + Name: "Shell", + Input: s, + }, + }, + } + autoChat.Entries = append(autoChat.Entries, newEntry) + if err := all.ConfigSave(); err != nil { + log.Warn("Error saving config after adding to auto chat:", err) + } else { + log.Info("Added new entry to 'auto' chat.") + } + } +}
\ No newline at end of file |
