mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 17:18:29 +00:00
- Remove embedchain adapter; add crewai rag adapter and update all search tools - Add loaders: pdf, youtube (video & channel), github, docs site, mysql, postgresql - Add configurable similarity threshold, limit params, and embedding_model support - Improve chromadb compatibility (sanitize metadata, convert columns, fix chunking) - Fix xml encoding, Python 3.10 issues, and youtube url spoofing - Update crewai dependency and instructions; refresh uv.lock - Update tests for new rag adapter and search params
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
from tempfile import TemporaryDirectory
|
|
from typing import cast
|
|
from pathlib import Path
|
|
|
|
|
|
from crewai_tools.adapters.crewai_rag_adapter import CrewAIRagAdapter
|
|
from crewai_tools.tools.rag.rag_tool import RagTool
|
|
|
|
|
|
def test_rag_tool_initialization():
|
|
"""Test that RagTool initializes with CrewAI adapter by default."""
|
|
class MyTool(RagTool):
|
|
pass
|
|
|
|
tool = MyTool()
|
|
assert tool.adapter is not None
|
|
assert isinstance(tool.adapter, CrewAIRagAdapter)
|
|
|
|
adapter = cast(CrewAIRagAdapter, tool.adapter)
|
|
assert adapter.collection_name == "rag_tool_collection"
|
|
assert adapter._client is not None
|
|
|
|
|
|
def test_rag_tool_add_and_query():
|
|
"""Test adding content and querying with RagTool."""
|
|
class MyTool(RagTool):
|
|
pass
|
|
|
|
tool = MyTool()
|
|
|
|
tool.add("The sky is blue on a clear day.")
|
|
tool.add("Machine learning is a subset of artificial intelligence.")
|
|
|
|
result = tool._run(query="What color is the sky?")
|
|
assert "Relevant Content:" in result
|
|
|
|
result = tool._run(query="Tell me about machine learning")
|
|
assert "Relevant Content:" in result
|
|
|
|
|
|
def test_rag_tool_with_file():
|
|
"""Test RagTool with file content."""
|
|
with TemporaryDirectory() as tmpdir:
|
|
test_file = Path(tmpdir) / "test.txt"
|
|
test_file.write_text("Python is a programming language known for its simplicity.")
|
|
|
|
class MyTool(RagTool):
|
|
pass
|
|
|
|
tool = MyTool()
|
|
tool.add(str(test_file))
|
|
|
|
result = tool._run(query="What is Python?")
|
|
assert "Relevant Content:" in result
|