Skip to main content

Generate JSON that strictly matches a schema with automatic retries.

Project description

LetsJSON

让模型输出强约束 JSON:

  • 按 schema 校验字段与类型
  • 不符合时自动重试(默认 3 次)
  • 超过重试次数仍失败则抛错

使用(uv)

uv sync
from openai import OpenAI
from letsjson import LetsJSON

client = OpenAI()  # 自动读取 OPENAI_API_KEY
generator = LetsJSON(client, repeat=3)  # repeat 可选,默认 3

result = generator.gen(
    "把西红柿炒蛋任务分解最后一个任务是int1",
    {"step1": str, "step2": str, "step3": int},
)
print(result)

行为

  • 返回值:dict
  • 必须和 schema 键完全一致(不允许缺失或多余)
  • 类型严格校验(例如 int 不接受 bool
  • 所有尝试失败后抛出 LetsJSONGenerationError

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

letsjson-0.1.2.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

letsjson-0.1.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file letsjson-0.1.2.tar.gz.

File metadata

  • Download URL: letsjson-0.1.2.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for letsjson-0.1.2.tar.gz
Algorithm Hash digest
SHA256 78ade4f67ca80536c1c210a2c15e20ccbaeccaa838c5e44dcca5c5dcb85df0e6
MD5 58f3683e8a2e004d62d5558091c38608
BLAKE2b-256 43e1d82782e3d63849a2267d2789e6e691b401715dd7e58b920a5ab10a280024

See more details on using hashes here.

File details

Details for the file letsjson-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: letsjson-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for letsjson-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5f1eab1198a0bb6bf018f8641d0de05f275230f426c1bff0e3e6500f2c90bc7e
MD5 afc67cd86d95bc00386f0ac54209d7eb
BLAKE2b-256 564aaa5458e4fa14021c56f4da7fbdc918f5e0e02949ab6165651473fc3c63d3

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