mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-26 21:39:43 +02:00
add relevant coderrabit suggestions
This commit is contained in:
parent
dee54bf5e1
commit
8e52a0b201
7 changed files with 534 additions and 296 deletions
|
|
@ -920,29 +920,32 @@ async def fetch_relevant_documents(
|
|||
}
|
||||
)
|
||||
elif connector == "CONFLUENCE_CONNECTOR":
|
||||
source_object, confluence_chunks = await connector_service.search_confluence(
|
||||
user_query=reformulated_query,
|
||||
user_id=user_id,
|
||||
search_space_id=search_space_id,
|
||||
top_k=top_k,
|
||||
search_mode=search_mode,
|
||||
(
|
||||
source_object,
|
||||
confluence_chunks,
|
||||
) = await connector_service.search_confluence(
|
||||
user_query=reformulated_query,
|
||||
user_id=user_id,
|
||||
search_space_id=search_space_id,
|
||||
top_k=top_k,
|
||||
search_mode=search_mode,
|
||||
)
|
||||
|
||||
# Add to sources and raw documents
|
||||
if source_object:
|
||||
all_sources.append(source_object)
|
||||
all_raw_documents.extend(confluence_chunks)
|
||||
|
||||
# Stream found document count
|
||||
if streaming_service and writer:
|
||||
writer(
|
||||
{
|
||||
"yield_value": streaming_service.format_terminal_info_delta(
|
||||
f"📚 Found {len(confluence_chunks)} Confluence pages related to your query"
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
# Add to sources and raw documents
|
||||
if source_object:
|
||||
all_sources.append(source_object)
|
||||
all_raw_documents.extend(confluence_chunks)
|
||||
|
||||
# Stream found document count
|
||||
if streaming_service and writer:
|
||||
writer(
|
||||
{
|
||||
"yield_value": streaming_service.format_terminal_info_delta(
|
||||
f"📚 Found {len(confluence_chunks)} Confluence pages related to your query"
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
error_message = f"Error searching connector {connector}: {e!s}"
|
||||
print(error_message)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ Allows fetching pages and their comments from specified spaces.
|
|||
"""
|
||||
|
||||
import base64
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any
|
||||
|
||||
import requests
|
||||
|
|
|
|||
|
|
@ -918,7 +918,9 @@ async def run_confluence_indexing_with_new_session(
|
|||
await run_confluence_indexing(
|
||||
session, connector_id, search_space_id, user_id, start_date, end_date
|
||||
)
|
||||
logger.info(f"Background task finished: Indexing Confluence connector {connector_id}")
|
||||
logger.info(
|
||||
f"Background task finished: Indexing Confluence connector {connector_id}"
|
||||
)
|
||||
|
||||
|
||||
async def run_confluence_indexing(
|
||||
|
|
|
|||
|
|
@ -145,7 +145,11 @@ class SearchSourceConnectorBase(BaseModel):
|
|||
|
||||
elif connector_type == SearchSourceConnectorType.CONFLUENCE_CONNECTOR:
|
||||
# For CONFLUENCE_CONNECTOR, only allow specific keys
|
||||
allowed_keys = ["CONFLUENCE_BASE_URL", "CONFLUENCE_EMAIL", "CONFLUENCE_API_TOKEN"]
|
||||
allowed_keys = [
|
||||
"CONFLUENCE_BASE_URL",
|
||||
"CONFLUENCE_EMAIL",
|
||||
"CONFLUENCE_API_TOKEN",
|
||||
]
|
||||
if set(config.keys()) != set(allowed_keys):
|
||||
raise ValueError(
|
||||
f"For CONFLUENCE_CONNECTOR connector type, config must only contain these keys: {allowed_keys}"
|
||||
|
|
|
|||
|
|
@ -1072,6 +1072,7 @@ class ConnectorService:
|
|||
}
|
||||
|
||||
return result_object, jira_chunks
|
||||
|
||||
async def search_confluence(
|
||||
self,
|
||||
user_query: str,
|
||||
|
|
@ -1145,7 +1146,7 @@ class ConnectorService:
|
|||
description += "..."
|
||||
|
||||
# For URL, we can use a placeholder or construct a URL to the Confluence page if available
|
||||
url = ""
|
||||
url = "" # TODO: Add base_url to metadata
|
||||
if page_id:
|
||||
url = f"{metadata.get('base_url')}/pages/{page_id}"
|
||||
|
||||
|
|
|
|||
|
|
@ -2413,7 +2413,9 @@ async def index_confluence_pages(
|
|||
)
|
||||
|
||||
confluence_client = ConfluenceConnector(
|
||||
base_url=confluence_base_url, email=confluence_email, api_token=confluence_api_token
|
||||
base_url=confluence_base_url,
|
||||
email=confluence_email,
|
||||
api_token=confluence_api_token,
|
||||
)
|
||||
|
||||
# Calculate date range
|
||||
|
|
@ -2528,9 +2530,7 @@ async def index_confluence_pages(
|
|||
logger.warning(
|
||||
f"Skipping page with missing ID or title: {page_id or 'Unknown'}"
|
||||
)
|
||||
skipped_pages.append(
|
||||
f"{page_title or 'Unknown'} (missing data)"
|
||||
)
|
||||
skipped_pages.append(f"{page_title or 'Unknown'} (missing data)")
|
||||
documents_skipped += 1
|
||||
continue
|
||||
|
||||
|
|
@ -2549,7 +2549,9 @@ async def index_confluence_pages(
|
|||
if comment.get("body") and comment["body"].get("storage"):
|
||||
comment_body = comment["body"]["storage"].get("value", "")
|
||||
|
||||
comment_author = comment.get("version", {}).get("authorId", "Unknown")
|
||||
comment_author = comment.get("version", {}).get(
|
||||
"authorId", "Unknown"
|
||||
)
|
||||
comment_date = comment.get("version", {}).get("createdAt", "")
|
||||
|
||||
comments_content += f"**Comment by {comment_author}** ({comment_date}):\n{comment_body}\n\n"
|
||||
|
|
@ -2558,15 +2560,15 @@ async def index_confluence_pages(
|
|||
full_content = f"# {page_title}\n\n{page_content}{comments_content}"
|
||||
|
||||
if not full_content.strip():
|
||||
logger.warning(
|
||||
f"Skipping page with no content: {page_title}"
|
||||
)
|
||||
logger.warning(f"Skipping page with no content: {page_title}")
|
||||
skipped_pages.append(f"{page_title} (no content)")
|
||||
documents_skipped += 1
|
||||
continue
|
||||
|
||||
# Create a simple summary
|
||||
summary_content = f"Confluence Page: {page_title}\n\nSpace ID: {space_id}\n\n"
|
||||
summary_content = (
|
||||
f"Confluence Page: {page_title}\n\nSpace ID: {space_id}\n\n"
|
||||
)
|
||||
if page_content:
|
||||
# Take first 500 characters of content for summary
|
||||
content_preview = page_content[:500]
|
||||
|
|
@ -2611,9 +2613,7 @@ async def index_confluence_pages(
|
|||
]
|
||||
|
||||
# Create and store new document
|
||||
logger.info(
|
||||
f"Creating new document for page {page_title}"
|
||||
)
|
||||
logger.info(f"Creating new document for page {page_title}")
|
||||
document = Document(
|
||||
search_space_id=search_space_id,
|
||||
title=f"Confluence - {page_title}",
|
||||
|
|
@ -2633,9 +2633,7 @@ async def index_confluence_pages(
|
|||
|
||||
session.add(document)
|
||||
documents_indexed += 1
|
||||
logger.info(
|
||||
f"Successfully indexed new page {page_title}"
|
||||
)
|
||||
logger.info(f"Successfully indexed new page {page_title}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
|
|
@ -2656,7 +2654,9 @@ async def index_confluence_pages(
|
|||
|
||||
# Commit all changes
|
||||
await session.commit()
|
||||
logger.info("Successfully committed all Confluence document changes to database")
|
||||
logger.info(
|
||||
"Successfully committed all Confluence document changes to database"
|
||||
)
|
||||
|
||||
# Log success
|
||||
await task_logger.log_task_success(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue