diff --git a/backend/alembic/versions/47433d30de82_create_indexattempt_table.py b/backend/alembic/versions/47433d30de82_create_indexattempt_table.py index 2319b2eb2b6..58fa06d3b1e 100644 --- a/backend/alembic/versions/47433d30de82_create_indexattempt_table.py +++ b/backend/alembic/versions/47433d30de82_create_indexattempt_table.py @@ -1,7 +1,7 @@ """Create IndexAttempt table Revision ID: 47433d30de82 -Revises: +Revises: Create Date: 2023-05-04 00:55:32.971991 """ diff --git a/backend/danswer/background/connector_deletion.py b/backend/danswer/background/connector_deletion.py index e5d0c6d2eea..a9602b3817c 100644 --- a/backend/danswer/background/connector_deletion.py +++ b/backend/danswer/background/connector_deletion.py @@ -1,12 +1,12 @@ """ To delete a connector / credential pair: -(1) find all documents associated with connector / credential pair where there +(1) find all documents associated with connector / credential pair where there this the is only connector / credential pair that has indexed it (2) delete all documents from document stores (3) delete all entries from postgres -(4) find all documents associated with connector / credential pair where there +(4) find all documents associated with connector / credential pair where there are multiple connector / credential pairs that have indexed it -(5) update document store entries to remove access associated with the +(5) update document store entries to remove access associated with the connector / credential pair from the access list (6) delete all relevant entries from postgres """ diff --git a/backend/danswer/bots/slack/blocks.py b/backend/danswer/bots/slack/blocks.py index 5efe693de53..32388470c4c 100644 --- a/backend/danswer/bots/slack/blocks.py +++ b/backend/danswer/bots/slack/blocks.py @@ -132,7 +132,7 @@ def build_qa_response_blocks( quotes_blocks: list[Block] = [] if not answer: answer_block = SectionBlock( - text=f"Sorry, I was unable to find an answer, but I did find some potentially relevant docs 🤓" + text="Sorry, I was unable to find an answer, but I did find some potentially relevant docs 🤓" ) else: answer_block = SectionBlock(text=answer) diff --git a/backend/danswer/bots/slack/listener.py b/backend/danswer/bots/slack/listener.py index eda0f3819d7..d9bb65b74ad 100644 --- a/backend/danswer/bots/slack/listener.py +++ b/backend/danswer/bots/slack/listener.py @@ -76,7 +76,7 @@ def _process_slack_event(client: SocketModeClient, req: SocketModeRequest) -> No # this should never happen, but we can't continue without a channel since # we can't send a response without it if not channel: - channel_specific_logger.error(f"Found message without channel - skipping") + channel_specific_logger.error("Found message without channel - skipping") return message_subtype = event.get("subtype") diff --git a/backend/danswer/connectors/bookstack/client.py b/backend/danswer/connectors/bookstack/client.py index 822fae0672a..57f2b616e5b 100644 --- a/backend/danswer/connectors/bookstack/client.py +++ b/backend/danswer/connectors/bookstack/client.py @@ -30,7 +30,7 @@ def get(self, endpoint: str, params: dict[str, str]) -> dict[str, Any]: try: json = response.json() - except: + except Exception: json = {} if response.status_code >= 300: diff --git a/backend/danswer/connectors/confluence/connector.py b/backend/danswer/connectors/confluence/connector.py index acd44b1acea..78bafc299fc 100644 --- a/backend/danswer/connectors/confluence/connector.py +++ b/backend/danswer/connectors/confluence/connector.py @@ -110,9 +110,10 @@ def _fetch(start_ind: int, batch_size: int) -> Collection[dict[str, Any]]: limit=batch_size, expand="body.storage.value,version", ) - except: + except Exception: logger.warning( - f"Batch failed with space {self.space} at offset {start_ind} with size {batch_size}, processing pages individually..." + f"Batch failed with space {self.space} at offset {start_ind} " + f"with size {batch_size}, processing pages individually..." ) view_pages: list[dict[str, Any]] = [] @@ -130,7 +131,8 @@ def _fetch(start_ind: int, batch_size: int) -> Collection[dict[str, Any]]: ) except HTTPError as e: logger.warning( - f"Page failed with space {self.space} at offset {start_ind + i}, trying alternative expand option: {e}" + f"Page failed with space {self.space} at offset {start_ind + i}, " + f"trying alternative expand option: {e}" ) # Use view instead, which captures most info but is less complete view_pages.extend( @@ -155,7 +157,7 @@ def _fetch(start_ind: int, batch_size: int) -> Collection[dict[str, Any]]: for i in range(self.batch_size): try: pages.extend(_fetch(start_ind + i, 1)) - except: + except Exception: logger.exception( "Ran into exception when fetching pages from Confluence" ) diff --git a/backend/danswer/connectors/linear/connector.py b/backend/danswer/connectors/linear/connector.py index 561aacc8981..067fb561da2 100644 --- a/backend/danswer/connectors/linear/connector.py +++ b/backend/danswer/connectors/linear/connector.py @@ -85,8 +85,8 @@ def _process_issues( """ query IterateIssueBatches($first: Int, $after: String) { issues( - orderBy: updatedAt, - first: $first, + orderBy: updatedAt, + first: $first, after: $after, filter: { updatedAt: { diff --git a/backend/danswer/connectors/slack/utils.py b/backend/danswer/connectors/slack/utils.py index 9a0ebb67a9d..5932a08c5ff 100644 --- a/backend/danswer/connectors/slack/utils.py +++ b/backend/danswer/connectors/slack/utils.py @@ -163,7 +163,7 @@ def replace_channels_basic(message: str) -> str: """Simply replaces all channel mentions with `#` in order to make a message work as part of a link""" # Find user IDs in the message - channel_matches = re.findall("<#(.*?)\|(.*?)>", message) + channel_matches = re.findall(r"<#(.*?)\|(.*?)>", message) for channel_id, channel_name in channel_matches: message = message.replace( f"<#{channel_id}|{channel_name}>", f"#{channel_name}" diff --git a/backend/danswer/connectors/web/connector.py b/backend/danswer/connectors/web/connector.py index 7979b5b8d0a..100e280db36 100644 --- a/backend/danswer/connectors/web/connector.py +++ b/backend/danswer/connectors/web/connector.py @@ -152,7 +152,7 @@ def load_from_state(self) -> GenerateDocumentsOutput: logger.info(f"Redirected to {final_page}") current_url = final_page if current_url in visited_links: - logger.info(f"Redirected page already indexed") + logger.info("Redirected page already indexed") continue visited_links.add(current_url) diff --git a/backend/danswer/datastores/datastore_utils.py b/backend/danswer/datastores/datastore_utils.py index d1fbe72dfb8..d606f289852 100644 --- a/backend/danswer/datastores/datastore_utils.py +++ b/backend/danswer/datastores/datastore_utils.py @@ -58,10 +58,10 @@ class CrossConnectorDocumentMetadata(BaseModel): T = TypeVar("T") -def _add_if_not_exists(l: list[T], item: T) -> list[T]: - if item in l: - return l - return l + [item] +def _add_if_not_exists(obj_list: list[T], item: T) -> list[T]: + if item in obj_list: + return obj_list + return obj_list + [item] def update_cross_connector_document_metadata_map( diff --git a/backend/danswer/datastores/vespa/store.py b/backend/danswer/datastores/vespa/store.py index d8d7a93db13..9238dc61d0d 100644 --- a/backend/danswer/datastores/vespa/store.py +++ b/backend/danswer/datastores/vespa/store.py @@ -437,7 +437,7 @@ def hybrid_retrieval( VespaIndex.yql_base + vespa_where_clauses + f"{{targetHits: {10 * num_to_retrieve}}}nearestNeighbor(embeddings, query_embedding) or " - + f'{{grammar: "weakAnd"}}userInput(@query)' + + '{grammar: "weakAnd"}userInput(@query)' ) query_embedding = embed_query(query) diff --git a/backend/danswer/db/connector_credential_pair.py b/backend/danswer/db/connector_credential_pair.py index f1c89e24c68..aac7fab0f77 100644 --- a/backend/danswer/db/connector_credential_pair.py +++ b/backend/danswer/db/connector_credential_pair.py @@ -21,7 +21,7 @@ def get_connector_credential_pairs( ) -> list[ConnectorCredentialPair]: stmt = select(ConnectorCredentialPair) if not include_disabled: - stmt = stmt.where(ConnectorCredentialPair.connector.disabled == False) + stmt = stmt.where(ConnectorCredentialPair.connector.disabled is False) results = db_session.scalars(stmt) return list(results.all()) diff --git a/backend/danswer/direct_qa/llm_utils.py b/backend/danswer/direct_qa/llm_utils.py index 453ca182052..8b00875b07d 100644 --- a/backend/danswer/direct_qa/llm_utils.py +++ b/backend/danswer/direct_qa/llm_utils.py @@ -95,7 +95,7 @@ def get_default_qa_model( llm=llm, qa_handler=qa_handler, ) - except: + except Exception: logger.exception( "Unable to build a QABlock with the new approach, going back to the " "legacy approach" diff --git a/backend/danswer/direct_qa/qa_prompts.py b/backend/danswer/direct_qa/qa_prompts.py index 320409f939b..5cc43cc239f 100644 --- a/backend/danswer/direct_qa/qa_prompts.py +++ b/backend/danswer/direct_qa/qa_prompts.py @@ -15,10 +15,10 @@ QUOTE_PAT = "Quote:" BASE_PROMPT = ( - f"Answer the query based on provided documents and quote relevant sections. " - f"Respond with a json containing a concise answer and up to three most relevant quotes from the documents. " - f'Respond with "?" for the answer if the query cannot be answered based on the documents. ' - f"The quotes must be EXACT substrings from the documents." + "Answer the query based on provided documents and quote relevant sections. " + "Respond with a json containing a concise answer and up to three most relevant quotes from the documents. " + 'Respond with "?" for the answer if the query cannot be answered based on the documents. ' + "The quotes must be EXACT substrings from the documents." ) SAMPLE_QUESTION = "Where is the Eiffel Tower?" @@ -81,7 +81,7 @@ def _prepend(s: str, ppt: bool) -> str: prompt_current += _prepend(f"DOCUMENT SOURCE: {chunk.source_type}\n", prepend_tab) if chunk.metadata: - prompt_current += _prepend(f"METADATA:\n", prepend_tab) + prompt_current += _prepend("METADATA:\n", prepend_tab) connector_class = identify_connector_class(DocumentSource(chunk.source_type)) for metadata_line in connector_class.parse_metadata(chunk.metadata): prompt_current += _prepend(f"\t{metadata_line}\n", prepend_tab) diff --git a/backend/danswer/main.py b/backend/danswer/main.py index a6eec74b89c..f1c3e2ab6c2 100644 --- a/backend/danswer/main.py +++ b/backend/danswer/main.py @@ -54,7 +54,7 @@ def validation_exception_handler( def value_error_handler(_: Request, exc: ValueError) -> JSONResponse: try: raise (exc) - except: + except Exception: # log stacktrace logger.exception("ValueError") return JSONResponse( diff --git a/backend/danswer/server/search_backend.py b/backend/danswer/server/search_backend.py index 49709598028..ca6d3f6ec0a 100644 --- a/backend/danswer/server/search_backend.py +++ b/backend/danswer/server/search_backend.py @@ -151,7 +151,7 @@ def stream_direct_qa( logger.debug(f"Received QA query: {question.query}") logger.debug(f"Query filters: {question.filters}") if question.use_keyword: - logger.debug(f"User selected Keyword Search") + logger.debug("User selected Keyword Search") @log_generator_function_time() def stream_qa_portions( diff --git a/backend/scripts/reset_postgres.py b/backend/scripts/reset_postgres.py index 60eff918573..f88cf0dd628 100644 --- a/backend/scripts/reset_postgres.py +++ b/backend/scripts/reset_postgres.py @@ -29,12 +29,12 @@ def wipe_all_rows(database: str) -> None: table_names = cur.fetchall() # have to delete from these first to not run into psycopg2.errors.ForeignKeyViolation - cur.execute(f"DELETE FROM chunk") - cur.execute(f"DELETE FROM document_by_connector_credential_pair") - cur.execute(f"DELETE FROM document") - cur.execute(f"DELETE FROM connector_credential_pair") - cur.execute(f"DELETE FROM index_attempt") - cur.execute(f"DELETE FROM credential") + cur.execute("DELETE FROM chunk") + cur.execute("DELETE FROM document_by_connector_credential_pair") + cur.execute("DELETE FROM document") + cur.execute("DELETE FROM connector_credential_pair") + cur.execute("DELETE FROM index_attempt") + cur.execute("DELETE FROM credential") conn.commit() for table_name in table_names: