langchain-nimble 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langchain_nimble-0.1.0/LICENSE +21 -0
- langchain_nimble-0.1.0/PKG-INFO +48 -0
- langchain_nimble-0.1.0/README.md +27 -0
- langchain_nimble-0.1.0/langchain_nimble/__init__.py +15 -0
- langchain_nimble-0.1.0/langchain_nimble/py.typed +0 -0
- langchain_nimble-0.1.0/langchain_nimble/retrievers.py +97 -0
- langchain_nimble-0.1.0/pyproject.toml +71 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 LangChain, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: langchain-nimble
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An integration package connecting Nimble and LangChain
|
|
5
|
+
Home-page: https://github.com/langchain-ai/langchain
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.9,<4.0
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Requires-Dist: langchain-core (>=0.3.15,<0.4.0)
|
|
16
|
+
Project-URL: Repository, https://github.com/langchain-ai/langchain
|
|
17
|
+
Project-URL: Release Notes, https://github.com/langchain-ai/langchain/releases?q=tag%3A%22nimble%3D%3D0%22&expanded=true
|
|
18
|
+
Project-URL: Source Code, https://github.com/langchain-ai/langchain/tree/master/libs/partners/nimble
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# langchain-nimble
|
|
22
|
+
|
|
23
|
+
This package contains the LangChain integration with Nimble
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install -U langchain-nimble
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
And you should configure credentials by setting the following environment variables:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
export NIMBLE_API_KEY=<PLACEHOLDER_FOR_YOUR_NIMBLE_API_KEY>
|
|
35
|
+
```
|
|
36
|
+
You can get your API key from [Nimble's website](https://nimbleway.com/)
|
|
37
|
+
Just, go to the log-in page and sign up for a new account. After that, you can get your API key from the dashboard.
|
|
38
|
+
|
|
39
|
+
## Retrievers
|
|
40
|
+
`NimbleSearchRetriever` class exposes LLMs from Nimble.
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from langchain_nimble import NimbleSearchRetriever
|
|
44
|
+
|
|
45
|
+
retriever = NimbleSearchRetriever()
|
|
46
|
+
retriever.invoke("Nimbleway")
|
|
47
|
+
```
|
|
48
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# langchain-nimble
|
|
2
|
+
|
|
3
|
+
This package contains the LangChain integration with Nimble
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install -U langchain-nimble
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
And you should configure credentials by setting the following environment variables:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
export NIMBLE_API_KEY=<PLACEHOLDER_FOR_YOUR_NIMBLE_API_KEY>
|
|
15
|
+
```
|
|
16
|
+
You can get your API key from [Nimble's website](https://nimbleway.com/)
|
|
17
|
+
Just, go to the log-in page and sign up for a new account. After that, you can get your API key from the dashboard.
|
|
18
|
+
|
|
19
|
+
## Retrievers
|
|
20
|
+
`NimbleSearchRetriever` class exposes LLMs from Nimble.
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from langchain_nimble import NimbleSearchRetriever
|
|
24
|
+
|
|
25
|
+
retriever = NimbleSearchRetriever()
|
|
26
|
+
retriever.invoke("Nimbleway")
|
|
27
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from importlib import metadata
|
|
2
|
+
|
|
3
|
+
from langchain_nimble.retrievers import NimbleSearchRetriever
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
__version__ = metadata.version(__package__)
|
|
7
|
+
except metadata.PackageNotFoundError:
|
|
8
|
+
# Case where package metadata is not available.
|
|
9
|
+
__version__ = ""
|
|
10
|
+
del metadata # optional, avoids polluting the results of dir(__package__)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"NimbleSearchRetriever",
|
|
14
|
+
"__version__",
|
|
15
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from typing import List, Any
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
from langchain_core.callbacks.manager import CallbackManagerForRetrieverRun
|
|
7
|
+
from langchain_core.documents.base import Document
|
|
8
|
+
from langchain_core.retrievers import BaseRetriever
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SearchEngine(str, Enum):
|
|
12
|
+
"""
|
|
13
|
+
Enum representing the search engines supported by Nimble
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
GOOGLE = "google_search"
|
|
17
|
+
GOOGLE_SGE = "google_sge"
|
|
18
|
+
BING = "bing_search"
|
|
19
|
+
YANDEX = "yandex_search"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ParsingType(str, Enum):
|
|
23
|
+
"""
|
|
24
|
+
Enum representing the parsing types supported by Nimble
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
PLAIN_TEXT = "plain_text"
|
|
28
|
+
MARKDOWN = "markdown"
|
|
29
|
+
SIMPLIFIED_HTML = "simplified_html"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class NimbleSearchRetriever(BaseRetriever):
|
|
33
|
+
"""Nimbleway Search API retriever.
|
|
34
|
+
Allows you to retrieve search results from Google, Bing, and Yandex.
|
|
35
|
+
Visit https://www.nimbleway.com/ and sign up to receive
|
|
36
|
+
an API key and to see more info.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
api_key: The API key for Nimbleway.
|
|
40
|
+
search_engine: The search engine to use. Default is Google.
|
|
41
|
+
render: Whether to render the results web sites. Default is True.
|
|
42
|
+
locale: The locale to use. Default is "en".
|
|
43
|
+
country: The country to use. Default is "US".
|
|
44
|
+
parsing_type: The parsing type to use. Default is "plain_text".
|
|
45
|
+
links: The list of links to search for. Default is None. (if enabled will
|
|
46
|
+
ignore the query)
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
api_key: str = None
|
|
50
|
+
k: int = 3
|
|
51
|
+
search_engine: SearchEngine = SearchEngine.GOOGLE
|
|
52
|
+
render: bool = True
|
|
53
|
+
locale: str = "en"
|
|
54
|
+
country: str = "US"
|
|
55
|
+
parsing_type: ParsingType = ParsingType.PLAIN_TEXT
|
|
56
|
+
links: List[str] = None
|
|
57
|
+
|
|
58
|
+
def _get_relevant_documents(
|
|
59
|
+
self, query: str, *, run_manager: CallbackManagerForRetrieverRun,
|
|
60
|
+
**kwargs: Any
|
|
61
|
+
) -> List[Document]:
|
|
62
|
+
request_body = {
|
|
63
|
+
"query": query,
|
|
64
|
+
"num_results": kwargs.get("k", self.k),
|
|
65
|
+
"search_engine": kwargs.get("search_engine", self.search_engine),
|
|
66
|
+
"parse": kwargs.get("parse", self.parse),
|
|
67
|
+
"render": kwargs.get("render", self.render),
|
|
68
|
+
"locale": kwargs.get("locale", self.locale),
|
|
69
|
+
"country": kwargs.get("country", self.country),
|
|
70
|
+
"parsing_type": kwargs.get("parsing_type", self.parsing_type),
|
|
71
|
+
"links": kwargs.get("links", self.links)
|
|
72
|
+
}
|
|
73
|
+
route = "extract" if self.links else "search"
|
|
74
|
+
response = requests.post(
|
|
75
|
+
f"https://searchit-server.crawlit.live/{route}",
|
|
76
|
+
json=request_body,
|
|
77
|
+
headers={
|
|
78
|
+
"Authorization": f"Basic {self.api_key or os.getenv('NIMBLE_API_KEY')}",
|
|
79
|
+
"Content-Type": "application/json",
|
|
80
|
+
},
|
|
81
|
+
)
|
|
82
|
+
response.raise_for_status()
|
|
83
|
+
raw_json_content = response.json()
|
|
84
|
+
docs = [
|
|
85
|
+
Document(
|
|
86
|
+
page_content=doc.get("page_content", ""),
|
|
87
|
+
metadata={
|
|
88
|
+
"title": doc.get("metadata", {}).get("title", ""),
|
|
89
|
+
"snippet": doc.get("metadata", {}).get("snippet", ""),
|
|
90
|
+
"url": doc.get("metadata", {}).get("url", ""),
|
|
91
|
+
"position": doc.get("metadata", {}).get("position", -1),
|
|
92
|
+
"entity_type": doc.get("metadata", {}).get("entity_type", ""),
|
|
93
|
+
},
|
|
94
|
+
)
|
|
95
|
+
for doc in raw_json_content.get("body", [])
|
|
96
|
+
]
|
|
97
|
+
return docs
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["poetry-core>=1.0.0"]
|
|
3
|
+
build-backend = "poetry.core.masonry.api"
|
|
4
|
+
|
|
5
|
+
[tool.poetry]
|
|
6
|
+
name = "langchain-nimble"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "An integration package connecting Nimble and LangChain"
|
|
9
|
+
authors = []
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
repository = "https://github.com/langchain-ai/langchain"
|
|
12
|
+
license = "MIT"
|
|
13
|
+
|
|
14
|
+
[tool.mypy]
|
|
15
|
+
disallow_untyped_defs = "True"
|
|
16
|
+
|
|
17
|
+
[tool.poetry.urls]
|
|
18
|
+
"Source Code" = "https://github.com/langchain-ai/langchain/tree/master/libs/partners/nimble"
|
|
19
|
+
"Release Notes" = "https://github.com/langchain-ai/langchain/releases?q=tag%3A%22nimble%3D%3D0%22&expanded=true"
|
|
20
|
+
|
|
21
|
+
[tool.poetry.dependencies]
|
|
22
|
+
python = ">=3.9,<4.0"
|
|
23
|
+
langchain-core = "^0.3.15"
|
|
24
|
+
|
|
25
|
+
[tool.ruff.lint]
|
|
26
|
+
select = ["E", "F", "I", "T201"]
|
|
27
|
+
|
|
28
|
+
[tool.coverage.run]
|
|
29
|
+
omit = ["tests/*"]
|
|
30
|
+
|
|
31
|
+
[tool.pytest.ini_options]
|
|
32
|
+
addopts = "--strict-markers --strict-config --durations=5"
|
|
33
|
+
markers = [
|
|
34
|
+
"compile: mark placeholder test used to compile integration tests without running them",
|
|
35
|
+
]
|
|
36
|
+
asyncio_mode = "auto"
|
|
37
|
+
|
|
38
|
+
[tool.poetry.group.test]
|
|
39
|
+
optional = true
|
|
40
|
+
|
|
41
|
+
[tool.poetry.group.codespell]
|
|
42
|
+
optional = true
|
|
43
|
+
|
|
44
|
+
[tool.poetry.group.test_integration]
|
|
45
|
+
optional = true
|
|
46
|
+
|
|
47
|
+
[tool.poetry.group.lint]
|
|
48
|
+
optional = true
|
|
49
|
+
|
|
50
|
+
[tool.poetry.group.dev]
|
|
51
|
+
optional = true
|
|
52
|
+
|
|
53
|
+
[tool.poetry.group.dev.dependencies]
|
|
54
|
+
|
|
55
|
+
[tool.poetry.group.test.dependencies]
|
|
56
|
+
pytest = "^7.4.3"
|
|
57
|
+
pytest-asyncio = "^0.23.2"
|
|
58
|
+
pytest-socket = "^0.7.0"
|
|
59
|
+
pytest-watcher = "^0.3.4"
|
|
60
|
+
langchain-tests = "0.3.10"
|
|
61
|
+
|
|
62
|
+
[tool.poetry.group.codespell.dependencies]
|
|
63
|
+
codespell = "^2.2.6"
|
|
64
|
+
|
|
65
|
+
[tool.poetry.group.test_integration.dependencies]
|
|
66
|
+
|
|
67
|
+
[tool.poetry.group.lint.dependencies]
|
|
68
|
+
ruff = "^0.5"
|
|
69
|
+
|
|
70
|
+
[tool.poetry.group.typing.dependencies]
|
|
71
|
+
mypy = "^1.10"
|