Skip to content
Snippets Groups Projects
Commit f29561cd authored by leehuwuj's avatar leehuwuj
Browse files

add cache to toolfactory load_tools

parent 442abae8
No related branches found
No related tags found
No related merge requests found
import os import os
import yaml import yaml
import json
import importlib import importlib
from cachetools import cached, LRUCache
from llama_index.core.tools.tool_spec.base import BaseToolSpec from llama_index.core.tools.tool_spec.base import BaseToolSpec
from llama_index.core.tools.function_tool import FunctionTool from llama_index.core.tools.function_tool import FunctionTool
...@@ -19,6 +20,14 @@ class ToolFactory: ...@@ -19,6 +20,14 @@ class ToolFactory:
} }
@staticmethod @staticmethod
@cached(
LRUCache(maxsize=100),
key=lambda tool_type, tool_name, config: (
tool_type,
tool_name,
json.dumps(config, sort_keys=True),
),
)
def load_tools(tool_type: str, tool_name: str, config: dict) -> list[FunctionTool]: def load_tools(tool_type: str, tool_name: str, config: dict) -> list[FunctionTool]:
source_package = ToolFactory.TOOL_SOURCE_PACKAGE_MAP[tool_type] source_package = ToolFactory.TOOL_SOURCE_PACKAGE_MAP[tool_type]
try: try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment