-
Notifications
You must be signed in to change notification settings - Fork 1
/
chat.go
56 lines (44 loc) · 1.24 KB
/
chat.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package options
import (
"errors"
tea "github.com/charmbracelet/bubbletea"
"github.com/MohammadBnei/go-ai-cli/service"
"github.com/MohammadBnei/go-ai-cli/ui/event"
"github.com/MohammadBnei/go-ai-cli/ui/list"
"github.com/MohammadBnei/go-ai-cli/ui/loadchat"
"github.com/MohammadBnei/go-ai-cli/ui/savechat"
)
type chatModel struct {
list list.Model
title string
}
const (
SAVE = "save"
SAVE_MODELFILE = "save as modelfile"
LOAD = "load"
CLEAR = "clear"
)
func NewChatOptionsModel(pc *service.PromptConfig) tea.Model {
items := getCOItemsAsUiList(pc)
return list.NewFancyListModel("Options > Chat", items, &list.DelegateFunctions{
ChooseFn: func(id string) tea.Cmd {
switch id {
case SAVE:
return event.AddStack(savechat.NewSaveChatModel(pc), "Loading Save chat...")
case LOAD:
return event.AddStack(loadchat.NewLoadChatModel(pc), "Loading Load chat...")
case CLEAR:
pc.ChatMessages.ClearMessages()
return event.RemoveStack(list.Model{})
}
return event.Error(errors.New("unknown option: " + id))
},
})
}
func getCOItemsAsUiList(pc *service.PromptConfig) []list.Item {
return []list.Item{
{ItemId: SAVE, ItemTitle: "Save"},
{ItemId: LOAD, ItemTitle: "Load"},
{ItemId: CLEAR, ItemTitle: "Clear"},
}
}