Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

UN-2708 [MISC] Remove unused clear cache functionality from platform (#1484)

Chandrasekharan Mf2f39c78be90
diff --git a/backend/workflow_manager/workflow_v2/constants.py b/backend/workflow_manager/workflow_v2/constants.py
index 29d400ffe..6473737ad 100644
--- a/backend/workflow_manager/workflow_v2/constants.py
+++ b/backend/workflow_manager/workflow_v2/constants.py
@@ -48,9 +48,6 @@ class Tool:
class WorkflowMessages:
- CACHE_CLEAR_SUCCESS = "Cache cleared successfully."
- CACHE_CLEAR_FAILED = "Failed to clear cache."
- CACHE_EMPTY = "Cache is already empty."
CELERY_TIMEOUT_MESSAGE = (
"Your request is being processed. Please wait."
"You can check the status using the status API."
diff --git a/backend/workflow_manager/workflow_v2/urls/workflow.py b/backend/workflow_manager/workflow_v2/urls/workflow.py
index d6ae40400..2073e46ff 100644
--- a/backend/workflow_manager/workflow_v2/urls/workflow.py
+++ b/backend/workflow_manager/workflow_v2/urls/workflow.py
@@ -20,7 +20,6 @@ workflow_execute = WorkflowViewSet.as_view({"post": "execute", "put": "activate"
execution_entity = WorkflowExecutionViewSet.as_view({"get": "retrieve"})
execution_list = WorkflowExecutionViewSet.as_view({"get": "list"})
execution_log_list = WorkflowExecutionLogViewSet.as_view({"get": "list"})
-workflow_clear_cache = WorkflowViewSet.as_view({"get": "clear_cache"})
workflow_clear_file_marker = WorkflowViewSet.as_view({"get": "clear_file_marker"})
workflow_schema = WorkflowViewSet.as_view({"get": "get_schema"})
can_update = WorkflowViewSet.as_view({"get": "can_update"})
@@ -28,11 +27,6 @@ urlpatterns = format_suffix_patterns(
[
path("", workflow_list, name="workflow-list"),
path("<uuid:pk>/", workflow_detail, name="workflow-detail"),
- path(
- "<uuid:pk>/clear-cache/",
- workflow_clear_cache,
- name="clear-cache",
- ),
path(
"<uuid:pk>/clear-file-marker/",
workflow_clear_file_marker,
diff --git a/backend/workflow_manager/workflow_v2/views.py b/backend/workflow_manager/workflow_v2/views.py
index 01f750345..7e24e6296 100644
--- a/backend/workflow_manager/workflow_v2/views.py
+++ b/backend/workflow_manager/workflow_v2/views.py
@@ -232,12 +232,6 @@ class WorkflowViewSet(viewsets.ModelViewSet):
serializer = WorkflowSerializer(workflow)
return Response(serializer.data, status=status.HTTP_200_OK)
- @action(detail=True, methods=["get"])
- def clear_cache(self, request: Request, *args: Any, **kwargs: Any) -> Response:
- workflow = self.get_object()
- response: dict[str, Any] = WorkflowHelper.clear_cache(workflow_id=workflow.id)
- return Response(response.get("message"), status=response.get("status"))
-
@action(detail=True, methods=["get"])
def can_update(self, request: Request, pk: str) -> Response:
response: dict[str, Any] = WorkflowHelper.can_update_workflow(pk)
diff --git a/backend/workflow_manager/workflow_v2/workflow_helper.py b/backend/workflow_manager/workflow_v2/workflow_helper.py
index dc7409432..c42e06180 100644
--- a/backend/workflow_manager/workflow_v2/workflow_helper.py
+++ b/backend/workflow_manager/workflow_v2/workflow_helper.py
@@ -907,23 +907,6 @@ class WorkflowHelper:
mode=workflow_execution.execution_mode,
)
- # TODO: Access cache through a manager
- @staticmethod
- def clear_cache(workflow_id: str) -> dict[str, Any]:
- """Function to clear cache with a specific pattern."""
- response: dict[str, Any] = {}
- try:
- key_pattern = f"*:cache:{workflow_id}:*"
- CacheService.clear_cache(key_pattern)
- response["message"] = WorkflowMessages.CACHE_CLEAR_SUCCESS
- response["status"] = 200
- return response
- except Exception as exc:
- logger.error(f"Error occurred while clearing cache : {exc}")
- response["message"] = WorkflowMessages.CACHE_CLEAR_FAILED
- response["status"] = 400
- return response
-
@staticmethod
def clear_file_marker(workflow_id: str) -> dict[str, Any]:
"""Function to clear file marker from the cache."""
diff --git a/frontend/src/components/agency/agency/Agency.jsx b/frontend/src/components/agency/agency/Agency.jsx
index d2b49935d..025f0fa08 100644
--- a/frontend/src/components/agency/agency/Agency.jsx
+++ b/frontend/src/components/agency/agency/Agency.jsx
@@ -12,8 +12,8 @@ import {
BugOutlined,
SettingOutlined,
PlayCircleOutlined,
- ClearOutlined,
HistoryOutlined,
+ LoadingOutlined,
} from "@ant-design/icons";
import { useEffect, useState } from "react";
import { Link } from "react-router-dom";
@@ -31,6 +31,7 @@ import { useAlertStore } from "../../../store/alert-store";
import { useSessionStore } from "../../../store/session-store";
import { useExceptionHandler } from "../../../hooks/useExceptionHandler";
import useRequestUrl from "../../../hooks/useRequestUrl";
+import useClearFileHistory from "../../../hooks/useClearFileHistory";
import { CreateApiDeploymentModal } from "../../deployments/create-api-deployment-modal/CreateApiDeploymentModal.jsx";
import { EtlTaskDeploy } from "../../pipelines-or-deployments/etl-task-deploy/EtlTaskDeploy.jsx";
import usePostHogEvents from "../../../hooks/usePostHogEvents.js";
@@ -69,6 +70,8 @@ function Agency() {
const handleException = useExceptionHandler();
const apiDeploymentService = apiDeploymentsService();
const pipelineServiceInstance = pipelineService();
+ const { clearFileHistory, isClearing: isClearingFileHistory } =
+ useClearFileHistory();
const prompt = details?.prompt_text;
const [prevLoadingType, setPrevLoadingType] = useState("");
const [isUpdateSteps, setIsUpdateSteps] = useState(false);
@@ -874,39 +877,6 @@ function Agency() {
}
};
- // Handle Clear Cache action
- const handleClearCache = () => {
- const workflowId = details?.id;
- if (!workflowId) {
- setAlertDetails({
- type: "error",
- content: "Invalid workflow id",
- });
- return;
- }
-
- const requestOptions = {
- method: "GET",
- url: getUrl(`workflow/${workflowId}/clear-cache/`),
- };
-
- axiosPrivate(requestOptions)
- .then((res) => {
- const msg = res?.data;
- setAlertDetails({
- type: "success",
- content: msg,
- });
- })
- .catch((err) => {
- const msg = err?.response?.data || "Failed to clear cache.";
- setAlertDetails({
- type: "error",
- content: msg,
- });
- });
- };
-
// Handle tool selection from sidebar
const handleToolSelection = async (functionName) => {
setSelectedTool(functionName);
@@ -982,36 +952,9 @@ function Agency() {
};
// Handle Clear Processed File History action
- const handleClearFileMarker = () => {
+ const handleClearFileMarker = async () => {
const workflowId = details?.id;
- if (!workflowId) {
- setAlertDetails({
- type: "error",
- content: "Invalid workflow id",
- });
- return;
- }
-
- const requestOptions = {
- method: "GET",
- url: getUrl(`workflow/${workflowId}/clear-file-marker/`),
- };
-
- axiosPrivate(requestOptions)
- .then((res) => {
- const msg = res?.data;
- setAlertDetails({
- type: "success",
- content: msg,
- });
- })
- .catch((err) => {
- const msg = err?.response?.data || "Failed to clear file marker.";
- setAlertDetails({
- type: "error",
- content: msg,
- });
- });
+ await clearFileHistory(workflowId);
};
// Handle dropdown menu click
@@ -1020,9 +963,6 @@ function Agency() {
case "run-workflow":
handleRunWorkflow();
break;
- case "clear-cache":
- handleClearCache();
- break;
case "clear-history":
handleClearFileMarker();
break;
@@ -1036,16 +976,13 @@ function Agency() {
key: "run-workflow",
label: "Run Workflow",
icon: <PlayCircleOutlined />,
- },
- {
- key: "clear-cache",
- label: "Clear Cache",
- icon: <ClearOutlined />,
+ disabled: isClearingFileHistory || loadingType === "EXECUTE",
},
{
key: "clear-history",
label: "Clear Processed File History",
- icon: <HistoryOutlined />,
+ icon: isClearingFileHistory ? <LoadingOutlined /> : <HistoryOutlined />,
+ disabled: isClearingFileHistory || loadingType === "EXECUTE",
},
];
@@ -1089,8 +1026,8 @@ function Agency() {
<Button
type="primary"
icon={<SettingOutlined />}
- loading={loadingType === "EXECUTE"}
- disabled={loadingType === "EXECUTE"}
+ loading={loadingType === "EXECUTE" || isClearingFileHistory}
+ disabled={loadingType === "EXECUTE" || isClearingFileHistory}
>
Actions
</Button>
diff --git a/frontend/src/components/deployments/api-deployment/ApiDeployment.jsx b/frontend/src/components/deployments/api-deployment/ApiDeployment.jsx
index d09e02de5..a211e07c1 100644
--- a/frontend/src/components/deployments/api-deployment/ApiDeployment.jsx
+++ b/frontend/src/components/deployments/api-deployment/ApiDeployment.jsx
@@ -248,6 +248,7 @@ function ApiDeployment() {
};
const actionItems = [
+ // Configuration Section
{
key: "1",
label: (
@@ -295,38 +296,24 @@ function ApiDeployment() {
<Space
direction="horizontal"
className="action-items"
- onClick={() =>
- downloadPostmanCollection(apiDeploymentsApiService, selectedRow?.id)
- }
+ onClick={() => setOpenNotificationModal(true)}
>
<div>
- <CloudDownloadOutlined />
+ <NotificationOutlined />
</div>
<div>
- <Typography.Text>Download Postman Collection</Typography.Text>
+ <Typography.Text>Setup Notifications</Typography.Text>
</div>
</Space>
),
},
{
- key: "4",
- label: (
- <Space
- direction="horizontal"
- className="action-items"
- onClick={() => setOpenCodeModal(true)}
- >
- <div>
- <CodeOutlined />
- </div>
- <div>
- <Typography.Text>Code Snippets</Typography.Text>
- </div>
- </Space>
- ),
+ key: "divider-config",
+ type: "divider",
},
+ // Operation Section
{
- key: "5",
+ key: "4",
label: (
<Space
direction="horizontal"
@@ -353,36 +340,65 @@ function ApiDeployment() {
</Space>
),
},
+ {
+ key: "divider-operation",
+ type: "divider",
+ },
+ // Developer related Section
+ {
+ key: "5",
+ label: (
+ <Space
+ direction="horizontal"
+ className="action-items"
+ onClick={() => setOpenCodeModal(true)}
+ >
+ <div>
+ <CodeOutlined />
+ </div>
+ <div>
+ <Typography.Text>Code Snippets</Typography.Text>
+ </div>
+ </Space>
+ ),
+ },
{
key: "6",
label: (
<Space
direction="horizontal"
className="action-items"
- onClick={() => setOpenDeleteModal(true)}
+ onClick={() =>
+ downloadPostmanCollection(apiDeploymentsApiService, selectedRow?.id)
+ }
>
<div>
- <DeleteOutlined />
+ <CloudDownloadOutlined />
</div>
<div>
- <Typography.Text>Delete</Typography.Text>
+ <Typography.Text>Download Postman Collection</Typography.Text>
</div>
</Space>
),
},
+ {
+ key: "divider-dev-related",
+ type: "divider",
+ },
+ // Delete related section
{
key: "7",
label: (
<Space
direction="horizontal"
className="action-items"
- onClick={() => setOpenNotificationModal(true)}
+ onClick={() => setOpenDeleteModal(true)}
>
<div>
- <NotificationOutlined />
+ <DeleteOutlined />
</div>
<div>
- <Typography.Text>Setup Notifications</Typography.Text>
+ <Typography.Text>Delete</Typography.Text>
</div>
</Space>
),
diff --git a/frontend/src/components/pipelines-or-deployments/pipelines/Pipelines.css b/frontend/src/components/pipelines-or-deployments/pipelines/Pipelines.css
index 0509db898..4d8c6247f 100644
--- a/frontend/src/components/pipelines-or-deployments/pipelines/Pipelines.css
+++ b/frontend/src/components/pipelines-or-deployments/pipelines/Pipelines.css
@@ -4,3 +4,13 @@
display: flex;
flex-direction: column;
}
+
+.action-item-disabled {
+ opacity: 0.5;
+ cursor: not-allowed;
+}
+
+.action-item-enabled {
+ opacity: 1;
+ cursor: pointer;
+}
diff --git a/frontend/src/components/pipelines-or-deployments/pipelines/Pipelines.jsx b/frontend/src/components/pipelines-or-deployments/pipelines/Pipelines.jsx
index 98785a5c1..8b22d6a8b 100644
--- a/frontend/src/components/pipelines-or-deployments/pipelines/Pipelines.jsx
+++ b/frontend/src/components/pipelines-or-deployments/pipelines/Pipelines.jsx
@@ -1,5 +1,4 @@
import {
- ClearOutlined,
DeleteOutlined,
EllipsisOutlined,
SyncOutlined,
@@ -11,6 +10,7 @@ import {
KeyOutlined,
CloudDownloadOutlined,
CopyOutlined,
+ LoadingOutlined,
} from "@ant-design/icons";
import {
Button,
@@ -43,6 +43,7 @@ import { useExceptionHandler } from "../../../hooks/useExceptionHandler.jsx";
import { pipelineService } from "../pipeline-service.js";
import { ManageKeys } from "../../deployments/manage-keys/ManageKeys.jsx";
import usePipelineHelper from "../../../hooks/usePipelineHelper.js";
+import useClearFileHistory from "../../../hooks/useClearFileHistory";
import { NotificationModal } from "../notification-modal/NotificationModal.jsx";
import { usePromptStudioStore } from "../../../store/prompt-studio-store";
import { PromptStudioModal } from "../../common/PromptStudioModal";
@@ -62,6 +63,8 @@ function Pipelines({ type }) {
const { setAlertDetails } = useAlertStore();
const axiosPrivate = useAxiosPrivate();
const handleException = useExceptionHandler();
+ const { clearFileHistory, isClearing: isClearingFileHistory } =
+ useClearFileHistory();
const [isEdit, setIsEdit] = useState(false);
const [openLogsModal, setOpenLogsModal] = useState(false);
const [executionLogs, setExecutionLogs] = useState([]);
@@ -270,49 +273,19 @@ function Pipelines({ type }) {
});
};
- const clearCache = () => {
- const requestOptions = {
- method: "GET",
- url: `/api/v1/unstract/${sessionDetails?.orgId}/workflow/${selectedPorD.workflow_id}/clear-cache/`,
- headers: {
- "X-CSRFToken": sessionDetails?.csrfToken,
- },
- };
- axiosPrivate(requestOptions)
- .then(() => {
- setOpenDeleteModal(false);
- setAlertDetails({
- type: "success",
- content: "Pipeline Cache Cleared Successfully",
- });
- })
- .catch((err) => {
- setAlertDetails(handleException(err));
- });
- };
-
- const clearFileMarkers = () => {
- const requestOptions = {
- method: "GET",
- url: `/api/v1/unstract/${sessionDetails?.orgId}/workflow/${selectedPorD.workflow_id}/clear-file-marker/`,
- headers: {
- "X-CSRFToken": sessionDetails?.csrfToken,
- },
- };
- axiosPrivate(requestOptions)
- .then(() => {
- setOpenDeleteModal(false);
- setAlertDetails({
- type: "success",
- content: "Pipeline File History Cleared Successfully",
- });
- })
- .catch((err) => {
- setAlertDetails(handleException(err));
- });
+ const clearFileMarkers = async () => {
+ const workflowId = selectedPorD?.workflow_id;
+ const success = await clearFileHistory(
+ workflowId,
+ "Pipeline File History Cleared Successfully"
+ );
+ if (success && openDeleteModal) {
+ setOpenDeleteModal(false);
+ }
};
const actionItems = [
+ // Configuration Section
{
key: "1",
label: (
@@ -332,19 +305,6 @@ function Pipelines({ type }) {
},
{
key: "2",
- label: (
- <Space
- direction="horizontal"
- className="action-items"
- onClick={() => setOpenDeleteModal(true)}
- >
- <DeleteOutlined />
- <Typography.Text>Delete</Typography.Text>
- </Space>
- ),
- },
- {
- key: "3",
label: (
<Space
direction="horizontal"
@@ -364,17 +324,42 @@ function Pipelines({ type }) {
),
},
{
- key: "4",
+ key: "3",
label: (
<Space
direction="horizontal"
className="action-items"
+ onClick={() => setOpenNotificationModal(true)}
+ >
+ <NotificationOutlined />
+ <Typography.Text>Setup Notifications</Typography.Text>
+ </Space>
+ ),
+ },
+ {
+ key: "divider-config",
+ type: "divider",
+ },
+ // Operation Section
+ {
+ key: "4",
+ label: (
+ <Space
+ direction="horizontal"
+ className={`action-items ${
+ isClearingFileHistory
+ ? "action-item-disabled"
+ : "action-item-enabled"
+ }`}
onClick={() =>
- downloadPostmanCollection(pipelineApiService, selectedPorD?.id)
+ !isClearingFileHistory &&
+ handleSync({
+ pipeline_id: selectedPorD.id,
+ })
}
>
- <CloudDownloadOutlined />
- <Typography.Text>Download Postman Collection</Typography.Text>
+ <SyncOutlined />
+ <Typography.Text>Sync Now</Typography.Text>
</Space>
),
},
@@ -402,28 +387,44 @@ function Pipelines({ type }) {
</Space>
),
},
+ {
+ key: "divider-operation",
+ type: "divider",
+ },
+ // Developer related Section
{
key: "6",
label: (
<Space
direction="horizontal"
className="action-items"
- onClick={() => clearCache()}
+ onClick={() =>
+ downloadPostmanCollection(pipelineApiService, selectedPorD?.id)
+ }
>
- <ClearOutlined />
- <Typography.Text>Clear Cache</Typography.Text>
+ <CloudDownloadOutlined />
+ <Typography.Text>Download Postman Collection</Typography.Text>
</Space>
),
},
+ {
+ key: "divider-dev-related",
+ type: "divider",
+ },
+ // Delete related section
{
key: "7",
label: (
<Space
direction="horizontal"
- className="action-items"
- onClick={() => clearFileMarkers()}
+ className={`action-items ${
+ isClearingFileHistory
+ ? "action-item-disabled"
+ : "action-item-enabled"
+ }`}
+ onClick={() => !isClearingFileHistory && clearFileMarkers()}
>
- <HighlightOutlined />
+ {isClearingFileHistory ? <LoadingOutlined /> : <HighlightOutlined />}
<Typography.Text>Clear Processed File History</Typography.Text>
</Space>
),
@@ -434,27 +435,10 @@ function Pipelines({ type }) {
<Space
direction="horizontal"
className="action-items"
- onClick={() =>
- handleSync({
- pipeline_id: selectedPorD.id,
- })
- }
- >
- <SyncOutlined />
- <Typography.Text>Sync Now</Typography.Text>
- </Space>
- ),
- },
- {
- key: "9",
- label: (
- <Space
- direction="horizontal"
- className="action-items"
- onClick={() => setOpenNotificationModal(true)}
+ onClick={() => setOpenDeleteModal(true)}
>
- <NotificationOutlined />
- <Typography.Text>Setup Notifications</Typography.Text>
+ <DeleteOutlined />
+ <Typography.Text>Delete</Typography.Text>
</Space>
),
},
diff --git a/frontend/src/components/workflows/workflow/workflow-service.js b/frontend/src/components/workflows/workflow/workflow-service.js
index 494efe4b2..ea50c8909 100644
--- a/frontend/src/components/workflows/workflow/workflow-service.js
+++ b/frontend/src/components/workflows/workflow/workflow-service.js
@@ -58,16 +58,6 @@ function workflowService() {
};
return axiosPrivate(options);
},
- clearCache: (id) => {
- options = {
- url: `${path}/workflow/${id}/clear-cache/`,
- method: "GET",
- headers: {
- "X-CSRFToken": csrfToken,
- },
- };
- return axiosPrivate(options);
- },
clearFileMarkers: (id) => {
options = {
url: `${path}/workflow/${id}/clear-file-marker/`,
diff --git a/frontend/src/hooks/useClearFileHistory.js b/frontend/src/hooks/useClearFileHistory.js
new file mode 100644
index 000000000..5ad264f2c
--- /dev/null
+++ b/frontend/src/hooks/useClearFileHistory.js
@@ -0,0 +1,62 @@
+import { useState } from "react";
+
+import { workflowService } from "../components/workflows/workflow/workflow-service";
+import { useAlertStore } from "../store/alert-store";
+import { useExceptionHandler } from "./useExceptionHandler";
+
+/**
+ * Custom hook for clearing file history with loading state management
+ * Prevents race conditions by tracking operation status
+ * @return {Object} Object containing clearFileHistory function and isClearing state
+ */
+const useClearFileHistory = () => {
+ const [isClearing, setIsClearing] = useState(false);
+ const { setAlertDetails } = useAlertStore();
+ const handleException = useExceptionHandler();
+
+ // Get the workflow service instance at the top level of the hook
+ const workflowServiceInstance = workflowService();
+
+ /**
+ * Clear file history for a workflow
+ * @param {string} workflowId - The workflow ID
+ * @param {string} successMessage - Custom success message
+ * @return {Promise<boolean>} - Returns true if successful, false otherwise
+ */
+ const clearFileHistory = async (
+ workflowId,
+ successMessage = "File history cleared successfully"
+ ) => {
+ if (!workflowId) {
+ setAlertDetails({
+ type: "error",
+ content: "Invalid workflow id",
+ });
+ return false;
+ }
+
+ setIsClearing(true);
+
+ try {
+ const res = await workflowServiceInstance.clearFileMarkers(workflowId);
+ const msg = res?.data || successMessage;
+ setAlertDetails({
+ type: "success",
+ content: msg,
+ });
+ return true;
+ } catch (err) {
+ setAlertDetails(handleException(err, "Failed to clear file history"));
+ return false;
+ } finally {
+ setIsClearing(false);
+ }
+ };
+
+ return {
+ clearFileHistory,
+ isClearing,
+ };
+};
+
+export default useClearFileHistory;
diff --git a/tools/classifier/src/config/properties.json b/tools/classifier/src/config/properties.json
index d2d5d49c7..4cee3c5d6 100644
--- a/tools/classifier/src/config/properties.json
+++ b/tools/classifier/src/config/properties.json
@@ -2,7 +2,7 @@
"schemaVersion": "0.0.1",
"displayName": "File Classifier",
"functionName": "classify",
- "toolVersion": "0.0.66",
+ "toolVersion": "0.0.67",
"description": "Classifies a file into a bin based on its contents",
"input": {
"description": "File to be classified"
diff --git a/tools/classifier/src/helper.py b/tools/classifier/src/helper.py
index d6936a50a..8314cd91a 100644
--- a/tools/classifier/src/helper.py
+++ b/tools/classifier/src/helper.py
@@ -2,11 +2,9 @@ import re
from pathlib import Path
from typing import Any
-from unstract.sdk.cache import ToolCache
-from unstract.sdk.constants import LogLevel, MetadataKey, ToolEnv, UsageKwargs
+from unstract.sdk.constants import LogLevel, MetadataKey, UsageKwargs
from unstract.sdk.llm import LLM
from unstract.sdk.tool.base import BaseTool
-from unstract.sdk.utils import ToolUtils
from unstract.sdk.x2txt import TextExtractionResult, X2Text
@@ -185,37 +183,18 @@ class ClassifierHelper:
"""Find classification for text.
Args:
- use_cache (bool): Whether to use cache
- settings_string (str): hash of settings
+ use_cache (bool): Whether to use cache (deprecated, not used)
+ settings_string (str): hash of settings (deprecated, not used)
prompt (str): Prompt
bins (list[str]): Classification Bins
llm (LLM): LLM
Returns:
- Optional[str]: Classification or None if not found in cache.
- If found in cache, returns the classification from the cache.
- If not found in cache, calls the LLM and returns the
- classification.
+ Optional[str]: Classification from the LLM.
"""
- classification = None
- cache_key = None
- if use_cache:
- cache_key = (
- f"cache:{self.tool.workflow_id}:"
- f"{ToolUtils.hash_str(settings_string)}:"
- f"{ToolUtils.hash_str(prompt)}"
- )
- self.tool.stream_log("Trying to fetch result from cache.")
- classification = self.get_result_from_cache(cache_key=cache_key)
- if classification is not None:
- return classification
-
- self.tool.stream_log("No classification found in cache, calling LLM.")
+ self.tool.stream_log("Calling LLM for classification.")
llm_response = self.call_llm(prompt=prompt, llm=llm)
classification = self.clean_llm_response(llm_response=llm_response, bins=bins)
- if use_cache and cache_key:
- self.tool.stream_log("Saving result to cache.")
- self.save_result_to_cache(cache_key=cache_key, result=classification)
return classification
def call_llm(self, prompt: str, llm: LLM) -> str:
@@ -279,40 +258,3 @@ class ClassifierHelper:
bin_to_copy_to=ReservedBins.UNKNOWN,
)
return classification
-
- def get_result_from_cache(self, cache_key: str) -> str | None:
- """Get result from cache.
-
- Args:
- cache_key (str): key
-
- Returns:
- Optional[str]: result
- """
- cache = ToolCache(
- tool=self.tool,
- platform_host=self.tool.get_env_or_die(ToolEnv.PLATFORM_HOST),
- platform_port=int(self.tool.get_env_or_die(ToolEnv.PLATFORM_PORT)),
- )
- cached_response: str | None = cache.get(cache_key)
- if cached_response is not None:
- classification = cached_response
- self.tool.stream_cost(cost=0.0, cost_units="cache")
- return classification
- return None
-
- def save_result_to_cache(self, cache_key: str, result: Any) -> None:
- """Save result to cache.
-
- Args:
- cache_key (str): key
- result (Any): result to save in cache
- Returns:
- None: None
- """
- cache = ToolCache(
- tool=self.tool,
- platform_host=self.tool.get_env_or_die(ToolEnv.PLATFORM_HOST),
- platform_port=int(self.tool.get_env_or_die(ToolEnv.PLATFORM_PORT)),
- )
- cache.set(cache_key, result)