Skip to content

Commit b3024ff

Browse files
committed
update search to use new models
1 parent 19c1d27 commit b3024ff

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

cogs/commands.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,7 @@ async def chat(
13231323
input_type=discord.SlashCommandOptionType.integer,
13241324
max_value=16,
13251325
min_value=1,
1326+
default=3,
13261327
)
13271328
@discord.option(
13281329
name="nodes",
@@ -1331,6 +1332,7 @@ async def chat(
13311332
input_type=discord.SlashCommandOptionType.integer,
13321333
max_value=8,
13331334
min_value=1,
1335+
default=4,
13341336
)
13351337
@discord.option(
13361338
name="deep",
@@ -1343,14 +1345,14 @@ async def chat(
13431345
description="Response mode, doesn't work on deep searches",
13441346
guild_ids=ALLOWED_GUILDS,
13451347
required=False,
1346-
default="refine",
1348+
default="compact",
13471349
choices=["refine", "compact", "tree_summarize"],
13481350
)
13491351
@discord.option(
13501352
name="model",
13511353
description="The model to use for the request (querying, not composition)",
13521354
required=False,
1353-
default="gpt-4-32k",
1355+
default="gpt-4-1106-preview",
13541356
autocomplete=Settings_autocompleter.get_index_and_search_models,
13551357
)
13561358
@discord.option(
@@ -1365,12 +1367,12 @@ async def search(
13651367
self,
13661368
ctx: discord.ApplicationContext,
13671369
query: str,
1368-
scope: int,
1369-
nodes: int,
1370-
deep: bool,
1371-
response_mode: str,
1372-
model: str,
1373-
multistep: bool,
1370+
scope: int = 3,
1371+
nodes: int = 4,
1372+
deep: bool = False,
1373+
response_mode: str = "refine",
1374+
model: str ="gpt-4-1106-preview",
1375+
multistep: bool = False,
13741376
):
13751377
await self.search_cog.search_command(
13761378
ctx,

models/search_model.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,14 @@ async def search(
221221
multistep=False,
222222
redo=None,
223223
):
224-
DEFAULT_SEARCH_NODES = 1
224+
DEFAULT_SEARCH_NODES = 4
225225
if not user_api_key:
226226
os.environ["OPENAI_API_KEY"] = self.openai_key
227227
else:
228228
os.environ["OPENAI_API_KEY"] = user_api_key
229229
openai.api_key = os.environ["OPENAI_API_KEY"]
230230

231+
231232
# Initialize the search cost
232233
price = 0
233234

@@ -239,28 +240,21 @@ async def search(
239240
)
240241

241242
try:
242-
llm_predictor_presearch = OpenAI(
243-
max_tokens=50,
244-
temperature=0.4,
243+
llm_predictor_presearch = ChatOpenAI(
244+
max_tokens=100,
245+
temperature=0,
245246
presence_penalty=0.65,
246-
model_name="text-davinci-003",
247+
model_name=model,
247248
)
248249

249250
# Refine a query to send to google custom search API
250251
prompt = 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 inferring knowledge about the current day, insert the current day into the refined prompt. If the original query is inferring knowledge about the current month, insert the current month and year into the refined prompt. If the original query is inferring knowledge about the current year, insert the current year into the refined prompt. Generally, if the original query is inferring knowledge about something that happened recently, insert the current month into the refined query. Avoid inserting 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. Don’t 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:"
251-
query_refined = await llm_predictor_presearch.agenerate(
252-
prompts=[prompt],
252+
query_refined = await llm_predictor_presearch.apredict(
253+
text=prompt,
253254
)
254-
query_refined_text = query_refined.generations[0][0].text
255+
query_refined_text = query_refined
255256

256-
await self.usage_service.update_usage(
257-
query_refined.llm_output.get("token_usage").get("total_tokens"),
258-
"davinci",
259-
)
260-
price += await self.usage_service.get_price(
261-
query_refined.llm_output.get("token_usage").get("total_tokens"),
262-
"davinci",
263-
)
257+
print("The query refined text is: " + query_refined_text)
264258

265259
except Exception as e:
266260
traceback.print_exc()
@@ -345,7 +339,10 @@ async def search(
345339

346340
embedding_model = OpenAIEmbedding()
347341

348-
llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0, model_name=model))
342+
if "vision" in model:
343+
llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0, model=model, max_tokens=4096))
344+
else:
345+
llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0, model=model))
349346

350347
token_counter = TokenCountingHandler(
351348
tokenizer=tiktoken.encoding_for_model(model).encode, verbose=False

0 commit comments

Comments
 (0)