mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-26 11:58:28 +02:00
Built in tool cache with tool call id (#3617)
* k * improved * k * nit * nit * nit
This commit is contained in:
@@ -151,7 +151,7 @@ def auto_add_search_tool_to_personas(db_session: Session) -> None:
|
|||||||
logger.notice("Completed adding SearchTool to relevant Personas.")
|
logger.notice("Completed adding SearchTool to relevant Personas.")
|
||||||
|
|
||||||
|
|
||||||
_built_in_tools_cache: dict[int, Type[Tool]] | None = None
|
_built_in_tools_cache: dict[str, Type[Tool]] | None = None
|
||||||
|
|
||||||
|
|
||||||
def refresh_built_in_tools_cache(db_session: Session) -> None:
|
def refresh_built_in_tools_cache(db_session: Session) -> None:
|
||||||
@@ -173,15 +173,21 @@ def refresh_built_in_tools_cache(db_session: Session) -> None:
|
|||||||
),
|
),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
if tool_info:
|
if tool_info and tool.in_code_tool_id:
|
||||||
_built_in_tools_cache[tool.id] = tool_info["cls"]
|
_built_in_tools_cache[tool.in_code_tool_id] = tool_info["cls"]
|
||||||
|
|
||||||
|
|
||||||
def get_built_in_tool_by_id(
|
def get_built_in_tool_by_id(
|
||||||
tool_id: int, db_session: Session, force_refresh: bool = False
|
in_code_tool_id: str, db_session: Session, force_refresh: bool = False
|
||||||
) -> Type[Tool]:
|
) -> Type[Tool]:
|
||||||
global _built_in_tools_cache
|
global _built_in_tools_cache
|
||||||
if _built_in_tools_cache is None or force_refresh:
|
|
||||||
|
# If the tool is not in the cache, refresh it once
|
||||||
|
if (
|
||||||
|
_built_in_tools_cache is None
|
||||||
|
or force_refresh
|
||||||
|
or in_code_tool_id not in _built_in_tools_cache
|
||||||
|
):
|
||||||
refresh_built_in_tools_cache(db_session)
|
refresh_built_in_tools_cache(db_session)
|
||||||
|
|
||||||
if _built_in_tools_cache is None:
|
if _built_in_tools_cache is None:
|
||||||
@@ -189,7 +195,9 @@ def get_built_in_tool_by_id(
|
|||||||
"Built-in tools cache is None despite being refreshed. Should never happen."
|
"Built-in tools cache is None despite being refreshed. Should never happen."
|
||||||
)
|
)
|
||||||
|
|
||||||
if tool_id in _built_in_tools_cache:
|
if in_code_tool_id not in _built_in_tools_cache:
|
||||||
return _built_in_tools_cache[tool_id]
|
raise ValueError(
|
||||||
else:
|
f"No built-in tool found in the cache with ID {in_code_tool_id}"
|
||||||
raise ValueError(f"No built-in tool found in the cache with ID {tool_id}")
|
)
|
||||||
|
|
||||||
|
return _built_in_tools_cache[in_code_tool_id]
|
||||||
|
@@ -148,7 +148,9 @@ def construct_tools(
|
|||||||
|
|
||||||
for db_tool_model in persona.tools:
|
for db_tool_model in persona.tools:
|
||||||
if db_tool_model.in_code_tool_id:
|
if db_tool_model.in_code_tool_id:
|
||||||
tool_cls = get_built_in_tool_by_id(db_tool_model.id, db_session)
|
tool_cls = get_built_in_tool_by_id(
|
||||||
|
db_tool_model.in_code_tool_id, db_session
|
||||||
|
)
|
||||||
|
|
||||||
# Handle Search Tool
|
# Handle Search Tool
|
||||||
if tool_cls.__name__ == SearchTool.__name__:
|
if tool_cls.__name__ == SearchTool.__name__:
|
||||||
|
@@ -14,7 +14,11 @@ const cspHeader = `
|
|||||||
base-uri 'self';
|
base-uri 'self';
|
||||||
form-action 'self';
|
form-action 'self';
|
||||||
frame-ancestors 'none';
|
frame-ancestors 'none';
|
||||||
${process.env.NEXT_PUBLIC_CLOUD_ENABLED === "true" ? "upgrade-insecure-requests;" : ""}
|
${
|
||||||
|
process.env.NEXT_PUBLIC_CLOUD_ENABLED === "true"
|
||||||
|
? "upgrade-insecure-requests;"
|
||||||
|
: ""
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
|
Reference in New Issue
Block a user