LLMの出力をPydanticモデルで型安全に扱うためのPythonライブラリ
Project description
dariko
LLMの出力をPydanticモデルで型安全に扱うためのPythonライブラリ。
特徴
- LLMの出力をPydanticモデルで型安全に扱える
- 型アノテーションから自動的に出力モデルを推論
- バッチ処理に対応
- シンプルなAPI
インストール
pip install dariko
使用方法
基本的な使い方
from pydantic import BaseModel
from dariko import ask, configure
# APIキーの設定
configure("your-api-key") # または環境変数 DARIKO_API_KEY を設定
# 出力モデルの定義
class Person(BaseModel):
name: str
age: int
dummy: bool
api_key: str
# 型アノテーションから自動的にモデルを推論
result: Person = ask("test")
print(result.name) # "test"
print(result.age) # 20
print(result.dummy) # True
明示的にモデルを指定
result = ask("test", output_model=Person)
バッチ処理
from dariko import ask_batch
prompts = ["test1", "test2"]
results = ask_batch(prompts, output_model=Person)
開発
セットアップ
git clone https://github.com/yourusername/dariko.git
cd dariko
pip install -e .
テスト
pytest tests/
ライセンス
MIT License
from pydantic import BaseModel
from dariko import ask
class Person(BaseModel):
name: str
age: int
result: Person = ask("次の JSON を返して: {name:'Alice', age:30}")
print(result)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dariko-0.2.3.tar.gz
(7.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dariko-0.2.3.tar.gz.
File metadata
- Download URL: dariko-0.2.3.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
666d0d47a85432b36a23e4296c7135e5daa8c30076d5e6cfed1ec015318bfa5c
|
|
| MD5 |
1f82fb29c2150144a5996760ec23386a
|
|
| BLAKE2b-256 |
a0453229ff3cf63b9e497748f9aa1e40546d504e619858ea52fba564f4679a8f
|
File details
Details for the file dariko-0.2.3-py3-none-any.whl.
File metadata
- Download URL: dariko-0.2.3-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
787a77405fbed285be7aa541f3c04c7aa6b803dbe3d7a0fdd75adbada07b4095
|
|
| MD5 |
e700d8bfb6b3bc8dd7181f2e0baf5e8a
|
|
| BLAKE2b-256 |
11f42751614bc54ee8e9ef5a076666f91952c0ad552e06fd341d636f1d0cd3c3
|