pocketbase integration for persisting data

This commit is contained in:
Kristian 2023-10-06 17:17:26 +02:00
parent 488f733ab1
commit 732e8856b7
3 changed files with 40 additions and 15 deletions

View File

@ -19,6 +19,7 @@ var (
)
func Run() {
pb.Init()
discord, err := discordgo.New("Bot " + BotToken)
if err != nil {
log.Fatal(err)
@ -28,7 +29,6 @@ func Run() {
discord.Open()
defer discord.Close()
pb.Run()
log.Info("BitBot is running...")
c := make(chan os.Signal, 1)

View File

@ -10,10 +10,10 @@ import (
)
const (
maxTokens = 2000
maxContextTokens = 16000
maxTokens = 4000
maxContextTokens = 2000
maxMessageTokens = 2000
systemMessageText = "0. your name is bit you are a discord bot 1. Identify the key points or main ideas of the original answers.\n2. Summarize each answer using concise and informative language.\n3. Prioritize clarity and brevity, capturing the essence of the information provided.\n4. Trim down unnecessary details and avoid elaboration.\n5. Make sure the summarized answers still convey accurate and meaningful information."
systemMessageText = "0. your name is !bit you are a discord bot 1. Identify the key points or main ideas of the original answers.\n2. Summarize each answer using concise and informative language.\n3. Prioritize clarity and brevity, capturing the essence of the information provided.\n4. Trim down unnecessary details and avoid elaboration.\n5. Make sure the summarized answers still convey accurate and meaningful information."
)
func populateConversationHistory(session *discordgo.Session, channelID string, conversationHistory []openai.ChatCompletionMessage) []openai.ChatCompletionMessage {
@ -94,19 +94,19 @@ func chatGPT(session *discordgo.Session, channelID string, message string, conve
}
messages = append(messages, userMessage)
// Perform GPT-3.5 Turbo completion
log.Info("Starting GPT-3.5 Turbo completion...")
// Perform GPT-4 completion
log.Info("Starting completion...")
resp, err := client.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
MaxTokens: maxTokens,
FrequencyPenalty: 0.3,
PresencePenalty: 0.6,
Model: openai.GPT3Dot5Turbo16K,
Model: openai.GPT3Dot5Turbo,
Messages: messages,
},
)
log.Info("GPT-3.5 Turbo completion done.")
log.Info("completion done.")
// Handle API errors
if err != nil {

View File

@ -1,17 +1,42 @@
// pb.go
package pb
import (
"sync"
"github.com/charmbracelet/log"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/models"
)
func Run() {
app := pocketbase.New()
var (
app *pocketbase.PocketBase
once sync.Once
)
func() {
if err := app.Start(); err != nil {
log.Fatal(err)
}
}()
// Init initializes the PocketBase app
func Init() {
once.Do(func() {
app = pocketbase.New()
// Add any necessary configuration or initialization here
func() {
if err := app.Start(); err != nil {
log.Fatal(err)
}
}()
})
}
func GetRecordById(collectionID string, recordID string) (*models.Record, error) {
// Access the PocketBase DAO and perform database operations
// Example: Retrieve all records from the "articles" collection
record, err := app.Dao().FindRecordById(collectionID, recordID)
if err != nil {
log.Error(err)
return nil, err
}
return record, nil
}