mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-09-23 02:53:32 +00:00
6125f5ced0
Knowledge base: fold the embedding provider base URL into the snippet fingerprint so re-pointing the provider triggers a reindex even when the model name is unchanged. Reject empty knowledge base content. Cap concurrent background snippet embeds at 4 and tie embedding work to the app lifecycle context. Reindex when the embedding base URL changes, not just the model or dimensions. Prompt injection: neutralize << >> block delimiters in snippets, transcripts, subjects, and contact fields so untrusted content can't forge a boundary the model relies on. OTP: set the verified flag inside the Lua match script so verification is atomic. Only count codes that were actually emailed toward the resend cap, and check the cap before sending instead of incrementing up front. Tools: fetch only the enabled tools among the allowed IDs, and route all registrations through one helper so custom tools can't shadow built-ins. Agent queue: hand a dropped response job off to a human instead of leaving the conversation assigned to the assistant with no reply. Also let GetAllConversationMessages return every message when limit is non-positive, populate admin forms without triggering validation, and default the copilot name to Juno.
31 lines
1.4 KiB
Go
31 lines
1.4 KiB
Go
package ai
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/abhinavxd/libredesk/internal/ai/models"
|
|
)
|
|
|
|
func TestSnippetFingerprint(t *testing.T) {
|
|
item := models.KnowledgeBaseItem{Title: "Refunds", Content: "We refund within 30 days."}
|
|
base := snippetFingerprint(item, "https://api.openai.com/v1", "text-embedding-3-small", 1536)
|
|
|
|
if snippetFingerprint(item, "https://api.openai.com/v1", "text-embedding-3-small", 1536) != base {
|
|
t.Fatal("fingerprint must be stable for identical inputs")
|
|
}
|
|
|
|
// Every field that makes stored vectors comparable must change the fingerprint, or a reindex is skipped when it shouldn't be.
|
|
cases := map[string]string{
|
|
"base URL changed": snippetFingerprint(item, "https://llm.internal/v1", "text-embedding-3-small", 1536),
|
|
"model changed": snippetFingerprint(item, "https://api.openai.com/v1", "text-embedding-3-large", 1536),
|
|
"dimensions changed": snippetFingerprint(item, "https://api.openai.com/v1", "text-embedding-3-small", 3072),
|
|
"title changed": snippetFingerprint(models.KnowledgeBaseItem{Title: "Returns", Content: item.Content}, "https://api.openai.com/v1", "text-embedding-3-small", 1536),
|
|
"content changed": snippetFingerprint(models.KnowledgeBaseItem{Title: item.Title, Content: "We refund within 14 days."}, "https://api.openai.com/v1", "text-embedding-3-small", 1536),
|
|
}
|
|
for name, fp := range cases {
|
|
if fp == base {
|
|
t.Errorf("%s: fingerprint should differ from the baseline", name)
|
|
}
|
|
}
|
|
}
|