langchain-shinapi 0.1.1__py3-none-any.whl
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_shinapi/__init__.py +4 -0
- langchain_shinapi/py.typed +0 -0
- langchain_shinapi/retrievers.py +41 -0
- langchain_shinapi/tools.py +43 -0
- langchain_shinapi-0.1.1.dist-info/METADATA +53 -0
- langchain_shinapi-0.1.1.dist-info/RECORD +8 -0
- langchain_shinapi-0.1.1.dist-info/WHEEL +4 -0
- langchain_shinapi-0.1.1.dist-info/licenses/LICENSE +21 -0
|
File without changes
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Optional
|
|
4
|
+
|
|
5
|
+
from langchain_core.callbacks import CallbackManagerForRetrieverRun
|
|
6
|
+
from langchain_core.documents import Document
|
|
7
|
+
from langchain_core.retrievers import BaseRetriever
|
|
8
|
+
from pydantic import ConfigDict, Field, SecretStr
|
|
9
|
+
from shinapi import SearchResult, ShinAPI
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def document_of(result: SearchResult) -> Document:
|
|
13
|
+
metadata = {field: value for field, value in result.items() if field != "text"}
|
|
14
|
+
return Document(page_content=result["text"], metadata=metadata)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ShinAPIRetriever(BaseRetriever):
|
|
18
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
19
|
+
|
|
20
|
+
k: int = Field(default=8, ge=1, le=32)
|
|
21
|
+
exclude_domains: list[str] = Field(default_factory=list)
|
|
22
|
+
exclude_text: list[str] = Field(default_factory=list)
|
|
23
|
+
api_key: Optional[SecretStr] = Field(default=None, exclude=True)
|
|
24
|
+
client: Optional[ShinAPI] = Field(default=None, exclude=True)
|
|
25
|
+
|
|
26
|
+
def model_post_init(self, context: Any) -> None:
|
|
27
|
+
if self.client is None:
|
|
28
|
+
key = self.api_key.get_secret_value() if self.api_key else None
|
|
29
|
+
self.client = ShinAPI(key)
|
|
30
|
+
|
|
31
|
+
def _get_relevant_documents(
|
|
32
|
+
self, query: str, *, run_manager: CallbackManagerForRetrieverRun
|
|
33
|
+
) -> list[Document]:
|
|
34
|
+
assert self.client is not None
|
|
35
|
+
answer = self.client.search(
|
|
36
|
+
query,
|
|
37
|
+
max_results=self.k,
|
|
38
|
+
exclude_domains=self.exclude_domains,
|
|
39
|
+
exclude_text=self.exclude_text,
|
|
40
|
+
)
|
|
41
|
+
return [document_of(result) for result in answer["results"]]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Any, Literal, Optional
|
|
5
|
+
|
|
6
|
+
from langchain_core.callbacks import CallbackManagerForToolRun
|
|
7
|
+
from langchain_core.tools import BaseTool
|
|
8
|
+
from langchain_core.tools.base import ArgsSchema
|
|
9
|
+
from pydantic import ConfigDict, Field, SecretStr
|
|
10
|
+
from shinapi import SEARCH_DESCRIPTION, SEARCH_INPUT, SearchResponse, ShinAPI
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ShinAPISearch(BaseTool):
|
|
14
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
15
|
+
|
|
16
|
+
name: str = "shinapi_search"
|
|
17
|
+
description: str = SEARCH_DESCRIPTION
|
|
18
|
+
args_schema: Optional[ArgsSchema] = SEARCH_INPUT
|
|
19
|
+
response_format: Literal["content", "content_and_artifact"] = "content_and_artifact"
|
|
20
|
+
api_key: Optional[SecretStr] = Field(default=None, exclude=True)
|
|
21
|
+
client: Optional[ShinAPI] = Field(default=None, exclude=True)
|
|
22
|
+
|
|
23
|
+
def model_post_init(self, context: Any) -> None:
|
|
24
|
+
if self.client is None:
|
|
25
|
+
key = self.api_key.get_secret_value() if self.api_key else None
|
|
26
|
+
self.client = ShinAPI(key)
|
|
27
|
+
|
|
28
|
+
def _run(
|
|
29
|
+
self,
|
|
30
|
+
query: str,
|
|
31
|
+
max_results: Optional[int] = None,
|
|
32
|
+
exclude_domains: Optional[list[str]] = None,
|
|
33
|
+
exclude_text: Optional[list[str]] = None,
|
|
34
|
+
run_manager: Optional[CallbackManagerForToolRun] = None,
|
|
35
|
+
) -> tuple[str, SearchResponse]:
|
|
36
|
+
assert self.client is not None
|
|
37
|
+
answer = self.client.search(
|
|
38
|
+
query,
|
|
39
|
+
max_results=max_results,
|
|
40
|
+
exclude_domains=exclude_domains,
|
|
41
|
+
exclude_text=exclude_text,
|
|
42
|
+
)
|
|
43
|
+
return json.dumps(answer, ensure_ascii=False), answer
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: langchain-shinapi
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Search what high-authority Japanese sites say now, as a LangChain tool and retriever. By ShinAPI.
|
|
5
|
+
Project-URL: Homepage, https://shinapi.com
|
|
6
|
+
Project-URL: Documentation, https://docs.shinapi.com
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: agents,japan,japanese,langchain,llm,rag,search
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Requires-Dist: langchain-core<2,>=1
|
|
12
|
+
Requires-Dist: shinapi>=0.1
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# langchain-shinapi
|
|
16
|
+
|
|
17
|
+
Search what high-authority Japanese sites say now, from LangChain: a tool for agents and a retriever for RAG. By
|
|
18
|
+
[ShinAPI](https://shinapi.com).
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
pip install langchain-shinapi
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Get a key in the [console](https://console.shinapi.com) and set `SHINAPI_KEY`, or pass `api_key`.
|
|
25
|
+
|
|
26
|
+
## The tool
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from langchain.agents import create_agent
|
|
30
|
+
from langchain_shinapi import ShinAPISearch
|
|
31
|
+
|
|
32
|
+
agent = create_agent("anthropic:claude-sonnet-5-5", tools=[ShinAPISearch()])
|
|
33
|
+
agent.invoke({"messages": [{"role": "user", "content": "2026年の年収の壁はいくらですか"}]})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The tool answers the model with the search's JSON, and keeps the parsed answer as the message's artifact. Its
|
|
37
|
+
description tells the model what is indexed and what to do with each outcome: `answered`, `no_match_in_scope` or
|
|
38
|
+
`out_of_scope`.
|
|
39
|
+
|
|
40
|
+
## The retriever
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from langchain_shinapi import ShinAPIRetriever
|
|
44
|
+
|
|
45
|
+
retriever = ShinAPIRetriever(k=8, exclude_domains=["example.co.jp"])
|
|
46
|
+
for document in retriever.invoke("育児休業給付金の支給率"):
|
|
47
|
+
print(document.metadata["url"], document.metadata["attribution"], document.page_content)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Each passage is a document: its text is the page content, and its URL, title, publisher, dates, licence and credit line
|
|
51
|
+
are the metadata. Show the attribution where you show the text.
|
|
52
|
+
|
|
53
|
+
Read the [docs](https://docs.shinapi.com).
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
langchain_shinapi/__init__.py,sha256=gSOPdVntR-wCoMVxzXSU48Np429rIkIfaUiMRpO9jcw,157
|
|
2
|
+
langchain_shinapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
langchain_shinapi/retrievers.py,sha256=FMabeixHaXpEULwKVPeowUJ1_GlZa5_GPfRjWrn9jRw,1565
|
|
4
|
+
langchain_shinapi/tools.py,sha256=2-RJXIIecAUx96G53xp_kc8YEO877gIfjOOwbcX8f6U,1605
|
|
5
|
+
langchain_shinapi-0.1.1.dist-info/METADATA,sha256=fHUjYzpsgRtgCbrNSKACMzVEdJ--JYtc9cYVsryJ78w,1882
|
|
6
|
+
langchain_shinapi-0.1.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
7
|
+
langchain_shinapi-0.1.1.dist-info/licenses/LICENSE,sha256=-MWyAH_C2F5k_arU0CmFoUFL4ZeKZql7w2ro9S39fzE,1064
|
|
8
|
+
langchain_shinapi-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ShinAPI
|
|
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.
|