Enable large language models to output structured data.
Project description
llm2dict
llm2dict 是一个 Python 包,旨在通过与大语言模型(LLM)的两次交互,将自然语言转换为结构化的 Python 字典或列表数据。这个包的核心功能是通过两次提问,第一次获取大语言模型的自然语言回答,第二次则提取特定格式的数据并将其转换为 Python 可执行的代码,最终返回结构化的数据(dict或list)。
功能特点
在代码中使用 LLM 的输出时,通常需要对输出文本进行处理,流程如下:
LLM->str->python_function(str)->dict
传统方式需要手动编写 Python 提取函数,但 LLM 的输出可能存在意外情况,难以完全匹配提取逻辑。此外,不同问题对应的提取格式也可能不同,增加了开发复杂度。
llm2dict 将提取格式的任务交给 LLM 处理:
- 第一次提问:获取 LLM 的自然语言回答。
- 第二次提问:让 LLM 根据第一次的回答和指定的数据结构,生成提取数据的 Python 代码。
- 代码执行:自动执行生成的代码,返回结构化的数据。
你只需提供输入问题和期望的数据结构,llm2dict 会完成剩余的工作,简化了从 LLM 输出到结构化数据的转换流程。
安装与使用
你可以通过以下命令安装 llm2dict 包:
pip install llm2dict
使用示例
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
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 llm2dict-0.0.1.tar.gz.
File metadata
- Download URL: llm2dict-0.0.1.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a429550a4aa9c01c437004cb44b746d933077dc7b5b849b43730823b6636e91e
|
|
| MD5 |
41a740dc83ba910e248a0d390e6dce80
|
|
| BLAKE2b-256 |
3ac7fbc1b0f94e3b17a5e8a6808c7e0554499d102e38761c8501122b96c91e50
|
File details
Details for the file llm2dict-0.0.1-py3-none-any.whl.
File metadata
- Download URL: llm2dict-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c80c4b460742263d0a3f0a096ec5c354eb2936340491de67a46f6d0f45847d69
|
|
| MD5 |
b8d8cf45ab5ebc35a4deef435d161447
|
|
| BLAKE2b-256 |
aee0fc905fd51d2388e04ac6948a2caba4b0af2d9e8cd5f772a9c77a621f6d1f
|