Add a preview to truths
All checks were successful
Build and Publish college-bot-v2 / build_and_publish (push) Successful in 13s
All checks were successful
Build and Publish college-bot-v2 / build_and_publish (push) Successful in 13s
This commit is contained in:
parent
7f500db043
commit
8b21954443
1 changed files with 85 additions and 74 deletions
|
@ -1053,14 +1053,13 @@ class Ollama(commands.Cog):
|
|||
ctx.author,
|
||||
system
|
||||
)
|
||||
async with httpx.AsyncClient() as client:
|
||||
r = CONFIG["truth"].get("api", "https://bots.nexy7574.co.uk/jimmy/v2/api")
|
||||
username = CONFIG["truth"].get("username", "1")
|
||||
password = CONFIG["truth"].get("password", "2")
|
||||
response = await client.get(
|
||||
r + "/truths",
|
||||
async with httpx.AsyncClient(base_url=r, auth=(username, password)) as http_client:
|
||||
response = await http_client.get(
|
||||
"/truths",
|
||||
timeout=60,
|
||||
auth=(username, password),
|
||||
)
|
||||
response.raise_for_status()
|
||||
truths = response.json()
|
||||
|
@ -1130,8 +1129,17 @@ class Ollama(commands.Cog):
|
|||
if similar:
|
||||
if len(similar) > 1:
|
||||
lns = []
|
||||
for truth_id, _ratio in similar.items():
|
||||
lns.append(f"* `{truth_id}`: {_ratio:.2f}%")
|
||||
keys = sorted(similar.keys(), key=lambda k: similar[k], reverse=True)
|
||||
for truth_id in keys:
|
||||
_ratio = similar[truth_id]
|
||||
truth = discord.utils.get(truths, id=truth_id)
|
||||
first_line = truth.content.splitlines()[0]
|
||||
preview = discord.utils.escape_markdown(textwrap.shorten(first_line, 100))
|
||||
lns.append(f"* `{truth_id}`: {_ratio}% - `{preview}`")
|
||||
if len(lns) > 5:
|
||||
lc = len(lns) - 5
|
||||
lns = lns[:5]
|
||||
lns.append(f"*... and {lc} more*")
|
||||
embed.add_field(
|
||||
name="Possibly repeated truth",
|
||||
value="This truth was similar to the following existing ones:\n" + "\n".join(lns),
|
||||
|
@ -1140,9 +1148,12 @@ class Ollama(commands.Cog):
|
|||
else:
|
||||
truth_id = tuple(similar)[0]
|
||||
_ratio = similar[truth_id]
|
||||
truth = discord.utils.get(truths, id=truth_id)
|
||||
first_line = truth.content.splitlines()[0]
|
||||
preview = discord.utils.escape_markdown(textwrap.shorten(first_line, 512))
|
||||
embed.add_field(
|
||||
name="Possibly repeated truth",
|
||||
value=f"This truth was {_ratio:.2f}% similar to `{truth_id}`."
|
||||
value=f"This truth was {_ratio}% similar to `{truth_id}`.\n>>> {preview}"
|
||||
)
|
||||
|
||||
embed.set_footer(
|
||||
|
|
Loading…
Reference in a new issue