Skip to main content

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


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.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dariko-0.2.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file dariko-0.2.1.tar.gz.

File metadata

  • Download URL: dariko-0.2.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for dariko-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1d6220bab7b4cdcd73e4d214dc1d92e6fb0e75f8679a7c3e40219bd7f9f1fae9
MD5 67ddbce2ee0a75c2fc1e5c7b4c1f5778
BLAKE2b-256 00cebff0cb289fba28dbd418f8136b6e06a06ee5db49fcc676223c7288b7a5c8

See more details on using hashes here.

File details

Details for the file dariko-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: dariko-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for dariko-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4807b4da4f15a918f50648b67f3347eea3a27bf26114e4f98d8a995216f04d25
MD5 27307014fc854092d439711379f64016
BLAKE2b-256 80ae9405c9efcda9642f3189e15b74df2a03bb7ac8ff1e77999e13237a1abbb1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page