From 3109f645e65a2ec40bf93012dfb61ef065c595ea Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Fri, 7 Jun 2024 20:08:18 +0100 Subject: [PATCH] Include fuzzy matching for truths --- requirements.txt | 1 + src/cogs/ollama.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 8fc8697..8bc947c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,3 +23,4 @@ python-magic~=0.4 aiofiles~=23.2 fastapi~=0.111 uvicorn[standard]~=0.30 +fuzzywuzzy[speedup]~=0.18 diff --git a/src/cogs/ollama.py b/src/cogs/ollama.py index e6d094a..3c0c248 100644 --- a/src/cogs/ollama.py +++ b/src/cogs/ollama.py @@ -18,6 +18,7 @@ from discord import Interaction from discord.ext import commands from discord.ui import View, button from yarl import URL +from fuzzywuzzy import fuzz from conf import CONFIG from .quote_quota import TruthPayload @@ -1115,12 +1116,17 @@ class Ollama(commands.Cog): last_edit = time.time() for truth in truths: + _ratio = fuzz.ratio(truth.content, embed.description) if truth.content == embed.description: embed.add_field( name="Repeated truth :(", value="This truth was already truthed. Shit AI." ) - break + elif _ratio >= 70: + embed.add_field( + name="Likely repeated truth", + value=f"Is a {_ratio:.2f}% match to truth {truth.id!r}." + ) embed.set_footer( text="Finished generating truth based off of {:,} messages, using server {!r} | {!s}".format( len(messages) - 2,