Disable streaming for KB sync summary LLM to prevent token leaking into chat; remove workspace_icon from update-notion-page

This commit is contained in:
CREDO23 2026-02-18 15:10:51 +02:00
parent d28aed14b3
commit 594379ea69
3 changed files with 14 additions and 8 deletions

View file

@ -162,7 +162,7 @@ async def validate_llm_config(
async def get_search_space_llm_instance( async def get_search_space_llm_instance(
session: AsyncSession, search_space_id: int, role: str session: AsyncSession, search_space_id: int, role: str, disable_streaming: bool = False
) -> ChatLiteLLM | ChatLiteLLMRouter | None: ) -> ChatLiteLLM | ChatLiteLLMRouter | None:
""" """
Get a ChatLiteLLM instance for a specific search space and role. Get a ChatLiteLLM instance for a specific search space and role.
@ -218,7 +218,7 @@ async def get_search_space_llm_instance(
logger.debug( logger.debug(
f"Using Auto mode (LLM Router) for search space {search_space_id}, role {role}" f"Using Auto mode (LLM Router) for search space {search_space_id}, role {role}"
) )
return ChatLiteLLMRouter() return ChatLiteLLMRouter(disable_streaming=disable_streaming)
except Exception as e: except Exception as e:
logger.error(f"Failed to create ChatLiteLLMRouter: {e}") logger.error(f"Failed to create ChatLiteLLMRouter: {e}")
return None return None
@ -284,6 +284,9 @@ async def get_search_space_llm_instance(
if global_config.get("litellm_params"): if global_config.get("litellm_params"):
litellm_kwargs.update(global_config["litellm_params"]) litellm_kwargs.update(global_config["litellm_params"])
if disable_streaming:
litellm_kwargs["disable_streaming"] = True
return ChatLiteLLM(**litellm_kwargs) return ChatLiteLLM(**litellm_kwargs)
# Get the LLM configuration from database (NewLLMConfig) # Get the LLM configuration from database (NewLLMConfig)
@ -357,6 +360,9 @@ async def get_search_space_llm_instance(
if llm_config.litellm_params: if llm_config.litellm_params:
litellm_kwargs.update(llm_config.litellm_params) litellm_kwargs.update(llm_config.litellm_params)
if disable_streaming:
litellm_kwargs["disable_streaming"] = True
return ChatLiteLLM(**litellm_kwargs) return ChatLiteLLM(**litellm_kwargs)
except Exception as e: except Exception as e:
@ -374,20 +380,20 @@ async def get_agent_llm(
async def get_document_summary_llm( async def get_document_summary_llm(
session: AsyncSession, search_space_id: int session: AsyncSession, search_space_id: int, disable_streaming: bool = False
) -> ChatLiteLLM | ChatLiteLLMRouter | None: ) -> ChatLiteLLM | ChatLiteLLMRouter | None:
"""Get the search space's document summary LLM instance.""" """Get the search space's document summary LLM instance."""
return await get_search_space_llm_instance( return await get_search_space_llm_instance(
session, search_space_id, LLMRole.DOCUMENT_SUMMARY session, search_space_id, LLMRole.DOCUMENT_SUMMARY, disable_streaming=disable_streaming
) )
# Backward-compatible alias (LLM preferences are now per-search-space, not per-user) # Backward-compatible alias (LLM preferences are now per-search-space, not per-user)
async def get_user_long_context_llm( async def get_user_long_context_llm(
session: AsyncSession, user_id: str, search_space_id: int session: AsyncSession, user_id: str, search_space_id: int, disable_streaming: bool = False
) -> ChatLiteLLM | ChatLiteLLMRouter | None: ) -> ChatLiteLLM | ChatLiteLLMRouter | None:
""" """
Deprecated: Use get_document_summary_llm instead. Deprecated: Use get_document_summary_llm instead.
The user_id parameter is ignored as LLM preferences are now per-search-space. The user_id parameter is ignored as LLM preferences are now per-search-space.
""" """
return await get_document_summary_llm(session, search_space_id) return await get_document_summary_llm(session, search_space_id, disable_streaming=disable_streaming)

View file

@ -104,7 +104,7 @@ class NotionKBSyncService:
logger.debug("Generating summary and embeddings") logger.debug("Generating summary and embeddings")
user_llm = await get_user_long_context_llm( user_llm = await get_user_long_context_llm(
self.db_session, user_id, search_space_id self.db_session, user_id, search_space_id, disable_streaming=True # disable streaming to avoid leaking into the chat
) )
if user_llm: if user_llm:

View file

@ -195,7 +195,7 @@ function ApprovalCard({
<div className="space-y-2"> <div className="space-y-2">
<div className="text-xs font-medium text-muted-foreground">Notion Account</div> <div className="text-xs font-medium text-muted-foreground">Notion Account</div>
<div className="w-full rounded-md border border-input bg-muted/50 px-3 py-2 text-sm"> <div className="w-full rounded-md border border-input bg-muted/50 px-3 py-2 text-sm">
{account.workspace_icon} {account.workspace_name} {account.workspace_name}
</div> </div>
</div> </div>
)} )}