bug fixes for index compositions

Kaveen Kumarasinghe 1 year ago
parent 6040d16600
commit b28795c69d

@ -87,7 +87,7 @@ class SearchService(discord.Cog, name="SearchService"):
await ctx.defer() if not redo else None
try:
response = await self.model.search(
response, refined_text = await self.model.search(
ctx, query, user_api_key, search_scope, nodes
)
except ValueError:
@ -111,7 +111,7 @@ class SearchService(discord.Cog, name="SearchService"):
)
urls = "\n".join(f"<{url}>" for url in urls)
query_response_message = f"**Query:**\n\n`{query.strip()}`\n\n**Query response:**\n\n{response.response.strip()}\n\n**Sources:**\n{urls}"
query_response_message = f"**Question:**\n\n`{query.strip()}`\n\n**Google Search Query**\n\n`{refined_text.strip()}`\n\n**Final Answer:**\n\n{response.response.strip()}\n\n**Sources:**\n{urls}"
query_response_message = query_response_message.replace(
"<|endofstatement|>", ""
)

@ -31,7 +31,7 @@ from services.environment_service import EnvService
from models.openai_model import Model
__version__ = "10.2.6"
__version__ = "10.3.0"
PID_FILE = Path("bot.pid")

@ -1,4 +1,5 @@
import os
import random
import tempfile
import traceback
import asyncio
@ -693,18 +694,24 @@ class ComposeModal(discord.ui.View):
# Map everything into the short to long cache
for index in self.indexes:
SHORT_TO_LONG_CACHE[index[:99]] = index
if len(index) > 94:
index_name = index[:94] + "-" + str(random.randint(0000,9999))
SHORT_TO_LONG_CACHE[index_name] = index
else:
SHORT_TO_LONG_CACHE[index[:99]] = index
# Reverse the SHORT_TO_LONG_CACHE index
LONG_TO_SHORT_CACHE = {v: k for k, v in SHORT_TO_LONG_CACHE.items()}
# A text entry field for the name of the composed index
self.name = name
# A discord UI select menu with all the indexes. Limited to 25 entries. For the label field in the SelectOption,
# cut it off at 100 characters to prevent the message from being too long
self.index_select = discord.ui.Select(
placeholder="Select index(es) to compose",
options=[
discord.SelectOption(label=str(index)[:99], value=index[:99])
discord.SelectOption(label=LONG_TO_SHORT_CACHE[index], value=LONG_TO_SHORT_CACHE[index])
for index in self.indexes
][0:25],
max_values=len(self.indexes) if len(self.indexes) < 25 else 25,
@ -721,7 +728,7 @@ class ComposeModal(discord.ui.View):
discord.ui.Select(
placeholder="Select index(es) to compose",
options=[
discord.SelectOption(label=index[:99], value=index[:99])
discord.SelectOption(label=LONG_TO_SHORT_CACHE[index], value=LONG_TO_SHORT_CACHE[index])
for index in self.indexes
][i : i + 25],
max_values=len(self.indexes[i : i + 25]),

@ -4,6 +4,7 @@ import random
import re
import tempfile
import traceback
from datetime import datetime
from functools import partial
import discord
@ -180,10 +181,7 @@ class Search:
# Refine a query to send to google custom search API
query_refined = llm_predictor_presearch.generate(
prompts=[
"You are refining a query to send to the Google Custom Search API. Change the query such that putting it into the Google Custom Search API will return the most relevant websites to assist us in answering the original query. Respond with only the refined query for the original query. Don't use punctuation or quotation marks. The original query is: "
+ query
+ "\nRefined Query:"
prompts=[f"You are to be given a search query for google. Change the query such that putting it into the Google Custom Search API will return the most relevant websites to assist in answering the original query. If the original query is asking about something that is relevant to the current day, insert the current_date into the refined query. If the user is asking about something that may be relevant to the current month, insert the current year and month into the refined query, if the query is asking for something relevant to the current year, insert the current year into the refined query. There is no need to insert a day, month, or year for queries that purely ask about facts and about things that don't have much time-relevance. The current_date is {str(datetime.now().date())}. Do not insert the current_date if not neccessary. Respond with only the refined query for the original query. Dont use punctuation or quotation marks.\n\nExamples:\n---\nOriginal Query: Who is Harald Baldr?\nRefined Query: Harald Baldr biography\n---\nOriginal Query: What happened today with the Ohio train derailment?\nRefined Query: Ohio train derailment details {str(datetime.now().date())}\n---\nOriginal Query: Is copper in drinking water bad for you?\nRefined Query: copper in drinking water adverse effects\n---\nOriginal Query: What's the current time in Mississauga?\nRefined Query: current time Mississauga\nNow, refine the user input query.\nOriginal Query: {query}\nRefined Query:"
]
)
query_refined_text = query_refined.generations[0][0].text
@ -316,4 +314,4 @@ class Search:
if ctx:
await self.try_delete(in_progress_message)
return response
return response, query_refined_text

Loading…
Cancel
Save