-
Notifications
You must be signed in to change notification settings - Fork 9
INTPYTHON-580 Add CrewAI Integration Tests #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
4555b08
INTPYTHON-580 Add CrewAI Integration Tests
blink1073 5a52c3a
update config file
blink1073 505d93b
fix test
blink1073 f413cdd
fix config
blink1073 82dfb87
fix branch
blink1073 bab81a7
fix branch
blink1073 a0c87df
fix runner
blink1073 5cd625c
fix runner
blink1073 5f853af
run on ubuntu
blink1073 b7eec87
increase timeout
blink1073 02c9bd5
increase timeout
blink1073 7e331ea
verify failure
blink1073 81e605f
use glob pattern
blink1073 4405b70
make tests verbose
blink1073 4edb341
Merge branch 'main' of github.com:mongodb-labs/ai-ml-pipeline-testing…
blink1073 ae5d015
fix var handling
blink1073 5d8af3c
try ubuntu24
blink1073 1bc74a5
fix usage
blink1073 169295a
debug
blink1073 408d8ae
update test
blink1073 2000b76
update test
blink1073 9b373a1
update test
blink1073 f1de603
update test
blink1073 4ed3277
debug
blink1073 29fe0ed
change expected term
blink1073 dc1fd25
use upstream
blink1073 52e0777
improve the test
blink1073 f5d0d6e
improve the test
blink1073 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
REPO_NAME=crewAI-tools | ||
REPO_ORG=crewAIInc | ||
DATABASE=crewai_test_db |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
|
||
# Get the MONGODB_URI and OPENAI_API_KEY. | ||
SCRIPT_DIR=$(realpath "$(dirname ${BASH_SOURCE[0]})") | ||
ROOT_DIR=$(dirname $SCRIPT_DIR) | ||
. $ROOT_DIR/env.sh | ||
|
||
. $ROOT_DIR/.evergreen/utils.sh | ||
|
||
PYTHON_BINARY=$(find_python3) | ||
|
||
$PYTHON_BINARY -m venv venv_pipeline | ||
source venv_pipeline/bin/activate | ||
|
||
pip install uv | ||
|
||
uv sync --extra mongodb | ||
uv run pytest -v tests/tools/test*mongodb*.py | ||
|
||
mv ../test_mongodb_vector_search_tool.py . | ||
uv run python test_mongodb_vector_search_tool.py | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import os | ||
from crewai import Agent | ||
from crewai import Task | ||
from crewai import Crew, Process, LLM | ||
from crewai.cli.constants import DEFAULT_LLM_MODEL | ||
from crewai_tools import MongoDBVectorSearchTool, MongoDBVectorSearchConfig | ||
from langchain_community.document_loaders import PyPDFLoader | ||
import time | ||
|
||
# Set environment as LiteLLM expects | ||
os.environ["AZURE_API_KEY"] = os.environ["AZURE_OPENAI_API_KEY"] | ||
caseyclements marked this conversation as resolved.
Show resolved
Hide resolved
|
||
os.environ["AZURE_API_BASE"] = os.environ["AZURE_OPENAI_ENDPOINT"] | ||
os.environ["AZURE_API_VERSION"] = os.environ["OPENAI_API_VERSION"] | ||
|
||
# Pre-populate a collection and an index | ||
print("Creating collection...") | ||
conn_string = os.environ.get( | ||
"MONGODB_URI", "mongodb://localhost:27017?directConnection=true" | ||
) | ||
database_name = "crewai_test_db" | ||
collection_name = "vector_test" | ||
|
||
tool = MongoDBVectorSearchTool( | ||
connection_string=conn_string, | ||
database_name=database_name, | ||
collection_name=collection_name, | ||
) | ||
coll = tool._coll | ||
coll.delete_many({}) | ||
|
||
# Insert documents from a pdf. | ||
print("Loading documents...") | ||
loader = PyPDFLoader("https://arxiv.org/pdf/2303.08774.pdf") | ||
tool.add_texts([i.page_content for i in loader.load()]) | ||
|
||
print("Creating vector index...") | ||
if not any([ix["name"] == "vector_index" for ix in coll.list_search_indexes()]): | ||
tool.create_vector_search_index(dimensions=1536, auto_index_timeout=60) | ||
|
||
# Create the MongoDB tool | ||
print("Creating tool and waiting for index to be complete...") | ||
|
||
# Wait for index to be complete. | ||
n_docs = coll.count_documents({}) | ||
tool.query_config = MongoDBVectorSearchConfig(limit=n_docs, oversampling_factor=1) | ||
start = time.monotonic() | ||
while time.monotonic() - start <= 60: | ||
if len(tool._run("sandwich")) == n_docs: | ||
break | ||
else: | ||
time.sleep(1) | ||
|
||
# Assemble a crew | ||
researcher = Agent( | ||
role="AI Accuracy Researcher", | ||
goal="Find and extract key information from a technical document", | ||
backstory="You're specialized in analyzing technical content to extract insights and answers", | ||
verbose=False, | ||
tools=[tool], | ||
llm=LLM(model=f"azure/{DEFAULT_LLM_MODEL}"), | ||
) | ||
research_task = Task( | ||
description="Research information in a technical document", | ||
expected_output="A summary of the accuracy of GPT-4", | ||
agent=researcher, | ||
) | ||
crew = Crew( | ||
agents=[researcher], | ||
tasks=[research_task], | ||
process=Process.sequential, | ||
verbose=False, | ||
) | ||
|
||
# Get the result and assert something about the results | ||
print("Running the crew...") | ||
result = crew.kickoff() | ||
text = result.raw.lower() | ||
assert "advancements" in text or "improvements" in text, text | ||
assert "GPT-4" in result.raw |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.