aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-05-10 20:20:52 +0000
committerterminaldweller <devi@terminaldweller.com>2024-05-10 20:20:52 +0000
commit394a7e93caadd21e777b77e804c1c663e555cf50 (patch)
tree98ec0c0b7ac1bbc4369fc3d2a32a08319f4f20eb
parentadding chat to gemini (diff)
downloadmilla-394a7e93caadd21e777b77e804c1c663e555cf50.tar.gz
milla-394a7e93caadd21e777b77e804c1c663e555cf50.zip
fixes #5
-rw-r--r--main.go22
1 files changed, 17 insertions, 5 deletions
diff --git a/main.go b/main.go
index c2c3565..737454f 100644
--- a/main.go
+++ b/main.go
@@ -96,6 +96,7 @@ func returnGeminiResponse(resp *genai.GenerateContentResponse) string {
func runIRC(appConfig TomlConfig, ircChan chan *girc.Client) {
var Memory []MemoryElement
+ var GPTMemory []openai.ChatCompletionMessage
irc := girc.New(girc.Config{
Server: appConfig.IrcServer,
@@ -288,6 +289,10 @@ func runIRC(appConfig TomlConfig, ircChan chan *girc.Client) {
// return
// }
+ if len(cs.History) > appConfig.MemoryLImit {
+ cs.History = cs.History[:0]
+ }
+
geminiResponse := returnGeminiResponse(resp)
log.Println(geminiResponse)
@@ -351,16 +356,14 @@ func runIRC(appConfig TomlConfig, ircChan chan *girc.Client) {
gptClient := openai.NewClientWithConfig(config)
- messages := make([]openai.ChatCompletionMessage, 0)
-
- messages = append(messages, openai.ChatCompletionMessage{
- Role: "system",
+ GPTMemory = append(GPTMemory, openai.ChatCompletionMessage{
+ Role: openai.ChatMessageRoleUser,
Content: prompt,
})
resp, err := gptClient.CreateChatCompletion(ctx, openai.ChatCompletionRequest{
Model: appConfig.Model,
- Messages: messages,
+ Messages: GPTMemory,
})
if err != nil {
client.Cmd.ReplyTo(event, fmt.Sprintf("error: %s", err.Error()))
@@ -368,6 +371,15 @@ func runIRC(appConfig TomlConfig, ircChan chan *girc.Client) {
return
}
+ GPTMemory = append(GPTMemory, openai.ChatCompletionMessage{
+ Role: openai.ChatMessageRoleAssistant,
+ Content: resp.Choices[0].Message.Content,
+ })
+
+ if len(GPTMemory) > appConfig.MemoryLImit {
+ GPTMemory = GPTMemory[:0]
+ }
+
var writer bytes.Buffer
err = quick.Highlight(
&writer,