Skip to content

Commit 7889fcc

Browse files
committed
Merge branch 'main' into PYTHON-5389
2 parents df7a55c + 2d2f67c commit 7889fcc

File tree

5 files changed

+132
-0
lines changed

5 files changed

+132
-0
lines changed

.evergreen/config.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,20 @@ tasks:
208208
- func: "setup remote atlas"
209209
- func: "execute tests"
210210

211+
- name: test-crewai-tools-local
212+
tags: [local]
213+
commands:
214+
- func: "fetch repo"
215+
- func: "setup local atlas"
216+
- func: "execute tests"
217+
218+
- name: test-crewai-tools-remote
219+
tags: [remote]
220+
commands:
221+
- func: "fetch repo"
222+
- func: "setup remote atlas"
223+
- func: "execute tests"
224+
211225
- name: test-haystack-embeddings-local
212226
tags: [local]
213227
commands:
@@ -359,6 +373,16 @@ buildvariants:
359373
- name: test-pymongo-voyageai-local
360374
- name: test-pymongo-voyageai-remote
361375

376+
- name: test-crewai-tools-rhel
377+
display_name: CrewAI-Tools Ubuntu
378+
expansions:
379+
DIR: crewai-tools
380+
run_on:
381+
- ubuntu2404-small
382+
tasks:
383+
- name: test-crewai-tools-local
384+
- name: test-crewai-tools-remote
385+
362386
- name: test-haystack-embeddings-rhel
363387
display_name: Haystack Embeddings RHEL
364388
tags: [python]

.evergreen/setup-remote.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ case $DIR in
4141
pymongo-voyageai)
4242
MONGODB_URI=$VOYAGEAI_MONGODB_URI
4343
;;
44+
crewai-tools)
45+
MONGODB_URI=$CREWAI_TOOLS_URI
46+
;;
4447
langchain-js)
4548
MONGODB_URI=$LANGCHAIN_MONGODB_URI
4649
;;

crewai-tools/config.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
REPO_NAME=crewAI-tools
2+
REPO_ORG=crewAIInc
3+
DATABASE=crewai_test_db

crewai-tools/run.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
# Get the MONGODB_URI and OPENAI_API_KEY.
6+
SCRIPT_DIR=$(realpath "$(dirname ${BASH_SOURCE[0]})")
7+
ROOT_DIR=$(dirname $SCRIPT_DIR)
8+
. $ROOT_DIR/env.sh
9+
10+
. $ROOT_DIR/.evergreen/utils.sh
11+
12+
PYTHON_BINARY=$(find_python3)
13+
14+
$PYTHON_BINARY -m venv venv_pipeline
15+
source venv_pipeline/bin/activate
16+
17+
pip install uv
18+
19+
uv sync --extra mongodb
20+
uv run pytest -v tests/tools/test*mongodb*.py
21+
22+
mv ../test_mongodb_vector_search_tool.py .
23+
uv run python test_mongodb_vector_search_tool.py
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import os
2+
from crewai import Agent
3+
from crewai import Task
4+
from crewai import Crew, Process, LLM
5+
from crewai.cli.constants import DEFAULT_LLM_MODEL
6+
from crewai_tools import MongoDBVectorSearchTool, MongoDBVectorSearchConfig
7+
from langchain_community.document_loaders import PyPDFLoader
8+
import time
9+
10+
# Set environment as LiteLLM expects
11+
os.environ["AZURE_API_KEY"] = os.environ["AZURE_OPENAI_API_KEY"]
12+
os.environ["AZURE_API_BASE"] = os.environ["AZURE_OPENAI_ENDPOINT"]
13+
os.environ["AZURE_API_VERSION"] = os.environ["OPENAI_API_VERSION"]
14+
15+
# Pre-populate a collection and an index
16+
print("Creating collection...")
17+
conn_string = os.environ.get(
18+
"MONGODB_URI", "mongodb://localhost:27017?directConnection=true"
19+
)
20+
database_name = "crewai_test_db"
21+
collection_name = "vector_test"
22+
23+
tool = MongoDBVectorSearchTool(
24+
connection_string=conn_string,
25+
database_name=database_name,
26+
collection_name=collection_name,
27+
)
28+
coll = tool._coll
29+
coll.delete_many({})
30+
31+
# Insert documents from a pdf.
32+
print("Loading documents...")
33+
loader = PyPDFLoader("https://arxiv.org/pdf/2303.08774.pdf")
34+
tool.add_texts([i.page_content for i in loader.load()])
35+
36+
print("Creating vector index...")
37+
if not any([ix["name"] == "vector_index" for ix in coll.list_search_indexes()]):
38+
tool.create_vector_search_index(dimensions=1536, auto_index_timeout=60)
39+
40+
# Create the MongoDB tool
41+
print("Creating tool and waiting for index to be complete...")
42+
43+
# Wait for index to be complete.
44+
n_docs = coll.count_documents({})
45+
tool.query_config = MongoDBVectorSearchConfig(limit=n_docs, oversampling_factor=1)
46+
start = time.monotonic()
47+
while time.monotonic() - start <= 60:
48+
if len(tool._run("sandwich")) == n_docs:
49+
break
50+
else:
51+
time.sleep(1)
52+
53+
# Assemble a crew
54+
researcher = Agent(
55+
role="AI Accuracy Researcher",
56+
goal="Find and extract key information from a technical document",
57+
backstory="You're specialized in analyzing technical content to extract insights and answers",
58+
verbose=False,
59+
tools=[tool],
60+
llm=LLM(model=f"azure/{DEFAULT_LLM_MODEL}"),
61+
)
62+
research_task = Task(
63+
description="Research information in a technical document",
64+
expected_output="A summary of the accuracy of GPT-4",
65+
agent=researcher,
66+
)
67+
crew = Crew(
68+
agents=[researcher],
69+
tasks=[research_task],
70+
process=Process.sequential,
71+
verbose=False,
72+
)
73+
74+
# Get the result and assert something about the results
75+
print("Running the crew...")
76+
result = crew.kickoff()
77+
text = result.raw.lower()
78+
assert "advancements" in text or "improvements" in text, text
79+
assert "GPT-4" in result.raw

0 commit comments

Comments
 (0)