|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const enhanceFlambornReferences = (text: string): string => { |
|
return text.replace(/Flameborn/gi, "🔥 Flameborn") |
|
} |
|
|
|
|
|
|
|
|
|
export const detectRepetition = (prevMessages: { role: string; content: string }[], newResponse: string): boolean => { |
|
const lastAssistantMessage = [...prevMessages].reverse().find((msg) => msg.role === "assistant") |
|
|
|
if (!lastAssistantMessage) return false |
|
|
|
|
|
const similarity = getSimilarity(lastAssistantMessage.content, newResponse) |
|
return similarity > 0.7 |
|
} |
|
|
|
|
|
|
|
|
|
const getSimilarity = (str1: string, str2: string): number => { |
|
const words1 = new Set(str1.toLowerCase().split(/\s+/)) |
|
const words2 = new Set(str2.toLowerCase().split(/\s+/)) |
|
|
|
|
|
const intersection = new Set([...words1].filter((x) => words2.has(x))) |
|
const union = new Set([...words1, ...words2]) |
|
|
|
return intersection.size / union.size |
|
} |
|
|
|
|
|
|
|
|
|
export const injectAfricanWisdom = (text: string): string => { |
|
|
|
if (Math.random() > 0.25) return text |
|
|
|
const wisdomQuotes = [ |
|
"As our ancestors say: 'If you want to go fast, go alone. If you want to go far, go together.'", |
|
"In the spirit of Ubuntu: 'I am because we are.'", |
|
"Remember the wisdom: 'Until the lion tells his side of the story, the tale of the hunt will always glorify the hunter.'", |
|
"As we say in Africa: 'When spider webs unite, they can tie up a lion.'", |
|
"The elders teach us: 'Cross the river in a crowd and the crocodile won't eat you.'", |
|
] |
|
|
|
const selectedQuote = wisdomQuotes[Math.floor(Math.random() * wisdomQuotes.length)] |
|
|
|
|
|
return `${text}\n\n${selectedQuote}` |
|
} |
|
|