From a2c5f9c3dad69fb6e8a925f94813defba2b83cf9 Mon Sep 17 00:00:00 2001 From: Kaveen Kumarasinghe Date: Sat, 25 Feb 2023 03:34:47 -0500 Subject: [PATCH] readme, bugfixes, dedup --- cogs/search_service_cog.py | 3 +++ detailed_guides/AI-SEARCH.md | 4 +++- detailed_guides/CUSTOM-INDEXES.md | 2 +- models/index_model.py | 4 ++-- sample.env | 6 ++++++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cogs/search_service_cog.py b/cogs/search_service_cog.py index d2d1e8c..d046c41 100644 --- a/cogs/search_service_cog.py +++ b/cogs/search_service_cog.py @@ -140,6 +140,9 @@ class SearchService(discord.Cog, name="SearchService"): ) urls = "\n".join(f"<{url}>" for url in urls) + # Deduplicate the urls + urls = "\n".join(dict.fromkeys(urls.split("\n"))) + if from_followup: original_link, followup_question = ( from_followup.original_link, diff --git a/detailed_guides/AI-SEARCH.md b/detailed_guides/AI-SEARCH.md index ecaeac0..9c04a5d 100644 --- a/detailed_guides/AI-SEARCH.md +++ b/detailed_guides/AI-SEARCH.md @@ -7,4 +7,6 @@ GOOGLE_SEARCH_ENGINE_ID="...." You first need to create a programmable search engine and get the search engine ID: https://developers.google.com/custom-search/docs/tutorial/creatingcse -Then you can get the API key, click the "Get a key" button on this page: https://developers.google.com/custom-search/v1/introduction \ No newline at end of file +Then you can get the API key, click the "Get a key" button on this page: https://developers.google.com/custom-search/v1/introduction + +You can limit the max price that is charged for a single search request by setting `MAX_SEARCH_PRICE` in your `.env` file. \ No newline at end of file diff --git a/detailed_guides/CUSTOM-INDEXES.md b/detailed_guides/CUSTOM-INDEXES.md index 39f84c4..12f8b06 100644 --- a/detailed_guides/CUSTOM-INDEXES.md +++ b/detailed_guides/CUSTOM-INDEXES.md @@ -16,4 +16,4 @@ You can also compose a singular index with itself with "Deep Compose", this will Doing a deep composition will also allow you to use the `child_branch_factor` parameter for `/index query`, increasing this past 1 will take a much longer time to query and will be much more expensive for large documents, so be wary. -**When doing Deep Compositions, it's highly reccomended to keep the document size small, or only do deep compositions on single documents.** This is because a deep composition reorganizes the simple index into a tree structure and uses GPT3 to summarize different nodes of the tree, which will lead to high costs. For example, a deep composition of a 300 page lab manual and the contents of my personal website at https://kaveenk.com cost me $2 USD roughly. \ No newline at end of file +**When doing Deep Compositions, it's highly recommended to keep the document size small, or only do deep compositions on single documents.** This is because a deep composition reorganizes the simple index into a tree structure and uses GPT3 to summarize different nodes of the tree, which will lead to high costs. For example, a deep composition of a 300 page lab manual and the contents of my personal website at https://kaveenk.com cost me $2 USD roughly. To save on costs, you can limit the max price a deep composition can charge you by setting `MAX_DEEP_COMPOSE_PRICE` in your `.env` file. \ No newline at end of file diff --git a/models/index_model.py b/models/index_model.py index 038868a..89c303c 100644 --- a/models/index_model.py +++ b/models/index_model.py @@ -596,7 +596,7 @@ class Index_handler: ) # Save the composed index - tree_index.save_to_disk(f"indexes/{user_id}/{name}.json") + tree_index.save_to_disk(f"indexes/{user_id}/{name}") self.index_storage[user_id].queryable_index = tree_index else: @@ -624,7 +624,7 @@ class Index_handler: name = f"composed_index_{date.today().month}_{date.today().day}.json" # Save the composed index - simple_index.save_to_disk(f"indexes/{user_id}/{name}.json") + simple_index.save_to_disk(f"indexes/{user_id}/{name}") self.index_storage[user_id].queryable_index = simple_index async def backup_discord( diff --git a/sample.env b/sample.env index 0b21bfa..052423f 100644 --- a/sample.env +++ b/sample.env @@ -45,3 +45,9 @@ FORCE_ENGLISH = "False" # The welcome message to send it the welcome setting is set to true WELCOME_MESSAGE = "Hi There! Welcome to our Discord server. We hope you'll enjoy our server and we look forward to engaging with you!" # This is a fallback message if gpt3 fails to generate a welcome message. + +# Max price to pay for a single search request +MAX_SEARCH_PRICE = 1.00 + +# Max price to pay for a deep composition +MAX_DEEP_COMPOSE_PRICE = 3.00 \ No newline at end of file