root/agent-smart-home-system/: llm-json-parse-0.1.0 metadata and description

Simple index

Shared JSON parsing utilities with optional LLM-based repair

description_content_type text/markdown
requires_dist
  • json-repair>=0.58.6
  • jsonschema>=4.26.0
  • openai>=2.29.0
requires_python >=3.12

Because this project isn't in the mirror_whitelist, no releases from root/pypi are included.

File Tox results History
llm_json_parse-0.1.0-py3-none-any.whl
Size
5 KB
Type
Python Wheel
Python
3
llm_json_parse-0.1.0.tar.gz
Size
4 KB
Type
Source

llm-json-parse

用于解析和修复 LLM 返回的 JSON 文本的共享库。

安装

如果单独使用本包:

uv add llm-json-parse

在 monorepo 中以源码方式引用

下面是“在 monorepo 的另一个项目中,直接引用本包源码”的推荐做法。

方式一:Path 依赖(最直接)

在消费方项目的 pyproject.toml 中添加:

[project]
dependencies = [
  "llm-json-parse"
]

[tool.uv.sources]
llm-json-parse = { path = "../../shared/llm-json-parse", editable = true }

然后在消费方项目目录执行:

uv sync

说明:

方式二:uv workspace(更规范的 monorepo 管理)

在 monorepo 根目录 pyproject.toml 中声明 workspace:

[tool.uv.workspace]
members = [
  "shared/llm-json-parse",
  "apps/your-consumer"
]

在消费方项目 pyproject.toml 中添加:

[project]
dependencies = [
  "llm-json-parse"
]

[tool.uv.sources]
llm-json-parse = { workspace = true }

然后在 monorepo 根目录执行:

uv sync

验证引用是否生效

在消费方项目中执行:

uv run python -c "import llm_json_parse; print(llm_json_parse.__all__)"

如果能正常输出 ['JsonRepairError', 'JsonParserWithRepair', 'create_openai_provider'],说明引用成功。

快速示例

提供大模型集成

from llm_json_parse import JsonParserWithRepair, create_openai_provider

llm_provider = create_openai_provider(
  model="gpt-3.5-turbo",
  api_key="your-openai-api-key",
  base_url="https://api.openai.com/v1",
)

parser = JsonParserWithRepair(llm_provider=llm_provider)

修复字符串

from llm_json_parse import JsonParserWithRepair


parser = JsonParserWithRepair()


async def run(parser_text: str):
  result = await parser(parser_text)
  return result