langchain-shinapi 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.

Potentially problematic release.


This version of langchain-shinapi might be problematic. Click here for more details.

@@ -0,0 +1,23 @@
1
+ node_modules/
2
+ dist/
3
+ dist-worker/
4
+ .astro/
5
+ .turbo/
6
+ .wrangler/
7
+ .dev.vars
8
+ *.local
9
+ .env
10
+ .DS_Store
11
+ coverage/
12
+ *.tsbuildinfo
13
+ tmp-*
14
+ scratch/
15
+
16
+ # Generated by wrangler types in each Worker on install and before its typecheck: the runtime at its compatibility date and flags.
17
+ apps/*/worker-configuration.d.ts
18
+ __pycache__/
19
+
20
+ # Written by scripts/deploy.ts beside each wrangler.json while it deploys.
21
+ apps/*/wrangler.deploy.json
22
+ .venv/
23
+ .api-key
@@ -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.
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.5
2
+ Name: langchain-shinapi
3
+ Version: 0.1.0
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,39 @@
1
+ # langchain-shinapi
2
+
3
+ Search what high-authority Japanese sites say now, from LangChain: a tool for agents and a retriever for RAG. By
4
+ [ShinAPI](https://shinapi.com).
5
+
6
+ ```sh
7
+ pip install langchain-shinapi
8
+ ```
9
+
10
+ Get a key in the [console](https://console.shinapi.com) and set `SHINAPI_KEY`, or pass `api_key`.
11
+
12
+ ## The tool
13
+
14
+ ```python
15
+ from langchain.agents import create_agent
16
+ from langchain_shinapi import ShinAPISearch
17
+
18
+ agent = create_agent("anthropic:claude-sonnet-5-5", tools=[ShinAPISearch()])
19
+ agent.invoke({"messages": [{"role": "user", "content": "2026年の年収の壁はいくらですか"}]})
20
+ ```
21
+
22
+ The tool answers the model with the search's JSON, and keeps the parsed answer as the message's artifact. Its
23
+ description tells the model what is indexed and what to do with each outcome: `answered`, `no_match_in_scope` or
24
+ `out_of_scope`.
25
+
26
+ ## The retriever
27
+
28
+ ```python
29
+ from langchain_shinapi import ShinAPIRetriever
30
+
31
+ retriever = ShinAPIRetriever(k=8, exclude_domains=["example.co.jp"])
32
+ for document in retriever.invoke("育児休業給付金の支給率"):
33
+ print(document.metadata["url"], document.metadata["attribution"], document.page_content)
34
+ ```
35
+
36
+ Each passage is a document: its text is the page content, and its URL, title, publisher, dates, licence and credit line
37
+ are the metadata. Show the attribution where you show the text.
38
+
39
+ Read the [docs](https://docs.shinapi.com).
@@ -0,0 +1,4 @@
1
+ from langchain_shinapi.retrievers import ShinAPIRetriever
2
+ from langchain_shinapi.tools import ShinAPISearch
3
+
4
+ __all__ = ["ShinAPIRetriever", "ShinAPISearch"]
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,17 @@
1
+ {
2
+ "name": "@shinapi/langchain",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "description": "langchain-shinapi, the LangChain tool and retriever of ShinAPI, tested here and published to PyPI from its pyproject.toml",
6
+ "type": "module",
7
+ "scripts": {
8
+ "typecheck": "tsc --noEmit",
9
+ "test": "vitest run"
10
+ },
11
+ "devDependencies": {
12
+ "@shinapi/sdk-python": "workspace:*",
13
+ "@types/node": "catalog:",
14
+ "typescript": "catalog:",
15
+ "vitest": "catalog:"
16
+ }
17
+ }
@@ -0,0 +1,20 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "langchain-shinapi"
7
+ version = "0.1.0"
8
+ description = "Search what high-authority Japanese sites say now, as a LangChain tool and retriever. By ShinAPI."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.11"
12
+ keywords = ["langchain", "search", "japan", "japanese", "llm", "rag", "agents"]
13
+ dependencies = ["langchain-core>=1,<2", "shinapi>=0.1"]
14
+
15
+ [project.urls]
16
+ Homepage = "https://shinapi.com"
17
+ Documentation = "https://docs.shinapi.com"
18
+
19
+ [tool.hatch.build.targets.wheel]
20
+ packages = ["langchain_shinapi"]
@@ -0,0 +1,16 @@
1
+ import { INSTALL_MS, pythonWith, unittest } from "@shinapi/sdk-python/venv";
2
+ import { describe, expect, it } from "vitest";
3
+
4
+ const HERE = new URL("..", import.meta.url).pathname;
5
+
6
+ describe("langchain-shinapi", () => {
7
+ it(
8
+ "passes its own tests against the LangChain it names",
9
+ () => {
10
+ const run = unittest(pythonWith(HERE, ["../sdk-python", "."]), HERE);
11
+ expect(run.stderr).toContain("OK");
12
+ expect(run.status).toBe(0);
13
+ },
14
+ INSTALL_MS,
15
+ );
16
+ });
@@ -0,0 +1,119 @@
1
+ import io
2
+ import json
3
+ import os
4
+ import unittest
5
+ from unittest import mock
6
+
7
+ from langchain_core.documents import Document
8
+ from langchain_core.messages import ToolMessage
9
+ from langchain_core.utils.function_calling import convert_to_openai_tool
10
+ from shinapi import SEARCH_DESCRIPTION, SEARCH_INPUT, ShinAPI
11
+
12
+ from langchain_shinapi import ShinAPIRetriever, ShinAPISearch
13
+
14
+ RESULT = {
15
+ "title": "婚姻届",
16
+ "url": "https://www.city.example.jp/kon",
17
+ "publisher": "例市",
18
+ "published_at": "2026-04-01",
19
+ "author": None,
20
+ "image": None,
21
+ "favicon": None,
22
+ "last_changed_at": "2026-11-02",
23
+ "licence": "publisher-terms",
24
+ "attribution": "例市",
25
+ "score": 0.5,
26
+ "text": "婚姻届は市役所に出します。",
27
+ }
28
+ ANSWER = {
29
+ "outcome": "answered",
30
+ "incomplete": False,
31
+ "results": [RESULT],
32
+ "request_id": "4bf92f3577b34da6a3ce929d0e0e4736",
33
+ }
34
+
35
+
36
+ class Response(io.BytesIO):
37
+ status = 200
38
+
39
+
40
+ class Opener:
41
+ def __init__(self):
42
+ self.asked = []
43
+
44
+ def __call__(self, request, timeout):
45
+ self.asked.append(request)
46
+ return Response(json.dumps(ANSWER).encode())
47
+
48
+ def body(self, index=0):
49
+ return json.loads(self.asked[index].data)
50
+
51
+
52
+ def client(opener, key="shin_test"):
53
+ return ShinAPI(key, opener=opener)
54
+
55
+
56
+ class TheTool(unittest.TestCase):
57
+ def test_says_what_the_api_takes(self):
58
+ search = ShinAPISearch(client=client(Opener()))
59
+ tool = convert_to_openai_tool(search)["function"]
60
+ self.assertEqual(tool["name"], "shinapi_search")
61
+ self.assertEqual(tool["description"], SEARCH_DESCRIPTION)
62
+ self.assertEqual(tool["parameters"]["properties"], SEARCH_INPUT["properties"])
63
+ self.assertEqual(tool["parameters"]["required"], ["query"])
64
+
65
+ def test_answers_a_call_with_the_json_and_the_answer(self):
66
+ opener = Opener()
67
+ search = ShinAPISearch(client=client(opener))
68
+ message = search.invoke(
69
+ {
70
+ "type": "tool_call",
71
+ "id": "call-1",
72
+ "name": "shinapi_search",
73
+ "args": {"query": "婚姻届", "max_results": 4, "exclude_domains": ["a.jp"]},
74
+ }
75
+ )
76
+ self.assertIsInstance(message, ToolMessage)
77
+ self.assertEqual(json.loads(message.content), ANSWER)
78
+ self.assertIn("婚姻届は市役所に出します。", message.content)
79
+ self.assertEqual(message.artifact, ANSWER)
80
+ self.assertEqual(
81
+ opener.body(), {"query": "婚姻届", "max_results": 4, "exclude_domains": ["a.jp"]}
82
+ )
83
+
84
+ def test_takes_its_key_from_the_environment(self):
85
+ opener = Opener()
86
+ with mock.patch.dict(os.environ, {"SHINAPI_KEY": "shin_env"}):
87
+ search = ShinAPISearch()
88
+ search.client._opener = opener
89
+ search.invoke({"query": "年金"})
90
+ self.assertEqual(opener.asked[0].get_header("Authorization"), "Bearer shin_env")
91
+
92
+ def test_takes_the_key_it_is_given(self):
93
+ search = ShinAPISearch(api_key="shin_given")
94
+ opener = Opener()
95
+ search.client._opener = opener
96
+ search.invoke({"query": "年金"})
97
+ self.assertEqual(opener.asked[0].get_header("Authorization"), "Bearer shin_given")
98
+ self.assertNotIn("shin_given", repr(search))
99
+
100
+
101
+ class TheRetriever(unittest.TestCase):
102
+ def test_returns_each_passage_as_a_document(self):
103
+ opener = Opener()
104
+ retriever = ShinAPIRetriever(client=client(opener), k=4, exclude_text=["広告"])
105
+ documents = retriever.invoke("婚姻届")
106
+ metadata = {field: value for field, value in RESULT.items() if field != "text"}
107
+ self.assertEqual(documents, [Document(page_content=RESULT["text"], metadata=metadata)])
108
+ self.assertEqual(
109
+ opener.body(),
110
+ {"query": "婚姻届", "max_results": 4, "exclude_domains": [], "exclude_text": ["広告"]},
111
+ )
112
+
113
+ def test_refuses_a_count_the_api_refuses(self):
114
+ with self.assertRaises(ValueError):
115
+ ShinAPIRetriever(client=client(Opener()), k=64)
116
+
117
+
118
+ if __name__ == "__main__":
119
+ unittest.main()
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "types": ["node"]
5
+ },
6
+ "include": ["src"]
7
+ }