llama-index-tools-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 llama-index-tools-shinapi might be problematic. Click here for more details.
- llama_index_tools_shinapi-0.1.0/.gitignore +23 -0
- llama_index_tools_shinapi-0.1.0/LICENSE +21 -0
- llama_index_tools_shinapi-0.1.0/PKG-INFO +42 -0
- llama_index_tools_shinapi-0.1.0/README.md +28 -0
- llama_index_tools_shinapi-0.1.0/llama_index/tools/shinapi/__init__.py +3 -0
- llama_index_tools_shinapi-0.1.0/llama_index/tools/shinapi/base.py +36 -0
- llama_index_tools_shinapi-0.1.0/llama_index/tools/shinapi/py.typed +0 -0
- llama_index_tools_shinapi-0.1.0/package.json +17 -0
- llama_index_tools_shinapi-0.1.0/pyproject.toml +20 -0
- llama_index_tools_shinapi-0.1.0/src/python.test.ts +16 -0
- llama_index_tools_shinapi-0.1.0/tests/test_llama_index.py +89 -0
- llama_index_tools_shinapi-0.1.0/tsconfig.json +7 -0
|
@@ -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,42 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: llama-index-tools-shinapi
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Search what high-authority Japanese sites say now, as a LlamaIndex tool. 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,llama-index,llm,rag,search
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Requires-Dist: llama-index-core<0.15,>=0.14
|
|
12
|
+
Requires-Dist: shinapi>=0.1
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# llama-index-tools-shinapi
|
|
16
|
+
|
|
17
|
+
Search what high-authority Japanese sites say now, from LlamaIndex: a tool spec for agents. By
|
|
18
|
+
[ShinAPI](https://shinapi.com).
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
pip install llama-index-tools-shinapi
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Get a key in the [console](https://console.shinapi.com) and set `SHINAPI_KEY`, or pass `api_key`.
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from llama_index.core.agent.workflow import FunctionAgent
|
|
28
|
+
from llama_index.llms.anthropic import Anthropic
|
|
29
|
+
from llama_index.tools.shinapi import ShinAPIToolSpec
|
|
30
|
+
|
|
31
|
+
agent = FunctionAgent(
|
|
32
|
+
tools=ShinAPIToolSpec().to_tool_list(),
|
|
33
|
+
llm=Anthropic(model="claude-sonnet-5-5"),
|
|
34
|
+
)
|
|
35
|
+
await agent.run("2026年の年収の壁はいくらですか")
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The tool answers the model with the search's JSON: each passage as published, with its URL, publisher, dates, licence
|
|
39
|
+
and the credit line to show. Its description tells the model what is indexed and what to do with each outcome:
|
|
40
|
+
`answered`, `no_match_in_scope` or `out_of_scope`.
|
|
41
|
+
|
|
42
|
+
Read the [docs](https://docs.shinapi.com).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# llama-index-tools-shinapi
|
|
2
|
+
|
|
3
|
+
Search what high-authority Japanese sites say now, from LlamaIndex: a tool spec for agents. By
|
|
4
|
+
[ShinAPI](https://shinapi.com).
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
pip install llama-index-tools-shinapi
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Get a key in the [console](https://console.shinapi.com) and set `SHINAPI_KEY`, or pass `api_key`.
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
from llama_index.core.agent.workflow import FunctionAgent
|
|
14
|
+
from llama_index.llms.anthropic import Anthropic
|
|
15
|
+
from llama_index.tools.shinapi import ShinAPIToolSpec
|
|
16
|
+
|
|
17
|
+
agent = FunctionAgent(
|
|
18
|
+
tools=ShinAPIToolSpec().to_tool_list(),
|
|
19
|
+
llm=Anthropic(model="claude-sonnet-5-5"),
|
|
20
|
+
)
|
|
21
|
+
await agent.run("2026年の年収の壁はいくらですか")
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The tool answers the model with the search's JSON: each passage as published, with its URL, publisher, dates, licence
|
|
25
|
+
and the credit line to show. Its description tells the model what is indexed and what to do with each outcome:
|
|
26
|
+
`answered`, `no_match_in_scope` or `out_of_scope`.
|
|
27
|
+
|
|
28
|
+
Read the [docs](https://docs.shinapi.com).
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Annotated, Any, Optional
|
|
3
|
+
|
|
4
|
+
from llama_index.core.tools.tool_spec.base import BaseToolSpec
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
from shinapi import SEARCH_DESCRIPTION, SEARCH_INPUT, ShinAPI
|
|
7
|
+
|
|
8
|
+
_FIELDS: dict[str, Any] = SEARCH_INPUT["properties"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _described(name: str) -> Any:
|
|
12
|
+
return Field(description=_FIELDS[name]["description"])
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ShinAPIToolSpec(BaseToolSpec):
|
|
16
|
+
spec_functions = ["search"]
|
|
17
|
+
|
|
18
|
+
def __init__(self, api_key: Optional[str] = None, client: Optional[ShinAPI] = None) -> None:
|
|
19
|
+
self.client = client or ShinAPI(api_key)
|
|
20
|
+
|
|
21
|
+
def search(
|
|
22
|
+
self,
|
|
23
|
+
query: Annotated[str, _described("query")],
|
|
24
|
+
max_results: Annotated[int, _described("max_results")] = _FIELDS["max_results"]["default"],
|
|
25
|
+
exclude_domains: Annotated[Optional[list[str]], _described("exclude_domains")] = None,
|
|
26
|
+
exclude_text: Annotated[Optional[list[str]], _described("exclude_text")] = None,
|
|
27
|
+
) -> str:
|
|
28
|
+
answer = self.client.search(
|
|
29
|
+
query,
|
|
30
|
+
max_results=max_results,
|
|
31
|
+
exclude_domains=exclude_domains,
|
|
32
|
+
exclude_text=exclude_text,
|
|
33
|
+
)
|
|
34
|
+
return json.dumps(answer, ensure_ascii=False)
|
|
35
|
+
|
|
36
|
+
search.__doc__ = SEARCH_DESCRIPTION
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shinapi/llama-index",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "llama-index-tools-shinapi, the LlamaIndex tool 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 = "llama-index-tools-shinapi"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Search what high-authority Japanese sites say now, as a LlamaIndex tool. By ShinAPI."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
keywords = ["llama-index", "search", "japan", "japanese", "llm", "rag", "agents"]
|
|
13
|
+
dependencies = ["llama-index-core>=0.14,<0.15", "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
|
+
include = ["llama_index/"]
|
|
@@ -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("llama-index-tools-shinapi", () => {
|
|
7
|
+
it(
|
|
8
|
+
"passes its own tests against the LlamaIndex 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,89 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import unittest
|
|
5
|
+
from unittest import mock
|
|
6
|
+
|
|
7
|
+
from llama_index.core.tools import FunctionTool
|
|
8
|
+
from shinapi import SEARCH_DESCRIPTION, SEARCH_INPUT, ShinAPI
|
|
9
|
+
|
|
10
|
+
from llama_index.tools.shinapi import ShinAPIToolSpec
|
|
11
|
+
|
|
12
|
+
RESULT = {
|
|
13
|
+
"title": "婚姻届",
|
|
14
|
+
"url": "https://www.city.example.jp/kon",
|
|
15
|
+
"publisher": "例市",
|
|
16
|
+
"published_at": "2026-04-01",
|
|
17
|
+
"author": None,
|
|
18
|
+
"image": None,
|
|
19
|
+
"favicon": None,
|
|
20
|
+
"last_changed_at": "2026-11-02",
|
|
21
|
+
"licence": "publisher-terms",
|
|
22
|
+
"attribution": "例市",
|
|
23
|
+
"score": 0.5,
|
|
24
|
+
"text": "婚姻届は市役所に出します。",
|
|
25
|
+
}
|
|
26
|
+
ANSWER = {
|
|
27
|
+
"outcome": "answered",
|
|
28
|
+
"incomplete": False,
|
|
29
|
+
"results": [RESULT],
|
|
30
|
+
"request_id": "4bf92f3577b34da6a3ce929d0e0e4736",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Response(io.BytesIO):
|
|
35
|
+
status = 200
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class Opener:
|
|
39
|
+
def __init__(self):
|
|
40
|
+
self.asked = []
|
|
41
|
+
|
|
42
|
+
def __call__(self, request, timeout):
|
|
43
|
+
self.asked.append(request)
|
|
44
|
+
return Response(json.dumps(ANSWER).encode())
|
|
45
|
+
|
|
46
|
+
def body(self, index=0):
|
|
47
|
+
return json.loads(self.asked[index].data)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def spec(opener):
|
|
51
|
+
return ShinAPIToolSpec(client=ShinAPI("shin_test", opener=opener))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def only_tool(opener) -> FunctionTool:
|
|
55
|
+
[tool] = spec(opener).to_tool_list()
|
|
56
|
+
return tool
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class TheTool(unittest.TestCase):
|
|
60
|
+
def test_says_what_the_api_takes(self):
|
|
61
|
+
metadata = only_tool(Opener()).metadata
|
|
62
|
+
self.assertEqual(metadata.name, "search")
|
|
63
|
+
self.assertIn(SEARCH_DESCRIPTION, metadata.description)
|
|
64
|
+
parameters = metadata.get_parameters_dict()
|
|
65
|
+
self.assertEqual(parameters["required"], ["query"])
|
|
66
|
+
for name, field in SEARCH_INPUT["properties"].items():
|
|
67
|
+
self.assertEqual(parameters["properties"][name]["description"], field["description"])
|
|
68
|
+
self.assertEqual(parameters["properties"]["max_results"]["default"], 8)
|
|
69
|
+
|
|
70
|
+
def test_shows_the_model_every_field_of_the_answer(self):
|
|
71
|
+
opener = Opener()
|
|
72
|
+
output = only_tool(opener).call(query="婚姻届", max_results=4, exclude_text=["広告"])
|
|
73
|
+
self.assertEqual(json.loads(output.content), ANSWER)
|
|
74
|
+
self.assertIn("例市", output.content)
|
|
75
|
+
self.assertEqual(
|
|
76
|
+
opener.body(), {"query": "婚姻届", "max_results": 4, "exclude_text": ["広告"]}
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
def test_takes_its_key_from_the_environment(self):
|
|
80
|
+
opener = Opener()
|
|
81
|
+
with mock.patch.dict(os.environ, {"SHINAPI_KEY": "shin_env"}):
|
|
82
|
+
tool_spec = ShinAPIToolSpec()
|
|
83
|
+
tool_spec.client._opener = opener
|
|
84
|
+
tool_spec.search("年金")
|
|
85
|
+
self.assertEqual(opener.asked[0].get_header("Authorization"), "Bearer shin_env")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
if __name__ == "__main__":
|
|
89
|
+
unittest.main()
|