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.0.tar.gz (3.5 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.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: letsjson-0.1.0.tar.gz
  • Upload date:
  • Size: 3.5 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.0.tar.gz
Algorithm Hash digest
SHA256 715d3d9b854f2437cf3dcc3f91fea2d592800ebf75061b2541ccb60275a72e02
MD5 4faf472e26e3f3e07cb068ada8be8ff9
BLAKE2b-256 1dd08fff0bece1fd8f1a57e66365d5c34e8a9e8bf4e234a6286f607c387020f1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: letsjson-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09982d15ad3e5cf24fb15dff7f9daad9dde5896af2ac9277af825655bd1a7272
MD5 d20f0413d6c835a5491c4ce893b6bbec
BLAKE2b-256 78313f8a161619cca1a1f952aae20488a345dc29295251827d97cc4f25f586f9

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