llm mail integration
This commit is contained in:
@@ -5,7 +5,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
pb "github.com/qdrant/go-client/qdrant"
|
||||
openai "github.com/sashabaranov/go-openai"
|
||||
@@ -54,6 +56,13 @@ WICHTIGE REGELN:
|
||||
Basierend auf diesen Informationen, beantworte bitte folgende Frage:
|
||||
%s`, contextText, question)
|
||||
|
||||
slog.Debug("[LLM] AskQuery Prompt",
|
||||
"model", config.Cfg.Chat.Model,
|
||||
"system", systemPrompt,
|
||||
"user", userPrompt,
|
||||
)
|
||||
|
||||
start := time.Now()
|
||||
stream, err := chatClient.CreateChatCompletionStream(ctx, openai.ChatCompletionRequest{
|
||||
Model: config.Cfg.Chat.Model,
|
||||
Messages: []openai.ChatCompletionMessage{
|
||||
@@ -79,6 +88,12 @@ Basierend auf diesen Informationen, beantworte bitte folgende Frage:
|
||||
}
|
||||
}
|
||||
|
||||
slog.Debug("[LLM] AskQuery Antwort",
|
||||
"dauer", time.Since(start).Round(time.Millisecond),
|
||||
"zeichen", answer.Len(),
|
||||
"antwort", answer.String(),
|
||||
)
|
||||
|
||||
return answer.String(), chunks, nil
|
||||
}
|
||||
|
||||
@@ -146,7 +161,7 @@ func searchKnowledge(ctx context.Context, embClient *openai.Client, query string
|
||||
seen := make(map[string]bool)
|
||||
for _, hit := range searchResult.Result {
|
||||
text := hit.Payload["text"].GetStringValue()
|
||||
if seen[text] {
|
||||
if text == "" || seen[text] {
|
||||
continue
|
||||
}
|
||||
seen[text] = true
|
||||
@@ -176,6 +191,12 @@ func ChatDirect(question string) (string, error) {
|
||||
|
||||
systemPrompt := `Du bist ein hilfreicher persönlicher Assistent. Antworte auf Deutsch, präzise und direkt.`
|
||||
|
||||
slog.Debug("[LLM] ChatDirect Prompt",
|
||||
"model", config.Cfg.Chat.Model,
|
||||
"user", question,
|
||||
)
|
||||
|
||||
start := time.Now()
|
||||
stream, err := chatClient.CreateChatCompletionStream(ctx, openai.ChatCompletionRequest{
|
||||
Model: config.Cfg.Chat.Model,
|
||||
Messages: []openai.ChatCompletionMessage{
|
||||
@@ -200,6 +221,13 @@ func ChatDirect(question string) (string, error) {
|
||||
answer.WriteString(response.Choices[0].Delta.Content)
|
||||
}
|
||||
}
|
||||
|
||||
slog.Debug("[LLM] ChatDirect Antwort",
|
||||
"dauer", time.Since(start).Round(time.Millisecond),
|
||||
"zeichen", answer.Len(),
|
||||
"antwort", answer.String(),
|
||||
)
|
||||
|
||||
return answer.String(), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user