Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slack doc set fix #3737

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions backend/onyx/db/slack_channel_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from onyx.db.persona import mark_persona_as_deleted
from onyx.db.persona import upsert_persona
from onyx.db.prompts import get_default_prompt
from onyx.tools.built_in_tools import get_search_tool
from onyx.utils.errors import EERequiredError
from onyx.utils.variable_functionality import (
fetch_versioned_implementation_with_fallback,
Expand Down Expand Up @@ -47,6 +48,10 @@ def create_slack_channel_persona(
) -> Persona:
"""NOTE: does not commit changes"""

search_tool = get_search_tool(db_session)
if search_tool is None:
raise ValueError("Search tool not found")

# create/update persona associated with the Slack channel
persona_name = _build_persona_name(channel_name)
default_prompt = get_default_prompt(db_session)
Expand All @@ -60,6 +65,7 @@ def create_slack_channel_persona(
llm_filter_extraction=enable_auto_filters,
recency_bias=RecencyBiasSetting.AUTO,
prompt_ids=[default_prompt.id],
tool_ids=[search_tool.id],
document_set_ids=document_set_ids,
llm_model_provider_override=None,
llm_model_version_override=None,
Expand Down
20 changes: 15 additions & 5 deletions backend/onyx/tools/built_in_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,10 @@ def load_builtin_tools(db_session: Session) -> None:
logger.notice("All built-in tools are loaded/verified.")


def auto_add_search_tool_to_personas(db_session: Session) -> None:
def get_search_tool(db_session: Session) -> ToolDBModel | None:
"""
Automatically adds the SearchTool to all Persona objects in the database that have
`num_chunks` either unset or set to a value that isn't 0. This is done to migrate
Persona objects that were created before the concept of Tools were added.
Retrieves for the SearchTool from the BUILT_IN_TOOLS list.
"""
# Fetch the SearchTool from the database based on in_code_tool_id from BUILT_IN_TOOLS
search_tool_id = next(
(
tool["in_code_tool_id"]
Expand All @@ -119,13 +116,26 @@ def auto_add_search_tool_to_personas(db_session: Session) -> None:
),
None,
)

if not search_tool_id:
raise RuntimeError("SearchTool not found in the BUILT_IN_TOOLS list.")

search_tool = db_session.execute(
select(ToolDBModel).where(ToolDBModel.in_code_tool_id == search_tool_id)
).scalar_one_or_none()

return search_tool


def auto_add_search_tool_to_personas(db_session: Session) -> None:
"""
Automatically adds the SearchTool to all Persona objects in the database that have
`num_chunks` either unset or set to a value that isn't 0. This is done to migrate
Persona objects that were created before the concept of Tools were added.
"""
# Fetch the SearchTool from the database based on in_code_tool_id from BUILT_IN_TOOLS
search_tool = get_search_tool(db_session)

if not search_tool:
raise RuntimeError("SearchTool not found in the database.")

Expand Down
Loading