ingst chat message added

This commit is contained in:
Christoph K.
2026-03-12 19:20:05 +01:00
parent 5337e7af6f
commit 75003b9534
2 changed files with 50 additions and 0 deletions

View File

@@ -37,6 +37,18 @@ var (
Name: "ingest",
Description: "Importiert Markdown-Notizen aus brain_root in die Wissensdatenbank",
},
{
Name: "remember",
Description: "Speichert eine Nachricht in der Wissensdatenbank",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Name: "text",
Description: "Der Text, der gespeichert werden soll",
Required: true,
},
},
},
}
)
@@ -107,6 +119,8 @@ func onInteraction(s *discordgo.Session, i *discordgo.InteractionCreate) {
handleAsk(s, i, i.ApplicationCommandData().Options[0].StringValue())
case "ingest":
handleIngest(s, i)
case "remember":
handleRemember(s, i)
}
}
@@ -170,6 +184,25 @@ func handleIngest(s *discordgo.Session, i *discordgo.InteractionCreate) {
})
}
func handleRemember(s *discordgo.Session, i *discordgo.InteractionCreate) {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseDeferredChannelMessageWithSource,
})
text := i.ApplicationCommandData().Options[0].StringValue()
author := i.Member.User.Username
source := fmt.Sprintf("discord/#%s", i.ChannelID)
err := brain.IngestChatMessage(text, author, source)
var msg string
if err != nil {
msg = fmt.Sprintf("❌ Fehler beim Speichern: %v", err)
} else {
msg = fmt.Sprintf("✅ Gespeichert: _%s_", text)
}
s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Content: &msg})
}
func queryAndFormat(question string) string {
answer, chunks, err := brain.AskQuery(question)
if err != nil {

View File

@@ -234,4 +234,21 @@ func ingestChunks(ctx context.Context, embClient *openai.Client, pointsClient pb
return err
}
// IngestChatMessage speichert eine einzelne Chat-Nachricht in Qdrant.
func IngestChatMessage(text, author, source string) error {
ctx := context.Background()
ctx = metadata.AppendToOutgoingContext(ctx, "api-key", config.Cfg.Qdrant.APIKey)
embClient := config.NewEmbeddingClient()
conn := config.NewQdrantConn()
defer conn.Close()
ensureCollection(ctx, pb.NewCollectionsClient(conn))
pointsClient := pb.NewPointsClient(conn)
fullText := fmt.Sprintf("[%s] %s", author, text)
c := chunk{Text: fullText, Source: source, Type: "chat"}
return ingestChunks(ctx, embClient, pointsClient, []chunk{c})
}
func boolPtr(b bool) *bool { return &b }