chore(lint): ruff checks

This commit is contained in:
DESKTOP-RTLN3BA\$punk 2025-11-26 13:22:31 -08:00
parent 34fbee0c28
commit 8f30cfd69a
8 changed files with 44 additions and 26 deletions

View file

@ -8,9 +8,10 @@ Create Date: 2025-11-13 23:20:12.912741
from collections.abc import Sequence from collections.abc import Sequence
from alembic import op
from sqlalchemy import text from sqlalchemy import text
from alembic import op
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision: str = "36" revision: str = "36"
down_revision: str | None = "35" down_revision: str | None = "35"
@ -49,7 +50,9 @@ def upgrade() -> None:
] ]
for constraint_name in constraints_to_drop: for constraint_name in constraints_to_drop:
if constraint_exists(connection, "user_search_space_preferences", constraint_name): if constraint_exists(
connection, "user_search_space_preferences", constraint_name
):
op.drop_constraint( op.drop_constraint(
constraint_name, constraint_name,
"user_search_space_preferences", "user_search_space_preferences",
@ -67,13 +70,18 @@ def downgrade() -> None:
# Re-add the foreign key constraints if they don't exist # Re-add the foreign key constraints if they don't exist
constraints_to_create = [ constraints_to_create = [
("user_search_space_preferences_long_context_llm_id_fkey", "long_context_llm_id"), (
"user_search_space_preferences_long_context_llm_id_fkey",
"long_context_llm_id",
),
("user_search_space_preferences_fast_llm_id_fkey", "fast_llm_id"), ("user_search_space_preferences_fast_llm_id_fkey", "fast_llm_id"),
("user_search_space_preferences_strategic_llm_id_fkey", "strategic_llm_id"), ("user_search_space_preferences_strategic_llm_id_fkey", "strategic_llm_id"),
] ]
for constraint_name, column_name in constraints_to_create: for constraint_name, column_name in constraints_to_create:
if not constraint_exists(connection, "user_search_space_preferences", constraint_name): if not constraint_exists(
connection, "user_search_space_preferences", constraint_name
):
op.create_foreign_key( op.create_foreign_key(
constraint_name, constraint_name,
"user_search_space_preferences", "user_search_space_preferences",

View file

@ -39,6 +39,7 @@ from app.tasks.connector_indexers import (
index_airtable_records, index_airtable_records,
index_clickup_tasks, index_clickup_tasks,
index_confluence_pages, index_confluence_pages,
index_crawled_urls,
index_discord_messages, index_discord_messages,
index_elasticsearch_documents, index_elasticsearch_documents,
index_github_repos, index_github_repos,
@ -49,7 +50,6 @@ from app.tasks.connector_indexers import (
index_luma_events, index_luma_events,
index_notion_pages, index_notion_pages,
index_slack_messages, index_slack_messages,
index_crawled_urls,
) )
from app.users import current_active_user from app.users import current_active_user
from app.utils.check_ownership import check_ownership from app.utils.check_ownership import check_ownership
@ -1537,6 +1537,7 @@ async def run_elasticsearch_indexing(
exc_info=True, exc_info=True,
) )
# Add new helper functions for crawled web page indexing # Add new helper functions for crawled web page indexing
async def run_web_page_indexing_with_new_session( async def run_web_page_indexing_with_new_session(
connector_id: int, connector_id: int,

View file

@ -118,7 +118,9 @@ class ConnectorService:
# Extract webcrawler-specific metadata # Extract webcrawler-specific metadata
url = metadata.get("source", metadata.get("url", "")) url = metadata.get("source", metadata.get("url", ""))
title = document.get("title", metadata.get("title", "Untitled Document")) title = document.get(
"title", metadata.get("title", "Untitled Document")
)
description = metadata.get("description", "") description = metadata.get("description", "")
language = metadata.get("language", "") language = metadata.get("language", "")
last_crawled_at = metadata.get("last_crawled_at", "") last_crawled_at = metadata.get("last_crawled_at", "")

View file

@ -67,6 +67,7 @@ async def _check_and_trigger_schedules():
index_airtable_records_task, index_airtable_records_task,
index_clickup_tasks_task, index_clickup_tasks_task,
index_confluence_pages_task, index_confluence_pages_task,
index_crawled_urls_task,
index_discord_messages_task, index_discord_messages_task,
index_elasticsearch_documents_task, index_elasticsearch_documents_task,
index_github_repos_task, index_github_repos_task,
@ -77,7 +78,6 @@ async def _check_and_trigger_schedules():
index_luma_events_task, index_luma_events_task,
index_notion_pages_task, index_notion_pages_task,
index_slack_messages_task, index_slack_messages_task,
index_crawled_urls_task
) )
# Map connector types to their tasks # Map connector types to their tasks

View file

@ -177,7 +177,9 @@ async def index_crawled_urls(
continue continue
# Format content as structured document # Format content as structured document
structured_document = crawler.format_to_structured_document(crawl_result) structured_document = crawler.format_to_structured_document(
crawl_result
)
# Generate unique identifier hash for this URL # Generate unique identifier hash for this URL
unique_identifier_hash = generate_unique_identifier_hash( unique_identifier_hash = generate_unique_identifier_hash(
@ -185,7 +187,9 @@ async def index_crawled_urls(
) )
# Generate content hash # Generate content hash
content_hash = generate_content_hash(structured_document, search_space_id) content_hash = generate_content_hash(
structured_document, search_space_id
)
# Check if document with this unique identifier already exists # Check if document with this unique identifier already exists
existing_document = await check_document_by_unique_identifier( existing_document = await check_document_by_unique_identifier(
@ -205,7 +209,9 @@ async def index_crawled_urls(
continue continue
else: else:
# Content has changed - update the existing document # Content has changed - update the existing document
logger.info(f"Content changed for URL {url}. Updating document.") logger.info(
f"Content changed for URL {url}. Updating document."
)
# Generate summary with metadata # Generate summary with metadata
user_llm = await get_user_long_context_llm( user_llm = await get_user_long_context_llm(
@ -360,10 +366,14 @@ async def index_crawled_urls(
# Build result message # Build result message
result_message = None result_message = None
if failed_urls: if failed_urls:
failed_summary = "; ".join([f"{url}: {error}" for url, error in failed_urls[:5]]) failed_summary = "; ".join(
[f"{url}: {error}" for url, error in failed_urls[:5]]
)
if len(failed_urls) > 5: if len(failed_urls) > 5:
failed_summary += f" (and {len(failed_urls) - 5} more)" failed_summary += f" (and {len(failed_urls) - 5} more)"
result_message = f"Completed with {len(failed_urls)} failures: {failed_summary}" result_message = (
f"Completed with {len(failed_urls)} failures: {failed_summary}"
)
await task_logger.log_task_success( await task_logger.log_task_success(
log_entry, log_entry,

View file

@ -70,6 +70,7 @@ def create_periodic_schedule(
index_airtable_records_task, index_airtable_records_task,
index_clickup_tasks_task, index_clickup_tasks_task,
index_confluence_pages_task, index_confluence_pages_task,
index_crawled_urls_task,
index_discord_messages_task, index_discord_messages_task,
index_elasticsearch_documents_task, index_elasticsearch_documents_task,
index_github_repos_task, index_github_repos_task,
@ -80,7 +81,6 @@ def create_periodic_schedule(
index_luma_events_task, index_luma_events_task,
index_notion_pages_task, index_notion_pages_task,
index_slack_messages_task, index_slack_messages_task,
index_crawled_urls_task,
) )
# Map connector type to task # Map connector type to task

View file

@ -477,16 +477,13 @@ def validate_connector_config(
"Firecrawl API key should start with 'fc-'. Please verify your API key." "Firecrawl API key should start with 'fc-'. Please verify your API key."
) )
def validate_initial_urls() -> None: def validate_initial_urls() -> None:
initial_urls = config.get("INITIAL_URLS", "") initial_urls = config.get("INITIAL_URLS", "")
if initial_urls and initial_urls.strip(): if initial_urls and initial_urls.strip():
urls = [url.strip() for url in initial_urls.split("\n") if url.strip()] urls = [url.strip() for url in initial_urls.split("\n") if url.strip()]
for url in urls: for url in urls:
if not validators.url(url): if not validators.url(url):
raise ValueError( raise ValueError(f"Invalid URL format in INITIAL_URLS: {url}")
f"Invalid URL format in INITIAL_URLS: {url}"
)
# Lookup table for connector validation rules # Lookup table for connector validation rules
connector_rules = { connector_rules = {