-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconverseLogic.go
130 lines (107 loc) · 3.48 KB
/
converseLogic.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main
import (
"aigen/aigenRest"
"log"
"fyne.io/fyne/v2"
)
// Default logic to handle communication with GPT
func defaultCallConverseLogic(message string, tab1 *fyne.Container) {
//message = longTermMemory(message)
model, err := getSelectedModel()
if err != nil {
log.Println(err)
}
var messageCall string
var code error
switch model {
case "OpenAI", "":
messageCall, code = aigenRest.MakeApiCall(message)
case "Claude":
messageCall, code = aigenRest.CallClaude(message)
case "Ollama":
messageCall, code = aigenRest.CallOllama(message)
}
if code != nil {
log.Printf("Error making API call: %v", code)
}
limit := 120
notificationMessage := messageCall
if len(notificationMessage) > limit {
notificationMessage = notificationMessage[:limit]
}
aigenRest.SendNotificationNow(notificationMessage)
log.Printf("Message call: %v", messageCall)
if err != nil {
log.Printf("Error making API call: %v", err)
}
botMessages(messageCall, err, tab1, "text")
addBotMessages := addMessage("Bot", messageCall)
if addBotMessages != nil {
log.Printf("Error adding bot message: %v", addBotMessages)
}
}
// Long Term Memory Logic to add last conversation to GPT
func longTermMemory(message string) string {
lastConvo, lastMessagesSuccess := getLastMessages()
if lastMessagesSuccess != nil {
log.Println(lastMessagesSuccess)
}
//Loop Through Messages From DB and Append
for _, lastConversation := range lastConvo {
//Append text and feed to GPT for long term memory
message = message + " " + lastConversation.Content
log.Printf("Message: %v", message)
}
//Add Prompt to GPT before the lastConversation
message = "This is a conversation betwee us, you are Bot and I am you. " +
"sometimes don't even use this last conversation, just use the last message. , it is for context. " +
"" + message
return message
}
// Display Image and Generate Image Logic
func imageGenerationLogic(message string, tab1 *fyne.Container) {
//generate image
messageCall, err := aigenRest.ImageGenerationCall(message)
limit := 120
notificationMessage := message
if len(notificationMessage) > limit {
notificationMessage = notificationMessage[:limit]
}
//Send notifications after operation
aigenRest.SendNotificationNow("Image Generated Successfully For:" + notificationMessage)
log.Printf("Message call: %v", messageCall)
if err != nil {
log.Printf("Error making API call: %v", err)
}
botMessages(messageCall, err, tab1, "image")
addBotMessages := addMessageWithMedia("Bot", message, "none", messageCall)
if addBotMessages != nil {
log.Printf("Error adding bot message: %v", addBotMessages)
}
}
// Handles Text Detected As Tweet Generation
// twitterPushLogic pushes post to X after processing
func twitterPushLogic(message string, tab1 *fyne.Container) {
messageCall, err := aigenRest.MakeApiCall(message)
limit := 280
/* sendToTwitter, sentSuccess := aigenRest.SendTweet(messageCall)
if sentSuccess != nil {
log.Println(sentSuccess)
log.Println(sendToTwitter)
}
*/
notificationMessage := "Sent Tweet:" + messageCall
if len(notificationMessage) > limit {
notificationMessage = notificationMessage[:limit]
}
aigenRest.SendNotificationNow(notificationMessage)
log.Printf("Message call: %v", messageCall)
if err != nil {
log.Printf("Error making API call: %v", err)
}
botMessages("Tweet Sent:"+messageCall, err, tab1, "text")
addBotMessages := addMessage("Bot", messageCall)
if addBotMessages != nil {
log.Printf("Error adding bot message: %v", addBotMessages)
}
}