mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 00:58:30 +00:00
Fix MongoDBVectorSearchTool serialization and schema (#389)
* Fix MongoDBVectorSearchTool serialization * fix base class
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import json
|
|
||||||
import os
|
import os
|
||||||
from importlib.metadata import version
|
from importlib.metadata import version
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
@@ -46,7 +45,7 @@ class MongoDBVectorSearchConfig(BaseModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class MongoDBToolSchema(MongoDBVectorSearchConfig):
|
class MongoDBToolSchema(BaseModel):
|
||||||
"""Input for MongoDBTool."""
|
"""Input for MongoDBTool."""
|
||||||
|
|
||||||
query: str = Field(
|
query: str = Field(
|
||||||
@@ -264,6 +263,8 @@ class MongoDBVectorSearchTool(BaseTool):
|
|||||||
return [str(_id) for _id in result.upserted_ids.values()]
|
return [str(_id) for _id in result.upserted_ids.values()]
|
||||||
|
|
||||||
def _run(self, query: str) -> str:
|
def _run(self, query: str) -> str:
|
||||||
|
from bson import json_util
|
||||||
|
|
||||||
try:
|
try:
|
||||||
query_config = self.query_config or MongoDBVectorSearchConfig()
|
query_config = self.query_config or MongoDBVectorSearchConfig()
|
||||||
limit = query_config.limit
|
limit = query_config.limit
|
||||||
@@ -306,7 +307,7 @@ class MongoDBVectorSearchTool(BaseTool):
|
|||||||
# Format
|
# Format
|
||||||
for doc in cursor:
|
for doc in cursor:
|
||||||
docs.append(doc)
|
docs.append(doc)
|
||||||
return json.dumps(docs)
|
return json_util.dumps(docs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error: {e}")
|
logger.error(f"Error: {e}")
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
Reference in New Issue
Block a user