Skip to content

Commit

Permalink
Ensure load and search tool spec loads documents (#11733)
Browse files Browse the repository at this point in the history
  • Loading branch information
logan-markewich authored Mar 7, 2024
1 parent 0ae69d4 commit 48a286a
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"""


from typing import Any, Dict, List, Optional, Type

from llama_index.core.bridge.pydantic import BaseModel
from llama_index.core.indices.base import BaseIndex
from llama_index.core.indices.vector_store import VectorStoreIndex
from llama_index.core.schema import Document
from llama_index.core.tools.function_tool import FunctionTool
from llama_index.core.tools.tool_spec.base import SPEC_FUNCTION_TYPE, BaseToolSpec
from llama_index.core.tools.types import ToolMetadata
Expand Down Expand Up @@ -123,6 +123,19 @@ def to_tool_list(
def load(self, *args: Any, **kwargs: Any) -> Any:
# Call the wrapped tool and save the result in the index
docs = self._tool(*args, **kwargs).raw_output

# convert to Document if necessary
if isinstance(docs, list):
for i, doc in enumerate(docs):
if not isinstance(doc, Document):
docs[i] = Document(text=str(doc))
elif isinstance(docs, str):
docs = [Document(text=docs)]
elif isinstance(docs, Document):
docs = [docs]
else:
doc = [Document(text=str(docs))]

if self._index:
for doc in docs:
self._index.insert(doc, **self._index_kwargs)
Expand Down

0 comments on commit 48a286a

Please sign in to comment.