pocketbase integration for persisting data
This commit is contained in:
parent
488f733ab1
commit
732e8856b7
@ -19,6 +19,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
|
pb.Init()
|
||||||
discord, err := discordgo.New("Bot " + BotToken)
|
discord, err := discordgo.New("Bot " + BotToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -28,7 +29,6 @@ func Run() {
|
|||||||
|
|
||||||
discord.Open()
|
discord.Open()
|
||||||
defer discord.Close()
|
defer discord.Close()
|
||||||
pb.Run()
|
|
||||||
log.Info("BitBot is running...")
|
log.Info("BitBot is running...")
|
||||||
|
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
|
|||||||
14
bot/chat.go
14
bot/chat.go
@ -10,10 +10,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
maxTokens = 2000
|
maxTokens = 4000
|
||||||
maxContextTokens = 16000
|
maxContextTokens = 2000
|
||||||
maxMessageTokens = 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 {
|
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)
|
messages = append(messages, userMessage)
|
||||||
|
|
||||||
// Perform GPT-3.5 Turbo completion
|
// Perform GPT-4 completion
|
||||||
log.Info("Starting GPT-3.5 Turbo completion...")
|
log.Info("Starting completion...")
|
||||||
resp, err := client.CreateChatCompletion(
|
resp, err := client.CreateChatCompletion(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
openai.ChatCompletionRequest{
|
openai.ChatCompletionRequest{
|
||||||
MaxTokens: maxTokens,
|
MaxTokens: maxTokens,
|
||||||
FrequencyPenalty: 0.3,
|
FrequencyPenalty: 0.3,
|
||||||
PresencePenalty: 0.6,
|
PresencePenalty: 0.6,
|
||||||
Model: openai.GPT3Dot5Turbo16K,
|
Model: openai.GPT3Dot5Turbo,
|
||||||
Messages: messages,
|
Messages: messages,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
log.Info("GPT-3.5 Turbo completion done.")
|
log.Info("completion done.")
|
||||||
|
|
||||||
// Handle API errors
|
// Handle API errors
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
39
pb/pb.go
39
pb/pb.go
@ -1,17 +1,42 @@
|
|||||||
|
// pb.go
|
||||||
package pb
|
package pb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/charmbracelet/log"
|
"github.com/charmbracelet/log"
|
||||||
"github.com/pocketbase/pocketbase"
|
"github.com/pocketbase/pocketbase"
|
||||||
|
"github.com/pocketbase/pocketbase/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Run() {
|
var (
|
||||||
app := pocketbase.New()
|
app *pocketbase.PocketBase
|
||||||
|
once sync.Once
|
||||||
|
)
|
||||||
|
|
||||||
func() {
|
// Init initializes the PocketBase app
|
||||||
if err := app.Start(); err != nil {
|
func Init() {
|
||||||
log.Fatal(err)
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user