Merge pull request #147 from Hikari-Haru/search-sources

Add sources to a search based on which nodes it has fetched
Kaveen Kumarasinghe 2 years ago committed by GitHub
commit b93a8ce1ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,7 @@
import traceback import traceback
import aiohttp import aiohttp
import re
import discord import discord
from models.deepl_model import TranslationModel from models.deepl_model import TranslationModel
@ -49,6 +50,10 @@ class SearchService(discord.Cog, name="SearchService"):
response = await self.model.search(query, user_api_key, search_scope, nodes) response = await self.model.search(query, user_api_key, search_scope, nodes)
url_extract_pattern = "https?:\\/\\/(?:www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)"
urls = re.findall(url_extract_pattern, str(response.get_formatted_sources(length=200)), flags=re.IGNORECASE)
urls = "\n".join(f"<{url}>" for url in urls)
await ctx.respond( await ctx.respond(
f"**Query:**\n\n{query.strip()}\n\n**Query response:**\n\n{response.response.strip()}" f"**Query:**\n\n{query.strip()}\n\n**Query response:**\n\n{response.response.strip()}\n\n**Sources:**\n{urls}"
) )

Loading…
Cancel
Save