buttons for different stuff
This commit is contained in:
parent
785591ab4c
commit
f5b513fa05
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -87,7 +87,7 @@ func cleanGeminiFile(fullname string) error {
|
|||
return log.Errorf("parsePB() == nil")
|
||||
}
|
||||
uuid := parts[1]
|
||||
if argv.Clean.Match != "" {
|
||||
if argv.Clean != nil && argv.Clean.Match != "" {
|
||||
if !strings.HasPrefix(uuid, argv.Clean.Match) {
|
||||
return log.Errorf("uuid %s does not match %s", uuid, argv.Clean.Match)
|
||||
}
|
||||
|
@ -101,6 +101,7 @@ func cleanGeminiFile(fullname string) error {
|
|||
me.chats.ConfigSave()
|
||||
} else {
|
||||
log.Info("file was perfect. os.Remove() here", fullname)
|
||||
chat.PrintChatGeminiTable()
|
||||
os.Remove(fullname)
|
||||
|
||||
}
|
||||
|
|
15
doConnect.go
15
doConnect.go
|
@ -10,8 +10,11 @@ import (
|
|||
"google.golang.org/genai"
|
||||
)
|
||||
|
||||
// doConnect initializes the Gemini client and handles the request flow.
|
||||
func doConnect() error {
|
||||
func initGeminiAPI() error {
|
||||
if me.ctx != nil {
|
||||
// already initialized
|
||||
return nil
|
||||
}
|
||||
apiKey := os.Getenv("GEMINI_API_KEY")
|
||||
if apiKey == "" {
|
||||
return log.Errorf("GEMINI_API_KEY environment variable not set")
|
||||
|
@ -23,6 +26,12 @@ func doConnect() error {
|
|||
if err != nil {
|
||||
return log.Errorf("failed to create new genai client: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// doConnect initializes the Gemini client and handles the request flow.
|
||||
func doConnect() error {
|
||||
initGeminiAPI()
|
||||
|
||||
if me.lastChat == nil {
|
||||
log.Info("WTF. lastChat is nil")
|
||||
|
@ -105,7 +114,7 @@ func simpleHello() error {
|
|||
|
||||
// Create the parts slice
|
||||
parts := []*genai.Part{
|
||||
{Text: "hello, how are you"},
|
||||
{Text: "What is my brothers name?"},
|
||||
}
|
||||
|
||||
content := []*genai.Content{{Parts: parts}}
|
||||
|
|
29
doGui.go
29
doGui.go
|
@ -14,6 +14,7 @@ import (
|
|||
"go.wit.com/lib/debugger"
|
||||
"go.wit.com/lib/gadgets"
|
||||
"go.wit.com/lib/gui/logsettings"
|
||||
"go.wit.com/lib/gui/shell"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
|
@ -30,14 +31,16 @@ func doGui() {
|
|||
// me.myGui.SetAppDefaultPlugin(me.forge.Config.DefaultGui)
|
||||
me.myGui.Default()
|
||||
|
||||
me.mainWindow = gadgets.NewGenericWindow("regex: a WIT Cloud private AI tool", "Current Conversations")
|
||||
win := gadgets.NewGenericWindow("regex: a WIT Cloud private AI tool", "Current Conversations")
|
||||
|
||||
drawWindow(me.mainWindow)
|
||||
drawWindow(win)
|
||||
|
||||
me.mainWindow.Custom = func() {
|
||||
win.Custom = func() {
|
||||
log.Warn("MAIN WINDOW CLOSE")
|
||||
me.myGui.StandardExit()
|
||||
os.Exit(0)
|
||||
}
|
||||
me.mainWindow = win
|
||||
|
||||
// sits here forever
|
||||
debug()
|
||||
|
@ -62,14 +65,22 @@ func drawWindow(win *gadgets.GenericWindow) {
|
|||
insertWin = makeChatsWindow()
|
||||
})
|
||||
|
||||
var oldWin *gadgets.GenericWindow
|
||||
grid.NewButton("old", func() {
|
||||
if oldWin != nil {
|
||||
oldWin.Toggle()
|
||||
return
|
||||
grid.NewButton("simple hello", func() {
|
||||
err := simpleHello()
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
oldWin = makeOldStuff()
|
||||
})
|
||||
grid.NewButton("submit question", func() {
|
||||
doEditorOnce()
|
||||
})
|
||||
grid.NewButton("print playback", func() {
|
||||
shell.RunVerbose([]string{"regex", "playback"})
|
||||
})
|
||||
grid.NewButton("clean", func() {
|
||||
doClean()
|
||||
})
|
||||
grid.NextRow()
|
||||
|
||||
grid.NewButton("debugger", func() {
|
||||
debugger.DebugWindow()
|
||||
|
|
10
main.go
10
main.go
|
@ -64,12 +64,10 @@ func main() {
|
|||
log.Printf("The current Gemini API session is UUID: %s\n", me.lastChat.GetUuid())
|
||||
}
|
||||
|
||||
/*
|
||||
err := doConnect()
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
*/
|
||||
err = initGeminiAPI()
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
|
||||
if argv.JsonFile != "" {
|
||||
doJSON()
|
||||
|
|
|
@ -66,9 +66,23 @@ func addBooksPB(win *gadgets.GenericWindow, pb *chatpb.Books) *chatpb.BooksTable
|
|||
}
|
||||
|
||||
// add a general show button
|
||||
bf := t.AddButtonFunc("cur version", func(chat *chatpb.Book) string { return "show" })
|
||||
bf.Custom = func(r *chatpb.Book) {
|
||||
log.Info("todo: show a chat window here", r.GetUuid())
|
||||
bf := t.AddButtonFunc("cur version", func(chat *chatpb.Book) string { return "submit" })
|
||||
bf.Custom = func(book *chatpb.Book) {
|
||||
log.Info("convert pb to genai GO API HERE", book.GetUuid())
|
||||
if book.GetGeminiRequest() == nil {
|
||||
return
|
||||
}
|
||||
aichat, err := convertToGenai(book.GetGeminiRequest())
|
||||
if err != nil {
|
||||
log.Info("convertToGenai() returned with error", err)
|
||||
return
|
||||
}
|
||||
err = submitChat(aichat)
|
||||
if err != nil {
|
||||
log.Info("submitChat() returned with error", err)
|
||||
return
|
||||
}
|
||||
log.Info("submitChat() appears to have worked?")
|
||||
}
|
||||
|
||||
// show the age of the chat
|
||||
|
|
|
@ -37,6 +37,7 @@ func makeChatsWindow() *gadgets.GenericWindow {
|
|||
insertWin := gadgets.NewGenericWindow("regex Chats", "Display Chats")
|
||||
insertWin.Win.Custom = func() {
|
||||
log.Info("test delete window here")
|
||||
insertWin.Hide()
|
||||
}
|
||||
grid := insertWin.Group.RawGrid()
|
||||
|
||||
|
@ -142,6 +143,7 @@ func makeBooksTable(chat *chatpb.Chat) *chatpb.Books {
|
|||
var pb *chatpb.Books
|
||||
|
||||
pb = chatpb.NewBooks()
|
||||
pb.TitleUuid = chat.Uuid
|
||||
|
||||
for _, entry := range chat.GetEntries() {
|
||||
if entry.GeminiRequest == nil {
|
||||
|
@ -155,5 +157,6 @@ func makeBooksTable(chat *chatpb.Chat) *chatpb.Books {
|
|||
newb.GeminiRequest = entry.GeminiRequest
|
||||
pb.Append(newb)
|
||||
}
|
||||
pb.ConfigSave()
|
||||
return pb
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue