dariko 0.0.1__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.
dariko-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Yuto Nose
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.
dariko-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.4
2
+ Name: dariko
3
+ Version: 0.0.1
4
+ Summary: Minimal type-checked LLM helper (experimental)
5
+ Author-email: Yuto Nose <yutoria0916@gmail.com>
6
+ License: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: pydantic>=2.7.0
11
+ Dynamic: license-file
12
+ Dynamic: requires-python
13
+
14
+ # dariko (experimental)
15
+
16
+ Python の型アノテーションを **ほぼ書かずに**
17
+ LLM 出力を `pydantic` で安全にパースするための最小ライブラリ。
18
+ 現在開発中
19
+
20
+ ```python
21
+ from pydantic import BaseModel
22
+ from dariko import ask
23
+
24
+ class Person(BaseModel):
25
+ name: str
26
+ age: int
27
+
28
+ result: Person = ask("次の JSON を返して: {name:'Alice', age:30}")
29
+ print(result)
dariko-0.0.1/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # dariko (experimental)
2
+
3
+ Python の型アノテーションを **ほぼ書かずに**
4
+ LLM 出力を `pydantic` で安全にパースするための最小ライブラリ。
5
+ 現在開発中
6
+
7
+ ```python
8
+ from pydantic import BaseModel
9
+ from dariko import ask
10
+
11
+ class Person(BaseModel):
12
+ name: str
13
+ age: int
14
+
15
+ result: Person = ask("次の JSON を返して: {name:'Alice', age:30}")
16
+ print(result)
@@ -0,0 +1,6 @@
1
+ from importlib.metadata import version as _v
2
+
3
+ from .core import ask, ValidationError
4
+
5
+ __all__ = ["ask", "ValidationError"]
6
+ __version__ = _v(__name__) # pyproject.toml のバージョンを反映
@@ -0,0 +1,47 @@
1
+ import inspect
2
+ from typing import Any, Type
3
+
4
+ from pydantic import ValidationError as _PydanticValidationError
5
+ from pydantic import TypeAdapter
6
+
7
+
8
+ class ValidationError(Exception):
9
+ """LLM 出力の型検証エラーを表す例外"""
10
+
11
+ def __init__(self, original: _PydanticValidationError):
12
+ super().__init__(str(original))
13
+ self.original = original
14
+
15
+
16
+ def _infer_output_model_from_locals(frame) -> Type[Any] | None:
17
+ """
18
+ 呼び出し元フレームのローカル変数型ヒント (__annotations__)
19
+ から戻り値を受け取る変数の型を推測する。
20
+ 最低限の実装として「注釈が 1 個だけならそれ」と割り切る。
21
+ """
22
+ hints: dict[str, Any] = frame.f_locals.get("__annotations__", {})
23
+ return next(iter(hints.values())) if len(hints) == 1 else None
24
+
25
+
26
+ def ask(prompt: str, *, output_model: Type[Any] | None = None) -> Any:
27
+ """
28
+ LLM へ prompt を投げ、output_model で検証済みのオブジェクトを返す。
29
+ output_model が未指定なら呼び出し元のローカル変数アノテーションを推測。
30
+ """
31
+ model = output_model
32
+ if model is None:
33
+ caller_frame = inspect.currentframe().f_back # 1 つ上のフレーム
34
+ model = _infer_output_model_from_locals(caller_frame)
35
+
36
+ if model is None:
37
+ raise TypeError("型アノテーションが取得できませんでした。output_model を指定してください。")
38
+
39
+ # --- ここを実際の LLM 呼び出しに差し替える ----------------------------
40
+ # 注: 最小構成ではダミーの JSON を返す
41
+ llm_raw_output = {"dummy": True, "prompt": prompt}
42
+ # ----------------------------------------------------------------------
43
+
44
+ try:
45
+ return TypeAdapter(model).validate_python(llm_raw_output)
46
+ except _PydanticValidationError as e:
47
+ raise ValidationError(e) from None
@@ -0,0 +1,47 @@
1
+ import inspect
2
+ from typing import Any, Type
3
+
4
+ from pydantic import ValidationError as _PydanticValidationError
5
+ from pydantic import TypeAdapter
6
+
7
+
8
+ class ValidationError(Exception):
9
+ """LLM 出力の型検証エラーを表す例外"""
10
+
11
+ def __init__(self, original: _PydanticValidationError):
12
+ super().__init__(str(original))
13
+ self.original = original
14
+
15
+
16
+ def _infer_output_model_from_locals(frame) -> Type[Any] | None:
17
+ """
18
+ 呼び出し元フレームのローカル変数型ヒント (__annotations__)
19
+ から戻り値を受け取る変数の型を推測する。
20
+ 最低限の実装として「注釈が 1 個だけならそれ」と割り切る。
21
+ """
22
+ hints: dict[str, Any] = frame.f_locals.get("__annotations__", {})
23
+ return next(iter(hints.values())) if len(hints) == 1 else None
24
+
25
+
26
+ def ask(prompt: str, *, output_model: Type[Any] | None = None) -> Any:
27
+ """
28
+ LLM へ prompt を投げ、output_model で検証済みのオブジェクトを返す。
29
+ output_model が未指定なら呼び出し元のローカル変数アノテーションを推測。
30
+ """
31
+ model = output_model
32
+ if model is None:
33
+ caller_frame = inspect.currentframe().f_back # 1 つ上のフレーム
34
+ model = _infer_output_model_from_locals(caller_frame)
35
+
36
+ if model is None:
37
+ raise TypeError("型アノテーションが取得できませんでした。output_model を指定してください。")
38
+
39
+ # --- ここを実際の LLM 呼び出しに差し替える ----------------------------
40
+ # 注: 最小構成ではダミーの JSON を返す
41
+ llm_raw_output = {"dummy": True, "prompt": prompt}
42
+ # ----------------------------------------------------------------------
43
+
44
+ try:
45
+ return TypeAdapter(model).validate_python(llm_raw_output)
46
+ except _PydanticValidationError as e:
47
+ raise ValidationError(e) from None
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.4
2
+ Name: dariko
3
+ Version: 0.0.1
4
+ Summary: Minimal type-checked LLM helper (experimental)
5
+ Author-email: Yuto Nose <yutoria0916@gmail.com>
6
+ License: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: pydantic>=2.7.0
11
+ Dynamic: license-file
12
+ Dynamic: requires-python
13
+
14
+ # dariko (experimental)
15
+
16
+ Python の型アノテーションを **ほぼ書かずに**
17
+ LLM 出力を `pydantic` で安全にパースするための最小ライブラリ。
18
+ 現在開発中
19
+
20
+ ```python
21
+ from pydantic import BaseModel
22
+ from dariko import ask
23
+
24
+ class Person(BaseModel):
25
+ name: str
26
+ age: int
27
+
28
+ result: Person = ask("次の JSON を返して: {name:'Alice', age:30}")
29
+ print(result)
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ dariko/__init__.py
6
+ dariko/core.py
7
+ dariko/dariko.py
8
+ dariko.egg-info/PKG-INFO
9
+ dariko.egg-info/SOURCES.txt
10
+ dariko.egg-info/dependency_links.txt
11
+ dariko.egg-info/requires.txt
12
+ dariko.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ pydantic>=2.7.0
@@ -0,0 +1 @@
1
+ dariko
@@ -0,0 +1,15 @@
1
+ [project]
2
+ name = "dariko"
3
+ version = "0.0.1"
4
+ description = "Minimal type-checked LLM helper (experimental)"
5
+ authors = [{ name = "Yuto Nose", email = "yutoria0916@gmail.com" }]
6
+ license = {text = "MIT"}
7
+ readme = "README.md"
8
+ requires-python = ">=3.9"
9
+ dependencies = [
10
+ "pydantic>=2.7.0"
11
+ ]
12
+
13
+ [build-system]
14
+ requires = ["setuptools>=61.0", "wheel"]
15
+ build-backend = "setuptools.build_meta"
dariko-0.0.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
dariko-0.0.1/setup.py ADDED
@@ -0,0 +1,11 @@
1
+ from setuptools import setup
2
+
3
+ setup(
4
+ name="dariko",
5
+ version="0.1.0",
6
+ packages=["dariko"],
7
+ install_requires=[
8
+ "pydantic>=2.0.0",
9
+ ],
10
+ python_requires=">=3.8",
11
+ )