Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Revert "Sanitize LLM control tokens from OpenAI-compatible responses"

rcourtmane3556455c6b2
diff --git a/internal/ai/providers/openai.go b/internal/ai/providers/openai.go
index 7035afe239..80b760da4b 100644
--- a/internal/ai/providers/openai.go
+++ b/internal/ai/providers/openai.go
@@ -8,23 +8,12 @@ import (
"io"
"net/http"
"net/url"
- "regexp"
"strings"
"time"
"github.com/rs/zerolog/log"
)
-// controlTokenPattern matches common LLM control tokens that shouldn't appear in output
-// These are internal tokens used by some models (llama.cpp, etc.) for chat templating
-var controlTokenPattern = regexp.MustCompile(`<\|[a-zA-Z_]+\|>`)
-
-// sanitizeContent removes LLM control tokens from content that shouldn't be shown to users
-func sanitizeContent(content string) string {
- // Remove control tokens like <|channel|>, <|constrain|>, <|message|>, etc.
- return controlTokenPattern.ReplaceAllString(content, "")
-}
-
const (
openaiAPIURL = "https://api.openai.com/v1/chat/completions"
openaiMaxRetries = 3
@@ -436,9 +425,6 @@ func (c *OpenAIClient) Chat(ctx context.Context, req ChatRequest) (*ChatResponse
contentToUse = choice.Message.ReasoningContent
}
- // Sanitize content to remove any leaked control tokens from local models
- contentToUse = sanitizeContent(contentToUse)
-
result := &ChatResponse{
Content: contentToUse,
ReasoningContent: choice.Message.ReasoningContent, // DeepSeek thinking mode
@@ -788,15 +774,12 @@ func (c *OpenAIClient) ChatStream(ctx context.Context, req ChatRequest, callback
delta := choice.Delta
- // Regular content - sanitize to remove any leaked control tokens
+ // Regular content
if delta.Content != "" {
- sanitized := sanitizeContent(delta.Content)
- if sanitized != "" {
- callback(StreamEvent{
- Type: "content",
- Data: ContentEvent{Text: sanitized},
- })
- }
+ callback(StreamEvent{
+ Type: "content",
+ Data: ContentEvent{Text: delta.Content},
+ })
}
// Reasoning content (DeepSeek)