Skip to content

Commit

Permalink
try fix
Browse files Browse the repository at this point in the history
  • Loading branch information
radiantspace committed May 24, 2024
1 parent 6df8087 commit 5140f63
Showing 1 changed file with 5 additions and 33 deletions.
38 changes: 5 additions & 33 deletions backend/app/telegram/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,49 +647,21 @@ func IsCreateImageCommand(prompt string) bool {
return foundTrigger && !foundStop
}

if isClose(word, triggerWords, 0) {
if contains(triggerWords, word) {
foundTrigger = true
}

if isClose(word, stopWords, 0) {
if contains(stopWords, word) {
foundStop = true
}
}

return foundTrigger && !foundStop
}

// Function to compute the Levenshtein distance between two strings
func levenshteinDistance(s1, s2 string) int {
if len(s1) == 0 {
return len(s2)
}
if len(s2) == 0 {
return len(s1)
}

if s1[len(s1)-1] == s2[len(s2)-1] {
return levenshteinDistance(s1[:len(s1)-1], s2[:len(s2)-1])
}

a := levenshteinDistance(s1, s2[:len(s2)-1]) // Insertion
b := levenshteinDistance(s1[:len(s1)-1], s2) // Deletion
c := levenshteinDistance(s1[:len(s1)-1], s2[:len(s2)-1]) // Substitution

// Return the min distance
if a < b && a < c {
return a + 1
} else if b < c {
return b + 1
} else {
return c + 1
}
}

// Helper function to check if a word is close to any word in a list
func isClose(word string, list []string, maxDistance int) bool {
for _, item := range list {
if levenshteinDistance(word, item) <= maxDistance {
func contains(arr []string, word string) bool {
for _, a := range arr {
if a == word {
return true
}
}
Expand Down

0 comments on commit 5140f63

Please sign in to comment.