summaryrefslogtreecommitdiff
path: root/bot.go
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2024-11-17 18:55:59 +0300
committerGrail Finder <wohilas@gmail.com>2024-11-17 18:55:59 +0300
commitd3cc8774b13a0c8e9fbf11947b9caca216595a8d (patch)
tree5fef07930e33f0d22fba949797e99c7b9570b01d /bot.go
parentb2c86989264f329bcd102eee7de5d91649643215 (diff)
Feat: toggle system; edit msg; switch focus
Diffstat (limited to 'bot.go')
-rw-r--r--bot.go39
1 files changed, 19 insertions, 20 deletions
diff --git a/bot.go b/bot.go
index 8a09e24..be35a09 100644
--- a/bot.go
+++ b/bot.go
@@ -310,28 +310,27 @@ func chatToText(showSys bool) string {
return strings.Join(s, "")
}
-func textToChat(chat []string) []models.MessagesStory {
+func textToMsg(rawMsg string) models.MessagesStory {
+ msg := models.MessagesStory{}
+ // system and tool?
+ if strings.HasPrefix(rawMsg, assistantIcon) {
+ msg.Role = assistantRole
+ msg.Content = strings.TrimPrefix(rawMsg, assistantIcon)
+ return msg
+ }
+ if strings.HasPrefix(rawMsg, userIcon) {
+ msg.Role = userRole
+ msg.Content = strings.TrimPrefix(rawMsg, userIcon)
+ return msg
+ }
+ return msg
+}
+
+func textSliceToChat(chat []string) []models.MessagesStory {
resp := make([]models.MessagesStory, len(chat))
for i, rawMsg := range chat {
- // trim icon
- var (
- role string
- msg string
- )
- // system and tool?
- if strings.HasPrefix(rawMsg, assistantIcon) {
- role = assistantRole
- msg = strings.TrimPrefix(rawMsg, assistantIcon)
- goto messagebuild
- }
- if strings.HasPrefix(rawMsg, userIcon) {
- role = assistantRole
- msg = strings.TrimPrefix(rawMsg, userIcon)
- goto messagebuild
- }
- messagebuild:
- resp[i].Role = role
- resp[i].Content = msg
+ msg := textToMsg(rawMsg)
+ resp[i] = msg
}
return resp
}