Skip to content

Commit ebe6099

Browse files
authored
Amy mongo integration (#3)
Fix formatting/linting and poetry.lock
1 parent c9309b3 commit ebe6099

File tree

7 files changed

+298
-115
lines changed

7 files changed

+298
-115
lines changed

β€Ždocs/docs/integrations/toolkits/mongo_database.ipynbβ€Ž

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,20 @@
3232
"from langchain.utilities.mongo_database import MongoDatabase\n",
3333
"\n",
3434
"db = MongoDatabase.from_uri(\"mongodb://localhost:27017/my_db\")\n",
35-
"db._client[\"my_db\"][\"my_collection\"].insert_many([\n",
36-
" {\"text\": \"Hello, world!\", \"language\": \"en\"},\n",
37-
" {\"text\": \"Bonjour, monde!\", \"language\": \"fr\"},\n",
38-
" {\"text\": \"Hola, mundo!\", \"language\": \"es\"},\n",
39-
" {\"text\": \"Hallo, Welt!\", \"language\": \"de\"},\n",
40-
" {\"text\": \"Ciao, mondo!\", \"language\": \"it\"},\n",
41-
" {\"text\": \"OlΓ‘, mundo!\", \"language\": \"pt\"},\n",
42-
" {\"text\": \"ΠŸΡ€ΠΈΠ²Π΅Ρ‚, ΠΌΠΈΡ€!\", \"language\": \"ru\"},\n",
43-
" {\"text\": \"δ½ ε₯½οΌŒδΈ–η•ŒοΌ\", \"language\": \"zh\"},\n",
44-
" {\"text\": \"γ“γ‚“γ«γ‘γ―δΈ–η•ŒοΌ\", \"language\": \"ja\"},\n",
45-
" {\"text\": \"μ•ˆλ…•, 세상아!\", \"language\": \"ko\"},\n",
46-
"])\n",
35+
"db._client[\"my_db\"][\"my_collection\"].insert_many(\n",
36+
" [\n",
37+
" {\"text\": \"Hello, world!\", \"language\": \"en\"},\n",
38+
" {\"text\": \"Bonjour, monde!\", \"language\": \"fr\"},\n",
39+
" {\"text\": \"Hola, mundo!\", \"language\": \"es\"},\n",
40+
" {\"text\": \"Hallo, Welt!\", \"language\": \"de\"},\n",
41+
" {\"text\": \"Ciao, mondo!\", \"language\": \"it\"},\n",
42+
" {\"text\": \"OlΓ‘, mundo!\", \"language\": \"pt\"},\n",
43+
" {\"text\": \"ΠŸΡ€ΠΈΠ²Π΅Ρ‚, ΠΌΠΈΡ€!\", \"language\": \"ru\"},\n",
44+
" {\"text\": \"δ½ ε₯½οΌŒδΈ–η•ŒοΌ\", \"language\": \"zh\"},\n",
45+
" {\"text\": \"γ“γ‚“γ«γ‘γ―δΈ–η•ŒοΌ\", \"language\": \"ja\"},\n",
46+
" {\"text\": \"μ•ˆλ…•, 세상아!\", \"language\": \"ko\"},\n",
47+
" ]\n",
48+
")\n",
4749
"# insert more documents if you would like\n",
4850
"toolkit = MongoDatabaseToolkit(db=db, llm=OpenAI(temperature=0))"
4951
]
@@ -67,7 +69,7 @@
6769
" llm=OpenAI(temperature=0),\n",
6870
" toolkit=toolkit,\n",
6971
" verbose=True,\n",
70-
" agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION\n",
72+
" agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,\n",
7173
")"
7274
]
7375
},

β€Ždocs/docs/integrations/toolkits/sql_database.ipynbβ€Ž

Lines changed: 84 additions & 9 deletions
Large diffs are not rendered by default.

β€Žlibs/langchain/langchain/utilities/mongo_database.pyβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import re
55
from ast import literal_eval
6-
from pprint import pformat, pprint
6+
from pprint import pformat
77
from typing import Any, Iterable, List, Optional
88

99
from pymongo import MongoClient
@@ -176,7 +176,7 @@ def _execute(self, command: str) -> dict[str, Any]:
176176

177177
# checks if command is a find query
178178
if not result and re.match(r"^db\.\w+\.find\w*\(\{.*\}\)", command):
179-
cursor = eval(command) # dangerous, might need to find a better solution
179+
cursor = eval(command) # dangerous, might need to find a better solution
180180
result_list = []
181181
for doc in cursor:
182182
result_list.append(doc)

β€Žlibs/langchain/poetry.lockβ€Ž

Lines changed: 88 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žlibs/langchain/tests/unit_tests/agents/test_mongo.pyβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66

77
def test_create_mongo_agent() -> None:
8-
db = MongoDatabase.from_uri("mongodb://%2Ftmp%2Fmongodb-27017.sock/test_db")
8+
db = MongoDatabase.from_uri(
9+
"mongodb://%2Ftmp%2Fmongodb-27017.sock/test_db?inMemory=true"
10+
)
911
queries = {"foo": "Final Answer: baz"}
1012
llm = FakeLLM(queries=queries, sequential_responses=True)
1113
toolkit = MongoDatabaseToolkit(db=db, llm=llm)

β€Žlibs/langchain/tests/unit_tests/test_mongo_database.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from langchain.utilities.mongo_database import MongoDatabase
88

9-
uri = "mongodb://%2Ftmp%2Fmongodb-27017.sock/test_db"
9+
uri = "mongodb://%2Ftmp%2Fmongodb-27017.sock/test_db?inMemory=true"
1010

1111

1212
def test_collection_info() -> None:

0 commit comments

Comments
Β (0)