Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

fix: vector retrieval type hint (#1024)

Wendong-Fan472a40ca577a
diff --git a/camel/loaders/unstructured_io.py b/camel/loaders/unstructured_io.py
index dcf138649..11cc7b503 100644
--- a/camel/loaders/unstructured_io.py
+++ b/camel/loaders/unstructured_io.py
@@ -13,8 +13,8 @@
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
import uuid
import warnings
+from io import IOBase
from typing import (
- IO,
Any,
Dict,
List,
@@ -154,13 +154,11 @@ class UnstructuredIO:
return None
@staticmethod
- def parse_bytes(
- file: IO[bytes], **kwargs: Any
- ) -> Union[List[Element], None]:
+ def parse_bytes(file: IOBase, **kwargs: Any) -> Union[List[Element], None]:
r"""Parses a bytes stream and converts its contents into elements.
Args:
- file (IO[bytes]): The file in bytes format to be parsed.
+ file (IOBase): The file in bytes format to be parsed.
**kwargs: Extra kwargs passed to the partition function.
Returns:
diff --git a/camel/retrievers/vector_retriever.py b/camel/retrievers/vector_retriever.py
index 89f22c7c8..5d95b81e0 100644
--- a/camel/retrievers/vector_retriever.py
+++ b/camel/retrievers/vector_retriever.py
@@ -13,7 +13,8 @@
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
import os
import warnings
-from typing import IO, Any, Dict, List, Optional, Union
+from io import IOBase
+from typing import Any, Dict, List, Optional, Union
from urllib.parse import urlparse
from camel.embeddings import BaseEmbedding, OpenAIEmbedding
@@ -72,7 +73,7 @@ class VectorRetriever(BaseRetriever):
def process(
self,
- content: Union[str, Element, IO[bytes]],
+ content: Union[str, Element, IOBase],
chunk_type: str = "chunk_by_title",
max_characters: int = 500,
embed_batch: int = 50,
@@ -85,7 +86,7 @@ class VectorRetriever(BaseRetriever):
specified vector storage.
Args:
- content (Union[str, Element, IO[bytes]]): Local file path, remote
+ content (Union[str, Element, IOBase]): Local file path, remote
URL, string content, Element object, or a binary file object.
chunk_type (str): Type of chunking going to apply. Defaults to
"chunk_by_title".
@@ -98,7 +99,7 @@ class VectorRetriever(BaseRetriever):
"""
if isinstance(content, Element):
elements = [content]
- elif isinstance(content, IO):
+ elif isinstance(content, IOBase):
elements = self.uio.parse_bytes(file=content, **kwargs) or []
else:
# Check if the content is URL
@@ -138,6 +139,8 @@ class VectorRetriever(BaseRetriever):
for vector, chunk in zip(batch_vectors, batch_chunks):
if isinstance(content, str):
content_path_info = {"content path": content}
+ elif isinstance(content, IOBase):
+ content_path_info = {"content path": "From file bytes"}
elif isinstance(content, Element):
content_path_info = {
"content path": content.metadata.file_directory